Skip to content

Commit

Permalink
a bunch of small cleanups:
Browse files Browse the repository at this point in the history
 - fix a bug where the Dark Library would get unloaded if you disconnected then reconnected equipment
 - fix a couple memory leaks
 - disable the STOP button when not looping
 - do not proceed to connect other equipment if user cancels camera connection
 - some minor cosmetic fixes: better tooltips and status bar text
  • Loading branch information
agalasso committed Mar 20, 2015
1 parent 992bb6c commit 4b43d29
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 70 deletions.
14 changes: 8 additions & 6 deletions camcal_import_dialog.cpp
Expand Up @@ -50,10 +50,12 @@ static void AddTableEntryPair(wxWindow *parent, wxFlexGridSizer *pTable, const w
}

CamCalImportDialog::CamCalImportDialog(wxWindow *parent) :
wxDialog(parent, wxID_ANY, _("Import Dark Library and Bad Pixel Map"), wxDefaultPosition, wxDefaultSize, wxCAPTION | wxCLOSE_BOX)
wxDialog(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxCAPTION | wxCLOSE_BOX)
{
wxBoxSizer* vSizer = new wxBoxSizer(wxVERTICAL);

SetTitle(wxString::Format(_("Import Darks to Profile %s"), pConfig->GetCurrentProfile()));

m_thisProfileId = pConfig->GetCurrentProfileId();
m_profileNames = pConfig->ProfileNames();

Expand All @@ -74,7 +76,7 @@ CamCalImportDialog::CamCalImportDialog(wxWindow *parent) :
m_darksChoice = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, drkChoices, 0, wxDefaultValidator, _("Darks Profiles"));
m_darksChoice->SetSelection(0);
m_darksChoice->Bind(wxEVT_COMMAND_CHOICE_SELECTED, &CamCalImportDialog::OnDarkProfileChoice, this);
AddTableEntryPair(this, drkGrid, _("Import profile"), m_darksChoice);
AddTableEntryPair(this, drkGrid, _("Import from profile"), m_darksChoice);
m_darkCameraChoice = new wxStaticText(this, wxID_ANY, wxEmptyString, wxPoint(-1, -1), wxSize(-1, -1));
AddTableEntryPair(this, drkGrid, _("Camera in profile"), m_darkCameraChoice);
darksGroup->Add(drkGrid, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 10);
Expand All @@ -88,7 +90,6 @@ CamCalImportDialog::CamCalImportDialog(wxWindow *parent) :

wxStaticText* bpmLabel = new wxStaticText(this, wxID_STATIC, _("Choose the profile with the bad-pixel map you want to use:"), wxDefaultPosition, wxDefaultSize, 0);
bpmGroup->Add(bpmLabel, 0, wxALIGN_CENTER_HORIZONTAL | wxALL | wxADJUST_MINSIZE, 10);
wxFlexGridSizer* bpmGrid = new wxFlexGridSizer(2, 2, 0, 0);

wxArrayString bpmChoices;
bpmChoices.Add(_("None"));
Expand All @@ -100,7 +101,8 @@ CamCalImportDialog::CamCalImportDialog(wxWindow *parent) :
m_bpmChoice = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, bpmChoices, 0, wxDefaultValidator, _("Bad-pix Map Profiles"));
m_bpmChoice->SetSelection(0);
m_bpmChoice->Bind(wxEVT_COMMAND_CHOICE_SELECTED, &CamCalImportDialog::OnBPMProfileChoice, this);
AddTableEntryPair(this, bpmGrid, _("Import profile"), m_bpmChoice);
wxFlexGridSizer *bpmGrid = new wxFlexGridSizer(2, 2, 0, 0);
AddTableEntryPair(this, bpmGrid, _("Import from profile"), m_bpmChoice);
m_bpmCameraChoice = new wxStaticText(this, wxID_ANY, wxEmptyString, wxPoint(-1, -1), wxSize(-1, -1));
AddTableEntryPair(this, bpmGrid, _("Camera in profile"), m_bpmCameraChoice);
bpmGroup->Add(bpmGrid, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 10);
Expand Down Expand Up @@ -217,8 +219,8 @@ void CamCalImportDialog::OnOk(wxCommandEvent& evt)

if (m_sourceDarksProfileId != -1)
{
sourceName = pFrame->DarkLibFileName(m_sourceDarksProfileId);
destName = pFrame->DarkLibFileName(m_thisProfileId);
sourceName = MyFrame::DarkLibFileName(m_sourceDarksProfileId);
destName = MyFrame::DarkLibFileName(m_thisProfileId);
if (wxCopyFile(sourceName, destName, true))
{
Debug.Write(wxString::Format("Dark library imported from profile %d to profile %d\n", m_sourceDarksProfileId, m_thisProfileId));
Expand Down
1 change: 1 addition & 0 deletions camera.cpp
Expand Up @@ -202,6 +202,7 @@ GuideCamera::GuideCamera(void)
GuideCamera::~GuideCamera(void)
{
ClearDarks();
ClearDefectMap();
}

static int CompareNoCase(const wxString& first, const wxString& second)
Expand Down
15 changes: 11 additions & 4 deletions confirm_dialog.cpp
Expand Up @@ -44,17 +44,19 @@ ConfirmDialog::ConfirmDialog(const wxString& prompt, const wxString& title, cons
sizer->Add(txt, wxSizerFlags(0).Border(wxALL, 10));
sizer->Add(dont_ask_again, wxSizerFlags(0).Border(wxALL, 10));


// Let CreateButtonSizer create platform-neutral OK/Cancel buttons with correct yes/no and EndModal event behavior - then relabel the buttons if
// client wants something other than OK and Cancel
wxBoxSizer *topLevelSizer = new wxBoxSizer(wxVERTICAL);
topLevelSizer->Add(sizer, wxSizerFlags(0).Expand());

// Let CreateButtonSizer create platform-neutral OK/Cancel buttons
// with correct yes/no and EndModal event behavior - then relabel
// the buttons if client wants something other than OK and Cancel

topLevelSizer->Add(CreateButtonSizer(wxOK | wxCANCEL), wxSizerFlags(0).Expand().Border(wxALL, 10));
if (!affirmLabel.IsEmpty())
FindWindow(wxID_OK)->SetLabel(affirmLabel);
if (!negativeLabel.IsEmpty())
FindWindow(wxID_CANCEL)->SetLabel(negativeLabel);

SetSizerAndFit(topLevelSizer);
}

Expand All @@ -67,7 +69,7 @@ static wxString ConfigKey(const wxString& name)
return "/Confirm" + name;
}

bool ConfirmDialog::Confirm(const wxString& prompt, const wxString& config_key, const wxString& title_arg, const wxString& affirmLabel, const wxString& negativeLabel)
bool ConfirmDialog::Confirm(const wxString& prompt, const wxString& config_key, const wxString& affirmLabel, const wxString& negativeLabel, const wxString& title_arg)
{
wxString key(ConfigKey(config_key));

Expand All @@ -90,6 +92,11 @@ bool ConfirmDialog::Confirm(const wxString& prompt, const wxString& config_key,
return false;
}

bool ConfirmDialog::Confirm(const wxString& prompt, const wxString& config_key, const wxString& title_arg)
{
return Confirm(prompt, config_key, wxEmptyString, wxEmptyString, title_arg);
}

void ConfirmDialog::ResetAllDontAskAgain(void)
{
pConfig->Global.DeleteGroup("/Confirm");
Expand Down
5 changes: 3 additions & 2 deletions confirm_dialog.h
Expand Up @@ -39,10 +39,11 @@ class ConfirmDialog :
public wxDialog
{
public:
ConfirmDialog(const wxString& prompt, const wxString& title, const wxString& affirmLabel = wxEmptyString, const wxString& negativeLabel = wxEmptyString);
ConfirmDialog(const wxString& prompt, const wxString& title, const wxString& affirmativeLabel, const wxString& negativeLabel);
~ConfirmDialog(void);

static bool Confirm(const wxString& prompt, const wxString& config_key, const wxString& title = "", const wxString& affirmLabel = wxEmptyString, const wxString& negativeLabel = wxEmptyString);
static bool Confirm(const wxString& prompt, const wxString& config_key, const wxString& title = "");
static bool Confirm(const wxString& prompt, const wxString& config_key, const wxString& affirmativeLabel, const wxString& negativeLabel, const wxString& title = "");
static void ResetAllDontAskAgain(void);

private:
Expand Down
2 changes: 1 addition & 1 deletion drift_tool.cpp
Expand Up @@ -747,7 +747,7 @@ wxWindow *DriftTool::CreateDriftToolWindow()
"Enter your camera pixel size on the Camera tab in the Brain.\n"
"\n"
"Would you like to run the drift tool anyway?"),
"/drift_tool_without_pixscale", _("Confirm"));
"/drift_tool_without_pixscale");

if (!confirmed)
{
Expand Down
32 changes: 22 additions & 10 deletions gear_dialog.cpp
Expand Up @@ -736,7 +736,9 @@ void GearDialog::UpdateButtonState(void)

void GearDialog::OnButtonConnectAll(wxCommandEvent& event)
{
OnButtonConnectCamera(event);
bool canceled = DoConnectCamera();
if (canceled)
return;
OnButtonConnectStepGuider(event);
OnButtonConnectScope(event);
OnButtonConnectAuxScope(event);
Expand Down Expand Up @@ -836,25 +838,27 @@ void GearDialog::OnButtonSetupCamera(wxCommandEvent& event)
m_pCamera->ShowPropertyDialog();
}

void GearDialog::OnButtonConnectCamera(wxCommandEvent& event)
bool GearDialog::DoConnectCamera(void)
{
int currProfileId = pConfig->GetCurrentProfileId();
wxString newCam = m_pCameras->GetStringSelection();
bool canceled = false;

try
{
if (m_pCamera == NULL)
{
throw ERROR_INFO("OnButtonConnectCamera called with m_pCamera == NULL");
throw ERROR_INFO("DoConnectCamera called with m_pCamera == NULL");
}

if (m_pCamera->Connected)
{
throw THROW_INFO("OnButtonConnectCamera: called when connected");
throw THROW_INFO("DoConnectCamera: called when connected");
}

wxString newCam = m_pCameras->GetStringSelection();
if (!m_camWarningIssued && m_lastCamera != _("None") && newCam != _("None") && m_lastCamera != newCam)
{
wxString darkName = pFrame->DarkLibFileName(currProfileId);
int currProfileId = pConfig->GetCurrentProfileId();
wxString darkName = MyFrame::DarkLibFileName(currProfileId);
wxString bpmName = DefectMap::DefectMapFileName(currProfileId);

// Can't use standard checks because we don't want to consider sensor-size
Expand All @@ -872,15 +876,16 @@ void GearDialog::OnButtonConnectCamera(wxCommandEvent& event)
m_pCameras->SetStringSelection(m_lastCamera);
wxCommandEvent dummy;
OnChoiceCamera(dummy);
throw THROW_INFO("OnButtonConnectCamera: user cancelled after camera-change warning");
canceled = true;
throw THROW_INFO("DoConnectCamera: user cancelled after camera-change warning");
}
}
}
pFrame->SetStatusText(_("Connecting to Camera ..."));

if (m_pCamera->Connect())
{
throw THROW_INFO("OnButtonConnectCamera: connect failed");
throw THROW_INFO("DoConnectCamera: connect failed");
}

Debug.AddLine("Connected Camera:" + m_pCamera->Name);
Expand Down Expand Up @@ -914,6 +919,13 @@ void GearDialog::OnButtonConnectCamera(wxCommandEvent& event)
}

UpdateButtonState();

return canceled;
}

void GearDialog::OnButtonConnectCamera(wxCommandEvent& event)
{
DoConnectCamera();
}

void GearDialog::OnButtonDisconnectCamera(wxCommandEvent& event)
Expand Down Expand Up @@ -1484,7 +1496,7 @@ bool GearDialog::IsEmptyProfile(void)
{
wxString lastCamera = pConfig->Profile.GetString("/camera/LastMenuchoice", _("None"));
wxString lastScope = pConfig->Profile.GetString("/scope/LastMenuChoice", _("None"));
return (lastCamera == _("None") || lastScope == _("None"));
return lastCamera == _("None") && lastScope == _("None");
}

void GearDialog::OnProfileChoice(wxCommandEvent& event)
Expand Down
1 change: 1 addition & 0 deletions gear_dialog.h
Expand Up @@ -131,6 +131,7 @@ class GearDialog : public wxDialog

void OnChoiceCamera(wxCommandEvent& event);
void OnButtonSetupCamera(wxCommandEvent& event);
bool DoConnectCamera(void);
void OnButtonConnectCamera(wxCommandEvent& event);
void OnButtonDisconnectCamera(wxCommandEvent& event);

Expand Down
2 changes: 1 addition & 1 deletion guider.cpp
Expand Up @@ -1470,7 +1470,7 @@ void Guider::DeleteAllBookmarks()
if (m_bookmarks.size())
{
bool confirmed = ConfirmDialog::Confirm(_("Are you sure you want to delete all Bookmarks?"),
"/delete_all_bookmarks_ok", _("Confirm"));
"/delete_all_bookmarks_ok");
if (confirmed)
{
m_bookmarks.clear();
Expand Down
36 changes: 13 additions & 23 deletions myframe.cpp
Expand Up @@ -452,7 +452,7 @@ void MyFrame::SetupMenuBar(void)
tools_menu->AppendCheckItem(MENU_LOG,_("Enable Guide &Log\tAlt-L"),_("Enable guide log file"));
tools_menu->AppendCheckItem(MENU_DEBUG,_("Enable Debug Log"),_("Enable debug log file"));
tools_menu->AppendCheckItem(MENU_LOGIMAGES,_("Enable Star Image Logging"),_("Enable logging of star images"));
tools_menu->AppendCheckItem(MENU_SERVER,_("Enable Server"),_("Enable / disable link to Nebulosity"));
tools_menu->AppendCheckItem(MENU_SERVER,_("Enable Server"),_("Enable PHD2 server capability"));
tools_menu->AppendCheckItem(EEGG_STICKY_LOCK,_("Sticky Lock Position"),_("Keep the same lock position when guiding starts"));

view_menu = new wxMenu();
Expand All @@ -472,12 +472,12 @@ void MyFrame::SetupMenuBar(void)
view_menu->AppendSeparator();
view_menu->Append(MENU_SLIT_OVERLAY_COORDS, _("Slit Position..."));
view_menu->AppendSeparator();
view_menu->Append(MENU_RESTORE_WINDOWS, _("Restore window positions"), _("Restore all windows to their default/docked positions"));
view_menu->Append(MENU_RESTORE_WINDOWS, _("Restore Window Positions"), _("Restore all windows to their default/docked positions"));

darks_menu = new wxMenu();
m_takeDarksMenuItem = darks_menu->Append(MENU_TAKEDARKS, _("Dark &Library..."), _("Build a dark library for this profile"));
m_refineDefMapMenuItem = darks_menu->Append(MENU_REFINEDEFECTMAP, _("Bad-pixel &Map..."), _("Adjust parameters to create or modify the bad-pixel map"));
m_importCamCalMenuItem = darks_menu->Append(MENU_IMPORTCAMCAL, _("Import from profile..."), _("Import existing dark library/bad-pixel map from a different profile"));
m_importCamCalMenuItem = darks_menu->Append(MENU_IMPORTCAMCAL, _("Import From Profile..."), _("Import existing dark library/bad-pixel map from a different profile"));
darks_menu->AppendSeparator();
m_useDarksMenuItem = darks_menu->AppendCheckItem(MENU_LOADDARK, _("Use &Dark Library"), _("Use the the dark library for this profile"));
m_useDefectMapMenuItem = darks_menu->AppendCheckItem(MENU_LOADDEFECTMAP, _("Use &Bad-pixel Map"), _("Use the bad-pixel map for this profile"));
Expand Down Expand Up @@ -798,7 +798,7 @@ void MyFrame::SetupToolBar()
MainToolbar->AddTool(BUTTON_GEAR, _("Equipment"), camera_bmp, _("Connect to equipment. Shift-click to reconnect the same equipment last connected."));
MainToolbar->AddTool(BUTTON_LOOP, _("Loop Exposure"), loop_bmp, _("Begin looping exposures for frame and focus"));
MainToolbar->AddTool(BUTTON_GUIDE, _("Guide"), guide_bmp, _("Begin guiding (PHD). Shift-click to force calibration."));
MainToolbar->AddTool(BUTTON_STOP, _("Stop"), stop_bmp, _("Abort the current action"));
MainToolbar->AddTool(BUTTON_STOP, _("Stop"), stop_bmp, _("Stop looping and guiding"));
MainToolbar->AddSeparator();
MainToolbar->AddControl(Dur_Choice, _("Exposure duration"));
MainToolbar->AddControl(Gamma_Slider, _("Gamma"));
Expand All @@ -808,6 +808,7 @@ void MyFrame::SetupToolBar()
MainToolbar->Realize();
MainToolbar->EnableTool(BUTTON_LOOP, false);
MainToolbar->EnableTool(BUTTON_GUIDE, false);
MainToolbar->EnableTool(BUTTON_STOP, false);
}

void MyFrame::UpdateCalibrationStatus(void)
Expand Down Expand Up @@ -925,6 +926,9 @@ void MyFrame::UpdateButtonsStatus(void)
if (cond_update_tool(MainToolbar, BUTTON_GEAR, !CaptureActive))
need_update = true;

if (cond_update_tool(MainToolbar, BUTTON_STOP, CaptureActive))
need_update = true;

bool dark_enabled = loop_enabled && !CaptureActive;
if (dark_enabled ^ m_takeDarksMenuItem->IsEnabled())
{
Expand Down Expand Up @@ -1840,7 +1844,7 @@ wxString MyFrame::DarkLibFileName(int profileId)
bool MyFrame::DarkLibExists(int profileId, bool showAlert)
{
bool bOk = false;
wxString fileName = DarkLibFileName(profileId);
wxString fileName = MyFrame::DarkLibFileName(profileId);

if (wxFileExists(fileName))
{
Expand Down Expand Up @@ -1909,7 +1913,7 @@ void MyFrame::CheckGeometry()
void MyFrame::SetDarkMenuState()
{
wxMenuItem *item = m_useDarksMenuItem;
bool haveDarkLib = DarkLibExists(pConfig->GetCurrentProfileId());
bool haveDarkLib = DarkLibExists(pConfig->GetCurrentProfileId(), true);
item->Enable(haveDarkLib);
if (!haveDarkLib)
item->Check(false);
Expand All @@ -1922,7 +1926,7 @@ void MyFrame::SetDarkMenuState()

void MyFrame::LoadDarkLibrary()
{
wxString filename = DarkLibFileName(pConfig->GetCurrentProfileId());
wxString filename = MyFrame::DarkLibFileName(pConfig->GetCurrentProfileId());

if (!pCamera || !pCamera->Connected)
{
Expand All @@ -1945,7 +1949,7 @@ void MyFrame::LoadDarkLibrary()

void MyFrame::SaveDarkLibrary(const wxString& note)
{
wxString filename = DarkLibFileName(pConfig->GetCurrentProfileId());
wxString filename = MyFrame::DarkLibFileName(pConfig->GetCurrentProfileId());

Debug.AddLine("saving dark library");

Expand All @@ -1955,24 +1959,10 @@ void MyFrame::SaveDarkLibrary(const wxString& note)
}
}

void MyFrame::LoadDefectMap()
{
DefectMap *defectMap = DefectMap::LoadDefectMap(pConfig->GetCurrentProfileId());
if (defectMap)
{
SetStatusText(_("Defect map loaded"));
pCamera->SetDefectMap(defectMap);
}
else
{
SetStatusText(_("Defect map not loaded"));
}
}

// Delete both the dark library file and any defect map file for this profile
void MyFrame::DeleteDarkLibraryFiles(int profileId)
{
wxString filename = DarkLibFileName(profileId);
wxString filename = MyFrame::DarkLibFileName(profileId);

if (wxFileExists(filename))
{
Expand Down
5 changes: 2 additions & 3 deletions myframe.h
Expand Up @@ -290,19 +290,18 @@ class MyFrame : public wxFrame
bool StartServer(bool state);
bool FlipRACal();
int RequestedExposureDuration();
void LoadDefectMap();
int GetFocalLength(void);
int GetLanguage(void);
bool GetAutoLoadCalibration(void);
void LoadCalibration(void);
int GetInstanceNumber() const { return m_instanceNumber; }
static wxString GetDefaultFileDir();
static wxString GetDarksDir();
bool DarkLibExists(int profileId, bool showAlert = true);
bool DarkLibExists(int profileId, bool showAlert);
void LoadDarkLibrary();
void SaveDarkLibrary(const wxString& note);
void DeleteDarkLibraryFiles(int profileID);
wxString DarkLibFileName(int profileId);
static wxString DarkLibFileName(int profileId);
void SetDarkMenuState();
void LoadDarkHandler(bool checkIt); // Use to also set menu item states
void LoadDefectMapHandler(bool checkIt);
Expand Down

0 comments on commit 4b43d29

Please sign in to comment.