• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kstars

lcgenerator.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           lcgenerator.cpp  -  description
00003                              -------------------
00004     begin                : Tue Oct  1 18:01:48 CDT 2002
00005     copyright            : (C) 2002 by Jasem Mutlaq
00006     email                : mutlaqja@ku.edu
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include <qvariant.h>
00019 #include <klineedit.h>
00020 #include <klistbox.h>
00021 #include <kpushbutton.h>
00022 #include <qcheckbox.h>
00023 #include <qgroupbox.h>
00024 #include <qlabel.h>
00025 #include <qpushbutton.h>
00026 #include <qlayout.h>
00027 #include <qtooltip.h>
00028 #include <qwhatsthis.h>
00029 #include <qfile.h>
00030 
00031 #include <kio/netaccess.h>
00032 #include <kmessagebox.h>
00033 #include <kstandarddirs.h>
00034 
00035 #include "lcgenerator.h"
00036 #include "imageviewer.h"
00037 #include "kstars.h"
00038 #include "kstarsdata.h"
00039 
00040 #include <kapplication.h>
00041 
00042 LCGenerator::LCGenerator( QWidget* parent)
00043     : KDialogBase( parent, "lcgenerator", false, i18n( "AAVSO Light Curve Generator"),0) , Hostprefix("http://www.aavso.org/cgi-bin/kstar.pl"), JDCutOff(2437600)
00044 {
00045 
00046   ksw = (KStars*) parent;
00047   createGUI();
00048   
00049   downloadJob = 0;
00050   
00051   file = new QFile();
00052 }
00053 
00054 LCGenerator::~LCGenerator()
00055 {
00056    delete file;
00057    delete downloadJob;
00058 }
00059 
00060 void LCGenerator::createGUI()
00061 {
00062 
00063     QWidget *page = new QWidget(this);
00064     setMainWidget(page);
00065     
00066     LCGeneratorDialogLayout = new QVBoxLayout( page, 11, 6, "LCGeneratorDialogLayout"); 
00067 
00068     SDLayout = new QHBoxLayout( 0, 0, 6, "SDLayout"); 
00069 
00070     StarInfoBox = new QGroupBox( page, "StarInfoBox" );
00071     StarInfoBox->setColumnLayout(0, Qt::Vertical );
00072     StarInfoBox->layout()->setSpacing( 6 );
00073     StarInfoBox->layout()->setMargin( 11 );
00074     StarInfoBoxLayout = new QVBoxLayout( StarInfoBox->layout() );
00075     StarInfoBoxLayout->setAlignment( Qt::AlignTop );
00076 
00077     DesignHLayout = new QHBoxLayout( 0, 0, 6, "DesignHLayout"); 
00078 
00079     desigLabel = new QLabel( StarInfoBox, "desigLabel" );
00080     desigLabel->setMinimumSize( QSize( 70, 0 ) );
00081     DesignHLayout->addWidget( desigLabel );
00082 
00083     DesignationIn = new KListBox( StarInfoBox, "DesignationIn" );
00084     DesignHLayout->addWidget( DesignationIn );
00085     StarInfoBoxLayout->addLayout( DesignHLayout );
00086     
00087     // Fill stars designations
00088     for (uint i=0; i< (ksw->data()->VariableStarsList.count()); i++)
00089      DesignationIn->insertItem(ksw->data()->VariableStarsList.at(i)->Designation);
00090 
00091     NameHLayout = new QHBoxLayout( 0, 0, 6, "NameHLayout"); 
00092 
00093     nameLabel = new QLabel( StarInfoBox, "nameLabel" );
00094     nameLabel->setMinimumSize( QSize( 70, 0 ) );
00095     NameHLayout->addWidget( nameLabel );
00096 
00097     NameIn = new KListBox( StarInfoBox, "NameIn" );
00098     NameHLayout->addWidget( NameIn );
00099     StarInfoBoxLayout->addLayout( NameHLayout );
00100     
00101     // Fill star names
00102     for (uint i=0; i<ksw->data()->VariableStarsList.count(); i++)
00103      NameIn->insertItem(ksw->data()->VariableStarsList.at(i)->Name);
00104 
00105     StartHLayout = new QHBoxLayout( 0, 0, 6, "StartHLayout"); 
00106 
00107     startLabel = new QLabel( StarInfoBox, "startLabel" );
00108     startLabel->setMinimumSize( QSize( 70, 0 ) );
00109     StartHLayout->addWidget( startLabel );
00110 
00111     StartDateIn = new KLineEdit( StarInfoBox, "StartDateIn" );
00112     StartHLayout->addWidget( StartDateIn );
00113     StarInfoBoxLayout->addLayout( StartHLayout );
00114 
00115     EndHLayout = new QHBoxLayout( 0, 0, 6, "EndHLayout"); 
00116 
00117     endLabel = new QLabel( StarInfoBox, "endLabel" );
00118     endLabel->setMinimumSize( QSize( 70, 0 ) );
00119     EndHLayout->addWidget( endLabel );
00120 
00121     EndDateIn = new KLineEdit( StarInfoBox, "EndDateIn" );
00122     EndHLayout->addWidget( EndDateIn );
00123     StarInfoBoxLayout->addLayout( EndHLayout );
00124     SDLayout->addWidget( StarInfoBox );
00125 
00126     DataSelectBox = new QGroupBox( page, "DataSelectBox" );
00127     DataSelectBox->setColumnLayout(0, Qt::Vertical );
00128     DataSelectBox->layout()->setSpacing( 6 );
00129     DataSelectBox->layout()->setMargin( 11 );
00130     DataSelectBoxLayout = new QVBoxLayout( DataSelectBox->layout() );
00131     DataSelectBoxLayout->setAlignment( Qt::AlignTop );
00132 
00133     VisualCheck = new QCheckBox( DataSelectBox, "VisualCheck" );
00134     VisualCheck->setChecked( TRUE );
00135     DataSelectBoxLayout->addWidget( VisualCheck );
00136 
00137     FainterCheck = new QCheckBox( DataSelectBox, "FainterCheck" );
00138     FainterCheck->setChecked( TRUE );
00139     DataSelectBoxLayout->addWidget( FainterCheck );
00140 
00141     DiscrepantCheck = new QCheckBox( DataSelectBox, "DiscrepantCheck" );
00142     DataSelectBoxLayout->addWidget( DiscrepantCheck );
00143 
00144     CCDBCheck = new QCheckBox( DataSelectBox, "CCDBCheck" );
00145     CCDBCheck->setChecked( TRUE );
00146     DataSelectBoxLayout->addWidget( CCDBCheck );
00147 
00148     CCDVCheck = new QCheckBox( DataSelectBox, "CCDVCheck" );
00149     CCDVCheck->setChecked( TRUE );
00150     DataSelectBoxLayout->addWidget( CCDVCheck );
00151 
00152     CCDRCheck = new QCheckBox( DataSelectBox, "CCDRCheck" );
00153     CCDRCheck->setChecked( TRUE );
00154     DataSelectBoxLayout->addWidget( CCDRCheck );
00155 
00156     CCDICheck = new QCheckBox( DataSelectBox, "CCDICheck" );
00157     CCDICheck->setChecked( TRUE );
00158     DataSelectBoxLayout->addWidget( CCDICheck );
00159 
00160     PlotHLayout = new QHBoxLayout( 0, 0, 6, "PlotHLayout"); 
00161 
00162     plotLabel = new QLabel( DataSelectBox, "plotLabel" );
00163     PlotHLayout->addWidget( plotLabel );
00164 
00165     AverageDayIn = new KLineEdit( DataSelectBox, "AverageDayIn" );
00166     PlotHLayout->addWidget( AverageDayIn );
00167 
00168     daysLabel = new QLabel( DataSelectBox, "daysLabel" );
00169     PlotHLayout->addWidget( daysLabel );
00170     DataSelectBoxLayout->addLayout( PlotHLayout );
00171     SDLayout->addWidget( DataSelectBox );
00172     LCGeneratorDialogLayout->addLayout( SDLayout );
00173 
00174     ButtonHLayout = new QHBoxLayout( 0, 0, 6, "ButtonHLayout"); 
00175 
00176     GetCurveButton = new KPushButton( page, "GetCurveButton" );
00177     ButtonHLayout->addWidget( GetCurveButton );
00178 
00179     UpdateListButton = new KPushButton( page, "UpdateListButton" );
00180     ButtonHLayout->addWidget( UpdateListButton );
00181     QSpacerItem* spacer = new QSpacerItem( 128, 16, QSizePolicy::Expanding, QSizePolicy::Minimum );
00182     ButtonHLayout->addItem( spacer );
00183 
00184     CloseButton = new KPushButton( page, "closeButton" );
00185     ButtonHLayout->addWidget( CloseButton );
00186     LCGeneratorDialogLayout->addLayout( ButtonHLayout );
00187     
00188     
00189     StarInfoBox->setTitle( i18n( "Star Info" ) );
00190     desigLabel->setText( i18n( "Designation:" ) );
00191     nameLabel->setText( i18n( "Or name:" ) );
00192     startLabel->setText( i18n( "Start date:" ) );
00193     QWhatsThis::add( startLabel, i18n( "Start date for the light curve plot in mm/dd/yy or JD" ) );
00194     endLabel->setText( i18n( "End date:" ) );
00195     QWhatsThis::add( endLabel, i18n( "End date for the light curve plot in mm/dd/yy or JD" ) );
00196     StartDateIn->setText( i18n( "default" ) );
00197     EndDateIn->setText( i18n( "default" ) );
00198     DataSelectBox->setTitle( i18n( "Data Selection" ) );
00199     VisualCheck->setText( i18n( "Visual" ) );
00200     FainterCheck->setText( i18n( "Fainter thans" ) );
00201     DiscrepantCheck->setText( i18n( "Discrepant data" ) );
00202     CCDBCheck->setText( i18n( "CCDB" ) );
00203     CCDVCheck->setText( i18n( "CCDV" ) );
00204     CCDRCheck->setText( i18n( "CCDR" ) );
00205     CCDICheck->setText( i18n( "CCDI" ) );
00206     plotLabel->setText( i18n( "Plot average:" ) );
00207     daysLabel->setText( i18n( "days" ) );
00208     GetCurveButton->setText( i18n( "Retrieve Curve" ) );
00209     UpdateListButton->setText( i18n( "Update List" ) );
00210     CloseButton->setText( i18n( "Close" ) );
00211     
00212     resize( QSize(500, 360) );
00213         
00214     // Signals/Slots
00215     QObject::connect(CloseButton, SIGNAL(clicked()), this, SLOT(close()));
00216     QObject::connect(GetCurveButton, SIGNAL(clicked()), this, SLOT(VerifyData()));
00217     QObject::connect(UpdateListButton, SIGNAL(clicked()), this, SLOT(updateStarList()));
00218     QObject::connect(DesignationIn, SIGNAL(highlighted(int)), this, SLOT(updateNameList(int)));
00219     QObject::connect(NameIn, SIGNAL(highlighted(int)), this, SLOT(updateDesigList(int)));
00220       
00221     
00222 }
00223 
00224 void LCGenerator::VerifyData()
00225 {
00226     QString InitialStartDate, InitialEndDate;
00227     QString FinalDesignation, FinalStartDate, FinalEndDate, AverageDays;
00228     bool AverageDaysOK;
00229 
00230     // Get initial user input
00231     if ( StartDateIn->text().isEmpty() ) StartDateIn->setText( i18n( "default" ) );
00232     if ( EndDateIn->text().isEmpty() ) EndDateIn->setText( i18n( "default" ) );
00233     InitialStartDate     = StartDateIn->text().lower();
00234     InitialEndDate       = EndDateIn->text().lower();
00235     AverageDays       =  AverageDayIn->text();
00236     FinalDesignation = DesignationIn->currentText();
00237 
00238     // set Julian day
00239     if (!setJD(InitialStartDate, &FinalStartDate, 0))
00240         return;
00241     if (!setJD(InitialEndDate, &FinalEndDate, 1))
00242         return;
00243 
00244     if (FinalEndDate.toInt() < FinalStartDate.toInt())
00245     {
00246         KMessageBox::error(this, i18n("End date must occur after start date."));
00247         return;
00248     }
00249 
00250    // Check that we have an integer for average number of days, if data field empty, then make it 'default'
00251    if (!AverageDays.isEmpty())
00252    {
00253         AverageDays.toInt(&AverageDaysOK);
00254         if (!AverageDaysOK)
00255         {
00256             KMessageBox::error(this, i18n("Average days must be a positive integer."));
00257             return;
00258          }
00259      else
00260      {
00261       if (AverageDays.toInt() < 0)
00262       {
00263         KMessageBox::error(this, i18n("Average days must be a positive integer."));
00264                 return;
00265       }
00266      }
00267       
00268    }
00269    else AverageDays = QString("default");
00270 
00271     //Download the curve!
00272    DownloadCurve(FinalStartDate, FinalEndDate, FinalDesignation, AverageDays);
00273   
00274 }
00275 
00276 bool LCGenerator::setJD(QString Date, QString *JD, int JDType)
00277 {
00278     uint i=0;
00279     int TempJD=0;
00280     int slashCount =0;
00281     int slashRefrence[2];
00282 
00283     int dateFormat[3];
00284     bool isNumber;
00285     
00286     const QString invalidFormatStartJD(i18n("Invalid date format. Correct format is mm/dd/yyyy or JD, leave 'default' to generate light curves for the past 500 days."));
00287     const QString invalidFormatENDJD(i18n("Invalid date format. Correct format is mm/dd/yyyy or JD, leave 'default' to generate light curves until today."));
00288     QString invalidFormatMsg(JDType ? invalidFormatENDJD : invalidFormatStartJD);
00289     
00290 
00291     // check for "default" date
00292     if (Date == i18n("default"))
00293     {
00294        *JD = "default";
00295        return true;
00296     }
00297 
00298     // Get slashcount and and slash refrences
00299     for (i=0; i<Date.length(); i++)
00300       if (Date.at(i) == '/')
00301       {
00302           slashRefrence[slashCount++] = i;
00303           if (slashCount > 2)
00304           {
00305              KMessageBox::error(this, invalidFormatMsg);
00306              return false;
00307           }
00308       }
00309 
00310     // check if the data appears to be in JD format
00311     if (!slashCount)
00312     {
00313         TempJD = Date.toInt(&isNumber, 10);
00314         if (!isNumber)
00315         {
00316              KMessageBox::error(this, invalidFormatMsg);
00317              return false;
00318         }
00319 
00320          if (TempJD >= JDCutOff)
00321         {
00322           JD->setNum(TempJD, 10);
00323           return true;
00324         }
00325         else
00326         {
00327              const char* invalidJD = I18N_NOOP("No data available for JD prior to %d");
00328              KMessageBox::error(this, QString().sprintf(invalidJD, JDCutOff));
00329              return false;
00330         }
00331     }
00332 
00333     // If it's not a Julian day, check for the format of the date
00334     // check if year is 4 digits
00335     if ( (Date.length() - slashRefrence[1] - 1) != 4)
00336      {
00337           KMessageBox::error(this, invalidFormatMsg);
00338           return false;
00339      }
00340 
00341     // form mm/dd/yyy fields
00342     dateFormat[0] = Date.mid(0, slashRefrence[0]).toInt();
00343     dateFormat[1] = Date.mid(slashRefrence[0]+1, slashRefrence[1] - (slashRefrence[0] +1)).toInt();
00344     dateFormat[2] = Date.mid(slashRefrence[1]+1, Date.length()).toInt();
00345 
00346     ExtDate tempdate(dateFormat[2], dateFormat[0], dateFormat[1]);
00347     if (!tempdate.isValid())
00348     {
00349         KMessageBox::error(this, invalidFormatMsg);
00350         return false;
00351      }
00352 
00353      // Convert to JD and verify its lower limit
00354      TempJD = tempdate.jd();
00355 
00356      if (TempJD >= JDCutOff)
00357         {
00358           JD->setNum(TempJD, 10);
00359           return true;
00360         }
00361         else
00362         {
00363              const char* invalidJD = I18N_NOOP("No data available for JD prior to %d");
00364              KMessageBox::error(this, QString().sprintf(invalidJD, JDCutOff));
00365              return false;
00366         }
00367   
00368 }
00369 
00370 void LCGenerator::DownloadCurve(QString FinalStartDate, QString FinalEndDate, QString FinalDesignation, QString AverageDay)
00371 {
00372 
00373     QString buf(Hostprefix);
00374     QString Yes("yes");
00375     QString No("no");
00376     
00377     //FainterCheck;
00378     //CCDVCheck;
00379     //CCDICheck;
00380     //CCDRCheck;
00381     //CCDBCheck;
00382     //VisualCheck;
00383     //DiscrepantCheck;
00384     
00385 
00386     buf.append("?"+FinalStartDate);
00387     buf.append("?"+FinalEndDate);
00388     buf.append("?"+FinalDesignation);
00389     buf.append("?"+AverageDay);
00390     buf.append("?"+ (FainterCheck->isOn() ? Yes : No));
00391     buf.append("?"+ (CCDVCheck->isOn() ? Yes : No));
00392     buf.append("?"+ (CCDICheck->isOn() ? Yes : No));
00393     buf.append("?"+ (CCDRCheck->isOn() ? Yes : No));
00394     buf.append("?"+ (CCDBCheck->isOn() ? Yes : No));
00395     buf.append("?"+ (VisualCheck->isOn() ? Yes : No));
00396     buf.append("?"+ (DiscrepantCheck->isOn() ? Yes : No));
00397     
00398 
00399     KURL url(buf);
00400     QString message = i18n( "Light Curve produced by the American Amateur Variable Star Observers" );
00401     // parent of imageview is KStars
00402     new ImageViewer(&url, message, ksw, "lightcurve");
00403         
00404 }
00405 
00406 void LCGenerator::updateDesigList(int index)
00407 {
00408 
00409     DesignationIn->setSelected(index, true);
00410     DesignationIn->centerCurrentItem();
00411     
00412 }
00413 
00414 void LCGenerator::updateNameList(int index)
00415 {
00416 
00417     NameIn->setSelected(index, true);
00418     NameIn->centerCurrentItem();
00419     
00420 }
00421 
00422 void LCGenerator::updateStarList()
00423 {
00424     file->setName( locateLocal( "appdata", "valaav.txt" ) );
00425     
00426     KURL AAVSOFile("http://www.aavso.org/observing/aids/valaav.txt");
00427     KURL saveFile (file->name());
00428     
00429     downloadJob = KIO::file_copy (AAVSOFile, saveFile, -1, true);
00430     connect (downloadJob, SIGNAL (result (KIO::Job *)), SLOT (downloadReady (KIO::Job *)));
00431 }
00432 
00433 void LCGenerator::downloadReady(KIO::Job * job)
00434 {
00435 
00436 downloadJob = 0;
00437 
00438     if ( job->error() )
00439     {
00440         job->showErrorDialog();
00441         closeEvent (0);
00442         return;     // exit this function
00443     }
00444 
00445     file->close(); // to get the newest informations of the file and not any informations from opening of the file
00446 
00447     if ( file->exists() )
00448     {
00449         ksw->data()->readVARData();
00450         
00451         DesignationIn->clear();
00452                 NameIn->clear();
00453         
00454         // Fill stars designations
00455                 for (uint i=0; i< (ksw->data()->VariableStarsList.count()); i++)
00456                 DesignationIn->insertItem(ksw->data()->VariableStarsList.at(i)->Designation);
00457 
00458                 // Fill star names
00459                 for (uint i=0; i<ksw->data()->VariableStarsList.count(); i++)
00460                 NameIn->insertItem(ksw->data()->VariableStarsList.at(i)->Name);
00461         
00462                 KMessageBox::information(this, i18n("AAVSO Star list downloaded successfully."));
00463 
00464         
00465         return;
00466     }
00467     closeEvent (0);
00468 
00469 }
00470 
00471 void LCGenerator::closeEvent (QCloseEvent *ev)
00472 {
00473     if (ev) // not if closeEvent (0) is called, because segfault
00474         ev->accept();   // parent-widgets should not get this event, so it will be filtered
00475     //this->~LCGenerator(); // destroy the object, so the object can only allocated with operator new, not as a global/local variable
00476 }
00477 
00478 #include "lcgenerator.moc"

kstars

Skip menu "kstars"
  • Main Page
  • Modules
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • keduca
  • kstars
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal