Allink  v0.1
ElementiGraficiComm.cpp
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 This program is free software; you can redistribute it and/or modify
00010 it under the terms of the GNU General Public License as published by
00011 the Free Software Foundation; either version 2 of the License, or
00012 (at your option) any later version.
00013 
00014 This program is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 GNU General Public License for more details.
00018 
00019 You should have received a copy of the GNU General Public License
00020 along with this program; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 ***********************************************************************/#include "ElementiGrafici.h"
00023 
00024 void ElementiGrafici::Ridisegna(){
00025 //   InfoStato(stringa);
00026 //   ImpInter(PuntiMax);
00027 //   ImpInter(0,PuntiMax);
00028 //   ImpNVisMin(0); ImpNVisMax(PuntiMax);
00029 //   ImpNElMin(0); ImpNElMax(PuntiMax);
00030   repaint();
00031   //  if(!VoltaMomenti) emit InterVisCambiato(NVisMin,NVisMax);
00032 }
00033 void ElementiGrafici::DisegnaLinee(){
00034   for(int s=0;s<NVar;s++){
00035     if(DIS_IF_TYPE(LineaCome[s],LINEA_TRATTO))
00036       LineaCome[s] = LINEA_PUNTO;
00037     else if(DIS_IF_TYPE(LineaCome[s],LINEA_PUNTO))
00038       LineaCome[s] = LINEA_TRATTO;
00039   }
00040   repaint();
00041 }
00042 void ElementiGrafici::DisegnaPunti(){
00043   for(int s=0;s<NVar;s++){
00044     if(DIS_IF_TYPE(LineaCome[s],LINEA_TRATTO))
00045       LineaCome[s] = LINEA_PUNTOETRATTO;
00046     else if(DIS_IF_TYPE(LineaCome[s],LINEA_PUNTOETRATTO))
00047       LineaCome[s] = LINEA_TRATTO;
00048   }
00049   repaint();
00050 }
00051 void ElementiGrafici::DisegnaGriglia(){
00052   Griglia = !Griglia;
00053   repaint();
00054 }
00055 void ElementiGrafici::DisegnaLogx(){
00056   if(DIS_IF_TYPE(LogLog,DIS_LOGX))
00057     DIS_REM_TYPE(LogLog,DIS_LOGX);
00058   else
00059     DIS_ADD_TYPE(LogLog,DIS_LOGX);
00060   repaint();
00061 }
00062 void ElementiGrafici::DisegnaLogy(){
00063   if(DIS_IF_TYPE(LogLog,DIS_LOGY))
00064     DIS_REM_TYPE(LogLog,DIS_LOGY);
00065   else
00066     DIS_ADD_TYPE(LogLog,DIS_LOGY);
00067   repaint();
00068 }
00069 void ElementiGrafici::SulSegnale(bool Segnale){
00070   if(PrimaVolta)
00071     return;
00072   DIS_ADD_TYPE(IfDisegna,DIS_TUTTI);
00073   DIS_REM_TYPE(IfDisegna,DIS_SEGNALE);
00074   if(Segnale)
00075     v1->Punta(CoordY);
00076 }
00077 void ElementiGrafici::SeRiscala(){
00078   if( DIS_IF_TYPE(IfRiscala,RIS_UNO) ){
00079     DIS_REM_TYPE(IfRiscala,RIS_UNO);
00080     DIS_ADD_TYPE(IfRiscala,RIS_TUTTI);
00081   }
00082   else{
00083     DIS_ADD_TYPE(IfRiscala,RIS_UNO);
00084     DIS_REM_TYPE(IfRiscala,RIS_TUTTI);
00085   }
00086   repaint();
00087 }
00088 void ElementiGrafici::SeRiscalaTutto(){
00089   if( DIS_IF_TYPE(IfRiscala,RIS_TUTTI) ){
00090     DIS_REM_TYPE(IfRiscala,RIS_TUTTI);
00091     DIS_ADD_TYPE(IfRiscala,RIS_UNO);
00092   }
00093   else {
00094     DIS_ADD_TYPE(IfRiscala,RIS_TUTTI);
00095     DIS_REM_TYPE(IfRiscala,RIS_UNO);
00096   }
00097   repaint();
00098 }
00099 void ElementiGrafici::NSet(){
00100   if(IfDisegna == DIS_SEGNALE){
00101     DIS_ADD_TYPE(IfDisegna,DIS_TUTTI);
00102     DIS_REM_TYPE(IfDisegna,DIS_SEGNALE);
00103   }
00104   else{
00105     DIS_REM_TYPE(IfDisegna,DIS_TUTTI);
00106     DIS_ADD_TYPE(IfDisegna,DIS_SEGNALE);
00107   }
00108   repaint();
00109 }
00110 void ElementiGrafici::SulGrafico(bool Grafico){
00111   if(PrimaVolta)
00112     return;
00113   IfSegnale = 0;
00114   if(Grafico)
00115     v1->CambiaPunti();
00116 }
00117 void ElementiGrafici::SuX(bool niente){
00118   if(niente)
00119     Coord = 0;
00120 }
00121 void ElementiGrafici::SuY(bool niente){
00122   if(niente)
00123     Coord = 1;
00124 }
00125 void ElementiGrafici::SuDX(bool niente){
00126   if(niente)
00127     Coord = 2;
00128 }
00129 void ElementiGrafici::SuDY(bool niente){
00130   if(niente)
00131     DIS_ADD_TYPE(IfDisegna,DIS_ERR);
00132   else 
00133     DIS_REM_TYPE(IfDisegna,DIS_ERR);
00134 }
00135 void ElementiGrafici::InfoStato(const char *testo){
00136   //  printf("Barra: %s\n",testo);
00137   QString Info = QString(testo);
00138   emit Stato(QString(testo));
00139 }
00140 void ElementiGrafici::InfoSequenza(const char *testo){
00141   QString Info = QString(testo);
00142   emit StatoSequenza(QString(testo));
00143 }  
00144 QSizePolicy ElementiGrafici::Dimensionamento() const{
00145   return QSizePolicy( QSizePolicy::Expanding,QSizePolicy::Expanding);
00146 }
00147 void ElementiGrafici::ImpNBin(int n){
00148   if(n>0){
00149     NBin = n;
00150     v1->CambiaNBin(n);
00151     emit NBinCambiati(n);
00152   }
00153 }
00154 void ElementiGrafici::ImpNMobile(int n){
00155   if(n>0){
00156     NMobile = n;
00157     emit NMobileCambiato(n);
00158   }
00159 }
00160 void ElementiGrafici::ImpNCorrela(int n){
00161   if(n>0){
00162     NCorrela = n;
00163     emit NCorrelaCambiato(n);
00164   }
00165 }
00166 void ElementiGrafici::ImpNVisMin(int n){
00167   if(n<0)
00168     return;
00169   else if(n < NVisMax){
00170     NVisMin = n;
00171     if(!VoltaMomenti) ImpNElMin(NVisMin);
00172     emit NVisMinCambiato(n);
00173   }
00174   else if(n>NVisMax){
00175     if(n < PuntiMax + 10){
00176       ImpNVisMax(n+10);
00177       NVisMin = n;
00178       if(!VoltaMomenti) ImpNElMin(NVisMin);
00179       emit NVisMinCambiato(n);
00180     }
00181     else
00182       return ;
00183   }
00184   if(!VoltaMomenti) ImpNElMin(NVisMin);
00185   if(PuntiMax < 1000 && !PrimaVolta)
00186     repaint();
00187 }
00188 void ElementiGrafici::ImpNVisMax(int n){
00189   if( n > NVisMin +5 && n<=PuntiMax){
00190     NVisMax = n;
00191     if(!VoltaMomenti) ImpNElMax(NVisMax);
00192     emit NVisMaxCambiato(n);
00193   }
00194   else if(n < NVisMin + 5 && n <= PuntiMax){
00195     if(NVisMin > 5){
00196       NVisMax = n;
00197       ImpNVisMin( n - 5);
00198       if(!VoltaMomenti) ImpNElMax(NVisMax);
00199       emit NVisMaxCambiato(n);
00200     }
00201     else 
00202       return ;
00203   }
00204   if(PuntiMax < 1000 && !PrimaVolta)
00205     repaint();
00206 }
00207 void ElementiGrafici::ImpNElMin(int n){
00208   if(n<0 )
00209     return;
00210   else if(n < NElMax){
00211     NElMin = n;
00212     emit NElMinCambiato(n);
00213     sprintf(cPos,"%.3g : 0.",NElMin*ScalaTopoX/(double)PuntiMax+xMin);
00214     emit StatoSequenza(QString(cPos));  
00215   }
00216   else if(n>NElMax){
00217     if(n < PuntiMax + 5){
00218       ImpNElMax(n+5);
00219       NElMin = n;
00220       emit NElMinCambiato(n);
00221       sprintf(cPos,"%.3g : 0.",NElMin*ScalaTopoX/(double)PuntiMax+xMin);
00222       emit StatoSequenza(QString(cPos));  
00223     }
00224     else
00225       return ;
00226   }
00227   if(NMax < 10000 && !PrimaVolta) repaint();
00228 }
00229 void ElementiGrafici::ImpNElMax(int n){
00230   if( n > NElMin +5 && n<=PuntiMax){
00231     NElMax = n;
00232     emit NElMaxCambiato(n);
00233     sprintf(cPos,"%.3g : 0.",NElMax*ScalaTopoX/(double)PuntiMax+xMin);
00234     emit StatoSequenza(QString(cPos));  
00235   }
00236   else if(n < NElMin + 5 && n <= PuntiMax){
00237     if(NElMin > 10){
00238       NElMax = n;
00239       ImpNElMin( n - 10);
00240       emit NElMaxCambiato(n);
00241       sprintf(cPos,"%.3g : 0.",NElMax*ScalaTopoX/(double)PuntiMax+xMin);
00242       emit StatoSequenza(QString(cPos));  
00243     }
00244     else {
00245       return ;
00246     }
00247   }
00248   if(NMax < 10000 && !PrimaVolta) repaint();
00249 }
00250 void ElementiGrafici::ImpNElMinY(int n){
00251   if(n<0 || n > RisY)
00252     return;
00253   NElMinY = n;
00254   emit NElMinYCambiato(n);
00255   sprintf(cPos,"%.3g : %.3g",0.,(height()-NElMinY)*ScalaTopoY/(double)height()+yMin);
00256   emit StatoSequenza(QString(cPos));  
00257   if(!PrimaVolta) repaint();
00258 }
00259 void ElementiGrafici::ImpNElMaxY(int n){
00260   if(n<0 || n > RisY)
00261     return;
00262   NElMaxY = n;
00263   emit NElMaxYCambiato(n);
00264   sprintf(cPos,"%.3g : %.3g",0.,(height()-NElMaxY)*ScalaTopoY/(double)height()+yMin);
00265   emit StatoSequenza(QString(cPos));  
00266   if(!PrimaVolta)   repaint();
00267 }
00268 void ElementiGrafici::NomeFile(const QString &S){
00269   sprintf(nomeFile,"%s",S.ascii());
00270   sprintf(stringa,"Carico il file %s",nomeFile);
00271   InfoStato(stringa);
00272 }
00273 void ElementiGrafici::NomeEntrata(const QString &S){
00274   sprintf(nomeFile,"%s",S.ascii());
00275   emit TestoCambiato(S);
00276 }
00277 void ElementiGrafici::NomeConf(const QString &S){
00278   sprintf(nomeConf,"%s",S.ascii());
00279   emit ConfCambiato(S);
00280 }
00281 void ElementiGrafici::NomeSalva(const QString &S){
00282   sprintf(nomeSalva,"%s",S.ascii());
00283   sprintf(stringa,"Salva il file %s",nomeSalva);
00284   InfoStato(stringa);
00285 }
00286 void ElementiGrafici::NomeTit(const QString &S){
00287   nomeTit.replace(0,S.length(),S);
00288 }
00289 void ElementiGrafici::NomeEtX(const QString &S){
00290   nomeEtX.replace(0,S.length(),S);
00291 }
00292 void ElementiGrafici::NomeEtY(const QString &S){
00293   nomeEtY.replace(0,S.length(),S);
00294 }
00295 void ElementiGrafici::NomeUscita(const QString &S){
00296   emit SalvaCambiato(S);
00297 }
00298 void ElementiGrafici::NomeTitolo(const QString &S){
00299   emit TitoloCambiato(S);
00300 }
00301 void ElementiGrafici::NomeEtichettaX(const QString &S){
00302   emit EtichettaXCambiato(S);
00303 }
00304 void ElementiGrafici::NomeEtichettaY(const QString &S){
00305   emit EtichettaYCambiato(S);
00306 }
00307 void ElementiGrafici::Salva(){
00308   NomeSalva(QString(nomeSalva));
00309   sprintf(stringa,"Salvo su %s",nomeSalva);
00310   InfoStato(stringa);
00311   if(!IfSegnale) v1->ScriviFile(nomeSalva,CoordY,LogLog,NVisMin,NVisMax);
00312   if( DIS_IF_TYPE(IfDisegna,DIS_PUNTI) )
00313     v1->ScriviPunti(nomeSalva);
00314   if( DIS_IF_TYPE(IfDisegna,DIS_MOMENTI) )
00315     v1->ScriviPunti(nomeSalva);
00316   else  v1->ScriviTutto(nomeSalva,LogLog,1.,1.);
00317 }
00318 void ElementiGrafici::ImpInter(int n){
00319   emit InterVisCambiato(n);
00320 }
00321 void ElementiGrafici::ImpInterEl(int n){
00322   emit InterElCambiato(n);
00323 }
00324 void ElementiGrafici::ImpInter(int Min,int Max){
00325   emit InterVisCambiato(Min,Max);
00326 }
00327 void ElementiGrafici::ImpInterEl(int Min,int Max){
00328   emit InterElCambiato(Min,Max);
00329 }
00330 void ElementiGrafici::ImpInterY(int Min,int Max){
00331   emit InterYCambiato(Min,Max);
00332 }
00333 void ElementiGrafici::ImpCoordX(int n){
00334   if(n < REF_SEQ || n > NVar) return;
00335   if(CoordX == n) return;
00336   CoordX = n;
00337   if(DIS_IF_TYPE(IfRiscala,RIS_UNO))
00338     v1->ImpCoordX(CoordY,CoordX);
00339   else if (DIS_IF_TYPE(IfRiscala,RIS_TUTTI)){
00340     v1->ImpCoordX(CoordX);
00341   }
00342   if(!PrimaVolta) repaint();
00343   emit CoordXCambiata(MIN(n,CoordX));
00344 }
00345 void ElementiGrafici::ImpCoordY(int n){
00346   if(n < 0 || n >= NVar) return;
00347   CoordY = n;
00348   v1->ImpCoordY(CoordY);
00349   if(!PrimaVolta) repaint();
00350   emit CoordYCambiata(CoordY);
00351 }
00352 void ElementiGrafici::ImpCoordDY(int n){
00353   if(n >= 0 && n < NVar){
00354     CoordDY = n;
00355   }
00356   if(!PrimaVolta) repaint();
00357   emit CoordYCambiata(CoordY);
00358 }
00359 void ElementiGrafici::ImpNVarY(int n, int m){
00360   emit InterCoordYCambiato(n,m-1);
00361 }
00362 void ElementiGrafici::ImpNVarX(int n, int m){
00363   emit InterCoordXCambiato(n,m-1);
00364 }