• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kstars

  • sources
  • kde-4.12
  • kdeedu
  • kstars
  • kstars
  • oal
execute.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  execute.cpp - description
3 
4  -------------------
5  begin : Friday July 21, 2009
6  copyright : (C) 2009 by Prakash Mohan
7  email : prakash.mohan@kdemail.net
8  ***************************************************************************/
9 
10 /***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  ***************************************************************************/
18 
19 #include "oal/execute.h"
20 
21 #include <QFile>
22 
23 #include <kmessagebox.h>
24 #include <kfiledialog.h>
25 #include "kstarsdata.h"
26 #include "oal/observer.h"
27 #include "oal/site.h"
28 #include "oal/session.h"
29 #include "oal/scope.h"
30 #include "oal/eyepiece.h"
31 #include "oal/lens.h"
32 #include "oal/filter.h"
33 #include "skyobjects/skyobject.h"
34 #include "dialogs/locationdialog.h"
35 #include "dialogs/finddialog.h"
36 
37 Execute::Execute() {
38  QWidget *w = new QWidget;
39  ui.setupUi( w );
40  setMainWidget( w );
41  setCaption( i18n( "Execute Session" ) );
42  setButtons( KDialog::User1|KDialog::Close );
43  setButtonGuiItem( KDialog::User1, KGuiItem( i18n("End Session"), QString(), i18n("Save and End the current session") ) );
44  ks = KStars::Instance();
45  currentTarget = NULL;
46  currentObserver = NULL;
47  currentScope = NULL;
48  currentEyepiece = NULL;
49  currentLens = NULL;
50  currentFilter = NULL;
51  currentSession = NULL;
52  nextSession = 0;
53  nextObservation = 0;
54  nextSite = 0;
55 
56  //initialize the global logObject
57  logObject = ks->data()->logObject();
58 
59  //initialize the lists and parameters
60  init();
61  ui.Target->hide();
62  ui.AddObject->hide();
63  ui.NextButton->hide();
64  ui.NextButton->setEnabled( false );
65  ui.Slew->setEnabled( false );
66 
67  //make connections
68  connect( this, SIGNAL( user1Clicked() ),
69  this, SLOT( slotEndSession() ) );
70  connect( ui.NextButton, SIGNAL( clicked() ),
71  this, SLOT( slotNext() ) );
72  connect( ui.Slew, SIGNAL( clicked() ),
73  this, SLOT( slotSlew() ) );
74  connect( ui.Location, SIGNAL( clicked() ),
75  this, SLOT( slotLocation() ) );
76  connect( ui.Target, SIGNAL( currentTextChanged(const QString) ),
77  this, SLOT( slotSetTarget(QString) ) );
78  connect( ui.SessionURL, SIGNAL( leftClickedUrl() ),
79  this, SLOT( slotShowSession() ) );
80  connect( ui.ObservationsURL, SIGNAL( leftClickedUrl() ),
81  this, SLOT( slotShowTargets() ) );
82  connect( ui.AddObject, SIGNAL( leftClickedUrl() ),
83  this, SLOT( slotAddObject() ) );
84 }
85 
86 void Execute::init() {
87  //initialize geo to current location of the ObservingList
88  geo = ks->observingList()->geoLocation();
89  ui.Location->setText( geo->fullName() );
90 
91  //set the date time to the dateTime from the OL
92  ui.Begin->setDateTime( ks->observingList()->dateTime().dateTime() );
93 
94  //load Targets
95  loadTargets();
96 
97  //load Equipment
98  loadEquipment();
99 
100  //load Observers
101  loadObservers();
102 
103  //set Current Items
104  loadCurrentItems();
105 }
106 void Execute::loadCurrentItems() {
107  //Set the current target, equipments and observer
108  if( currentTarget )
109  ui.Target->setCurrentRow( findIndexOfTarget( currentTarget->name() ), QItemSelectionModel::SelectCurrent );
110  else
111  ui.Target->setCurrentRow( 0, QItemSelectionModel::SelectCurrent );
112 
113  if( currentObserver )
114  ui.Observer->setCurrentIndex( ui.Observer->findText( currentObserver->name() + ' ' + currentObserver->surname() ) );
115  if( currentScope )
116  ui.Scope->setCurrentIndex( ui.Scope->findText( currentScope->name()) );
117  if( currentEyepiece )
118  ui.Eyepiece->setCurrentIndex( ui.Eyepiece->findText( currentEyepiece->name()) );
119  if( currentLens )
120  ui.Lens->setCurrentIndex( ui.Lens->findText( currentLens->name()) );
121  if( currentFilter )
122  ui.Filter->setCurrentIndex( ui.Filter->findText( currentFilter->name()) );
123 }
124 
125 int Execute::findIndexOfTarget( QString name ) {
126  for( int i = 0; i < ui.Target->count(); i++ )
127  if( ui.Target->item( i )->text() == name )
128  return i;
129  return -1;
130 }
131 
132 void Execute::slotNext() {
133  switch( ui.stackedWidget->currentIndex() ) {
134  case 0: {
135  saveSession();
136  break;
137  }
138  case 1: {
139  addTargetNotes();
140  break;
141  }
142  case 2: {
143  addObservation();
144  ui.stackedWidget->setCurrentIndex( 1 );
145  ui.NextButton->setText( i18n( "Next Page >" ) );
146  QString prevTarget = currentTarget->name();
147  loadTargets();
148  ui.Target->setCurrentRow( findIndexOfTarget( prevTarget ), QItemSelectionModel::SelectCurrent );
149  selectNextTarget();
150  break;
151  }
152  }
153 }
154 
155 bool Execute::saveSession() {
156  OAL::Site *site = logObject->findSiteByName( geo->fullName() );
157  if( ! site ) {
158  while( logObject->findSiteById( i18n( "site_" ) + QString::number( nextSite ) ) )
159  nextSite++;
160  site = new OAL::Site( geo, i18n( "site_" ) + QString::number( nextSite++ ) );
161  logObject->siteList()->append( site );
162  }
163  if( currentSession ){
164  currentSession->setSession( currentSession->id(), site->id(), ui.Begin->dateTime(), ui.Begin->dateTime(), ui.Weather->toPlainText(), ui.Equipment->toPlainText(), ui.Comment->toPlainText(), ui.Language->text() );
165  } else {
166  while( logObject->findSessionByName( i18n( "session_" ) + QString::number( nextSession ) ) )
167  nextSession++;
168  currentSession = new OAL::Session( i18n( "session_" ) + QString::number( nextSession++ ) , site->id(), ui.Begin->dateTime(), ui.Begin->dateTime(), ui.Weather->toPlainText(), ui.Equipment->toPlainText(), ui.Comment->toPlainText(), ui.Language->text() );
169  logObject->sessionList()->append( currentSession );
170  }
171  ui.stackedWidget->setCurrentIndex( 1 ); //Move to the next page
172  return true;
173 }
174 
175 void Execute::slotLocation() {
176  QPointer<LocationDialog> ld = new LocationDialog( this );
177  if ( ld->exec() == QDialog::Accepted ) {
178  geo = ld->selectedCity();
179  ui.Location->setText( geo -> fullName() );
180  }
181  delete ld;
182 }
183 
184 void Execute::loadTargets() {
185  ui.Target->clear();
186  sortTargetList();
187  foreach( SkyObject *o, ks->observingList()->sessionList() ) {
188  ui.Target->addItem( o->name() );
189  }
190 }
191 
192 void Execute::loadEquipment() {
193  ui.Scope->clear();
194  ui.Eyepiece->clear();
195  ui.Lens->clear();
196  ui.Filter->clear();
197  foreach( OAL::Scope *s, *( logObject->scopeList() ) )
198  ui.Scope->addItem( s->name() );
199  foreach( OAL::Eyepiece *e, *( logObject->eyepieceList() ) )
200  ui.Eyepiece->addItem( e->name() );
201  foreach( OAL::Lens *l, *( logObject->lensList() ) )
202  ui.Lens->addItem( l->name() );
203  foreach( OAL::Filter *f, *( logObject->filterList() ) )
204  ui.Filter->addItem( f->name() );
205 }
206 
207 void Execute::loadObservers() {
208  ui.Observer->clear();
209  foreach( OAL::Observer *o,*( logObject->observerList() ) )
210  ui.Observer->addItem( o->name() + ' ' + o->surname() );
211 }
212 
213 void Execute::sortTargetList() {
214  qSort( ks->observingList()->sessionList().begin(), ks->observingList()->sessionList().end(), Execute::timeLessThan );
215 }
216 
217  bool Execute::timeLessThan ( SkyObject *o1, SkyObject *o2 ) {
218  QTime t1 = KStars::Instance()->observingList()->scheduledTime( o1 ), t2 = KStars::Instance()->observingList()->scheduledTime( o2 );
219  if( t1 < QTime(12,0,0) )
220  t1.setHMS( t1.hour()+12, t1.minute(), t1.second() );
221  else
222  t1.setHMS( t1.hour()-12, t1.minute(), t1.second() );
223  if( t2 < QTime(12,0,0) )
224  t2.setHMS( t2.hour()+12, t2.minute(), t2.second() );
225  else
226  t2.setHMS( t2.hour()-12, t2.minute(), t2.second() );
227  return ( t1 < t2 ) ;
228 }
229 
230 void Execute::addTargetNotes() {
231  if( ! ui.Target->count() )
232  return;
233  SkyObject *o = KStars::Instance()->observingList()->findObjectByName( ui.Target->currentItem()->text() );
234  if( o ) {
235  currentTarget = o;
236  o->setNotes( ui.Notes->toPlainText() );
237  ui.Notes->clear();
238  loadObservationTab();
239  }
240 }
241 
242 void Execute::loadObservationTab() {
243  ui.Time->setTime( KStarsDateTime::currentDateTime().time() );
244  ui.stackedWidget->setCurrentIndex( 2 );
245  ui.NextButton->setText( i18n( "Next Target >" ) );
246 }
247 
248 bool Execute::addObservation() {
249  slotSetCurrentObjects();
250  while( logObject->findObservationByName( i18n( "observation_" ) + QString::number( nextObservation ) ) )
251  nextObservation++;
252  KStarsDateTime dt = currentSession->begin();
253  dt.setTime( ui.Time->time() );
254  OAL::Observation *o = new OAL::Observation( i18n( "observation_" ) + QString::number( nextObservation++ ) , currentObserver, currentSession, currentTarget, dt, ui.FaintestStar->value(), ui.Seeing->value(), currentScope, currentEyepiece, currentLens, currentFilter, ui.Description->toPlainText(), ui.Language->text() );
255  logObject->observationList()->append( o );
256  ui.Description->clear();
257  return true;
258 }
259 void Execute::slotEndSession() {
260  if( currentSession ) {
261 
262  currentSession->setSession( currentSession->id(), currentSession->site(), ui.Begin->dateTime(),
263  KStarsDateTime::currentDateTime(), ui.Weather->toPlainText(), ui.Equipment->toPlainText(),
264  ui.Comment->toPlainText(), ui.Language->text() );
265 
266  KUrl fileURL = KFileDialog::getSaveUrl( QDir::homePath(), "*.xml" );
267 
268  if( fileURL.isEmpty() ) {
269  // Cancel
270  return;
271  }
272 
273  if( fileURL.isValid() ) {
274 
275  QFile f( fileURL.path() );
276  if( ! f.open( QIODevice::WriteOnly ) ) {
277  QString message = i18n( "Could not open file %1", f.fileName() );
278  KMessageBox::sorry( 0, message, i18n( "Could Not Open File" ) );
279  return;
280  }
281  QTextStream ostream( &f );
282  ostream<< logObject->writeLog( false );
283  f.close();
284  }
285 
286  }
287  hide();
288  ui.stackedWidget->setCurrentIndex(0);
289  logObject->observationList()->clear();
290  logObject->sessionList()->clear();
291  delete currentSession;
292  currentTarget = NULL;
293  currentSession = NULL;
294 }
295 
296 void Execute::slotSetTarget( QString name ) {
297  currentTarget = ks->observingList()->findObjectByName( name );
298  if( ! currentTarget ) {
299  ui.NextButton->setEnabled( false );
300  ui.Slew->setEnabled( false );
301  return;
302  } else {
303  ui.NextButton->setEnabled( true );
304  ui.Slew->setEnabled( true );
305  ks->observingList()->selectObject( currentTarget );
306  ks->observingList()->slotCenterObject();
307  QString smag = "--";
308  if ( - 30.0 < currentTarget->mag() && currentTarget->mag() < 90.0 ) smag = QString::number( currentTarget->mag(), 'g', 2 ); // The lower limit to avoid display of unrealistic comet magnitudes
309  ui.Mag->setText( smag );
310  ui.Type->setText( currentTarget->typeName() );
311  ui.SchTime->setText( ks->observingList()->scheduledTime(currentTarget).toString( "h:mm:ss AP" ) ) ;
312  SkyPoint p = currentTarget->recomputeCoords( KStarsDateTime::currentDateTime() , geo );
313  dms lst(geo->GSTtoLST( KStarsDateTime::currentDateTime().gst() ));
314  p.EquatorialToHorizontal( &lst, geo->lat() );
315  ui.RA->setText( p.ra().toHMSString() ) ;
316  ui.Dec->setText( p.dec().toDMSString() );
317  ui.Alt->setText( p.alt().toDMSString() );
318  ui.Az->setText( p.az().toDMSString() );
319  ui.Notes->setText( currentTarget->notes() );
320  }
321 }
322 
323 void Execute::slotSlew() {
324  ks->observingList()->slotSlewToObject();
325 }
326 
327 void Execute::selectNextTarget() {
328  int i = findIndexOfTarget( currentTarget->name() ) + 1;
329  if( i < ui.Target->count() ) {
330  ui.Target->selectionModel()->clear();
331  ui.Target->setCurrentRow( i, QItemSelectionModel::SelectCurrent );
332  }
333 }
334 
335 void Execute::slotSetCurrentObjects() {
336  currentScope = logObject->findScopeByName( ui.Scope->currentText() );
337  currentEyepiece = logObject->findEyepieceByName( ui.Eyepiece->currentText() );
338  currentLens = logObject->findLensByName( ui.Lens->currentText() );
339  currentFilter = logObject->findFilterByName( ui.Filter->currentText() );
340  currentObserver = logObject->findObserverByName( ui.Observer->currentText() );
341 }
342 
343 void Execute::slotShowSession() {
344  ui.Target->hide();
345  ui.stackedWidget->setCurrentIndex( 0 );
346  ui.NextButton->hide();
347  ui.AddObject->hide();
348 }
349 
350 void Execute::slotShowTargets() {
351  if( saveSession() ) {
352  ui.Target->show();
353  ui.AddObject->show();
354  ui.stackedWidget->setCurrentIndex( 1 );
355  ui.NextButton->show();
356  ui.NextButton->setText( i18n( "Next Page >" ) );
357  }
358 }
359 
360 void Execute::slotAddObject() {
361  QPointer<FindDialog> fd = new FindDialog( ks );
362  if ( fd->exec() == QDialog::Accepted ) {
363  SkyObject *o = fd->selectedObject();
364  if( o != 0 ) {
365  ks->observingList()->slotAddObject( o, true );
366  init();
367  }
368  }
369  delete fd;
370 }
371 
372 
373 #include "execute.moc"
Execute::selectNextTarget
void selectNextTarget()
Definition: execute.cpp:327
OAL::Filter::name
QString name() const
Definition: filter.h:29
OAL::Eyepiece
Definition: eyepiece.h:25
SkyPoint::ra
const dms & ra() const
Definition: skypoint.h:171
LocationDialog
Dialog for changing the geographic location of the observer.
Definition: locationdialog.h:57
Execute::findIndexOfTarget
int findIndexOfTarget(QString)
Definition: execute.cpp:125
Execute::slotShowSession
void slotShowSession()
Definition: execute.cpp:343
site.h
Execute::timeLessThan
static bool timeLessThan(SkyObject *, SkyObject *)
Custom LessThan function for the sort by time This compares the times of the two skyobjects using an ...
Definition: execute.cpp:217
SkyPoint::az
const dms & az() const
Definition: skypoint.h:177
OAL::Eyepiece::name
QString name() const
Definition: eyepiece.h:29
skyobject.h
filter.h
Execute::addTargetNotes
void addTargetNotes()
Function to save the user notes set for the current object in the target combo box.
Definition: execute.cpp:230
OAL::Scope
Definition: scope.h:25
Execute::slotAddObject
void slotAddObject()
Definition: execute.cpp:360
QWidget
session.h
Execute::sortTargetList
void sortTargetList()
Sorts the target list using the scheduled time.
Definition: execute.cpp:213
KStars::Instance
static KStars * Instance()
Definition: kstars.h:125
Execute::slotSetTarget
void slotSetTarget(QString name)
set the currentTarget when the user selection is changed in the target combo box
Definition: execute.cpp:296
OAL::Observer::surname
QString surname()
Definition: observer.h:29
OAL::Scope::name
QString name() const
Definition: scope.h:32
Execute::loadObservationTab
void loadObservationTab()
loads the observation edit page
Definition: execute.cpp:242
Execute::Execute
Execute()
Default constructor.
Definition: execute.cpp:37
Execute::loadObservers
void loadObservers()
loads the observer list from the global logObject into the comboBoxes
Definition: execute.cpp:207
OAL::Observer::name
QString name()
Definition: observer.h:28
observer.h
KStarsDateTime::setTime
void setTime(const QTime &t)
Assign the Time according to a QTime object.
Definition: kstarsdatetime.cpp:133
Execute::saveSession
bool saveSession()
Definition: execute.cpp:155
Execute::slotShowTargets
void slotShowTargets()
Definition: execute.cpp:350
NaN::f
const float f
Definition: nan.h:36
SkyPoint
The sky coordinates of a point in the sky.
Definition: skypoint.h:50
Execute::slotNext
void slotNext()
Function to handle the UI when the 'next' button is pressed This calls the corresponding functions ba...
Definition: execute.cpp:132
Execute::loadEquipment
void loadEquipment()
loads the equipment list from the global logObject into the comboBoxes
Definition: execute.cpp:192
KStars::observingList
ObservingList * observingList() const
Definition: kstars.h:136
locationdialog.h
Execute::loadTargets
void loadTargets()
Loads the sessionlist from the OL into the target combo box.
Definition: execute.cpp:184
KStarsDateTime::currentDateTime
static KStarsDateTime currentDateTime(KDateTime::Spec ts=KDateTime::Spec::ClockTime())
Definition: kstarsdatetime.cpp:67
OAL::Filter
Definition: filter.h:25
scope.h
Execute::addObservation
bool addObservation()
Function to add the current observation to the observation list.
Definition: execute.cpp:248
execute.h
KStarsDateTime
Extension of KDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day...
Definition: kstarsdatetime.h:45
eyepiece.h
OAL::Session
Definition: session.h:26
Execute::slotSetCurrentObjects
void slotSetCurrentObjects()
Definition: execute.cpp:335
dms
An angle, stored as degrees, but expressible in many ways.
Definition: dms.h:42
lens.h
SkyPoint::dec
const dms & dec() const
Definition: skypoint.h:174
SkyPoint::EquatorialToHorizontal
void EquatorialToHorizontal(const dms *LST, const dms *lat)
Determine the (Altitude, Azimuth) coordinates of the SkyPoint from its (RA, Dec) coordinates, given the local sidereal time and the observer's latitude.
Definition: skypoint.cpp:55
Execute::init
void init()
This initializes the combo boxes, and sets up the dateTime and geolocation from the OL...
Definition: execute.cpp:86
Execute::slotEndSession
void slotEndSession()
Function to handle the state of current observation, and hiding the execute window.
Definition: execute.cpp:259
QTextStream
OAL::Site
Definition: site.h:27
OAL::Lens::name
QString name() const
Definition: lens.h:29
SkyObject::setNotes
void setNotes(QString _notes)
Definition: skyobject.h:323
finddialog.h
NaN::ld
const long double ld
Definition: nan.h:37
Execute::slotSlew
void slotSlew()
Definition: execute.cpp:323
Execute::loadCurrentItems
void loadCurrentItems()
Definition: execute.cpp:106
kstarsdata.h
OAL::Observer
Definition: observer.h:25
OAL::Observation
Definition: observation.h:36
SkyPoint::alt
const dms & alt() const
Definition: skypoint.h:180
SkyObject::name
virtual QString name(void) const
Definition: skyobject.h:124
KStarsDateTime::gst
dms gst() const
Definition: kstarsdatetime.cpp:138
SkyObject
Provides all necessary information about an object in the sky: its coordinates, name(s), type, magnitude, and QStringLists of URLs for images and webpages regarding the object.
Definition: skyobject.h:46
OAL::Lens
Definition: lens.h:25
OAL::Site::id
QString id() const
Definition: site.h:31
Execute::slotLocation
void slotLocation()
Opens the location dialog for setting the current location.
Definition: execute.cpp:175
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:19 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kstars

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

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal