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 
45 BEGIN_EVENT_TABLE(HDRMergeOptionsDialog,wxDialog)
46 EVT_CHOICE(XRCID("hdrmerge_option_mode"),HDRMergeOptionsDialog::OnModeChanged)
47 EVT_BUTTON(wxID_OK, HDRMergeOptionsDialog::OnOk)
49 
51 {
52  wxXmlResource::Get()->LoadDialog(this, parent, wxT("hdrmerge_options_dialog"));
53 
54 #ifdef __WXMSW__
55  wxIconBundle myIcons(huginApp::Get()->GetXRCPath() + wxT("data/hugin.ico"),wxBITMAP_TYPE_ICO);
56  SetIcons(myIcons);
57 #else
58  wxIcon myIcon(huginApp::Get()->GetXRCPath() + wxT("data/hugin.png"),wxBITMAP_TYPE_PNG);
59  SetIcon(myIcon);
60 #endif
61 
62  m_mode=XRCCTRL(*this,"hdrmerge_option_mode",wxChoice);
63  m_panel_avg=XRCCTRL(*this,"hdrmerge_option_panel_avg",wxPanel);
64  m_panel_avgslow=XRCCTRL(*this,"hdrmerge_option_panel_avgslow",wxPanel);
65  m_panel_khan=XRCCTRL(*this,"hdrmerge_option_panel_khan",wxPanel);
66  m_option_c=XRCCTRL(*this,"hdrmerge_option_c",wxCheckBox);
67  m_khan_iter=XRCCTRL(*this,"hdrmerge_option_khan_iter",wxSpinCtrl);
68  m_khan_iter->SetRange(1,100);
69  m_khan_sigma=XRCCTRL(*this,"hdrmerge_option_khan_sigma",wxTextCtrl);
70  m_option_khan_af=XRCCTRL(*this,"hdrmerge_option_khan_af",wxCheckBox);
71  m_option_khan_ag=XRCCTRL(*this,"hdrmerge_option_khan_ag",wxCheckBox);
72  m_option_khan_am=XRCCTRL(*this,"hdrmerge_option_khan_am",wxCheckBox);
73  this->CenterOnParent();
74 };
75 
77 {
78  m_cmd=cmd;
79  if (m_cmd.IsEmpty())
81  m_cmd.LowerCase();
82  // parse arguments
83  static const wxCmdLineEntryDesc cmdLineDesc[] =
84  {
85  { wxCMD_LINE_OPTION, "m", NULL, NULL, wxCMD_LINE_VAL_STRING },
86  { wxCMD_LINE_SWITCH, "c", NULL, NULL},
87  { wxCMD_LINE_OPTION, "i", NULL, NULL, wxCMD_LINE_VAL_NUMBER },
88  { wxCMD_LINE_OPTION, "s", NULL, NULL, wxCMD_LINE_VAL_STRING },
89  { wxCMD_LINE_OPTION, "a", NULL, NULL, wxCMD_LINE_VAL_STRING },
90  { wxCMD_LINE_NONE }
91  };
92  wxCmdLineParser parser;
93  parser.SetDesc(cmdLineDesc);
94  parser.SetCmdLine(m_cmd);
95  parser.Parse(false);
96  wxString param;
97  if(parser.Found(wxT("m"),&param))
98  {
99  if(param.CmpNoCase(wxT("avg_slow"))==0)
100  m_mode->SetSelection(1);
101  else
102  {
103  if(param.CmpNoCase(wxT("khan"))==0)
104  m_mode->SetSelection(2);
105  else
106  m_mode->SetSelection(0);
107  };
108  }
109  else
110  m_mode->SetSelection(0);
111  m_option_c->SetValue(parser.Found(wxT("c")));
112  long i;
113  if(parser.Found(wxT("i"),&i))
114  m_khan_iter->SetValue(i);
115  else
116  m_khan_iter->SetValue(4);
117  if(parser.Found(wxT("s"),&param))
118  {
119  //change locale for correct numeric output
120  char * p = setlocale(LC_NUMERIC,NULL);
121  char * old_locale = strdup(p);
122  setlocale(LC_NUMERIC,"C");
123  double sigma=0.0;
124  param.ToDouble(&sigma);
125  //reset locale
126  setlocale(LC_NUMERIC,old_locale);
127  free(old_locale);
128  //using current locale for value in GUI
129  m_khan_sigma->SetValue(wxString::Format(wxT("%.2f"),sigma));
130  }
131  else
132  m_khan_sigma->SetValue(wxT("30"));
133  if(parser.Found(wxT("a"),&param))
134  {
135  m_option_khan_af->SetValue(param.Contains(wxT("f")));
136  m_option_khan_ag->SetValue(param.Contains(wxT("g")));
137  m_option_khan_am->SetValue(param.Contains(wxT("m")));
138  }
139  wxCommandEvent dummy;
140  OnModeChanged(dummy);
141 };
142 
144 {
145  int selection=m_mode->GetSelection();
146  m_cmd.Clear();
147  bool correct_input=true;
148  double i = 0;
149  wxString errorstring(_("Invalid input\n"));
150  switch(selection)
151  {
152  case 0:
153  m_cmd.Append(wxT("-m avg"));
154  if(m_option_c->IsChecked())
155  m_cmd.Append(wxT(" -c"));
156  break;
157  case 1:
158  m_cmd.Append(wxT("-m avg_slow"));
159  break;
160  case 2:
161  m_cmd.Append(wxT("-m khan"));
162  if(m_khan_iter->GetValue())
163  {
164  m_cmd.Append(wxString::Format(wxT(" -i %d"),m_khan_iter->GetValue()));
165  }
166  else
167  {
168  correct_input=false;
169  errorstring.Append(wxString::Format(_("Input \"%s\" for %s is not a valid number\n"),
170  m_khan_iter->GetValue(),_("Iteration")));
171  };
172  if(m_khan_sigma->GetValue().ToDouble(&i))
173  {
174  //change locale for correct numeric output
175  char * p = setlocale(LC_NUMERIC,NULL);
176  char * old_locale = strdup(p);
177  setlocale(LC_NUMERIC,"C");
178  m_cmd.Append(wxString::Format(wxT(" -s %f"),i));
179  //reset locale
180  setlocale(LC_NUMERIC,old_locale);
181  free(old_locale);
182  }
183  else
184  {
185  correct_input=false;
186  errorstring.Append(wxString::Format(_("Input \"%s\" for %s is not a valid number\n"),
187  m_khan_iter->GetValue(),_("Sigma")));
188  };
189  if(m_option_khan_af->IsChecked() || m_option_khan_ag->IsChecked() ||
190  m_option_khan_am->IsChecked())
191  {
192  m_cmd.Append(wxT(" -a "));
193  if(m_option_khan_af->IsChecked())
194  m_cmd.Append(wxT("f"));
195  if(m_option_khan_ag->IsChecked())
196  m_cmd.Append(wxT("g"));
197  if(m_option_khan_am->IsChecked())
198  m_cmd.Append(wxT("m"));
199  }
200  break;
201  };
202  if(!correct_input)
203  wxMessageBox(errorstring,_("Wrong input"),wxOK | wxICON_INFORMATION);
204  return correct_input;
205 };
206 
207 void HDRMergeOptionsDialog::OnModeChanged(wxCommandEvent & e)
208 {
209  int selection=m_mode->GetSelection();
210  m_panel_avg->Show(selection==0);
211  m_panel_avgslow->Show(selection==1);
212  m_panel_khan->Show(selection==2);
213  GetSizer()->Fit(this);
214 };
215 
216 void HDRMergeOptionsDialog::OnOk(wxCommandEvent & e)
217 {
219  this->EndModal(wxOK);
220 };
221 
Dialog for reset panorama settings.
void SetCommandLineArgument(wxString cmd)
sets the currents state of the hdrmerge options
END_EVENT_TABLE()
include file for the hugin project
static huginApp * Get()
hack.. kind of a pseudo singleton...
Definition: huginApp.cpp:649
static double sigma
Definition of dialog for hdrmerge options.
void OnModeChanged(wxCommandEvent &e)
event handler when user selected different mode, refresh advanced option display
#define HUGIN_HDRMERGE_ARGS
include file for the hugin project
void OnOk(wxCommandEvent &e)
check inputs
platform/compiler specific stuff.