30 #include <wx/textfile.h>
36 wxXmlResource::Get()->LoadDialog(
this, parent,
"choice_aspect_dlg");
38 wxIconBundle myIcons(
huginApp::Get()->GetXRCPath() +
"data/hugin.ico", wxBITMAP_TYPE_ICO);
41 wxIcon myIcon(
huginApp::Get()->GetXRCPath() +
"data/hugin.png", wxBITMAP_TYPE_PNG);
44 m_aspectList = XRCCTRL(*
this,
"aspect_listbox", wxListBox);
76 if (selection != wxNOT_FOUND)
83 bool CheckInputs(wxWindow* parent, wxTextCtrl* labelCtrl, wxTextCtrl* aspectRatioCtrl,
double& value)
86 const wxString label = labelCtrl->GetValue().Trim(
true).Trim(
false);
87 if (label.IsEmpty() || label.Find(
separator) != wxNOT_FOUND)
90 wxMessageBox(_(
"You must provide a valid label."), _(
"Warning"), wxOK | wxICON_ERROR, parent);
94 wxString valueString = aspectRatioCtrl->GetValue();
95 int pos = valueString.Find(
":");
96 if (pos != wxNOT_FOUND)
101 double val1, val2 = 0;
102 if (valueString.Mid(0, pos).ToDouble(&val1) && valueString.Mid(pos + 1).ToDouble(&val2))
107 if (value > 1e-4 && value < 10000)
113 wxMessageBox(wxString::Format(_(
"The aspect ratio \"%s\" is not in the valid range."), aspectRatioCtrl->GetValue().c_str()), _(
"Warning"), wxOK | wxICON_ERROR, parent);
123 if (valueString.ToDouble(&value))
125 if (value > 1e-4 && value < 10000)
131 wxMessageBox(wxString::Format(_(
"The aspect ratio \"%s\" is not in the valid range."), aspectRatioCtrl->GetValue().c_str()), _(
"Warning"), wxOK | wxICON_ERROR, parent);
137 wxMessageBox(wxString::Format(_(
"The input \"%s\" is not a valid number."), aspectRatioCtrl->GetValue().c_str()), _(
"Warning"), wxOK | wxICON_ERROR, parent);
144 wxXmlResource::Get()->LoadDialog(&dlg,
this,
"add_aspect_dlg");
145 wxTextCtrl* labelCtrl = XRCCTRL(dlg,
"aspect_label_textctrl", wxTextCtrl);
146 wxTextCtrl* aspectRatioCtrl = XRCCTRL(dlg,
"aspect_ratio_textctrl", wxTextCtrl);
147 aspectRatioCtrl->SetValue(
"2:1");
149 dlg.Bind(wxEVT_COMMAND_BUTTON_CLICKED, [labelCtrl, aspectRatioCtrl, &dlg](wxCommandEvent &e)
152 if (
CheckInputs(&dlg, labelCtrl, aspectRatioCtrl, val))
154 dlg.EndModal(wxID_OK);
156 }, XRCID(
"wxID_OK"));
157 if (dlg.ShowModal() == wxID_OK)
160 if (
CheckInputs(&dlg, labelCtrl, aspectRatioCtrl, value))
197 XRCCTRL(*
this,
"wxID_OK", wxButton)->Enable(selection != wxNOT_FOUND);
198 XRCCTRL(*
this,
"remove_aspect_button", wxButton)->Enable(selection != wxNOT_FOUND &&
m_aspectRatioStrings.size() > 1);
207 const auto addAspect = [
this](
const double v1,
const double v2)
232 if (textFile.Exists())
237 for (wxString
line = textFile.GetFirstLine(); !textFile.Eof();
line = textFile.GetNextLine())
242 if (pos != wxNOT_FOUND && pos > 0 && pos +
separator.length() <
line.length())
244 const wxString aspectRatio =
line.Mid(pos +
separator.length());
245 if (aspectRatio.IsEmpty())
251 if (aspectRatio.ToCDouble(&ratio))
264 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
static huginApp * Get()
hack.. kind of a pseudo singleton...
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