Allink  v0.1
ElementiGrafici.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 #include "ElementiGrafici.h"
25 ;
26 #include <qevent.h>
27 #include <qpainter.h>
28 #include <qlabel.h>
29 
30 ElementiGrafici::ElementiGrafici(QWidget *parent,const char *name)
31 :QWidget(parent,name){
32  PuntiMax = 1000;
33  NVisMin=0;
34  NVisMax=1000;
35  NBin = 100;
36  NMobile = 1;
37  NCorrela = 2;
38  Coord = 2;
39  yMax = 1.;
40  CoordX = 0;
41  CoordY = 0;
42  CoordDY = 0;
43  NVar = 1;
44  FontSize = 42;
45  RatioWidthHeight = 1.3;
46  PointSize = 10;
47  IfNorm = 0;
48  GrigliaX = 6;
49  GrigliaY = 6;
50  //Punti = NULL;
51  //PuntiBlu = NULL;
52  //Ascissa = NULL;
53  stringa = new char[256];
54  // PuntiLinea = new QPointArray[3];
55  cPos = new char[30];
56  nomeFile = new char[160];
57  sprintf(nomeFile,"Density.dat");
58  nomeConf = new char[160];
59  sprintf(nomeConf,"Vis.conf");
60  nomeSalva = new char[160];
61  sprintf(nomeSalva,"Grafico.ps");
62  // nomeTit = new QString();
63  // nomeEtX = new QString();
64  // nomeEtY = new QString();
65  NomeEntrata(QString(nomeFile));
66  setPalette( QPalette( QColor( 250, 250, 200) ) );
67  // TempoGrafica = new QTimer(this, "tempo della grafica");
68  // connect(TempoGrafica,SIGNAL(timeout() ),this,SLOT());
69  ErrPrima = new QErrorMessage(this);
70  Messaggio = new QMessageBox(this,"Messaggio");
71  Stampante = new QPrinter(QPrinter::PrinterResolution);
72  Stampante->setFullPage(TRUE);
73  Stampante->setOutputToFile(TRUE);
74  Stampante->setOutputFileName(QString(nomeSalva));
75  Stampante->setOrientation(QPrinter::Landscape);
76  Stampante->setPageSize(QPrinter::A4);
77  Font.setFamily("Helvetica");
78  Font.setWeight(QFont::Bold);
79  IfDisegna = 0;
80  IfRiscala = RIS_TUTTI;
81  PrimaVolta = 1;
82  Linee = 1;
83  Quadrati = 0;
84  Griglia = 1;
85  NSequenza = 0;
86  IfStampa = 0;
87  NDis = 0;
88  m1.Min = 0.;
89  DigPrecX = 3;
90  DigPrecY = 3;
91  FormatPrecX = 'g';
92  FormatPrecY = 'g';
93  NElMinY=0;
94  NElMaxY=0;
95  ViewportX = 0.;//0.05;
96  ViewportY = 0.;//0.05;
97  GrLinee = new QColor[INIT_NUM];
98  GrLabel = new QString[INIT_NUM];
99  Colors = new QColor[INIT_NUM];
100  LineaCome = new int[INIT_NUM];
101  LineaQuale = new char*[INIT_NUM];
102  for(int c=0;c<10;c++) LineaQuale[c] = new char[INIT_NUM];
103  VoltaMomenti = 0;
104  QColor Colors1[INIT_NUM] = {QColor(157,128,43,255),
105  QColor(180,40,43,255),
106  QColor(20,180,70,255),
107  QColor(60,100,180,255),
108  QColor(180,50,180,255),
109  QColor(200,200,50,255),
110  QColor(50,180,180,255),
111  QColor(120,70,120,255),
112  QColor(180,10,240,255),
113  QColor(125,180,113,255),
114  QColor(160,110,110,255),
115  QColor(230,60,220,255),
116  QColor(132,20,220,255),
117  QColor(180,110,170,255),
118  QColor(225,0,143,255)};
119  //QColor(0,140,210,255)};
120  for(int c=0;c<10;c++){
121  Colors[c] = Colors1[c];
122  }
123  PosLegenda[0] = 2.0;
124  PosLegenda[1] = 2.0;
125  PosLegenda[2] = 3.0;
126  PosLegenda[3] = 3.0;
127  PosInterp[0] = .5;
128  PosInterp[1] = .2;
129 }
131  delete [] stringa;
132  delete [] cPos;
133  delete [] nomeFile;
134  delete [] nomeSalva;
135  delete [] nomeTit;
136  delete [] nomeConf;
137  delete [] nomeEtX;
138  delete [] nomeEtY;
139  delete [] GrLinee;
140  delete [] GrLabel;
141  delete [] Colors;
142  delete [] LineaCome;
143  delete [] LineaQuale;
144  delete ErrPrima;
145  delete Messaggio;
146  delete Stampante;
147 }
148 void ElementiGrafici::ChooseDataFile(char *FileName){
149  NomeEntrata(QString(FileName));
150 }
151 void ElementiGrafici::ChooseConfFile(char *FileName){
152  NomeConf(QString(FileName));
153 }
154 void ElementiGrafici::Apri(){
155  int NFile = 1;
156  char **argv = (char **)calloc(NFile,sizeof(char));
157  int FileList = 0;
158  for(int f=0;f<NFile;f++){
159  argv[f] = (char *)calloc(120,sizeof(char));
160  }
161  sprintf(argv[0],"%s",nomeFile);
162  Apri(argv,&FileList,NFile);
163  for(int f=0;f<NFile;f++){
164  free(argv[f]);
165  }
166  free(argv);
167 }
168 void ElementiGrafici::Apri(char **argv,int *FileList,int NFile){
169  if(!PrimaVolta){
170  delete v1;
171  // delete Punti;
172  }
173  NomeFile(QString(argv[FileList[0]]));
174  v1 = new VarDatFile(argv,FileList,NFile,NBin);
175  //v1 = new Variabili(argv[FileList[0]],NBin);
176  //for(int f=1;f<NFile;f++)
177  //v1->Aggiungi(argv[FileList[f]]);
178  NMax = v1->pNMax();
179  PuntiMax = NMax;
180  LogLog = DIS_NOLOG;
181  NVar = v1->pNVar();
182  GrLinee = (QColor *)realloc(GrLinee,NVar*sizeof(QColor));
183  delete [] GrLabel;
184  GrLabel = new QString[NVar];
185  //GrLabel = (QString *)realloc(GrLabel,NVar*sizeof(QString));
186  LineaCome = (int *)realloc(LineaCome,NVar*sizeof(int));
187  //LineaQuale = (char **)realloc(LineaQuale,NVar*sizeof(char));
188  //for(int c=0;c<NVar;c++)LineaQuale[c] = (char *)realloc(LineaQuale[c],60*sizeof(char));
189  for(int c=0,cc=0,init=0;c<NVar;c++,cc++){
190  if(!(c%10)) cc = init++;
191  if(init > 10) init = 0;
192  GrLinee[c] = Colors[cc];
193  LineaCome[c] = LINEA_TRATTO;
194  //sprintf(LineaQuale[c],"");
195  }
196  ImpNVarX(REF_SEQ,NVar);
197  ImpNVarY(0,NVar);
198  CoordX = 0;
199  CoordY = 0;
200  ImpInter(NVisMax=NMax);
201  ImpInterEl(NElMax=NMax);
202  ImpNVisMax(NVisMax=NMax);
203  ImpNVisMin(NVisMin=0);
204  ImpNElMax(NElMax=NMax);
205  ImpNElMin(NElMin=0);
206  if(NVar > 1){
207  CoordY = 1;
208  }
209  else {
210  CoordY = 0;
211  CoordX = REF_SEQ;
212  }
213  sprintf(stringa,"Caricati %d vettori da %d Punti da %s",NVar,NMax,nomeFile);
214  sprintf(stringa,"%s",v1->PrintHeader());
215  ImpCoordX(CoordX);
216  ImpCoordY(CoordY);
217  PrimaVolta = 0;
218  IfDisegna = 0;
219  DIS_ADD_TYPE(IfDisegna,DIS_TUTTI);
220  IfRiscala = 0;
221  DIS_ADD_TYPE(IfRiscala,RIS_TUTTI);
222  repaint();
223 }
224 void ElementiGrafici::ApriExt(double **ExtSt,int ExtNMax,int ExtNVar,int ExtNBin){
225  if(!PrimaVolta){
226  delete v1;
227  // delete Punti;
228  }
229  NBin = ExtNBin;
230  NMax = ExtNMax;
231  NVar = ExtNVar;
232  NomeFile(QString(nomeFile));
233  v1 = new VarDatFile(ExtSt,NMax,NVar,NBin);
234  LogLog = DIS_NOLOG;
235  NVar = v1->pNVar();
236  GrLinee = (QColor *)realloc(GrLinee,NVar*sizeof(QColor));
237  delete [] GrLabel;
238  GrLabel = new QString[NVar];
239  // GrLabel = (QString *)realloc(GrLinee,NVar*sizeof(QString));
240  LineaCome = (int *)realloc(LineaCome,NVar*sizeof(int));
241  //LineaQuale = (char **)realloc(LineaQuale,NVar*sizeof(char));
242  // for(int c=0;c<NVar;c++)LineaQuale[c] = (char *)realloc(LineaQuale[c],60*sizeof(char));
243  for(int c=0;c<NVar;c++){
244  if(c<10)
245  GrLinee[c] = Colors[c];
246  else
247  GrLinee[c] = Colors[0];
248  LineaCome[c] = LINEA_TRATTO;
249  //sprintf(LineaQuale[c],"");
250  }
251  ImpNVarX(-1,NVar);
252  ImpNVarY(0,NVar);
253  ImpInter(NVisMax=NMax);
254  ImpInterEl(NElMax=NMax);
255  ImpNVisMax(NVisMax=NMax);
256  ImpNVisMin(NVisMin=0);
257  ImpNElMax(NElMax=NMax);
258  ImpNElMin(NElMin=0);
259  sprintf(stringa,"Caricati %d vettori da %d Punti da %s",NVar,NMax,nomeFile);
260  sprintf(stringa,"%s",v1->PrintHeader());
261  ImpCoordX(CoordX);
262  ImpCoordY(CoordY);
263  PrimaVolta = 0;
264  //for(int i=0;i<NMax;i++) printf("%lf \n",ExtSt[0][i]);
265  printf("%d %d %d\n",NMax,NVar,NBin);
266  repaint();
267 }
268 void ElementiGrafici::ApriExt(VarDatFile *v1Ext){
269  if(!PrimaVolta){
270  delete v1;
271  // delete Punti;
272  }
273  v1 = new VarDatFile(0,0,0);
274  v1 = v1Ext;
275  NBin = v1->NBin;
276  NMax = v1->pNMax();
277  NVar = v1->pNVar();
278  NomeFile(QString(nomeFile));
279  LogLog = DIS_NOLOG;
280  GrLinee = (QColor *)realloc(GrLinee,NVar*sizeof(QColor));
281  delete [] GrLabel;
282  GrLabel = new QString[NVar];
283  // GrLabel = (QString *)realloc(GrLabel,NVar*sizeof(QString));
284  LineaCome = (int *)realloc(LineaCome,NVar*sizeof(int));
285  //LineaQuale = (char **)realloc(LineaQuale,NVar*sizeof(char));
286  //for(int c=0;c<NVar;c++)LineaQuale[c] = (char *)realloc(LineaQuale[c],60*sizeof(char));
287  for(int c=0;c<NVar;c++){
288  if(c<10)
289  GrLinee[c] = Colors[c];
290  else
291  GrLinee[c] = Colors[0];
292  LineaCome[c] = LINEA_TRATTO;
293  // sprintf(LineaQuale[c],"");
294  }
295  ImpNVarX(-1,NVar);
296  ImpNVarY(0,NVar);
297  CoordX = 0;
298  CoordY = 0;
299  ImpInter(NVisMax=NMax);
300  ImpInterEl(NElMax=NMax);
301  ImpNVisMax(NVisMax=NMax);
302  ImpNVisMin(NVisMin=0);
303  ImpNElMax(NElMax=NMax);
304  ImpNElMin(NElMin=0);
305  if(NMax > 10000) Griglia = 0;
306  sprintf(stringa,"Caricati %d vettori da %d Punti da %s",NVar,NMax,nomeFile);
307  sprintf(stringa,"%s",v1->PrintHeader());
308  IfSegnale = 1;
309  ImpCoordX(CoordX);
310  ImpCoordY(CoordY);
311  IfRiscala = RIS_TUTTI;
312  PrimaVolta = 0;
313  //for(int i=0;i<NMax;i++) printf("%lf \n",ExtSt[0][i]);
314  printf("%d %d %d\n",NMax,NVar,NBin);
315  repaint();
316 }
317 void ElementiGrafici::Aggiungi(){
318  if(PrimaVolta){
319  ErrPrima->message(QString("Aprire un file .dat prima"));
320  return;
321  }
322  NomeFile(QString(nomeFile));
323  if( v1->Aggiungi(nomeFile) == 0) return;
324  NMax = v1->pNMax();
325  PuntiMax = NMax;
326  // printf("Caricato un vettore da %d Punti da %s",NMax,nomeFile);
327  sprintf(stringa,"Caricato un vettore da %d Punti da %s",NMax,nomeFile);
328  sprintf(stringa,"%s",v1->PrintHeader());
329  NVar = v1->pNVar();
330  GrLinee = (QColor *)realloc(GrLinee,NVar*sizeof(QColor));
331  delete [] GrLabel;
332  GrLabel = new QString[NVar];
333  // GrLabel = (QString *)realloc(GrLabel,NVar*sizeof(QString));
334  LineaCome = (int *)realloc(LineaCome,NVar*sizeof(int));
335  //LineaQuale = (char **)realloc(LineaQuale,NVar*sizeof(char));
336  // for(int c=0;c<NVar;c++)LineaQuale[c] = (char *)realloc(LineaQuale[c],60*sizeof(char));
337  for(int c=0;c<NVar;c++){
338  if(c<10)
339  GrLinee[c] = Colors[c];
340  else
341  GrLinee[c] = Colors[0];
342  LineaCome[c] = LINEA_TRATTO;
343  }
344  ImpNVarX(-1,NVar);
345  ImpNVarY(0,NVar);
346  ImpCoordX(CoordX);
347  ImpCoordY(CoordY);
348  PuntiSegnale();
349 }
350 void ElementiGrafici::mouseMoveEvent(QMouseEvent *Topo){
351  sprintf(cPos,"%.3g : %.3g",
352  (double)(Topo->x())/(double)width()*ScalaTopoX+xMin,
353  (height()-Topo->y())/(double)height()*ScalaTopoY+yMin);
354  QString Info = QString(cPos);
355  emit StatoSequenza(QString(cPos));
356 }
357 void ElementiGrafici::DisegnaTesto(QPainter *p){
358  p->setBrush( Qt::blue );
359  p->setPen( Qt::blue );
360  p->drawText(width()/2,height()/2,QString("L'autocorrelazione di un rumore non bianco\n `e lorentziano e decade come \nr^-2"));
361  p->drawImage(QPoint(width()/2,height()/2),QImage(QString("Prova.png"),0),QRect(0,0,300,200),0);
362  p->drawRect(QRect(width()/2-100,height()/2-50,200,100));
363  p->drawText(0,height()/2,QString("L'autocorrelazione di un rumore non bianco\n `e lorentziano e decade come \nr^-2"));
364 }
365 QRect ElementiGrafici::PuntiRett(QPoint P) const{
366  QRect r(0,0,2*PointSize,2*PointSize);
367  r.moveCenter(P);
368  return r;
369 }
370 ImpostaNBin::ImpostaNBin(QWidget *parent,const char *name)
371  :Q3VBox(parent,name){
372  title = new QLabel(name,this,"title");
373  title->setAlignment( Qt::AlignCenter );
374  Qt::Orientation Orientazione = Qt::Horizontal;
375  // if(Modo == 1) Orientazione = Qt::Vertical;
376  slider = new QSlider(Orientazione, this ,"slider");
377  slider->setRange(0,100);
378  slider->setValue(0);
379 
380  slider->setTickPosition(QSlider::TicksBelow);
381  // else slider->setTickPosition(QSlider::TicksRight);
382 
383 
384  label = new QLabel(" ",this,"label");
385  label->setAlignment( Qt::AlignCenter );
386  connect(slider,SIGNAL(valueChanged(int)),label,SLOT(setNum(int)) );
387  connect(slider,SIGNAL(valueChanged(int)),SIGNAL(ValoreCambiato(int)) );
388 }
389 void ImpostaNBin::ImpNumero(int n){
390  if(n >= 0){
391  slider->setValue(n);
392  }
393 }
394 void ImpostaNBin::ImpInter(int Max){
395  if(Max > 0){
396  slider->setRange(0,Max);
397  }
398 }
399 void ImpostaNBin::ImpInter(int Min,int Max){
400  if(Min < Max){
401  slider->setRange(Min,Max);
402  }
403 }
404 int ImpostaNBin::Numero() const{
405  return slider->value();
406 }
407 // Sets::Sets(QWidget *parent,const char *name )
408 // :QMenuBar(parent,name){
409 // ASet = NULL;
410 // ASet = (QAction *)realloc(ASet,NSet*sizeof(QAction));
411 // char *stringa;
412 // stringa = (char *)malloc(100*sizeof(char));
413 // for(int v=0;v<NSet;v++){
414 // sprintf(stringa,"Set%d",v);
415 // //ASet[v] = addAction(QString(stringa));
416 // }
417 // //connect(slider,SIGNAL(valueChanged(int)),label,SLOT(setNum(int)) );
418 // //connect(slider,SIGNAL(valueChanged(int)),SIGNAL(ValoreCambiato(int)) );
419 // }
420 // void Sets::ImpCoord(int Coord){
421 
422 // }
char * nomeFile
Name of the current file opened.
ElementiGrafici(QWidget *parent=0, const char *name=0)
General constructor.
int pNMax()
Print the maximum number of data in the array.
Definition: VarDatFile.h:205
char * nomeConf
Name of the config file.
int NMax
Number of points per array.
double Min
Minimum value.
char * nomeSalva
Name of the output file.
void ChooseConfFile(char *FileName)
Choose the configuration file.
QString nomeTit
Title name.
char * PrintHeader()
Print the header.
Definition: VarDatFile.cpp:687
void ImpNElMin(int n)
Set the minimum elaboration point.
void ImpNVisMax(int n)
Set the maximum visualisation point.
QString nomeEtY
Y axis label.
int NDis
Current number of visualisation (debugging)
QString nomeEtX
X axis label.
void ChooseDataFile(char *FileName)
Choose the input file.
void ImpNVisMin(int n)
Set the minimum visualisation point.
int pNVar()
Print the number of variables.
Definition: VarDatFile.h:203
int NBin
Number of point of the distribution.
Definition: VarDatFile.h:201
Reads and stores a data file to be elaborated via Matematica.
Definition: VarDatFile.h:26
void ImpNElMax(int n)
Set the maximum elaboration point.
~ElementiGrafici()
Destructor.
int Aggiungi(char *file)
Add the content of the file into the memory.
Definition: VarDatFile.cpp:189
void ImpNVarX(int n, int m)
Type for coordinate change.
VarDatFile * v1
Class for the file handle.