1 /*
2 * phd.h
3 * PHD2 Guiding
4 *
5 * Created by Craig Stark.
6 * Copyright (c) 2006-2010 Craig Stark.
7 * All rights reserved.
8 *
9 * This source code is distributed under the following "BSD" license
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 * Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 * Redistributions in binary form must reproduce the above copyright notice,
15 * this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * Neither the name of Craig Stark, Stark Labs nor the names of its
18 * contributors may be used to endorse or promote products derived from
19 * this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 *
33 */
34
35 #ifndef PHD_H_INCLUDED
36 #define PHD_H_INCLUDED
37
38 #if defined(_WINDOWS)
39 // ensure that windows.h does not include winsock.h which is
40 // incompatible with winsock2.h
41 # undef NOMINMAX
42 # define NOMINMAX
43 # include <winsock2.h>
44 # include <windows.h>
45 #endif
46
47 #include <wx/wx.h>
48 #include <wx/aui/aui.h>
49 #include <wx/bitmap.h>
50 #include <wx/bmpbuttn.h>
51 #include <wx/config.h>
52 #include <wx/dcbuffer.h>
53 #include <wx/display.h>
54 #include <wx/ffile.h>
55 #include <wx/fileconf.h>
56 #include <wx/graphics.h>
57 #include <wx/grid.h>
58 #include <wx/html/helpctrl.h>
59 #include <wx/image.h>
60 #include <wx/infobar.h>
61 #include <wx/intl.h>
62 #include <wx/minifram.h>
63 #include <wx/msgqueue.h>
64 #include <wx/socket.h>
65 #include <wx/spinctrl.h>
66 #include <wx/splash.h>
67 #include <wx/statline.h>
68 #include <wx/stdpaths.h>
69 #include <wx/string.h>
70 #include <wx/textfile.h>
71 #include <wx/tglbtn.h>
72 #include <wx/thread.h>
73 #include <wx/utils.h>
74
75 #include <functional>
76 #include <map>
77 #include <math.h>
78 #include <stdarg.h>
79
80 #define APPNAME _T("PHD2 Guiding")
81 #define PHDVERSION _T("2.6.10")
82 #define PHDSUBVER _T("")
83 #define FULLVER PHDVERSION PHDSUBVER
84
85 #if defined (__WINDOWS__)
86 # pragma warning(disable:4189)
87 # pragma warning(disable:4018)
88 # pragma warning(disable:4305)
89 # pragma warning(disable:4100)
90 # pragma warning(disable:4996)
91 # if HAVE_VLD
92 # include <vld.h>
93 # endif
94 #endif // __WINDOWS__
95
96 WX_DEFINE_ARRAY_INT(int, ArrayOfInts);
97 WX_DEFINE_ARRAY_DOUBLE(double, ArrayOfDbl);
98
99 #if defined (__WINDOWS__)
100 #define PHD_OSNAME _T("Windows")
101 #define PATHSEPCH '\\'
102 #define PATHSEPSTR "\\"
103 #endif
104
105 #if defined (__APPLE__)
106 #define PHD_OSNAME _T("OSX")
107 #define PATHSEPCH '/'
108 #define PATHSEPSTR "/"
109 #endif
110
111 #if defined (__WXGTK__)
112 #define PHD_OSNAME _T("Linux")
113 #define PATHSEPCH '/'
114 #define PATHSEPSTR _T("/")
115 #endif
116
117 #define DEGREES_SYMBOL "\u00B0"
118 #define MICRONS_SYMBOL "\u00B5m"
119
120 //#define TEST_TRANSFORMS
121
122 #define ROUND(x) (int) floor((x) + 0.5)
123 #define ROUNDF(x) (int) floorf((x) + 0.5)
124 #define DIV_ROUND_UP(x, y) (((x) + (y) - 1) / (y))
125
126 /* eliminate warnings for unused variables */
127 #define POSSIBLY_UNUSED(x) (void)(x)
128 //#define POSSIBLY_UNUSED(x) printf(x)
129
130 // these macros are used for building messages for thrown exceptions
131 // It is surprisingly hard to get the line number into a string...
132 #define STRINGIFY(x) #x
133 #define TOSTRING(x) STRINGIFY(x)
134
135 #define THROW_INFO_BASE(intro, file, line) intro " " file ":" TOSTRING(line)
136 #define LOG_INFO(s) (Debug.AddLine(wxString(THROW_INFO_BASE("At", __FILE__, __LINE__) "->" s)))
137 #define THROW_INFO(s) (Debug.AddLine(wxString(THROW_INFO_BASE("Throw from", __FILE__, __LINE__) "->" s)))
138 #define ERROR_INFO(s) (Debug.AddLine(wxString(THROW_INFO_BASE("Error thrown from", __FILE__, __LINE__) "->" s)))
139
140 #if defined (__WINDOWS__)
141 #define PHD_MESSAGES_CATALOG "messages"
142 #endif
143
144 #if defined (__APPLE__)
145 #define PHD_MESSAGES_CATALOG "messages"
146 #endif
147
148 #if defined (__linux__) || defined (__FreeBSD__)
149 // On Linux the messages catalogs for all the applications are in the same directory
150 // in /usr/share/locale, so the catalog name must be the application name.
151 #define PHD_MESSAGES_CATALOG "phd2"
152 #endif
153
154 #include "phdconfig.h"
155 #include "configdialog.h"
156 #include "optionsbutton.h"
157 #include "usImage.h"
158 #include "point.h"
159 #include "star.h"
160 #include "circbuf.h"
161 #include "guidinglog.h"
162 #include "graph.h"
163 #include "statswindow.h"
164 #include "star_profile.h"
165 #include "target.h"
166 #include "graph-stepguider.h"
167 #include "guide_algorithms.h"
168 #include "guiders.h"
169 #include "messagebox_proxy.h"
170 #include "serialports.h"
171 #include "parallelports.h"
172 #include "onboard_st4.h"
173 #include "cameras.h"
174 #include "camera.h"
175 #include "mount.h"
176 #include "scopes.h"
177 #include "stepguiders.h"
178 #include "rotators.h"
179 #include "image_math.h"
180 #include "testguide.h"
181 #include "advanced_dialog.h"
182 #include "gear_dialog.h"
183 #include "myframe.h"
184 #include "debuglog.h"
185 #include "worker_thread.h"
186 #include "event_server.h"
187 #include "confirm_dialog.h"
188 #include "phdcontrol.h"
189 #include "runinbg.h"
190 #include "fitsiowrap.h"
191 #include "imagelogger.h"
192
193 class wxSingleInstanceChecker;
194
195 extern Mount *pMount;
196 extern Mount *pSecondaryMount;
197 extern Scope *pPointingSource; // For using an 'aux' mount connection to get pointing info if the user has specified one
198 extern GuideCamera *pCamera;
199
TheScope()200 inline static Scope *TheScope()
201 {
202 return static_cast<Scope *>(pMount && pMount->IsStepGuider() ? pSecondaryMount : pMount);
203 }
204
TheAO()205 inline static StepGuider *TheAO()
206 {
207 return static_cast<StepGuider *>(pMount && pMount->IsStepGuider() ? pMount : 0);
208 }
209
210 // these seem to be the windowing/display related globals
211 extern int XWinSize;
212 extern int YWinSize;
213
214 class PhdApp : public wxApp
215 {
216 wxSingleInstanceChecker *m_instanceChecker;
217 long m_instanceNumber;
218 bool m_resetConfig;
219 wxString m_resourcesDir;
220 wxDateTime m_logFileTime;
221
222 protected:
223
224 wxLocale m_locale;
225
226 public:
227
228 PhdApp();
229 bool OnInit();
230 int OnExit();
231 void OnInitCmdLine(wxCmdLineParser& parser);
232 bool OnCmdLineParsed(wxCmdLineParser & parser);
233 void TerminateApp();
234 void RestartApp();
235 void HandleRestart();
236 void ResetConfiguration();
237 virtual bool Yield(bool onlyIfNeeded = false);
238 static void ExecInMainThread(std::function<void()> func);
GetInstanceNumber()239 int GetInstanceNumber() const { return m_instanceNumber; }
GetPHDResourcesDir()240 const wxString& GetPHDResourcesDir() const { return m_resourcesDir; }
241 wxString GetLocalesDir() const;
GetLocale()242 const wxLocale& GetLocale() const { return m_locale; }
GetLogFileTime()243 const wxDateTime& GetLogFileTime() const { return m_logFileTime; }
244 static wxDateTime ImagingDay(const wxDateTime& dt);
245 static bool IsSameImagingDay(const wxDateTime& a, const wxDateTime& b);
246 void CheckLogRollover();
247 wxString UserAgent() const;
248 };
249
250 wxDECLARE_APP(PhdApp);
251
252 #endif // PHD_H_INCLUDED
253