summaryrefslogtreecommitdiffstats
path: root/kstars/kstars/kstars.cpp
blob: a637a1b76d7dd5fba35690a044c47b665aae8507 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/***************************************************************************
                          kstars.cpp  -  Trinity 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.                                   *
 *                                                                         *
 ***************************************************************************/
//JH 11.06.2002: replaced infoPanel with infoBoxes
//JH 24.08.2001: reorganized infoPanel
//JH 25.08.2001: added toolbar, converted menu items to TDEAction objects
//JH 25.08.2001: main window now resizable, window size saved in config file


#include <stdio.h>
#include <stdlib.h>
//#include <iostream.h>
#include <kdebug.h>
#include <tdeactioncollection.h>
#include <kiconloader.h>
#include <tqpalette.h>
#include <kstatusbar.h>

#include "Options.h"
#include "kstars.h"
#include "kstarsdata.h"
#include "kstarssplash.h"
#include "skymap.h"
#include "simclock.h"
#include "finddialog.h"
#include "ksutils.h"
#include "infoboxes.h"
#include "observinglist.h"
#include "imagesequence.h"
#include "toggleaction.h"

// to remove warnings
#include "indimenu.h"
#include "indidriver.h"

KStars::KStars( bool doSplash, bool clockrun, const TQString &startdate ) :
	DCOPObject("KStarsInterface"), TDEMainWindow(),
	skymap(0), centralWidget(0), topLayout(0), viewToolBar(0), TimeStep(0),
	actCoordSys(0), colorActionMenu(0), fovActionMenu(0),
	AAVSODialog(0), findDialog(0), kns(0), 
	indimenu(0), indidriver(0), indiseq(0),
	DialogIsObsolete(false), StartClockRunning( clockrun ), StartDateString( startdate )
{
	pd = new privatedata(this);

	// we're nowhere near ready to take dcop calls
	kapp->dcopClient()->suspend();

	if ( doSplash ) {
		pd->kstarsData = new KStarsData();
		TQObject::connect(pd->kstarsData, TQT_SIGNAL( initFinished(bool) ),
				this, TQT_SLOT( datainitFinished(bool) ) );

		pd->splash = new KStarsSplash(0, "Splash");
		TQObject::connect(pd->splash, TQT_SIGNAL( closeWindow() ), kapp, TQT_SLOT( quit() ) );
		TQObject::connect(pd->kstarsData, TQT_SIGNAL( progressText(TQString) ),
				pd->splash, TQT_SLOT( setMessage(TQString) ));
		pd->splash->show();
	}

	pd->kstarsData->initialize();

	//Set Geographic Location
	pd->kstarsData->setLocationFromOptions();

	//Pause the clock if the user gave the "--paused" arg
	if ( ! StartClockRunning ) pd->kstarsData->clock()->stop();
	
	//set up Dark color scheme for application windows
	DarkPalette = TQPalette(TQColor("red4"), TQColor("DarkRed"));
	DarkPalette.setColor( TQPalette::Active, TQColorGroup::Base, TQColor( "black" ) );
	DarkPalette.setColor( TQPalette::Active, TQColorGroup::Text, TQColor( "red2" ) );
	DarkPalette.setColor( TQPalette::Active, TQColorGroup::Highlight, TQColor( "red2" ) );
	DarkPalette.setColor( TQPalette::Active, TQColorGroup::HighlightedText, TQColor( "black" ) );
	//store original color scheme
	OriginalPalette = TQApplication::palette();

	#if ( __GLIBC__ >= 2 &&__GLIBC_MINOR__ >= 1 && !defined(__UCLIBC__))
	kdDebug() << "glibc >= 2.1 detected.  Using GNU extension sincos()" << endl;
	#else
	kdDebug() << "Did not find glibc >= 2.1.  Will use ANSI-compliant sin()/cos() functions." << endl;
	#endif

	obsList = new ObservingList( this, this );
}

KStars::~KStars()
{
	//store focus values in Options
	Options::setFocusRA( skymap->focus()->ra()->Hours() );
	Options::setFocusDec( skymap->focus()->dec()->Degrees() );

	//Store Window geometry in Options object
	Options::setWindowWidth( width() );
	Options::setWindowHeight( height() );

	//We need to explicitly save the colorscheme data to the config file
	data()->colorScheme()->saveToConfig( kapp->config() );

	//synch the config file with the Config object
	Options::writeConfig();

	clearCachedFindDialog();

	delete skymap;
	delete pd;
	delete centralWidget;
	delete AAVSODialog;
	delete indimenu;
	delete indidriver;
	delete indiseq;
	
	skymap = 0;
	pd = 0;
	centralWidget = 0;
	AAVSODialog = 0;
	indimenu = 0;
	indidriver = 0;
	indiseq = 0;
}

KStars::privatedata::~privatedata() {
	delete splash;
	delete kstarsData;

	splash = 0;
	kstarsData = 0;
}

void KStars::clearCachedFindDialog() {
	if ( findDialog  ) {  // dialog is cached
/**
	*Delete findDialog only if it is not opened
	*/
		if ( findDialog->isHidden() ) {
			delete findDialog;
			findDialog = 0;
			DialogIsObsolete = false;
		}
		else
			DialogIsObsolete = true;  // dialog was opened so it could not deleted
   }
}

void KStars::applyConfig() {
	if ( Options::isTracking() ) {
		actionCollection()->action("track_object")->setText( i18n( "Stop &Tracking" ) );
		actionCollection()->action("track_object")->setIconSet( BarIcon( "encrypted" ) );
	}

	//Toggle actions
	if ( Options::useAltAz() ) ((ToggleAction*)actionCollection()->action("coordsys"))->turnOff();
	((TDEToggleAction*)actionCollection()->action("show_time_box"))->setChecked( Options::showTimeBox() );
	((TDEToggleAction*)actionCollection()->action("show_location_box"))->setChecked( Options::showGeoBox() );
	((TDEToggleAction*)actionCollection()->action("show_focus_box"))->setChecked( Options::showFocusBox() );
	((TDEToggleAction*)actionCollection()->action("show_mainToolBar"))->setChecked( Options::showMainToolBar() );
	((TDEToggleAction*)actionCollection()->action("show_viewToolBar"))->setChecked( Options::showViewToolBar() );
	((TDEToggleAction*)actionCollection()->action("show_statusBar"))->setChecked( Options::showStatusBar() );
	((TDEToggleAction*)actionCollection()->action("show_sbAzAlt"))->setChecked( Options::showAltAzField() );
	((TDEToggleAction*)actionCollection()->action("show_sbRADec"))->setChecked( Options::showRADecField() );
	((TDEToggleAction*)actionCollection()->action("show_stars"))->setChecked( Options::showStars() );
	((TDEToggleAction*)actionCollection()->action("show_deepsky"))->setChecked( Options::showDeepSky() );
	((TDEToggleAction*)actionCollection()->action("show_planets"))->setChecked( Options::showPlanets() );
	((TDEToggleAction*)actionCollection()->action("show_clines"))->setChecked( Options::showCLines() );
	((TDEToggleAction*)actionCollection()->action("show_cnames"))->setChecked( Options::showCNames() );
	((TDEToggleAction*)actionCollection()->action("show_cbounds"))->setChecked( Options::showCBounds() );
	((TDEToggleAction*)actionCollection()->action("show_mw"))->setChecked( Options::showMilkyWay() );
	((TDEToggleAction*)actionCollection()->action("show_grid"))->setChecked( Options::showGrid() );
	((TDEToggleAction*)actionCollection()->action("show_horizon"))->setChecked( Options::showGround() );
	
	//color scheme
	pd->kstarsData->colorScheme()->loadFromConfig( kapp->config() );
	if ( Options::darkAppColors() ) {
		TQApplication::setPalette( DarkPalette, true );
	} else {
		TQApplication::setPalette( OriginalPalette, true );
	}

	//Infoboxes, toolbars, statusbars
	infoBoxes()->setVisible( Options::showInfoBoxes() );
	if ( ! Options::showMainToolBar() ) toolBar( "mainToolBar" )->hide();
	if ( ! Options::showViewToolBar() ) toolBar( "viewToolBar" )->hide();
	if ( ! Options::showAltAzField() ) statusBar()->removeItem(1);
	if ( ! Options::showRADecField() ) statusBar()->removeItem(2);

	//Geographic location
	setGeoLocation( Options::cityName(), Options::provinceName(), Options::countryName() );

	//Focus
	SkyObject *fo = data()->objectNamed( Options::focusObject() );
	if ( fo && fo != map()->focusObject() ) {
		map()->setClickedObject( fo );
		map()->setClickedPoint( fo );
		map()->slotCenter();
	}

	if ( ! fo ) {
		SkyPoint fp( Options::focusRA(), Options::focusDec() );
		if ( fp.ra()->Degrees() != map()->focus()->ra()->Degrees() || fp.dec()->Degrees() != map()->focus()->dec()->Degrees() ) {
			map()->setClickedPoint( &fp );
			map()->slotCenter();
		}
	}
}

void KStars::updateTime( const bool automaticDSTchange ) {
	dms oldLST( LST()->Degrees() );
	// 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();

	Data->updateTime( geo(), Map, automaticDSTchange );
	if ( infoBoxes()->timeChanged( Data->ut(), Data->lt(), LST() ) )
		Map->update();

	//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() ) );
//		Map->focus()->setRA( Map->focus()->ra()->Hours() + double( nSec )/3600. );
//		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() ) {
		TQTimer::singleShot( 0, Data->clock(), TQT_SLOT( manualTick() ) );
	}
}

KStarsData* KStars::data( void ) { return pd->kstarsData; }

SkyMap* KStars::map( void )  { return skymap; }

InfoBoxes* KStars::infoBoxes( void )  { return map()->infoBoxes(); }

GeoLocation* KStars::geo() { return data()->geo(); }

void KStars::mapGetsFocus() { map()->TQWidget::setFocus(); }

dms* KStars::LST() { return data()->LST; }

ObservingList* KStars::observingList() { return obsList; }

#include "kstars.moc"