30 #include <wx/textfile.h>
36 wxXmlResource::Get()->LoadDialog(
this, parent,
"choice_aspect_dlg");
37 m_aspectList = XRCCTRL(*
this,
"aspect_listbox", wxListBox);
69 if (selection != wxNOT_FOUND)
76 bool CheckInputs(wxWindow* parent, wxTextCtrl* labelCtrl, wxTextCtrl* aspectRatioCtrl,
double& value)
79 const wxString label = labelCtrl->GetValue().Trim(
true).Trim(
false);
80 if (label.IsEmpty() || label.Find(
separator) != wxNOT_FOUND)
83 wxMessageBox(_(
"You must provide a valid label."), _(
"Warning"), wxOK | wxICON_ERROR, parent);
87 wxString valueString = aspectRatioCtrl->GetValue();
88 int pos = valueString.Find(
":");
89 if (pos != wxNOT_FOUND)
94 double val1, val2 = 0;
95 if (valueString.Mid(0, pos).ToDouble(&val1) && valueString.Mid(pos + 1).ToDouble(&val2))
100 if (value > 1e-4 && value < 10000)
106 wxMessageBox(wxString::Format(_(
"The aspect ratio \"%s\" is not in the valid range."), aspectRatioCtrl->GetValue().c_str()), _(
"Warning"), wxOK | wxICON_ERROR, parent);
116 if (valueString.ToDouble(&value))
118 if (value > 1e-4 && value < 10000)
124 wxMessageBox(wxString::Format(_(
"The aspect ratio \"%s\" is not in the valid range."), aspectRatioCtrl->GetValue().c_str()), _(
"Warning"), wxOK | wxICON_ERROR, parent);
130 wxMessageBox(wxString::Format(_(
"The input \"%s\" is not a valid number."), aspectRatioCtrl->GetValue().c_str()), _(
"Warning"), wxOK | wxICON_ERROR, parent);
137 wxXmlResource::Get()->LoadDialog(&dlg,
this,
"add_aspect_dlg");
138 wxTextCtrl* labelCtrl = XRCCTRL(dlg,
"aspect_label_textctrl", wxTextCtrl);
139 wxTextCtrl* aspectRatioCtrl = XRCCTRL(dlg,
"aspect_ratio_textctrl", wxTextCtrl);
140 aspectRatioCtrl->SetValue(
"2:1");
142 dlg.Bind(wxEVT_COMMAND_BUTTON_CLICKED, [labelCtrl, aspectRatioCtrl, &dlg](wxCommandEvent &e)
145 if (
CheckInputs(&dlg, labelCtrl, aspectRatioCtrl, val))
147 dlg.EndModal(wxID_OK);
149 }, XRCID(
"wxID_OK"));
150 if (dlg.ShowModal() == wxID_OK)
153 if (
CheckInputs(&dlg, labelCtrl, aspectRatioCtrl, value))
190 XRCCTRL(*
this,
"wxID_OK", wxButton)->Enable(selection != wxNOT_FOUND);
191 XRCCTRL(*
this,
"remove_aspect_button", wxButton)->Enable(selection != wxNOT_FOUND &&
m_aspectRatioStrings.size() > 1);
200 const auto addAspect = [
this](
const double v1,
const double v2)
225 if (textFile.Exists())
230 for (wxString
line = textFile.GetFirstLine(); !textFile.Eof();
line = textFile.GetNextLine())
235 if (pos != wxNOT_FOUND && pos > 0 && pos +
separator.length() <
line.length())
237 const wxString aspectRatio =
line.Mid(pos +
separator.length());
238 if (aspectRatio.IsEmpty())
244 if (aspectRatio.ToCDouble(&ratio))
257 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
void StoreFramePosition(wxTopLevelWindow *frame, const wxString &basename)
Store window size and position in configfile/registry.
Definition of dialog for selecting and editing aspect ratios of crop.
void RestoreFramePosition(wxTopLevelWindow *frame, const wxString &basename)
Restore window size and position from configfile/registry.
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
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 ListBoxSelectionChanged()
implementation of activation/deactivation of buttons if necessary