30 #include <wx/textfile.h>
37 wxXmlResource::Get()->LoadDialog(
this, parent,
"choice_aspect_dlg");
38 m_aspectList = XRCCTRL(*
this,
"aspect_listbox", wxListBox);
70 if (selection != wxNOT_FOUND)
77 bool CheckInputs(wxWindow* parent, wxTextCtrl* labelCtrl, wxTextCtrl* aspectRatioCtrl,
double& value)
80 const wxString label = labelCtrl->GetValue().Trim(
true).Trim(
false);
81 if (label.IsEmpty() || label.Find(
separator) != wxNOT_FOUND)
84 wxMessageBox(_(
"You must provide a valid label."), _(
"Warning"), wxOK | wxICON_ERROR, parent);
88 wxString valueString = aspectRatioCtrl->GetValue();
89 int pos = valueString.Find(
":");
90 if (pos != wxNOT_FOUND)
95 double val1, val2 = 0;
96 if (valueString.Mid(0, pos).ToDouble(&val1) && valueString.Mid(pos + 1).ToDouble(&val2))
101 if (value > 1e-4 && value < 10000)
107 wxMessageBox(wxString::Format(_(
"The aspect ratio \"%s\" is not in the valid range."), aspectRatioCtrl->GetValue().c_str()), _(
"Warning"), wxOK | wxICON_ERROR, parent);
117 if (valueString.ToDouble(&value))
119 if (value > 1e-4 && value < 10000)
125 wxMessageBox(wxString::Format(_(
"The aspect ratio \"%s\" is not in the valid range."), aspectRatioCtrl->GetValue().c_str()), _(
"Warning"), wxOK | wxICON_ERROR, parent);
131 wxMessageBox(wxString::Format(_(
"The input \"%s\" is not a valid number."), aspectRatioCtrl->GetValue().c_str()), _(
"Warning"), wxOK | wxICON_ERROR, parent);
138 wxXmlResource::Get()->LoadDialog(&dlg,
this,
"add_aspect_dlg");
139 wxTextCtrl* labelCtrl = XRCCTRL(dlg,
"aspect_label_textctrl", wxTextCtrl);
140 wxTextCtrl* aspectRatioCtrl = XRCCTRL(dlg,
"aspect_ratio_textctrl", wxTextCtrl);
141 aspectRatioCtrl->SetValue(
"2:1");
143 dlg.Bind(wxEVT_COMMAND_BUTTON_CLICKED, [labelCtrl, aspectRatioCtrl, &dlg](wxCommandEvent &e)
146 if (
CheckInputs(&dlg, labelCtrl, aspectRatioCtrl, val))
148 dlg.EndModal(wxID_OK);
150 }, XRCID(
"wxID_OK"));
151 if (dlg.ShowModal() == wxID_OK)
154 if (
CheckInputs(&dlg, labelCtrl, aspectRatioCtrl, value))
191 XRCCTRL(*
this,
"wxID_OK", wxButton)->Enable(selection != wxNOT_FOUND);
192 XRCCTRL(*
this,
"remove_aspect_button", wxButton)->Enable(selection != wxNOT_FOUND &&
m_aspectRatioStrings.size() > 1);
201 const auto addAspect = [
this](
const double v1,
const double v2)
226 if (textFile.Exists())
231 for (wxString
line = textFile.GetFirstLine(); !textFile.Eof();
line = textFile.GetNextLine())
236 if (pos != wxNOT_FOUND && pos > 0 && pos +
separator.length() <
line.length())
238 const wxString aspectRatio =
line.Mid(pos +
separator.length());
239 if (aspectRatio.IsEmpty())
245 if (aspectRatio.ToCDouble(&ratio))
258 if (textFile.Exists())
bool CheckInputs(wxWindow *parent, wxTextCtrl *labelCtrl, wxTextCtrl *aspectRatioCtrl, double &value)
check the input of the add aspect ratio dialog
std::vector< double > m_aspectRatios
vector with values of all aspect ratios, ratio=width/height
static const wxString separator
void OnListBoxSelect(wxCommandEvent &e)
event handler for activation/deactivation of buttons if necessary
void OnOk(wxCommandEvent &e)
handler for Ok, check for valid inputs
wxArrayString m_aspectRatioStrings
array with names of all aspect ratios
void LoadAspectRatios()
load aspect ratios from file
Definition of dialog for selecting and editing aspect ratios of crop.
void SaveAspectRatios()
save the aspect ratios to the file
double GetSelectedAspectRatio() const
returns the selected aspect ratio
void OnRemoveAspectRatio(wxCommandEvent &e)
handler for removing selected aspect ratio
void StoreFramePosition(wxTopLevelWindow *frame, const wxString &basename)
include file for the hugin project
void OnAddAspectRatio(wxCommandEvent &e)
handler for adding new aspect ratio setting
std::string GetUserAppDataDir()
returns the directory for user specific Hugin settings, e.g.
wxListBox * m_aspectList
pointer to wxListBox of aspect ratios
wxFileName GetAspectRatioFilename() const
returns the file name for the list of aspect ratios
~SelectAspectRatioDialog()
destructor, save position and list of aspect ratios
SelectAspectRatioDialog(wxWindow *parent)
constructor, build dialog and load settings from file
void FillListBox()
read the settings from the file and add them to the list box if the file does not exist...
void RestoreFramePosition(wxTopLevelWindow *frame, const wxString &basename)
void ListBoxSelectionChanged()
implementation of activation/deactivation of buttons if necessary