kstars.cpp 13.8 KB
Newer Older
Chris Howells's avatar
adding  
Chris Howells committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/***************************************************************************
                          kstars.cpp  -  K Desktop Planetarium
                             -------------------
    begin                : Mon Feb  5 01:11:45 PST 2001
    copyright            : (C) 2001 by Jason Harris
    email                : jharris@30doradus.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

18
#include "kstars.h"
Chris Howells's avatar
adding  
Chris Howells committed
19

20
#include <QApplication>
21
#include <QDockWidget>
22

23 24
#include <KGlobal>
#include <KLocale>
Chris Howells's avatar
adding  
Chris Howells committed
25
#include <kdebug.h>
Jason Harris's avatar
Jason Harris committed
26
#include <kactioncollection.h>
27
#include <kstatusbar.h>
28
#include <ktoolbar.h>
Thorsten Roeder's avatar
Thorsten Roeder committed
29
#include <kicon.h>
Chris Howells's avatar
adding  
Chris Howells committed
30

31
#include "Options.h"
32 33
#include "kstarsdata.h"
#include "kstarssplash.h"
34
#include "kactionmenu.h"
35
#include "skymap.h"
Chris Howells's avatar
adding  
Chris Howells committed
36
#include "simclock.h"
37
#include "fov.h"
38
#include "dialogs/finddialog.h"
39
#include "dialogs/exportimagedialog.h"
40
#include "observinglist.h"
41
#include "oal/execute.h"
42
#include "whatsinteresting/wiview.h"
43
#include "whatsinteresting/wiusersettings.h"
Chris Howells's avatar
adding  
Chris Howells committed
44

45 46
#include "kstarsadaptor.h"

47 48 49
#include <config-kstars.h>

#ifdef HAVE_INDI_H
50 51 52
#include "indi/indimenu.h"
#include "indi/indidriver.h"
#include "indi/imagesequence.h"
53
#endif
54

55 56
KStars *KStars::pinstance = 0;

Rafal Kulaga's avatar
Rafal Kulaga committed
57 58 59 60
KStars::KStars( bool doSplash, bool clockrun, const QString &startdate )
    : KXmlGuiWindow(), kstarsData(0), skymap(0), TimeStep(0),
      colorActionMenu(0), fovActionMenu(0), findDialog(0),
      imgExportDialog(0), obsList(0), execute(0),
61 62
      avt(0), wut(0), wi(0), wiWiz(0), wiDock(0), skycal(0), sb(0), pv(0),
      jmt(0), fm(0), astrocalc(0), printingWizard(0), indimenu(0), indidriver(0),
Rafal Kulaga's avatar
Rafal Kulaga committed
63 64
      indiseq(0), ekosmenu(0), DialogIsObsolete(false), StartClockRunning( clockrun ),
      StartDateString( startdate )
Chris Howells's avatar
adding  
Chris Howells committed
65
{
66 67 68 69
    new KstarsAdaptor(this);
    QDBusConnection::sessionBus().registerObject("/KStars",  this);
    QDBusConnection::sessionBus().registerService("org.kde.kstars");

70 71 72
    // Set pinstance to yourself
    pinstance = this;

73 74
    connect( qApp, SIGNAL( aboutToQuit() ), this, SLOT( slotAboutToQuit() ) );

75 76 77 78
    //Initialize QActionGroups
    projectionGroup = new QActionGroup( this );
    cschemeGroup    = new QActionGroup( this );

79
    kstarsData = KStarsData::Create();
80
    Q_ASSERT( kstarsData );
81 82 83 84 85 86
    //Set Geographic Location from Options
    kstarsData->setLocationFromOptions();

    //Initialize Time and Date
    KStarsDateTime startDate = KStarsDateTime::fromString( StartDateString );
    if ( ! StartDateString.isEmpty() && startDate.isValid() )
87
        data()->changeDateTime( data()->geo()->LTtoUT( startDate ) );
88
    else
89
        data()->changeDateTime( KStarsDateTime::currentUtcDateTime() );
90 91 92 93 94
    
    // Initialize clock. If --paused is not in the comand line, look in options
    if ( clockrun )
        StartClockRunning =  Options::runClock();
    
95 96
    // Setup splash screen
    KStarsSplash *splash = 0;
97 98 99 100 101 102 103 104 105 106 107 108 109 110
    if ( doSplash ) {
        splash = new KStarsSplash(0);
        connect( kstarsData, SIGNAL( progressText(QString) ), splash, SLOT( setMessage(QString) ));
        splash->show();
    } else {
        connect( kstarsData, SIGNAL( progressText(QString) ), kstarsData, SLOT( slotConsoleMessage(QString) ) );
    }

    //set up Dark color scheme for application windows
    DarkPalette = QPalette(QColor("darkred"), QColor("darkred"));
    DarkPalette.setColor( QPalette::Normal, QPalette::Base, QColor( "black" ) );
    DarkPalette.setColor( QPalette::Normal, QPalette::Text, QColor( 238, 0, 0 ) );
    DarkPalette.setColor( QPalette::Normal, QPalette::Highlight, QColor( 238, 0, 0 ) );
    DarkPalette.setColor( QPalette::Normal, QPalette::HighlightedText, QColor( "black" ) );
111
    DarkPalette.setColor( QPalette::Inactive, QPalette::Text, QColor( 238, 0, 0 ) );
112 113 114
    //store original color scheme
    OriginalPalette = QApplication::palette();

115 116 117
    //Initialize data.  When initialization is complete, it will run dataInitFinished()
    if( !kstarsData->initialize() )
        return;
118
    delete splash;
119
    datainitFinished();
120

Jasem Mutlaq's avatar
Jasem Mutlaq committed
121
#if ( __GLIBC__ >= 2 &&__GLIBC_MINOR__ >= 1  && !defined(__UCLIBC__) )
122
    kDebug() << "glibc >= 2.1 detected.  Using GNU extension sincos()";
Jason Harris's avatar
Jason Harris committed
123
#else
124
    kDebug() << "Did not find glibc >= 2.1.  Will use ANSI-compliant sin()/cos() functions.";
Jason Harris's avatar
Jason Harris committed
125
#endif
Chris Howells's avatar
adding  
Chris Howells committed
126 127
}

128
KStars *KStars::createInstance( bool doSplash, bool clockrun, const QString &startdate ) {
129
    delete pinstance;
130 131 132
    // pinstance is set directly in constructor.
    new KStars( doSplash, clockrun, startdate );
    Q_ASSERT( pinstance && "pinstance must be non NULL");
133 134 135
    return pinstance;
}

Chris Howells's avatar
adding  
Chris Howells committed
136 137
KStars::~KStars()
{
138 139
    Q_ASSERT( pinstance );

140
    delete kstarsData;
141
    pinstance = 0;
142 143
}

Chris Howells's avatar
adding  
Chris Howells committed
144
void KStars::clearCachedFindDialog() {
145
    if ( findDialog  ) {  // dialog is cached
146
        /** Delete findDialog only if it is not opened */
147 148 149 150 151 152 153 154
        if ( findDialog->isHidden() ) {
            delete findDialog;
            findDialog = 0;
            DialogIsObsolete = false;
        }
        else
            DialogIsObsolete = true;  // dialog was opened so it could not deleted
    }
Chris Howells's avatar
adding  
Chris Howells committed
155 156
}

Jason Harris's avatar
Jason Harris committed
157
void KStars::applyConfig( bool doApplyFocus ) {
158 159
    if ( Options::isTracking() ) {
        actionCollection()->action("track_object")->setText( i18n( "Stop &Tracking" ) );
Pino Toscano's avatar
Pino Toscano committed
160
        actionCollection()->action("track_object")->setIcon( KIcon("document-encrypt") );
161 162
    }

163
    actionCollection()->action("coordsys")->setText(
164
        Options::useAltAz() ? i18n("Switch to star globe view (Equatorial &Coordinates)"): i18n("Switch to horizonal view (Horizontal &Coordinates)") );
165

166 167 168 169 170 171
    #ifdef HAVE_OPENGL
    Q_ASSERT( SkyMap::Instance() ); // This assert should not fail, because SkyMap is already created by now. Just throwing it in anyway.
    actionCollection()->action("opengl")->setText( (Options::useGL() ? i18n("Switch to QPainter backend"): i18n("Switch to OpenGL backend")) );
    #endif


172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
    actionCollection()->action("show_time_box"        )->setChecked( Options::showTimeBox() );
    actionCollection()->action("show_location_box"    )->setChecked( Options::showGeoBox() );
    actionCollection()->action("show_focus_box"       )->setChecked( Options::showFocusBox() );
    actionCollection()->action("show_statusBar"       )->setChecked( Options::showStatusBar() );
    actionCollection()->action("show_sbAzAlt"         )->setChecked( Options::showAltAzField() );
    actionCollection()->action("show_sbRADec"         )->setChecked( Options::showRADecField() );
    actionCollection()->action("show_stars"           )->setChecked( Options::showStars() );
    actionCollection()->action("show_deepsky"         )->setChecked( Options::showDeepSky() );
    actionCollection()->action("show_planets"         )->setChecked( Options::showSolarSystem() );
    actionCollection()->action("show_clines"          )->setChecked( Options::showCLines() );
    actionCollection()->action("show_cnames"          )->setChecked( Options::showCNames() );
    actionCollection()->action("show_cbounds"         )->setChecked( Options::showCBounds() );
    actionCollection()->action("show_mw"              )->setChecked( Options::showMilkyWay() );
    actionCollection()->action("show_equatorial_grid" )->setChecked( Options::showEquatorialGrid() );
    actionCollection()->action("show_horizontal_grid" )->setChecked( Options::showHorizontalGrid() );
    actionCollection()->action("show_horizon"         )->setChecked( Options::showGround() );
    actionCollection()->action("show_flags"           )->setChecked( Options::showFlags() );
189
    actionCollection()->action("show_supernovae"      )->setChecked( Options::showSupernovae() );
190
    statusBar()->setVisible( Options::showStatusBar() );
191 192

    //color scheme
193
    kstarsData->colorScheme()->loadFromConfig();
194
    QApplication::setPalette( Options::darkAppColors() ? DarkPalette : OriginalPalette );
195 196 197 198 199 200 201 202 203

    //Set toolbar options from config file
    toolBar("kstarsToolBar")->applySettings( KGlobal::config()->group( "MainToolBar" ) );
    toolBar( "viewToolBar" )->applySettings( KGlobal::config()->group( "ViewToolBar" ) );

    //Geographic location
    data()->setLocationFromOptions();

    //Focus
Jason Harris's avatar
Jason Harris committed
204 205 206 207 208
    if ( doApplyFocus ) {
        SkyObject *fo = data()->objectNamed( Options::focusObject() );
        if ( fo && fo != map()->focusObject() ) {
            map()->setClickedObject( fo );
            map()->setClickedPoint( fo );
209 210
            map()->slotCenter();
        }
Jason Harris's avatar
Jason Harris committed
211 212 213
    
        if ( ! fo ) {
            SkyPoint fp( Options::focusRA(), Options::focusDec() );
214
            if ( fp.ra().Degrees() != map()->focus()->ra().Degrees() || fp.dec().Degrees() != map()->focus()->dec().Degrees() ) {
Jason Harris's avatar
Jason Harris committed
215 216 217 218
                map()->setClickedPoint( &fp );
                map()->slotCenter();
            }
        }
219
    }
Jason Harris's avatar
Jason Harris committed
220 221
}

222 223 224 225 226
void KStars::showImgExportDialog() {
    if(imgExportDialog)
        imgExportDialog->show();
}

227 228
void KStars::syncFOVActions() {
    foreach(QAction *action, fovActionMenu->menu()->actions()) {
229 230 231 232
        if(action->text().isEmpty()) {
            continue;
        }

233 234 235 236 237 238 239 240 241 242
        if(Options::fOVNames().contains(action->text().remove(0, 1))) {
            action->setChecked(true);
        } else {
            action->setChecked(false);
        }
    }
}

void KStars::hideAllFovExceptFirst()
{
243 244 245 246
    // When there is only one visible FOV symbol, we don't need to do anything
    // Also, don't do anything if there are no available FOV symbols.
    if(data()->visibleFOVs.size() == 1 ||
       data()->availFOVs.size() == 0) {
247 248
        return;
    } else {
249 250 251 252 253 254 255 256
        // If there are no visible FOVs, select first available
        if(data()->visibleFOVs.size() == 0) {
            Options::setFOVNames(QStringList(data()->availFOVs.first()->name()));
        } else {
            Options::setFOVNames(QStringList(data()->visibleFOVs.first()->name()));
        }

        // Sync FOV and update skymap
257 258
        data()->syncFOV();
        syncFOVActions();
259
        map()->update(); // SkyMap::forceUpdate() is not required, as FOVs are drawn as overlays
260 261 262 263 264 265 266 267
    }
}

void KStars::selectNextFov()
{
    FOV *currentFov = data()->getVisibleFOVs().first();
    int currentIdx = data()->availFOVs.indexOf(currentFov);

268 269 270 271 272
    // If current FOV is not the available FOV list or there is only 1 FOV available, then return
    if(currentIdx == -1 || data()->availFOVs.size() < 2) {
        return;
    }

273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
    QStringList nextFovName;
    if(currentIdx == data()->availFOVs.size() - 1) {
        nextFovName << data()->availFOVs.first()->name();
    } else {
        nextFovName << data()->availFOVs.at(currentIdx + 1)->name();
    }

    Options::setFOVNames(nextFovName);
    data()->syncFOV();
    syncFOVActions();
    map()->update();
}

void KStars::selectPreviousFov()
{
    FOV *currentFov = data()->getVisibleFOVs().first();
    int currentIdx = data()->availFOVs.indexOf(currentFov);

291 292 293 294 295
    // If current FOV is not the available FOV list or there is only 1 FOV available, then return
    if(currentIdx == -1 || data()->availFOVs.size() < 2) {
        return;
    }

296 297 298 299 300 301 302 303 304 305 306 307 308
    QStringList prevFovName;
    if(currentIdx == 0) {
        prevFovName << data()->availFOVs.last()->name();
    } else {
        prevFovName << data()->availFOVs.at(currentIdx - 1)->name();
    }

    Options::setFOVNames(prevFovName);
    data()->syncFOV();
    syncFOVActions();
    map()->update();
}

309 310 311 312 313 314 315
void KStars::showWIWizard()
{
    wiDock->setVisible(false);
    wiWiz->restart();
    wiWiz->setVisible(true);
}

316
void KStars::showWI(ObsConditions *obs)
317
{
318 319 320 321 322 323 324
    if ( ! wi )
    {
        wi = new WIView(0, obs);
        wiDock = new QDockWidget(this);
        wiDock->setObjectName("What's Interesting");
        wiDock->setAllowedAreas(Qt::RightDockWidgetArea);
        wiDock->setWidget(wi->getWIBaseView());
325
//        wiDock->setMinimumSize(wi->getWIBaseView()->size());
326 327 328 329 330 331 332 333
        addDockWidget(Qt::RightDockWidgetArea, wiDock);
        wiDock->setVisible(true);
    }
    else
    {
        wi->updateModels(obs);
        wiDock->setVisible(true);
    }
334 335
}

336
void KStars::updateTime( const bool automaticDSTchange ) {
337 338 339 340 341
    // Due to frequently use of this function save data and map pointers for speedup.
    // Save options and geo() to a pointer would not speedup because most of time options
    // and geo will accessed only one time.
    KStarsData *Data = data();
    SkyMap *Map = map();
Alexey Khudyakov's avatar
Alexey Khudyakov committed
342
    // dms oldLST( Data->lst()->Degrees() );
343

344
    Data->updateTime( Data->geo(), Map, automaticDSTchange );
345 346 347 348 349

    //We do this outside of kstarsdata just to get the coordinates
    //displayed in the infobox to update every second.
    //	if ( !Options::isTracking() && LST()->Degrees() > oldLST.Degrees() ) {
    //		int nSec = int( 3600.*( LST()->Hours() - oldLST.Hours() ) );
350
    //		Map->focus()->setRA( Map->focus()->ra().Hours() + double( nSec )/3600. );
351 352 353 354 355 356 357 358 359 360 361 362
    //		if ( Options::useAltAz() ) Map->focus()->EquatorialToHorizontal( LST(), geo()->lat() );
    //		Map->showFocusCoords();
    //	}

    //If time is accelerated beyond slewTimescale, then the clock's timer is stopped,
    //so that it can be ticked manually after each update, in order to make each time
    //step exactly equal to the timeScale setting.
    //Wrap the call to manualTick() in a singleshot timer so that it doesn't get called until
    //the skymap has been completely updated.
    if ( Data->clock()->isManualMode() && Data->clock()->isActive() ) {
        QTimer::singleShot( 0, Data->clock(), SLOT( manualTick() ) );
    }
Chris Howells's avatar
adding  
Chris Howells committed
363 364
}

365 366 367 368 369 370
Execute* KStars::getExecute() {
    if( !execute )
        execute = new Execute();
    return execute;
}

Chris Howells's avatar
adding  
Chris Howells committed
371
#include "kstars.moc"
372