• 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
  • tools
obslistwizard.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  obslistwizard.cpp - Display overhead view of the solar system
3  -------------------
4  begin : Thu 23 Jun 2005
5  copyright : (C) 2005 by Jason Harris
6  email : jharris@30doradus.org
7  ***************************************************************************/
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  ***************************************************************************/
16 
17 #include "obslistwizard.h"
18 
19 #include <QVBoxLayout>
20 #include <QFrame>
21 
22 #include <knuminput.h>
23 #include <kpushbutton.h>
24 
25 #include "kstarsdata.h"
26 #include "geolocation.h"
27 #include "dialogs/locationdialog.h"
28 #include "skyobjects/skyobject.h"
29 #include "skyobjects/deepskyobject.h"
30 #include "skyobjects/starobject.h"
31 #include "widgets/dmsbox.h"
32 #include "widgets/magnitudespinbox.h"
33 #include "skycomponents/constellationboundarylines.h"
34 #include "skycomponents/skymapcomposite.h"
35 
36 ObsListWizardUI::ObsListWizardUI( QWidget *p ) : QFrame ( p ) {
37  setupUi( this );
38 }
39 
40 ObsListWizard::ObsListWizard( QWidget *ksparent ) :
41  KDialog( ksparent )
42 {
43  olw = new ObsListWizardUI( this );
44  setMainWidget( olw );
45  setCaption( i18n("Observing List Wizard") );
46  setButtons( KDialog::User1|KDialog::User2|KDialog::Ok|KDialog::Cancel );
47  setButtonGuiItem( KDialog::User2, KGuiItem( i18n("< &Back"), QString(), i18n("Go to previous Wizard page") ) );
48  setButtonGuiItem( KDialog::User1, KGuiItem( i18n("&Next >"), QString(), i18n("Go to next Wizard page") ) );
49  enableButton( KDialog::User2, false );
50 
51  connect( olw->AllButton, SIGNAL( clicked() ), this, SLOT( slotAllButton() ) );
52  connect( olw->NoneButton, SIGNAL( clicked() ), this, SLOT( slotNoneButton() ) );
53  connect( olw->DeepSkyButton, SIGNAL( clicked() ), this, SLOT( slotDeepSkyButton() ) );
54  connect( olw->SolarSystemButton, SIGNAL( clicked() ), this, SLOT( slotSolarSystemButton() ) );
55  connect( olw->LocationButton, SIGNAL( clicked() ), this, SLOT( slotChangeLocation() ) );
56 
57  connect( this, SIGNAL( user1Clicked() ), this, SLOT( slotNextPage() ) );
58  connect( this, SIGNAL( user2Clicked() ), this, SLOT( slotPrevPage() ) );
59 
60  //Update the count of objects when the user asks for it
61  connect( olw->updateButton, SIGNAL( clicked() ), this, SLOT( slotUpdateObjectCount() ) );
62 
63  // Enable the update count button when certain elements are changed
64  connect( olw->TypeList, SIGNAL( itemSelectionChanged() ), this, SLOT( slotObjectCountDirty() ) );
65  connect( olw->ConstellationList, SIGNAL( itemSelectionChanged() ), this, SLOT( slotObjectCountDirty() ) );
66  connect( olw->RAMin, SIGNAL( lostFocus() ), this, SLOT( slotParseRegion() ) );
67  connect( olw->RAMax, SIGNAL( lostFocus() ), this, SLOT( slotParseRegion() ) );
68  connect( olw->DecMin, SIGNAL( lostFocus() ), this, SLOT( slotParseRegion() ) );
69  connect( olw->DecMax, SIGNAL( lostFocus() ), this, SLOT( slotParseRegion() ) );
70  connect( olw->RA, SIGNAL( lostFocus() ), this, SLOT( slotParseRegion() ) );
71  connect( olw->Dec, SIGNAL( lostFocus() ), this, SLOT( slotParseRegion() ) );
72  connect( olw->Radius, SIGNAL( lostFocus() ), this, SLOT( slotObjectCountDirty() ) );
73  connect( olw->Date, SIGNAL( dateChanged(const QDate&) ), this, SLOT( slotObjectCountDirty() ) );
74  connect( olw->Mag, SIGNAL( valueChanged( double ) ), this, SLOT( slotObjectCountDirty() ) );
75  connect( olw->IncludeNoMag, SIGNAL( clicked() ), this, SLOT( slotObjectCountDirty() ) );
76  connect (olw->timeTo, SIGNAL(timeChanged(const QTime&)), this, SLOT(slotObjectCountDirty()));
77  connect (olw->timeFrom, SIGNAL(timeChanged(const QTime&)), this, SLOT(slotObjectCountDirty()));
78  connect (olw->minAlt, SIGNAL(valueChanged(double)), this, SLOT(slotObjectCountDirty()));
79  connect (olw->maxAlt, SIGNAL(valueChanged(double)), this, SLOT(slotObjectCountDirty()));
80 
81  connect( olw->SelectByDate, SIGNAL( clicked() ), this, SLOT( slotToggleDateWidgets() ) );
82  connect( olw->SelectByMagnitude, SIGNAL( clicked() ), this, SLOT( slotToggleMagWidgets() ) );
83 
84  connect( this, SIGNAL( okClicked() ), this, SLOT( slotApplyFilters() ) );
85 
86  geo = KStarsData::Instance()->geo();
87  olw->LocationButton->setText( geo->fullName() );
88  olw->Date->setDate(KStarsDateTime::currentLocalDate());
89  olw->timeFrom->setTime(QTime(18, 0));
90  olw->timeTo->setTime(QTime(23, 59));
91 
92  initialize();
93 }
94 
95 ObsListWizard::~ObsListWizard()
96 {
97 }
98 
99 void ObsListWizard::initialize()
100 {
101  KStarsData* data = KStarsData::Instance();
102  olw->olwStack->setCurrentIndex( 0 );
103 
104  //Populate the list of constellations
105  foreach ( SkyObject *p, data->skyComposite()->constellationNames() )
106  olw->ConstellationList->addItem( p->name() );
107 
108  //unSelect all object types
109  olw->TypeList->clearSelection();
110 
111  olw->Mag->setMinimum( -5.0 );
112  olw->Mag->setMaximum( 20.0 );
113  olw->Mag->setValue( 6.0 );
114 
115  olw->RA->setDegType( false );
116  olw->RAMin->setDegType( false );
117  olw->RAMax->setDegType( false );
118 
119  //Initialize object counts
120  ObjectCount = 0; //number of objects in observing list
121  StarCount = data->skyComposite()->stars().size(); //total number of stars
122  PlanetCount = 10; //Sun, Moon, 8 planets
123  AsteroidCount = data->skyComposite()->asteroids().size(); //total number of asteroids
124  CometCount = data->skyComposite()->comets().size(); //total number of comets
125  //DeepSkyObjects
126  OpenClusterCount = 0;
127  GlobClusterCount = 0;
128  GasNebCount = 0;
129  PlanNebCount = 0;
130  GalaxyCount = 0;
131 
132  foreach ( DeepSkyObject *o, data->skyComposite()->deepSkyObjects() ) {
133  if ( o->type() == SkyObject::GALAXY ) ++GalaxyCount; //most deepsky obj are galaxies, so check them first
134  else if ( o->type() == SkyObject::STAR || o->type() == SkyObject::CATALOG_STAR ) ++StarCount;
135  else if ( o->type() == SkyObject::OPEN_CLUSTER ) ++OpenClusterCount;
136  else if ( o->type() == SkyObject::GLOBULAR_CLUSTER ) ++GlobClusterCount;
137  else if ( o->type() == SkyObject::GASEOUS_NEBULA || o->type() == SkyObject::SUPERNOVA_REMNANT ) ++GasNebCount;
138  else if ( o->type() == SkyObject::PLANETARY_NEBULA ) ++PlanNebCount;
139  }
140 }
141 
142 bool ObsListWizard::isItemSelected( const QString &name, QListWidget *listWidget, bool *ok ) {
143  QList<QListWidgetItem*> items = listWidget->findItems( name, Qt::MatchContains );
144  if ( ok )
145  *ok = items.size();
146  return items.size() && listWidget->isItemSelected( items[0] );;
147 }
148 
149 void ObsListWizard::setItemSelected( const QString &name, QListWidget *listWidget, bool value, bool *ok ) {
150  QList<QListWidgetItem*> items = listWidget->findItems( name, Qt::MatchContains );
151  if ( ok )
152  *ok = items.size();
153  if ( items.size() )
154  listWidget->setItemSelected( items[0], value );
155 }
156 
157 //Advance to the next page in the stack. However, on page 2 the user
158 //selects what regional filter they want to use, and this determnes
159 //what the page following page 2 should be:
160 // + Constellation(s): the next page index is 3
161 // + Rectangular region: the next page index is 4
162 // + Circular region: the next page index is 5
163 // + No region selected (a.k.a. "all over the sky"): the next page index is 6
164 //
165 //Also, if the current page index is 3 or 4, then the next page should be 6.
166 //
167 //NOTE: the page indexes are hard-coded here, which isn't ideal. However,
168 //There's no easy way to access the pointers of widgets in the stack
169 //if you didn't save them at the start.
170 void ObsListWizard::slotNextPage() {
171  int NextPage = olw->olwStack->currentIndex() + 1;
172 
173  if ( olw->olwStack->currentIndex() == 2 ) {
174  //On the Region select page. Determine what
175  //the next page index should be.
176  //No need to handle "by constellation, it's already currentIndex + 1.
177  if ( isItemSelected( i18n("in a rectangular region"), olw->RegionList ) )
178  NextPage = 4;
179  if ( isItemSelected( i18n("in a circular region"), olw->RegionList ) )
180  NextPage = 5;
181  if ( isItemSelected( i18n("all over the sky"), olw->RegionList ) )
182  NextPage = 6;
183  }
184 
185  if ( olw->olwStack->currentIndex() == 3 || olw->olwStack->currentIndex() == 4 )
186  NextPage = 6;
187 
188  olw->olwStack->setCurrentIndex( NextPage );
189  if ( olw->olwStack->currentIndex() == olw->olwStack->count() - 1 )
190  enableButton( KDialog::User1, false );
191 
192  enableButton( KDialog::User2, true );
193 }
194 
195 //Advance to the previous page in the stack. However, because the
196 //path through the wizard branches depending on the user's choice of
197 //Region filter, the previous page is not always currentPage-1.
198 //Specifically, if the current page index is 4, 5, or 6, then the Previous
199 //page index should be 2 rather than currentIndex-1.
200 void ObsListWizard::slotPrevPage() {
201  int PrevPage = olw->olwStack->currentIndex() - 1;
202 
203  if ( olw->olwStack->currentIndex() == 4
204  || olw->olwStack->currentIndex() == 5
205  || olw->olwStack->currentIndex() == 6 )
206  PrevPage = 2;
207 
208  olw->olwStack->setCurrentIndex( PrevPage );
209  if ( olw->olwStack->currentIndex() == 0 )
210  enableButton( KDialog::User2, false );
211 
212  enableButton( KDialog::User1, true );
213 }
214 
215 void ObsListWizard::slotAllButton() {
216  for ( int i=0; i<olw->TypeList->count(); ++i )
217  olw->TypeList->setItemSelected( olw->TypeList->item(i), true );
218 }
219 
220 void ObsListWizard::slotNoneButton() { olw->TypeList->clearSelection(); }
221 
222 void ObsListWizard::slotDeepSkyButton()
223 {
224  olw->TypeList->clearSelection();
225  setItemSelected( i18n( "Open clusters" ), olw->TypeList, true );
226  setItemSelected( i18n( "Globular clusters" ), olw->TypeList, true );
227  setItemSelected( i18n( "Gaseous nebulae" ), olw->TypeList, true );
228  setItemSelected( i18n( "Planetary nebulae" ), olw->TypeList, true );
229  setItemSelected( i18n( "Galaxies" ), olw->TypeList, true );
230 }
231 
232 void ObsListWizard::slotSolarSystemButton()
233 {
234  olw->TypeList->clearSelection();
235  setItemSelected( i18n( "Sun, moon, planets" ), olw->TypeList, true );
236  setItemSelected( i18n( "Comets" ), olw->TypeList, true );
237  setItemSelected( i18n( "Asteroids" ), olw->TypeList, true );
238 }
239 
240 void ObsListWizard::slotChangeLocation()
241 {
242  QPointer<LocationDialog> ld = new LocationDialog( this );
243 
244  if ( ld->exec() == QDialog::Accepted ) {
245  //set geographic location
246  if ( ld->selectedCity() ) {
247  geo = ld->selectedCity();
248  olw->LocationButton->setText( geo->fullName() );
249  }
250  }
251  delete ld;
252 }
253 
254 void ObsListWizard::slotToggleDateWidgets()
255 {
256  olw->Date->setEnabled( olw->SelectByDate->isChecked() );
257  olw->LocationButton->setEnabled( olw->SelectByDate->isChecked() );
258  olw->timeTo->setEnabled(olw->SelectByDate->isChecked() );
259  olw->timeFrom->setEnabled(olw->SelectByDate->isChecked() );
260  olw->minAlt->setEnabled(olw->SelectByDate->isChecked() );
261  olw->maxAlt->setEnabled(olw->SelectByDate->isChecked() );
262 
263  // slotUpdateObjectCount();
264  slotObjectCountDirty();
265 }
266 
267 void ObsListWizard::slotToggleMagWidgets()
268 {
269  olw->Mag->setEnabled( olw->SelectByMagnitude->isChecked() );
270  olw->IncludeNoMag->setEnabled( olw->SelectByMagnitude->isChecked() );
271  slotObjectCountDirty();
272  // slotUpdateObjectCount();
273 }
274 
275 void ObsListWizard::slotParseRegion()
276 {
277  if ( sender()->objectName() == "RAMin" || sender()->objectName() == "RAMax"
278  || sender()->objectName() == "DecMin" || sender()->objectName() == "DecMax" ) {
279  if ( ! olw->RAMin->isEmpty() && ! olw->RAMax->isEmpty()
280  && ! olw->DecMin->isEmpty() && ! olw->DecMax->isEmpty() ) {
281  bool rectOk = false;
282  xRect1 = 0.0;
283  xRect2 = 0.0;
284  yRect1 = 0.0;
285  yRect2 = 0.0;
286 
287  xRect1 = olw->RAMin->createDms( false, &rectOk ).Hours();
288  if ( rectOk ) xRect2 = olw->RAMax->createDms( false, &rectOk ).Hours();
289  if ( rectOk ) yRect1 = olw->DecMin->createDms( true, &rectOk ).Degrees();
290  if ( rectOk ) yRect2 = olw->DecMax->createDms( true, &rectOk ).Degrees();
291  if ( xRect2 == 0.0 ) xRect2 = 24.0;
292 
293  if ( !rectOk ) {
294  // kWarning() << i18n( "Illegal rectangle specified, no region selection possible." ) ;
295  return;
296  }
297 
298  //Make sure yRect1 < yRect2.
299  if ( yRect1 > yRect2 ) {
300  double temp = yRect2;
301  yRect2 = yRect1;
302  yRect1 = temp;
303  }
304 
305  //If xRect1 > xRect2, we may need to swap the two values, or subtract 24h from xRect1.
306  if ( xRect1 > xRect2 ) {
307  if ( xRect1 - xRect2 > 12.0 ) { //the user probably wants a region that straddles 0h
308  xRect1 -= 24.0;
309  } else { //the user probably wants xRect2 to be the lower limit
310  double temp = xRect2;
311  xRect2 = xRect1;
312  xRect1 = temp;
313  }
314  }
315 
316  // slotUpdateObjectCount();
317  slotObjectCountDirty();
318  }
319 
320  } else if ( ! olw->RA->isEmpty() && ! olw->Dec->isEmpty() && ! olw->Radius->isEmpty() ) {
321  bool circOk;
322  dms ra = olw->RA->createDms( false, &circOk );
323  dms dc;
324  if ( circOk )
325  dc = olw->Dec->createDms( true, &circOk );
326  if ( circOk ) {
327  pCirc.set( ra, dc );
328  rCirc = olw->Radius->createDms( true, &circOk ).Degrees();
329  } else {
330  kWarning() << i18n( "Illegal circle specified, no region selection possible." ) ;
331  return;
332  }
333  // slotUpdateObjectCount();
334  slotObjectCountDirty();
335  }
336 }
337 
338 void ObsListWizard::slotObjectCountDirty() {
339  olw->updateButton->setDisabled( false );
340 }
341 
342 void ObsListWizard::slotUpdateObjectCount()
343 {
344  QApplication::setOverrideCursor( Qt::WaitCursor );
345  ObjectCount = 0;
346  if ( isItemSelected( i18n( "Stars" ), olw->TypeList ) )
347  ObjectCount += StarCount;
348  if ( isItemSelected( i18n( "Sun, moon, planets" ), olw->TypeList ) )
349  ObjectCount += PlanetCount;
350  if ( isItemSelected( i18n( "Comets" ), olw->TypeList ) )
351  ObjectCount += CometCount;
352  if ( isItemSelected( i18n( "Asteroids" ), olw->TypeList ) )
353  ObjectCount += AsteroidCount;
354  if ( isItemSelected( i18n( "Galaxies" ), olw->TypeList ) )
355  ObjectCount += GalaxyCount;
356  if ( isItemSelected( i18n( "Open clusters" ), olw->TypeList ) )
357  ObjectCount += OpenClusterCount;
358  if ( isItemSelected( i18n( "Globular clusters" ), olw->TypeList ) )
359  ObjectCount += GlobClusterCount;
360  if ( isItemSelected( i18n( "Gaseous nebulae" ), olw->TypeList ) )
361  ObjectCount += GasNebCount;
362  if ( isItemSelected( i18n( "Planetary nebulae" ), olw->TypeList ) )
363  ObjectCount += PlanNebCount;
364 
365  applyFilters( false ); //false = only adjust counts, do not build list
366  QApplication::restoreOverrideCursor();
367  olw->updateButton->setDisabled( true );
368 }
369 
370 void ObsListWizard::applyFilters( bool doBuildList )
371 {
372  bool filterPass = true;
373  KStarsData* data = KStarsData::Instance();
374  if ( doBuildList )
375  obsList().clear();
376 
377  //We don't need to call applyRegionFilter() if no region filter is selected, *and*
378  //we are just counting items (i.e., doBuildList is false)
379  bool needRegion = true;
380  if ( !doBuildList && isItemSelected( i18n( "all over the sky" ), olw->RegionList ) )
381  needRegion = false;
382 
383  double maglimit = 100.;
384  if ( olw->SelectByMagnitude->isChecked() )
385  maglimit = olw->Mag->value();
386 
387  //Stars
388  if ( isItemSelected( i18n( "Stars" ), olw->TypeList ) )
389  {
390  const QList<SkyObject*>& starList = data->skyComposite()->stars();
391  int starIndex( starList.size() );
392  if ( maglimit < 100. )
393  {
394  //Stars are sorted by mag, so use binary search algo to find index of faintest mag
395  int low(0), high(starList.size()-1), middle(high);
396  while ( low < high )
397  {
398  middle = (low + high)/2;
399  if ( maglimit == starList.at(middle)->mag() )
400  break;
401  if ( maglimit < starList.at(middle)->mag() )
402  high = middle - 1;
403  if ( maglimit > starList.at(middle)->mag() )
404  low = middle + 1;
405  }
406  //now, the star at "middle" has the right mag, but we want the *last* star that has this mag.
407  for ( starIndex=middle+1; starIndex < starList.size(); ++starIndex )
408  {
409  if ( starList.at(starIndex)->mag() > maglimit )
410  break;
411  }
412  }
413 
414  //DEBUG
415  kDebug() << QString("starIndex for mag %1: %2").arg(maglimit).arg(starIndex) << endl;
416 
417  if( !doBuildList )
418  {
419  //reduce StarCount by appropriate amount
420  ObjectCount -= StarCount;
421  ObjectCount += starIndex;
422  }
423  for ( int i=0; i < starIndex; ++i )
424  {
425  SkyObject *o = (SkyObject*)(starList[i]);
426 
427  // JM 2012-10-22: Skip unnamed stars
428  if (o->name() == "star")
429  {
430  if ( ! doBuildList )
431  --ObjectCount;
432  continue;
433  }
434 
435  if ( needRegion )
436  filterPass = applyRegionFilter( o, doBuildList, !doBuildList);
437  //Filter objects visible from geo at Date if region filter passes
438  if ( olw->SelectByDate->isChecked() && filterPass)
439  applyObservableFilter( o, doBuildList, !doBuildList);
440  }
441  }
442 
443  //Sun, Moon, Planets
444  if ( isItemSelected( i18n( "Sun, moon, planets" ), olw->TypeList ) )
445  {
446  if (maglimit < data->skyComposite()->findByName("Sun")->mag())
447  {
448  if ( ! doBuildList )
449  --ObjectCount;
450  filterPass = false;
451  }
452  else
453  filterPass = true;
454 
455  if ( needRegion && filterPass)
456  filterPass = applyRegionFilter( data->skyComposite()->findByName("Sun"), doBuildList );
457  if ( olw->SelectByDate->isChecked() && filterPass)
458  applyObservableFilter( data->skyComposite()->findByName("Sun"), doBuildList );
459 
460  if (maglimit < data->skyComposite()->findByName("Moon")->mag())
461  {
462  if ( ! doBuildList )
463  --ObjectCount;
464  filterPass = false;
465  }
466  else filterPass = true;
467 
468  if ( needRegion && filterPass)
469  filterPass = applyRegionFilter( data->skyComposite()->findByName("Moon"), doBuildList );
470  if ( olw->SelectByDate->isChecked() && filterPass)
471  applyObservableFilter( data->skyComposite()->findByName("Moon"), doBuildList );
472 
473  if (maglimit < data->skyComposite()->findByName("Mercury")->mag())
474  {
475  if ( ! doBuildList )
476  --ObjectCount;
477  filterPass = false;
478  }
479  else
480  filterPass = true;
481  if ( needRegion && filterPass)
482  filterPass = applyRegionFilter( data->skyComposite()->findByName(i18n( "Mercury" )), doBuildList );
483  if ( olw->SelectByDate->isChecked() && filterPass)
484  applyObservableFilter( data->skyComposite()->findByName(i18n( "Mercury" )), doBuildList );
485 
486  if (maglimit < data->skyComposite()->findByName("Venus")->mag())
487  {
488  if ( ! doBuildList )
489  --ObjectCount;
490  filterPass = false;
491  }
492  else
493  filterPass = true;
494 
495  if ( needRegion && filterPass)
496  filterPass = applyRegionFilter( data->skyComposite()->findByName(i18n( "Venus" )), doBuildList );
497  if ( olw->SelectByDate->isChecked() && filterPass)
498  applyObservableFilter( data->skyComposite()->findByName(i18n( "Venus" )), doBuildList );
499 
500  if (maglimit < data->skyComposite()->findByName("Mars")->mag())
501  {
502  if ( ! doBuildList )
503  --ObjectCount;
504  filterPass = false;
505  }
506  else
507  filterPass = true;
508  if ( needRegion && filterPass)
509  filterPass = applyRegionFilter( data->skyComposite()->findByName(i18n( "Mars" )), doBuildList );
510  if ( olw->SelectByDate->isChecked() && filterPass)
511  applyObservableFilter( data->skyComposite()->findByName(i18n( "Mars" )), doBuildList );
512 
513  if (maglimit < data->skyComposite()->findByName("Jupiter")->mag())
514  {
515  if ( ! doBuildList )
516  --ObjectCount;
517  filterPass = false;
518  }
519  else
520  filterPass = true;
521  if ( needRegion && filterPass)
522  filterPass = applyRegionFilter( data->skyComposite()->findByName(i18n( "Jupiter" )), doBuildList );
523  if ( olw->SelectByDate->isChecked() && filterPass)
524  applyObservableFilter( data->skyComposite()->findByName(i18n( "Jupiter" )), doBuildList );
525 
526  if (maglimit < data->skyComposite()->findByName("Saturn")->mag())
527  {
528  if ( ! doBuildList )
529  --ObjectCount;
530  filterPass = false;
531  }
532  else
533  filterPass = true;
534 
535  if ( needRegion && filterPass)
536  filterPass = applyRegionFilter( data->skyComposite()->findByName(i18n( "Saturn" )), doBuildList );
537  if ( olw->SelectByDate->isChecked() && filterPass)
538  applyObservableFilter( data->skyComposite()->findByName(i18n( "Saturn" )), doBuildList );
539 
540  if (maglimit < data->skyComposite()->findByName("Uranus")->mag())
541  {
542  if ( ! doBuildList )
543  --ObjectCount;
544  filterPass = false;
545  }
546  else
547  filterPass = true;
548 
549  if ( needRegion && filterPass)
550  filterPass = applyRegionFilter( data->skyComposite()->findByName(i18n( "Uranus" )), doBuildList );
551  if ( olw->SelectByDate->isChecked() && filterPass)
552  applyObservableFilter( data->skyComposite()->findByName(i18n( "Uranus" )), doBuildList );
553 
554  if (maglimit < data->skyComposite()->findByName("Neptune")->mag())
555  {
556  if ( ! doBuildList )
557  --ObjectCount;
558  filterPass = false;
559  }
560  else
561  filterPass = true;
562 
563 
564  if ( needRegion && filterPass)
565  filterPass = applyRegionFilter( data->skyComposite()->findByName(i18n( "Neptune" )), doBuildList );
566  if ( olw->SelectByDate->isChecked() && filterPass)
567  applyObservableFilter( data->skyComposite()->findByName(i18n( "Neptune" )), doBuildList );
568 
569  if (maglimit < data->skyComposite()->findByName("Pluto")->mag())
570  {
571  if ( ! doBuildList )
572  --ObjectCount;
573  filterPass = false;
574  }
575  else
576  filterPass = true;
577 
578  if ( needRegion && filterPass)
579  filterPass = applyRegionFilter( data->skyComposite()->findByName(i18n( "Pluto" )), doBuildList );
580  if ( olw->SelectByDate->isChecked() && filterPass)
581  applyObservableFilter( data->skyComposite()->findByName(i18n( "Pluto" )), doBuildList );
582  }
583 
584  //Deep sky objects
585  bool dso = ( isItemSelected( i18n( "Open clusters" ), olw->TypeList )
586  || isItemSelected( i18n( "Globular clusters" ), olw->TypeList )
587  || isItemSelected( i18n( "Gaseous nebulae" ), olw->TypeList )
588  || isItemSelected( i18n( "Planetary nebulae" ), olw->TypeList )
589  || isItemSelected( i18n( "Galaxies" ), olw->TypeList ) );
590 
591  if ( dso )
592  {
593  //Don't need to do anything if we are just counting objects and not
594  //filtering by region or magnitude
595  if ( needRegion || olw->SelectByMagnitude->isChecked() || olw->SelectByDate->isChecked())
596  {
597  foreach ( DeepSkyObject *o, data->skyComposite()->deepSkyObjects() )
598  {
599  //Skip unselected object types
600  bool typeSelected = false;
601  // if ( (o->type() == SkyObject::STAR || o->type() == SkyObject::CATALOG_STAR) &&
602  // isItemSelected( i18n( "Stars" ), olw->TypeList ) )
603  // typeSelected = true;
604  switch (o->type())
605  {
606  case SkyObject::OPEN_CLUSTER:
607  if (isItemSelected( i18n( "Open clusters" ), olw->TypeList ))
608  typeSelected = true;
609  break;
610 
611  case SkyObject::GLOBULAR_CLUSTER:
612  if (isItemSelected( i18n( "Globular clusters" ), olw->TypeList ) )
613  typeSelected = true;
614  break;
615 
616  case SkyObject::GASEOUS_NEBULA:
617  case SkyObject::SUPERNOVA_REMNANT:
618  if (isItemSelected( i18n( "Gaseous nebulae" ), olw->TypeList ) )
619  typeSelected = true;
620  break;
621 
622  case SkyObject::PLANETARY_NEBULA:
623  if (isItemSelected( i18n( "Planetary nebulae" ), olw->TypeList ) )
624  typeSelected = true;
625  break;
626  case SkyObject::GALAXY:
627  if (isItemSelected( i18n( "Galaxies" ), olw->TypeList ) )
628  typeSelected = true;
629  break;
630 
631  }
632 
633  if ( ! typeSelected ) continue;
634 
635  if ( olw->SelectByMagnitude->isChecked() )
636  {
637  if ( o->mag() > 90. )
638  {
639  if ( olw->IncludeNoMag->isChecked() )
640  {
641  if ( needRegion )
642  filterPass = applyRegionFilter( o, doBuildList );
643  if ( olw->SelectByDate->isChecked() && filterPass)
644  applyObservableFilter( o, doBuildList );
645  }
646  else if ( ! doBuildList )
647  --ObjectCount;
648  }
649  else
650  {
651  if ( o->mag() <= maglimit )
652  {
653  if ( needRegion )
654  filterPass = applyRegionFilter( o, doBuildList );
655  if ( olw->SelectByDate->isChecked() && filterPass)
656  applyObservableFilter( o, doBuildList );
657  } else if ( ! doBuildList )
658  --ObjectCount;
659  }
660  }
661  else
662  {
663  if ( needRegion )
664  filterPass = applyRegionFilter( o, doBuildList );
665  if ( olw->SelectByDate->isChecked() && filterPass)
666  applyObservableFilter( o, doBuildList );
667  }
668  }
669  }
670  }
671 
672  //Comets
673  if ( isItemSelected( i18n( "Comets" ), olw->TypeList ) )
674  {
675  foreach ( SkyObject *o, data->skyComposite()->comets() )
676  {
677  if ( needRegion )
678  filterPass = applyRegionFilter( o, doBuildList );
679  if ( olw->SelectByDate->isChecked() && filterPass)
680  applyObservableFilter( o, doBuildList );
681  }
682  }
683 
684  //Asteroids
685  if ( isItemSelected( i18n( "Asteroids" ), olw->TypeList ) )
686  {
687  foreach ( SkyObject *o, data->skyComposite()->asteroids() )
688  {
689  if ( olw->SelectByMagnitude->isChecked() )
690  {
691  if ( o->mag() > 90. )
692  {
693  if ( olw->IncludeNoMag->isChecked() )
694  if ( needRegion )
695  filterPass = applyRegionFilter( o, doBuildList );
696  if ( olw->SelectByDate->isChecked() && filterPass)
697  applyObservableFilter( o, doBuildList );
698  else if ( ! doBuildList )
699  --ObjectCount;
700  }
701  else
702  {
703  if ( o->mag() <= maglimit )
704  if ( needRegion )
705  filterPass = applyRegionFilter( o, doBuildList );
706  if ( olw->SelectByDate->isChecked() && filterPass)
707  applyObservableFilter( o, doBuildList );
708  else if ( ! doBuildList )
709  --ObjectCount;
710  }
711  }
712  else
713  {
714  if ( needRegion )
715  filterPass = applyRegionFilter( o, doBuildList );
716  if ( olw->SelectByDate->isChecked() && filterPass)
717  applyObservableFilter( o, doBuildList );
718  }
719  }
720  }
721 
722  //Update the object count label
723  if ( doBuildList )
724  ObjectCount = obsList().size();
725 
726  olw->CountLabel->setText( i18np("Your observing list currently has 1 object", "Your observing list currently has %1 objects", ObjectCount ) );
727 }
728 
729 bool ObsListWizard::applyRegionFilter( SkyObject *o, bool doBuildList,
730  bool doAdjustCount )
731 {
732  //select by constellation
733  if ( isItemSelected( i18n("by constellation"), olw->RegionList ) )
734  {
735  QString c = KStarsData::Instance()->skyComposite()->getConstellationBoundary()->constellationName( o );
736  if ( isItemSelected( c, olw->ConstellationList ) )
737  {
738  if ( doBuildList )
739  obsList().append ( o );
740 
741  return true;
742  }
743  else if ( doAdjustCount )
744  {
745  --ObjectCount;
746  return false;
747  }
748  else
749  return false;
750  }
751 
752  //select by rectangular region
753  else if ( isItemSelected( i18n("in a rectangular region"), olw->RegionList ) )
754  {
755  double ra = o->ra().Hours();
756  double dec = o->dec().Degrees();
757  bool addObject = false;
758  if ( dec >= yRect1 && dec <= yRect2 ) {
759  if ( xRect1 < 0.0 ) {
760  addObject = ra >= xRect1 + 24.0 || ra <= xRect2;
761  } else {
762  addObject = ra >= xRect1 && ra <= xRect2;
763  }
764  }
765 
766  if ( addObject)
767  {
768  if (doBuildList )
769  obsList().append( o );
770 
771  return true;
772  }
773 
774  else
775  {
776  if (doAdjustCount )
777  --ObjectCount;
778 
779  return false;
780  }
781  }
782 
783  //select by circular region
784  //make sure circ region data are valid
785  else if ( isItemSelected( i18n("in a circular region"), olw->RegionList ) )
786  {
787  if ( o->angularDistanceTo( &pCirc ).Degrees() < rCirc )
788  {
789  if ( doBuildList )
790  obsList().append( o );
791 
792  return true;
793  }
794  else if ( doAdjustCount )
795  {
796  --ObjectCount;
797  return false;
798  }
799  else
800  return false;
801  }
802 
803  //No region filter, just add the object
804  else if ( doBuildList )
805  {
806  obsList().append( o );
807  }
808 
809  return true;
810 }
811 
812 bool ObsListWizard::applyObservableFilter( SkyObject *o, bool doBuildList, bool doAdjustCount)
813 {
814  SkyPoint p = *o;
815 
816  //Check altitude of object every hour from 18:00 to midnight
817  //If it's ever above 15 degrees, flag it as visible
818  KStarsDateTime Evening( olw->Date->date(), QTime( 18, 0, 0 ) );
819  KStarsDateTime Midnight( olw->Date->date().addDays(1), QTime( 0, 0, 0 ) );
820  double minAlt=15, maxAlt=90;
821 
822  // Or use user-selected values, if they're valid
823  if (olw->timeFrom->time() < olw->timeTo->time())
824  {
825  Evening.setTime(olw->timeFrom->time());
826  Midnight.setTime(olw->timeTo->time());
827  Midnight.setDate(olw->Date->date());
828  }
829 
830  if (olw->minAlt->value() < olw->maxAlt->value())
831  {
832  minAlt = olw->minAlt->value();
833  maxAlt = olw->maxAlt->value();
834  }
835 
836  bool visible = false;
837  for ( KStarsDateTime t = Evening; t < Midnight; t = t.addSecs( 3600.0 ) )
838  {
839  dms LST = geo->GSTtoLST( t.gst() );
840  p.EquatorialToHorizontal( &LST, geo->lat() );
841 
842  if ( p.alt().Degrees() >= minAlt && p.alt().Degrees() <= maxAlt )
843  {
844  visible = true;
845  break;
846  }
847  }
848 
849 
850  if (visible )
851  return true;
852 
853  if ( doAdjustCount )
854  --ObjectCount;
855  if ( doBuildList )
856  obsList().takeAt( obsList().indexOf(o) );
857 
858  return false;
859 
860 }
861 
862 #include "obslistwizard.moc"
SkyPoint::ra
const dms & ra() const
Definition: skypoint.h:171
LocationDialog
Dialog for changing the geographic location of the observer.
Definition: locationdialog.h:57
KStarsData
KStarsData is the backbone of KStars.
Definition: kstarsdata.h:66
SkyMapComposite::asteroids
const QList< SkyObject * > & asteroids() const
Definition: skymapcomposite.cpp:568
skyobject.h
deepskyobject.h
ObsListWizardUI
Definition: obslistwizard.h:28
QWidget
KStarsData::Instance
static KStarsData * Instance()
Definition: kstarsdata.h:92
dms::Degrees
const double & Degrees() const
Definition: dms.h:98
SkyMapComposite::deepSkyObjects
const QList< DeepSkyObject * > & deepSkyObjects() const
Definition: skymapcomposite.cpp:554
SkyMapComposite::constellationNames
const QList< SkyObject * > & constellationNames() const
Definition: skymapcomposite.cpp:558
SkyObject::SUPERNOVA_REMNANT
Definition: skyobject.h:109
SkyObject::GALAXY
Definition: skyobject.h:109
KDialog
KStarsData::geo
GeoLocation * geo()
Definition: kstarsdata.h:164
KStarsDateTime::setTime
void setTime(const QTime &t)
Assign the Time according to a QTime object.
Definition: kstarsdatetime.cpp:133
geolocation.h
SkyPoint
The sky coordinates of a point in the sky.
Definition: skypoint.h:50
ObsListWizard::~ObsListWizard
~ObsListWizard()
Destructor.
Definition: obslistwizard.cpp:95
ObsListWizardUI::ObsListWizardUI
ObsListWizardUI(QWidget *p)
Definition: obslistwizard.cpp:36
skymapcomposite.h
locationdialog.h
magnitudespinbox.h
SkyMapComposite::comets
const QList< SkyObject * > & comets() const
Definition: skymapcomposite.cpp:572
KStarsDateTime::addSecs
KStarsDateTime addSecs(double s) const
Definition: kstarsdatetime.cpp:127
SkyMapComposite::stars
const QList< SkyObject * > & stars() const
Definition: skymapcomposite.cpp:563
KStarsDateTime
Extension of KDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day...
Definition: kstarsdatetime.h:45
KStarsData::skyComposite
SkyMapComposite * skyComposite()
Definition: kstarsdata.h:146
dms
An angle, stored as degrees, but expressible in many ways.
Definition: dms.h:42
SkyPoint::dec
const dms & dec() const
Definition: skypoint.h:174
dms::Hours
double Hours() const
Definition: dms.h:125
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
constellationboundarylines.h
SkyObject::mag
float mag(void) const
Definition: skyobject.h:182
DeepSkyObject
Provides all necessary information about a deep-sky object: data inherited from SkyObject (coordinate...
Definition: deepskyobject.h:43
SkyObject::type
int type(void) const
Definition: skyobject.h:164
NaN::ld
const long double ld
Definition: nan.h:37
starobject.h
SkyObject::PLANETARY_NEBULA
Definition: skyobject.h:109
GeoLocation::fullName
QString fullName() const
Definition: geolocation.cpp:56
SkyMapComposite::findByName
virtual SkyObject * findByName(const QString &name)
Search the children of this SkyMapComposite for a SkyObject whose name matches the argument...
Definition: skymapcomposite.cpp:426
SkyMapComposite::getConstellationBoundary
ConstellationBoundaryLines * getConstellationBoundary()
Definition: skymapcomposite.h:194
obslistwizard.h
kstarsdata.h
SkyObject::GASEOUS_NEBULA
Definition: skyobject.h:109
SkyPoint::alt
const dms & alt() const
Definition: skypoint.h:180
dmsbox.h
ConstellationBoundaryLines::constellationName
QString constellationName(SkyPoint *p)
Definition: constellationboundarylines.cpp:261
SkyObject::name
virtual QString name(void) const
Definition: skyobject.h:124
SkyObject::GLOBULAR_CLUSTER
Definition: skyobject.h:108
SkyObject::STAR
Definition: skyobject.h:108
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
QFrame
SkyObject::CATALOG_STAR
Definition: skyobject.h:108
SkyObject::OPEN_CLUSTER
Definition: skyobject.h:108
SkyPoint::angularDistanceTo
dms angularDistanceTo(const SkyPoint *sp, double *const positionAngle=0) const
Computes the angular distance between two SkyObjects.
Definition: skypoint.cpp:608
QList
ObsListWizard::ObsListWizard
ObsListWizard(QWidget *parent)
Constructor.
Definition: obslistwizard.cpp:40
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:20 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