Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HDRMergeOptionDialog.cpp
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
2 
13 /* This is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public
15  * License as published by the Free Software Foundation; either
16  * version 2 of the License, or (at your option) any later version.
17  *
18  * This software is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  * Lesser General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public
24  * License along with this software. If not, see
25  * <http://www.gnu.org/licenses/>.
26  *
27  */
28 
30 #include "base_wx/wxPlatform.h"
31 #ifdef __APPLE__
32 #include "panoinc_WX.h"
33 #include "panoinc.h"
34 #endif
35 #include <hugin/config_defaults.h>
36 #include "hugin/huginApp.h"
37 
38 // somewhere SetDesc gets defined.. this breaks wx/cmdline.h on OSX
39 #ifdef SetDesc
40 #undef SetDesc
41 #endif
42 
43 #include <wx/cmdline.h>
44 
46 {
47  wxXmlResource::Get()->LoadDialog(this, parent, wxT("hdrmerge_options_dialog"));
48 
49  m_mode=XRCCTRL(*this,"hdrmerge_option_mode",wxChoice);
50  m_mode->Bind(wxEVT_CHOICE, &HDRMergeOptionsDialog::OnModeChanged, this);
51  m_panel_avg=XRCCTRL(*this,"hdrmerge_option_panel_avg",wxPanel);
52  m_panel_avgslow=XRCCTRL(*this,"hdrmerge_option_panel_avgslow",wxPanel);
53  m_panel_khan=XRCCTRL(*this,"hdrmerge_option_panel_khan",wxPanel);
54  m_option_c=XRCCTRL(*this,"hdrmerge_option_c",wxCheckBox);
55  m_khan_iter=XRCCTRL(*this,"hdrmerge_option_khan_iter",wxSpinCtrl);
56  m_khan_iter->SetRange(1,100);
57  m_khan_sigma=XRCCTRL(*this,"hdrmerge_option_khan_sigma",wxTextCtrl);
58  m_option_khan_af=XRCCTRL(*this,"hdrmerge_option_khan_af",wxCheckBox);
59  m_option_khan_ag=XRCCTRL(*this,"hdrmerge_option_khan_ag",wxCheckBox);
60  m_option_khan_am=XRCCTRL(*this,"hdrmerge_option_khan_am",wxCheckBox);
61  this->CenterOnParent();
62  Bind(wxEVT_BUTTON, &HDRMergeOptionsDialog::OnOk, this, wxID_OK);
63 };
64 
66 {
67  m_cmd=cmd;
68  if (m_cmd.IsEmpty())
70  m_cmd.LowerCase();
71  // parse arguments
72  static const wxCmdLineEntryDesc cmdLineDesc[] =
73  {
74  { wxCMD_LINE_OPTION, "m", NULL, NULL, wxCMD_LINE_VAL_STRING },
75  { wxCMD_LINE_SWITCH, "c", NULL, NULL},
76  { wxCMD_LINE_OPTION, "i", NULL, NULL, wxCMD_LINE_VAL_NUMBER },
77  { wxCMD_LINE_OPTION, "s", NULL, NULL, wxCMD_LINE_VAL_STRING },
78  { wxCMD_LINE_OPTION, "a", NULL, NULL, wxCMD_LINE_VAL_STRING },
79  { wxCMD_LINE_NONE }
80  };
81  wxCmdLineParser parser;
82  parser.SetDesc(cmdLineDesc);
83  parser.SetCmdLine(m_cmd);
84  parser.Parse(false);
85  wxString param;
86  if(parser.Found(wxT("m"),&param))
87  {
88  if(param.CmpNoCase(wxT("avg_slow"))==0)
89  m_mode->SetSelection(1);
90  else
91  {
92  if(param.CmpNoCase(wxT("khan"))==0)
93  m_mode->SetSelection(2);
94  else
95  m_mode->SetSelection(0);
96  };
97  }
98  else
99  m_mode->SetSelection(0);
100  m_option_c->SetValue(parser.Found(wxT("c")));
101  long i;
102  if(parser.Found(wxT("i"),&i))
103  m_khan_iter->SetValue(i);
104  else
105  m_khan_iter->SetValue(4);
106  if(parser.Found(wxT("s"),&param))
107  {
108  //change locale for correct numeric output
109  char * p = setlocale(LC_NUMERIC,NULL);
110  char * old_locale = strdup(p);
111  setlocale(LC_NUMERIC,"C");
112  double sigma=0.0;
113  param.ToDouble(&sigma);
114  //reset locale
115  setlocale(LC_NUMERIC,old_locale);
116  free(old_locale);
117  //using current locale for value in GUI
118  m_khan_sigma->SetValue(wxString::Format(wxT("%.2f"),sigma));
119  }
120  else
121  m_khan_sigma->SetValue(wxT("30"));
122  if(parser.Found(wxT("a"),&param))
123  {
124  m_option_khan_af->SetValue(param.Contains(wxT("f")));
125  m_option_khan_ag->SetValue(param.Contains(wxT("g")));
126  m_option_khan_am->SetValue(param.Contains(wxT("m")));
127  }
128  wxCommandEvent dummy;
129  OnModeChanged(dummy);
130 };
131 
133 {
134  int selection=m_mode->GetSelection();
135  m_cmd.Clear();
136  bool correct_input=true;
137  double i = 0;
138  wxString errorstring(_("Invalid input\n"));
139  switch(selection)
140  {
141  case 0:
142  m_cmd.Append(wxT("-m avg"));
143  if(m_option_c->IsChecked())
144  m_cmd.Append(wxT(" -c"));
145  break;
146  case 1:
147  m_cmd.Append(wxT("-m avg_slow"));
148  break;
149  case 2:
150  m_cmd.Append(wxT("-m khan"));
151  if(m_khan_iter->GetValue())
152  {
153  m_cmd.Append(wxString::Format(wxT(" -i %d"),m_khan_iter->GetValue()));
154  }
155  else
156  {
157  correct_input=false;
158  errorstring.Append(wxString::Format(_("Input \"%s\" for %s is not a valid number\n"),
159  m_khan_iter->GetValue(),_("Iteration")));
160  };
161  if(m_khan_sigma->GetValue().ToDouble(&i))
162  {
163  //change locale for correct numeric output
164  char * p = setlocale(LC_NUMERIC,NULL);
165  char * old_locale = strdup(p);
166  setlocale(LC_NUMERIC,"C");
167  m_cmd.Append(wxString::Format(wxT(" -s %f"),i));
168  //reset locale
169  setlocale(LC_NUMERIC,old_locale);
170  free(old_locale);
171  }
172  else
173  {
174  correct_input=false;
175  errorstring.Append(wxString::Format(_("Input \"%s\" for %s is not a valid number\n"),
176  m_khan_iter->GetValue(),_("Sigma")));
177  };
178  if(m_option_khan_af->IsChecked() || m_option_khan_ag->IsChecked() ||
179  m_option_khan_am->IsChecked())
180  {
181  m_cmd.Append(wxT(" -a "));
182  if(m_option_khan_af->IsChecked())
183  m_cmd.Append(wxT("f"));
184  if(m_option_khan_ag->IsChecked())
185  m_cmd.Append(wxT("g"));
186  if(m_option_khan_am->IsChecked())
187  m_cmd.Append(wxT("m"));
188  }
189  break;
190  };
191  if(!correct_input)
192  wxMessageBox(errorstring,_("Wrong input"),wxOK | wxICON_INFORMATION);
193  return correct_input;
194 };
195 
196 void HDRMergeOptionsDialog::OnModeChanged(wxCommandEvent & e)
197 {
198  int selection=m_mode->GetSelection();
199  m_panel_avg->Show(selection==0);
200  m_panel_avgslow->Show(selection==1);
201  m_panel_khan->Show(selection==2);
202  GetSizer()->Fit(this);
203 };
204 
205 void HDRMergeOptionsDialog::OnOk(wxCommandEvent & e)
206 {
208  this->EndModal(wxOK);
209 };
210 
void SetCommandLineArgument(wxString cmd)
sets the currents state of the hdrmerge options
include file for the hugin project
static double sigma
Definition of dialog for hdrmerge options.
void OnModeChanged(wxCommandEvent &e)
event handler when user selected different mode, refresh advanced option display
HDRMergeOptionsDialog(wxWindow *parent)
Constructor, read from xrc ressource.
#define HUGIN_HDRMERGE_ARGS
include file for the hugin project
void OnOk(wxCommandEvent &e)
check inputs
platform/compiler specific stuff.