forked from OpenPHDGuiding/phd2
/
profile_wizard.cpp
584 lines (530 loc) · 26.2 KB
/
profile_wizard.cpp
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
/* profile_wizard.cpp
* PHD Guiding
*
* Created by Bruce Waddington in collaboration with Andy Galasso
* Copyright (c) 2014 Bruce Waddington
* All rights reserved.
*
* This source code is distributed under the following "BSD" license
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of Bret McKee, Dad Dog Development,
* Craig Stark, Stark Labs nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "phd.h"
#include "profile_wizard.h"
#include "calstep_dialog.h"
wxBEGIN_EVENT_TABLE(ProfileWizard, wxDialog)
EVT_BUTTON(ID_NEXT, ProfileWizard::OnNext)
EVT_BUTTON(ID_PREV, ProfileWizard::OnPrev)
EVT_CHOICE(ID_COMBO, ProfileWizard::OnGearChoice)
EVT_SPINCTRLDOUBLE(ID_PIXELSIZE, ProfileWizard::OnPixelSizeChange)
EVT_SPINCTRLDOUBLE(ID_FOCALLENGTH, ProfileWizard::OnFocalLengthChange)
EVT_SPINCTRLDOUBLE(ID_GUIDESPEED, ProfileWizard::OnGuideSpeedChange)
EVT_BUTTON(ID_DETECT_PIXELSIZE, ProfileWizard::OnDetectPixelSize)
wxEND_EVENT_TABLE()
static const int DialogWidth = 425;
static const int TextWrapPoint = 400;
// Help text heights - "tall" is for greetings page, "normal" is for gear selection panels
static const int TallHelpHeight = 150;
static const int NormalHelpHeight = 85;
static wxString TitlePrefix;
// Utility function to add the <label, input> pairs to a flexgrid
static void AddTableEntryPair(wxWindow *parent, wxSizer *pTable, const wxString& label, wxWindow *pControl)
{
wxStaticText *pLabel = new wxStaticText(parent, wxID_ANY, label + _(": "));
pTable->Add(pLabel, 1, wxALL, 5);
pTable->Add(pControl, 1, wxALL, 5);
}
static void AddTableEntryPair(wxWindow *parent, wxSizer *pTable, const wxString& label, wxSizer *group)
{
wxStaticText *pLabel = new wxStaticText(parent, wxID_ANY, label + _(": "));
pTable->Add(pLabel, 1, wxALL, 5);
pTable->Add(group, 1, wxALL, 5);
}
ProfileWizard::ProfileWizard(wxWindow *parent, bool firstLight) :
wxDialog(parent, wxID_ANY, _("New Profile Wizard"), wxDefaultPosition, wxDefaultSize, wxCAPTION | wxCLOSE_BOX),
m_launchDarks(true)
{
TitlePrefix = _("New Profile Wizard - ");
// Create overall vertical sizer
m_pvSizer = new wxBoxSizer(wxVERTICAL);
# include "icons/phd2_48.png.h"
wxBitmap phd2(wxBITMAP_PNG_FROM_DATA(phd2_48));
m_bitmaps[STATE_GREETINGS] = new wxBitmap(phd2);
m_bitmaps[STATE_WRAPUP] = new wxBitmap(phd2);
# include "icons/cam2.xpm"
m_bitmaps[STATE_CAMERA] = new wxBitmap(cam_icon);
# include "icons/scope1.xpm"
m_bitmaps[STATE_MOUNT] = new wxBitmap(scope_icon);
m_bitmaps[STATE_AUXMOUNT] = new wxBitmap(scope_icon);
# include "icons/ao.xpm"
m_bitmaps[STATE_AO] = new wxBitmap(ao_xpm);
#ifndef __WXGTK__ // this resizing make a later crash in UpdateState with wxGtk
m_bitmaps[STATE_CAMERA]->SetWidth(55);
m_bitmaps[STATE_CAMERA]->SetHeight(55);
m_bitmaps[STATE_MOUNT]->SetWidth(55);
m_bitmaps[STATE_MOUNT]->SetHeight(55);
m_bitmaps[STATE_AUXMOUNT]->SetWidth(55);
m_bitmaps[STATE_AUXMOUNT]->SetHeight(55);
#endif // __WXGTK__
// Build the superset of UI controls, minus state-specific labels and data
// User instructions at top
wxBoxSizer *instrSizer = new wxBoxSizer(wxHORIZONTAL);
m_bitmap = new wxStaticBitmap(this, wxID_ANY, *m_bitmaps[STATE_GREETINGS], wxDefaultPosition, wxSize(55, 55));
instrSizer->Add(m_bitmap, 0, wxALIGN_CENTER_VERTICAL | wxFIXED_MINSIZE, 5);
m_pInstructions = new wxStaticText(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(DialogWidth, 75), wxALIGN_LEFT | wxST_NO_AUTORESIZE);
wxFont font = m_pInstructions->GetFont();
font.SetWeight(wxFONTWEIGHT_BOLD);
m_pInstructions->SetFont(font);
instrSizer->Add(m_pInstructions, wxSizerFlags().Border(wxALL, 10));
m_pvSizer->Add(instrSizer);
// Verbose help block
m_pHelpGroup = new wxStaticBoxSizer(wxVERTICAL, this, _("More Info"));
m_pHelpText = new wxStaticText(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(DialogWidth, -1));
// Vertical sizing of help text will be handled in state machine
m_pHelpGroup->Add(m_pHelpText, wxSizerFlags().Border(wxLEFT, 10).Border(wxBOTTOM, 10));
m_pvSizer->Add(m_pHelpGroup, wxSizerFlags().Border(wxALL, 5));
// Gear label and combo box
m_pGearGrid = new wxFlexGridSizer(1, 2, 5, 15);
m_pGearLabel = new wxStaticText(this, wxID_ANY, "Temp:", wxDefaultPosition, wxDefaultSize);
m_pGearChoice = new wxChoice(this, ID_COMBO, wxDefaultPosition, wxDefaultSize,
GuideCamera::List(), 0, wxDefaultValidator, _("Gear"));
m_pGearGrid->Add(m_pGearLabel, 1, wxALL, 5);
m_pGearGrid->Add(m_pGearChoice, 1, wxLEFT, 10);
m_pvSizer->Add(m_pGearGrid, wxSizerFlags().Center().Border(wxALL, 5));
// Control for pixel-size and focal length
m_pUserProperties = new wxFlexGridSizer(3, 2, 5, 15);
m_pPixelSize = new wxSpinCtrlDouble(this, ID_PIXELSIZE, wxEmptyString, wxDefaultPosition,
wxDefaultSize, wxSP_ARROW_KEYS, 0.0, 20.0, 0.0, 0.1);
m_pPixelSize->SetDigits(2);
m_PixelSize = m_pPixelSize->GetValue();
m_pPixelSize->SetToolTip(_("Click Detect to read the pixel size from the camera. Otherwise, you can get this value from your camera documentation or from an online source. You can use the up/down control "
"or type in a value directly."));
m_detectPixelSizeBtn = new wxButton(this, ID_DETECT_PIXELSIZE, _("Detect"));
m_detectPixelSizeBtn->Enable(false);
m_detectPixelSizeBtn->SetToolTip(_("Connect to camera and detect pixel size"));
wxBoxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(m_pPixelSize, 1);
sizer->Add(m_detectPixelSizeBtn, 0, wxLEFT, 10);
AddTableEntryPair(this, m_pUserProperties, _("Guide camera un-binned pixel size (microns)"), sizer);
m_pFocalLength = new wxSpinCtrlDouble(this, ID_FOCALLENGTH, _T("foo2"), wxDefaultPosition,
wxDefaultSize, wxSP_ARROW_KEYS, 50, 3000, 300, 50);
m_pFocalLength->SetValue(300);
m_pFocalLength->SetDigits(0);
m_pFocalLength->SetToolTip(_("This is the focal length of the guide scope - or the imaging scope if you are using an off-axis-guider or "
"an adaptive optics device. You can use the up/down control or type in a value directly."));
m_FocalLength = (int) m_pFocalLength->GetValue();
AddTableEntryPair(this, m_pUserProperties, _("Guide scope focal length (mm)"), m_pFocalLength);
m_pGuideSpeed = new wxSpinCtrlDouble(this, ID_GUIDESPEED, wxEmptyString, wxDefaultPosition,
wxDefaultSize, wxSP_ARROW_KEYS, 0.2, 1.0, 0.5, 0.1);
m_pGuideSpeed->SetValue(0.5);
m_GuideSpeed = 0.5;
m_pGuideSpeed->SetDigits(2);
m_pGuideSpeed->SetToolTip(_("The mount guide speed you will use for calibration and guiding, expressed as a multiple of the sidereal rate. If you "
"don't know, leave the setting at the default value (0.5X)"));
AddTableEntryPair(this, m_pUserProperties, _("Mount guide speed (n.n x sidereal)"), m_pGuideSpeed);
m_pvSizer->Add(m_pUserProperties, wxSizerFlags().Center().Border(wxALL, 5));
// Wrapup panel
m_pWrapUp = new wxFlexGridSizer(2, 2, 5, 15);
m_pProfileName = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(250,-1));
m_pLaunchDarks = new wxCheckBox(this, wxID_ANY, _("Build dark library"));
m_pLaunchDarks->SetValue(m_launchDarks);
m_pLaunchDarks->SetToolTip(_("Check this to automatically start the process of building a dark library for this profile."));
AddTableEntryPair(this, m_pWrapUp, _("Profile Name"), m_pProfileName);
m_pWrapUp->Add(m_pLaunchDarks, wxSizerFlags().Border(wxTOP, 5).Border(wxLEFT, 10));
m_pvSizer->Add(m_pWrapUp, wxSizerFlags().Border(wxALL, 10).Expand().Center());
// Row of buttons for prev, help, next
wxBoxSizer *pButtonSizer = new wxBoxSizer(wxHORIZONTAL);
m_pPrevBtn = new wxButton(this, ID_PREV, _("< Back"));
m_pPrevBtn->SetToolTip(_("Back up to the previous screen"));
m_pNextBtn = new wxButton(this, ID_NEXT, _("Next >"));
m_pNextBtn->SetToolTip(_("Move forward to next screen"));
pButtonSizer->AddStretchSpacer();
pButtonSizer->Add(
m_pPrevBtn,
wxSizerFlags(0).Align(0).Border(wxALL, 5));
pButtonSizer->Add(
m_pNextBtn,
wxSizerFlags(0).Align(0).Border(wxALL, 5));
m_pvSizer->Add(pButtonSizer, wxSizerFlags().Expand().Border(wxALL, 10));
// Status bar for error messages
m_pStatusBar = new wxStatusBar(this, -1);
m_pStatusBar->SetFieldsCount(1);
m_pvSizer->Add(m_pStatusBar, 0, wxGROW);
SetAutoLayout(true);
SetSizerAndFit(m_pvSizer);
// Special cases - neither AuxMount nor AO requires an explicit user choice
m_SelectedAuxMount = _("None");
m_SelectedAO = _("None");
if (firstLight)
m_State = STATE_GREETINGS;
else
m_State = STATE_CAMERA;
UpdateState(0);
}
ProfileWizard::~ProfileWizard(void)
{
delete m_bitmaps[STATE_GREETINGS];
delete m_bitmaps[STATE_CAMERA];
delete m_bitmaps[STATE_MOUNT];
delete m_bitmaps[STATE_AUXMOUNT];
delete m_bitmaps[STATE_AO];
delete m_bitmaps[STATE_WRAPUP];
}
// Build verbose help strings based on dialog state
void ProfileWizard::ShowHelp(DialogState state)
{
wxString hText;
switch (m_State)
{
case STATE_GREETINGS:
hText = _("This short sequence of steps will help you identify the equipment you want to use for guiding and will associate it with a profile name of your choice. "
"This profile will then be available any time you run PHD2. At a minimum, you will need to choose both the guide camera and the mount interface that PHD2 will use for guiding. "
"You will also enter some information about the optical characteristics of your setup. "
"PHD2 will use this to create a good 'starter set' of guiding and calibration "
"parameters. If you are a new user, please review the 'Impatient Instructions' under the 'Help' menu after the wizard dialog has finished.");
break;
case STATE_CAMERA:
hText = _("Select your guide camera from the list. All cameras supported by PHD2 and all installed ASCOM cameras are shown. If your camera is not shown, "
"it is either not supported by PHD2 or its camera driver is not installed. You must also specify the camera pixel size, "
"guide scope focal length, and mount guide speed so PHD2 can compute reasonable default settings for you.");
break;
case STATE_MOUNT:
hText = _("Select your mount interface from the list. This determines how PHD2 will move the telescope and get pointing information. For most modern "
"mounts, the ASCOM interface is a good choice if you are running MS Windows. The other interfaces are available for "
"cases where ASCOM is not available or isn't well supported by mount firmware.");
break;
case STATE_AUXMOUNT:
hText = _("The mount interface you chose in the previous step doesn't provide pointing information, so PHD2 will not be able to automatically adjust "
"guiding for side-of-pier and declination. You can enable these features by choosing an 'Aux Mount' connection that does provide pointing "
"information. The Aux Mount interface will be used only for that purpose and not for sending guide commands.");
break;
case STATE_AO:
hText = _("If you have an adaptive optics (AO) device, you can select it here. The AO device will be used for high speed, small guiding corrections, "
"while the mount interface you chose earlier will be used for larger ('bump') corrections. Calibration of both interfaces will be handled automatically.");
break;
case STATE_WRAPUP:
hText = _("Your profile is complete and ready to save. Give it a name and, optionally, build a dark-frame library for it. This is strongly "
"recommended for best results in both calibration and guiding. You can always change the settings in this new profile by clicking on the PHD2 USB "
"icon, selecting the profile name you just entered, and making your changes there. If you are new to PHD2 or encounter problems, please use the 'Help' function for assistance.");
case STATE_DONE:
break;
}
// Need to do it this way to handle 125% font scaling in Windows accessibility
m_pHelpText = new wxStaticText(this, wxID_ANY, hText, wxDefaultPosition, wxSize(DialogWidth, -1));
m_pHelpText->Wrap(TextWrapPoint);
m_pHelpGroup->Clear(true);
m_pHelpGroup->Add(m_pHelpText, wxSizerFlags().Border(wxLEFT, 10).Border(wxBOTTOM, 10).Expand());
m_pHelpGroup->Layout();
SetSizerAndFit(m_pvSizer);
}
void ProfileWizard::ShowStatus(const wxString& msg, bool appending)
{
if (appending)
m_pStatusBar->SetStatusText(m_pStatusBar->GetStatusText() + " " + msg);
else
m_pStatusBar->SetStatusText(msg);
}
// Do semantic checks for 'next' commands
bool ProfileWizard::SemanticCheck(DialogState state, int change)
{
bool bOk = true; // Only 'next' commands could have problems
if (change > 0)
{
switch (state)
{
case STATE_GREETINGS:
break;
case STATE_CAMERA:
bOk = (m_SelectedCamera.length() > 0 && m_PixelSize > 0 && m_FocalLength > 0 && m_SelectedCamera != _("None"));
if (!bOk)
ShowStatus(_("Please specify camera type, guider focal length, and guide camera pixel size"));
break;
case STATE_MOUNT:
bOk = (m_SelectedMount.Length() > 0 && m_SelectedMount != _("None"));
if (!bOk)
ShowStatus(_("Please select a mount type to handle guider commands"));
break;
case STATE_AUXMOUNT:
break;
case STATE_AO:
break;
case STATE_WRAPUP:
m_ProfileName = m_pProfileName->GetValue();
bOk = m_ProfileName.length() > 0;
if (!bOk)
ShowStatus(_("Please specify a name for the profile."));
if (pConfig->GetProfileId(m_ProfileName) > 0)
{
bOk = false;
ShowStatus(_("There is already a profile with that name. Please choose a different name."));
}
break;
case STATE_DONE:
break;
}
}
return bOk;
}
static int RangeCheck(int thisval)
{
return wxMin(wxMax(thisval, 0), (int) ProfileWizard::STATE_DONE);
}
// State machine manager. Layout and content of dialog panel will be changed here based on state.
void ProfileWizard::UpdateState(const int change)
{
ShowStatus(wxEmptyString);
if (SemanticCheck(m_State, change))
{
m_State = (DialogState) RangeCheck(((int)m_State + change));
if (m_State >= 0 && m_State < NUM_PAGES)
{
const wxBitmap& bmp = *m_bitmaps[m_State];
m_bitmap->SetSize(bmp.GetSize());
m_bitmap->SetBitmap(bmp);
}
switch (m_State)
{
case STATE_GREETINGS:
SetTitle(TitlePrefix + _("Introduction"));
m_pPrevBtn->Enable(false);
m_pGearLabel->Show(false);
m_pGearChoice->Show(false);
m_pUserProperties->Show(false);
m_pWrapUp->Show(false);
m_pInstructions->SetLabel(_("Welcome to the PHD2 'first light' wizard"));
m_pHelpText->SetSizeHints(wxSize(-1, TallHelpHeight));
SetSizerAndFit(m_pvSizer);
break;
case STATE_CAMERA:
SetTitle(TitlePrefix + _("Choose a Guide Camera"));
m_pPrevBtn->Enable(true);
m_pGearLabel->SetLabel(_("Guide Camera:"));
m_pGearChoice->Clear();
m_pGearChoice->Append(GuideCamera::List());
if (m_SelectedCamera.length() > 0)
m_pGearChoice->SetStringSelection(m_SelectedCamera);
m_pGearLabel->Show(true);
m_pGearChoice->Show(true);
m_pUserProperties->Show(true);
m_pWrapUp->Show(false);
m_pHelpText->SetSizeHints(wxSize(-1, NormalHelpHeight));
SetSizerAndFit(m_pvSizer);
m_pInstructions->SetLabel(_("Select your guide camera and specify the optical properties of your guiding set-up"));
m_pInstructions->Wrap(TextWrapPoint);
break;
case STATE_MOUNT:
SetTitle(TitlePrefix + _("Choose a Mount Connection"));
m_pPrevBtn->Enable(true);
m_pGearLabel->SetLabel(_("Mount:"));
m_pGearChoice->Clear();
m_pGearChoice->Append(Scope::List());
if (m_SelectedMount.length() > 0)
m_pGearChoice->SetStringSelection(m_SelectedMount);
m_pUserProperties->Show(false);
m_pInstructions->SetLabel(_("Select your mount connection - this will determine how guide signals are transmitted"));
break;
case STATE_AUXMOUNT:
if (m_PositionAware) // Skip this state if the selected mount is already position aware
{
UpdateState(change);
}
else
{
SetTitle(TitlePrefix + _("Choose an Auxiliary Mount Connection (optional)"));
m_pGearLabel->SetLabel(_("Aux Mount:"));
m_pGearChoice->Clear();
m_pGearChoice->Append(Scope::AuxMountList());
m_pGearChoice->SetStringSelection(m_SelectedAuxMount); // SelectedAuxMount is never null
m_pInstructions->SetLabel(_("Since your primary mount connection does not report pointing position, you may want to choose an 'Aux Mount' connection"));
}
break;
case STATE_AO:
SetTitle(TitlePrefix + _("Choose an Adaptive Optics Device (optional)"));
m_pGearLabel->SetLabel(_("AO:"));
m_pGearChoice->Clear();
m_pGearChoice->Append(StepGuider::List());
m_pGearChoice->SetStringSelection(m_SelectedAO); // SelectedAO is never null
m_pInstructions->SetLabel(_("Specify your adaptive optics device if desired"));
if (change == -1) // User is backing up in wizard dialog
{
// Assert UI state for gear selection
m_pGearGrid->Show(true);
m_pNextBtn->SetLabel(_("Next >"));
m_pNextBtn->SetToolTip(_("Move forward to next screen"));
m_pWrapUp->Show(false);
}
break;
case STATE_WRAPUP:
SetTitle(TitlePrefix + _("Finish Creating Your New Profile"));
m_pGearGrid->Show(false);
m_pWrapUp->Show(true);
m_pNextBtn->SetLabel(_("Finish"));
m_pNextBtn->SetToolTip(_("Finish creating the equipment profile"));
m_pInstructions->SetLabel(_("Enter a name for your profile and optionally launch the process to build a dark library"));
SetSizerAndFit(m_pvSizer);
break;
case STATE_DONE:
WrapUp();
break;
}
}
ShowHelp(m_State);
}
static int GetCalibrationStepSize(int focalLength, double pixelSize, double guideSpeed, int binning)
{
int calibrationStep;
double const declination = 0.0;
CalstepDialog::GetCalibrationStepSize(focalLength, pixelSize, binning, guideSpeed,
CalstepDialog::DEFAULT_STEPS, declination, 0, &calibrationStep);
return calibrationStep;
}
// Set up some reasonable starting guiding parameters
static void SetGuideAlgoParams(double pixelSize, int focalLength, int binning)
{
double imageScale = MyFrame::GetPixelScale(pixelSize, focalLength, binning);
// Following based on empirical data using a range of image scales
double minMove = wxMax(0.1515 + 0.1548 / imageScale, 0.15); // Don't use a ridiculously small value
// Min moves for hysteresis guiding in RA and resist switch in Dec
pConfig->Profile.SetDouble("/scope/GuideAlgorithm/X/Hysteresis/minMove", minMove);
pConfig->Profile.SetDouble("/scope/GuideAlgorithm/Y/ResistSwitch/minMove", minMove);
}
// Wrapup logic - build the new profile, maybe launch the darks dialog
void ProfileWizard::WrapUp()
{
m_launchDarks = m_pLaunchDarks->GetValue();
int binning = 1; // assume starting with 1x1 binning
int calibrationStepSize = GetCalibrationStepSize(m_FocalLength, m_PixelSize, m_GuideSpeed, binning);
Debug.AddLine(wxString::Format("Profile Wiz: Name=%s, Camera=%s, Mount=%s, AuxMount=%s, AO=%s, PixelSize=%0.1f, FocalLength=%d, CalStep=%d, LaunchDarks=%d",
m_ProfileName, m_SelectedCamera, m_SelectedMount, m_SelectedAuxMount, m_SelectedAO, m_PixelSize, m_FocalLength, calibrationStepSize, m_launchDarks));
// create the new profile
if (pConfig->SetCurrentProfile(m_ProfileName))
{
ShowStatus(wxString::Format(_("Could not create profile %s"), m_ProfileName));
return;
}
// populate the profile. The caller will load the profile.
pConfig->Profile.SetString("/camera/LastMenuchoice", m_SelectedCamera);
pConfig->Profile.SetString("/scope/LastMenuChoice", m_SelectedMount);
pConfig->Profile.SetString("/scope/LastAuxMenuChoice", m_SelectedAuxMount);
pConfig->Profile.SetString("/stepguider/LastMenuChoice", m_SelectedAO);
pConfig->Profile.SetInt("/frame/focalLength", m_FocalLength);
pConfig->Profile.SetDouble("/camera/pixelsize", m_PixelSize);
pConfig->Profile.SetInt("/scope/CalibrationDuration", calibrationStepSize);
pConfig->Profile.SetDouble("/CalStepCalc/GuideSpeed", m_GuideSpeed);
GuideLog.EnableLogging(); // Especially for newbies
// Construct a good baseline set of guiding parameters based on image scale
SetGuideAlgoParams(m_PixelSize, m_FocalLength, binning);
EndModal(wxOK);
}
// Event handlers below
void ProfileWizard::OnGearChoice(wxCommandEvent& evt)
{
Scope *pMount;
switch (m_State)
{
case STATE_CAMERA:
m_SelectedCamera = m_pGearChoice->GetStringSelection();
m_detectPixelSizeBtn->Enable(!m_SelectedCamera.IsEmpty() && m_SelectedCamera != _("None"));
break;
case STATE_MOUNT:
m_SelectedMount = m_pGearChoice->GetStringSelection();
pMount = Scope::Factory(m_SelectedMount);
m_PositionAware = (pMount && pMount->CanReportPosition());
if (m_PositionAware)
{
m_SelectedAuxMount = _("None");
}
if (pMount)
{
delete pMount;
pMount = NULL;
}
break;
case STATE_AUXMOUNT:
m_SelectedAuxMount = m_pGearChoice->GetStringSelection();
break;
case STATE_AO:
m_SelectedAO = m_pGearChoice->GetStringSelection();
break;
case STATE_GREETINGS:
case STATE_WRAPUP:
case STATE_DONE:
break;
}
}
void ProfileWizard::OnDetectPixelSize(wxCommandEvent& evt)
{
GuideCamera *camera = GuideCamera::Factory(m_SelectedCamera);
double devPixelSize = 0;
try
{
wxBusyCursor busy;
if (!camera)
throw _("Could not initialize camera");
ShowStatus(_("Connecting to camera..."));
bool err = camera->Connect(GuideCamera::DEFAULT_CAMERA_ID);
ShowStatus(wxEmptyString);
if (err)
throw _("Could not connect to camera");
if (camera->GetDevicePixelSize(&devPixelSize) || devPixelSize == 0)
throw (_("Camera driver cannot report pixel size"));
m_pPixelSize->SetValue(devPixelSize);
wxSpinDoubleEvent dummy;
OnPixelSizeChange(dummy);
}
catch (const wxString& msg)
{
wxMessageBox(msg + _(". Please enter the correct un-binned pixel size from the camera documentation or vendor web site."), _("Detect Pixel Size"));
m_pPixelSize->SetValue(0.);
}
if (camera)
{
if (camera->Connected)
if (camera->Disconnect())
Debug.AddLine("Camera disconnect failed!");
delete camera;
}
}
void ProfileWizard::OnPixelSizeChange(wxSpinDoubleEvent& evt)
{
m_PixelSize = m_pPixelSize->GetValue();
}
void ProfileWizard::OnFocalLengthChange(wxSpinDoubleEvent& evt)
{
m_FocalLength = (int) m_pFocalLength->GetValue();
m_pFocalLength->SetValue(m_FocalLength); // Rounding
}
void ProfileWizard::OnGuideSpeedChange(wxSpinDoubleEvent& evt)
{
m_GuideSpeed = m_pGuideSpeed->GetValue();
}
void ProfileWizard::OnNext(wxCommandEvent& evt)
{
UpdateState(1);
}
void ProfileWizard::OnPrev(wxCommandEvent& evt)
{
UpdateState(-1);
}