Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CPDetectorDialog.cpp
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
2 
12 /* This is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public
14  * License as published by the Free Software Foundation; either
15  * version 2 of the License, or (at your option) any later version.
16  *
17  * This software is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  * Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public
23  * License along with this software. If not, see
24  * <http://www.gnu.org/licenses/>.
25  *
26  */
27 
28 #ifdef _WIN32
29 #include "wx/msw/wrapwin.h"
30  // Mingw define still DIFFERENCE, which conflicts with vigra, so disable it
31 #undef DIFFERENCE
32 #endif
33 #include "hugin/CPDetectorDialog.h"
34 #include "hugin_config.h"
35 #include "base_wx/huginConfig.h"
36 #include "hugin/config_defaults.h"
37 #include "hugin/huginApp.h"
38 
39 #if defined MAC_SELF_CONTAINED_BUNDLE
40  #include "base_wx/platform.h"
41  #include <wx/dir.h>
42  #include <CoreFoundation/CFBundle.h>
43 #endif
44 
45 // dialog for showing settings of one autopano setting
46 
47 BEGIN_EVENT_TABLE(CPDetectorDialog,wxDialog)
48  EVT_BUTTON(wxID_OK, CPDetectorDialog::OnOk)
49  EVT_BUTTON(XRCID("prefs_cpdetector_program_select"),CPDetectorDialog::OnSelectPath)
50  EVT_BUTTON(XRCID("prefs_cpdetector_program_descriptor_select"),CPDetectorDialog::OnSelectPathDescriptor)
51  EVT_BUTTON(XRCID("prefs_cpdetector_program_matcher_select"),CPDetectorDialog::OnSelectPathMatcher)
52  EVT_BUTTON(XRCID("prefs_cpdetector_program_stack_select"),CPDetectorDialog::OnSelectPathStack)
53  EVT_CHOICE(XRCID("prefs_cpdetector_type"),CPDetectorDialog::OnTypeChange)
54  EVT_CHOICEBOOK_PAGE_CHANGING(XRCID("choicebook_steps"),CPDetectorDialog::OnStepChanging)
56 
58 {
59  wxXmlResource::Get()->LoadDialog(this, parent, wxT("cpdetector_dialog"));
60 #ifdef __WXMSW__
61  wxIconBundle myIcons(huginApp::Get()->GetXRCPath() + wxT("data/hugin.ico"),wxBITMAP_TYPE_ICO);
62  SetIcons(myIcons);
63 #else
64  wxIcon myIcon(huginApp::Get()->GetXRCPath() + wxT("data/hugin.png"),wxBITMAP_TYPE_PNG);
65  SetIcon(myIcon);
66 #endif
67 
68 
69  //restore frame position and size
70  RestoreFramePosition(this,wxT("CPDetectorDialog"));
71 
72  m_edit_desc = XRCCTRL(*this, "prefs_cpdetector_desc", wxTextCtrl);
73  m_edit_prog = XRCCTRL(*this, "prefs_cpdetector_program", wxTextCtrl);
74  m_edit_args = XRCCTRL(*this, "prefs_cpdetector_args", wxTextCtrl);
75  m_label_args_cleanup = XRCCTRL(*this, "prefs_cpdetector_args_label_cleanup", wxStaticText);
76  m_edit_args_cleanup = XRCCTRL(*this, "prefs_cpdetector_args_cleanup", wxTextCtrl);
77  m_edit_prog_descriptor = XRCCTRL(*this, "prefs_cpdetector_program_descriptor", wxTextCtrl);
78  m_edit_args_descriptor = XRCCTRL(*this, "prefs_cpdetector_args_descriptor", wxTextCtrl);
79  m_edit_prog_matcher = XRCCTRL(*this, "prefs_cpdetector_program_matcher", wxTextCtrl);
80  m_edit_args_matcher = XRCCTRL(*this, "prefs_cpdetector_args_matcher", wxTextCtrl);
81  m_edit_prog_stack = XRCCTRL(*this, "prefs_cpdetector_program_stack", wxTextCtrl);
82  m_edit_args_stack = XRCCTRL(*this, "prefs_cpdetector_args_stack", wxTextCtrl);
83  m_check_option = XRCCTRL(*this, "prefs_cpdetector_option", wxCheckBox);
84  m_cpdetector_type = XRCCTRL(*this, "prefs_cpdetector_type", wxChoice);
85  m_choice_step = XRCCTRL(*this, "choicebook_steps", wxChoicebook);
86  // enable auto completion
87  m_edit_prog->AutoCompleteFileNames();
88  m_edit_prog_descriptor->AutoCompleteFileNames();
89  m_edit_prog_matcher->AutoCompleteFileNames();
90  m_edit_prog_stack->AutoCompleteFileNames();
91  m_cpdetector_type->SetSelection(1);
92  ChangeType();
93 };
94 
96 {
97  StoreFramePosition(this,wxT("CPDetectorDialog"));
98 };
99 
100 void CPDetectorDialog::OnOk(wxCommandEvent & e)
101 {
102 #ifdef __WXMAC__
103  if(m_cpdetector_type->GetSelection()==0)
104  {
105  wxMessageBox(_("Autopano from http://autopano.kolor.com is not available for OS X"),
106  _("Using Autopano-Sift instead"),wxOK|wxICON_EXCLAMATION, this);
107  m_cpdetector_type->SetSelection(1);
108  };
109 #endif
110  bool valid=true;
111  valid=valid && (m_edit_desc->GetValue().Trim().Len()>0);
112  if(m_choice_step->GetSelection()==0)
113  {
114  //detector with one step
115  valid=valid && (m_edit_prog->GetValue().Trim().Len()>0);
116  valid=valid && (m_edit_args->GetValue().Trim().Len()>0);
117  }
118  else
119  {
120  //detector with two steps
121  valid=valid && (m_edit_prog_descriptor->GetValue().Trim().Len()>0);
122  valid=valid && (m_edit_prog_matcher->GetValue().Trim().Len()>0);
123  valid=valid && (m_edit_args_descriptor->GetValue().Trim().Len()>0);
124  valid=valid && (m_edit_args_matcher->GetValue().Trim().Len()>0);
125  };
127  if(m_edit_prog_stack->GetValue().Trim().Len()>0)
128  valid=valid && (m_edit_args_stack->GetValue().Trim().Len()>0);
129  if(valid)
130  this->EndModal(wxOK);
131  else
132  wxMessageBox(_("At least one input field is empty.\nPlease check your inputs."),
133  _("Warning"),wxOK | wxICON_ERROR,this);
134 };
135 
137 {
138  m_edit_desc->SetValue(cpdet_config->settings[index].GetCPDetectorDesc());
139  //program names and arguments
140  if(cpdet_config->settings[index].IsTwoStepDetector())
141  {
142  m_choice_step->SetSelection(1);
143  m_edit_prog_descriptor->SetValue(cpdet_config->settings[index].GetProg());
144  m_edit_prog_matcher->SetValue(cpdet_config->settings[index].GetProgMatcher());
145  m_edit_args_descriptor->SetValue(cpdet_config->settings[index].GetArgs());
146  m_edit_args_matcher->SetValue(cpdet_config->settings[index].GetArgsMatcher());
147  }
148  else
149  {
150  m_choice_step->SetSelection(0);
151  m_edit_prog->SetValue(cpdet_config->settings[index].GetProg());
152  m_edit_args->SetValue(cpdet_config->settings[index].GetArgs());
153  if(cpdet_config->settings[index].IsCleanupPossible())
154  {
155  m_edit_args_cleanup->SetValue(cpdet_config->settings[index].GetArgsCleanup());
156  };
157  };
158  if(cpdet_config->settings[index].ContainsStacks())
159  {
160  m_edit_prog_stack->SetValue(cpdet_config->settings[index].GetProgStack());
161  m_edit_args_stack->SetValue(cpdet_config->settings[index].GetArgsStack());
162  };
163  m_cpdetector_type->SetSelection(cpdet_config->settings[index].GetType());
164  m_check_option->SetValue(cpdet_config->settings[index].GetOption());
165  ChangeType();
166 };
167 
169 {
170  cpdet_config->settings[index].SetCPDetectorDesc(m_edit_desc->GetValue().Trim());
171  cpdet_config->settings[index].SetType((CPDetectorType)m_cpdetector_type->GetSelection());
172  if(m_choice_step->GetSelection()==0)
173  {
174  cpdet_config->settings[index].SetProg(m_edit_prog->GetValue().Trim());
175  cpdet_config->settings[index].SetArgs(m_edit_args->GetValue().Trim());
176  if(cpdet_config->settings[index].IsCleanupPossible())
177  {
178  cpdet_config->settings[index].SetArgsCleanup(m_edit_args_cleanup->GetValue().Trim());
179  }
180  else
181  {
182  cpdet_config->settings[index].SetArgsCleanup(wxEmptyString);
183  };
184  }
185  else
186  {
187  cpdet_config->settings[index].SetProg(m_edit_prog_descriptor->GetValue().Trim());
188  cpdet_config->settings[index].SetArgs(m_edit_args_descriptor->GetValue().Trim());
189  cpdet_config->settings[index].SetProgMatcher(m_edit_prog_matcher->GetValue().Trim());
190  cpdet_config->settings[index].SetArgsMatcher(m_edit_args_matcher->GetValue().Trim());
191  };
192  if(cpdet_config->settings[index].ContainsStacks())
193  {
194  cpdet_config->settings[index].SetProgStack(m_edit_prog_stack->GetValue().Trim());
195  cpdet_config->settings[index].SetArgsStack(m_edit_args_stack->GetValue().Trim());
196  }
197  else
198  {
199  cpdet_config->settings[index].SetProgStack(wxEmptyString);
200  cpdet_config->settings[index].SetArgsStack(wxEmptyString);
201  }
202  cpdet_config->settings[index].SetOption(m_check_option->IsChecked());
203 };
204 
205 void CPDetectorDialog::OnTypeChange(wxCommandEvent &e)
206 {
207  ChangeType();
208 };
209 
211 {
212  CPDetectorType type=(CPDetectorType)m_cpdetector_type->GetSelection();
213  if(type==CPDetector_AutoPano)
214  {
215  m_choice_step->SetSelection(0);
216  twoStepAllowed=false;
217  }
218  else
219  {
220  twoStepAllowed=true;
221  }
222  XRCCTRL(*this,"panel_stack",wxPanel)->Enable(CPDetectorSetting::ContainsStacks(type));
223  switch(type)
224  {
227  m_check_option->SetLabel(_("Try to connect all overlapping images."));
228  m_check_option->Enable(true);
229  m_check_option->Show(true);
230  XRCCTRL(*this, "prefs_cpdetector_no_option",wxStaticText)->Show(false);
231  break;
233  m_check_option->SetLabel(_("Only work on image pairs without control points."));
234  m_check_option->Enable(true);
235  m_check_option->Show(true);
236  XRCCTRL(*this, "prefs_cpdetector_no_option",wxStaticText)->Show(false);
237  break;
238  default:
239  XRCCTRL(*this, "prefs_cpdetector_no_option",wxStaticText)->Show(true);
240  m_check_option->Enable(false);
241  m_check_option->Show(false);
242  break;
243  };
244  m_check_option->GetParent()->Layout();
245  bool cleanup_possible=CPDetectorSetting::IsCleanupPossible(type);
246  m_label_args_cleanup->Enable(cleanup_possible);
247  m_label_args_cleanup->Show(cleanup_possible);
248  m_edit_args_cleanup->Enable(cleanup_possible);
249  m_edit_args_cleanup->Show(cleanup_possible);
250  m_label_args_cleanup->GetParent()->Layout();
251  Layout();
252 };
253 
254 
255 bool CPDetectorDialog::ShowFileDialog(wxString & prog)
256 {
257  wxFileName executable(prog);
258 #ifdef MAC_SELF_CONTAINED_BUNDLE
259  wxString autopanoPath = MacGetPathToUserAppSupportAutoPanoFolder();
260 #endif
261  wxFileDialog dlg(this,_("Select control point detector program"),
262 #ifdef MAC_SELF_CONTAINED_BUNDLE
263  autopanoPath,
264 #else
265  executable.GetPath(),
266 #endif
267  executable.GetFullName(),
268 #ifdef __WXMSW__
269  _("Executables (*.exe,*.vbs,*.cmd, *.bat)|*.exe;*.vbs;*.cmd;*.bat"),
270 #else
271  wxT(""),
272 #endif
273  wxFD_OPEN, wxDefaultPosition);
274  if (dlg.ShowModal() == wxID_OK)
275  {
276  prog=dlg.GetPath();
277  return true;
278  }
279  else
280  return false;
281 };
282 
283 void CPDetectorDialog::OnSelectPath(wxCommandEvent &e)
284 {
285  wxString prog=m_edit_prog->GetValue();
286  if (ShowFileDialog(prog))
287  m_edit_prog->SetValue(prog);
288 };
289 
291 {
292  wxString prog=m_edit_prog_descriptor->GetValue();
293  if (ShowFileDialog(prog))
294  m_edit_prog_descriptor->SetValue(prog);
295 };
296 
298 {
299  wxString prog=m_edit_prog_matcher->GetValue();
300  if (ShowFileDialog(prog))
301  m_edit_prog_matcher->SetValue(prog);
302 };
303 
304 void CPDetectorDialog::OnSelectPathStack(wxCommandEvent &e)
305 {
306  wxString prog=m_edit_prog_stack->GetValue();
307  if (ShowFileDialog(prog))
308  m_edit_prog_stack->SetValue(prog);
309 };
310 
311 void CPDetectorDialog::OnStepChanging(wxChoicebookEvent &e)
312 {
313  if(!twoStepAllowed && e.GetOldSelection()==0)
314  {
315  wxBell();
316  e.Veto();
317  };
318 };
void OnSelectPath(wxCommandEvent &e)
select program with file open dialog
void UpdateFields(CPDetectorConfig *cpdet_config, int index)
updates edit fields with values from settings
implementation of huginApp Class
const bool IsCleanupPossible()
wxTextCtrl * m_edit_args_matcher
CPDetectorType
wxTextCtrl * m_edit_prog_stack
void OnSelectPathStack(wxCommandEvent &e)
select program for stack with file open dialog
wxChoicebook * m_choice_step
END_EVENT_TABLE()
void OnSelectPathMatcher(wxCommandEvent &e)
select program for feature matcher with file open dialog
void OnTypeChange(wxCommandEvent &e)
update dialog, when other cp detector type is changed
wxStaticText * m_label_args_cleanup
wxTextCtrl * m_edit_args
static huginApp * Get()
hack.. kind of a pseudo singleton...
Definition: huginApp.cpp:649
dialog for input settings of one autopano generator
void OnStepChanging(wxChoicebookEvent &e)
block selection of two step detector for autopano setting
wxTextCtrl * m_edit_args_stack
wxTextCtrl * m_edit_prog
ArraySettings settings
array which stores the different autopano settings
virtual ~CPDetectorDialog()
destructor, saves position and size
wxTextCtrl * m_edit_args_cleanup
wxChoice * m_cpdetector_type
void StoreFramePosition(wxTopLevelWindow *frame, const wxString &basename)
Store window size and position in configfile/registry.
Definition: LensCalApp.cpp:212
wxTextCtrl * m_edit_args_descriptor
void RestoreFramePosition(wxTopLevelWindow *frame, const wxString &basename)
Restore window size and position from configfile/registry.
Definition: LensCalApp.cpp:158
bool ShowFileDialog(wxString &prog)
shows file dialog
wxTextCtrl * m_edit_prog_matcher
wxCheckBox * m_check_option
functions for interaction with the hugin configuration file
wxTextCtrl * m_edit_desc
wxTextCtrl * m_edit_prog_descriptor
void OnSelectPathDescriptor(wxCommandEvent &e)
select program for feature descriptor with file open dialog
class for storing settings of different control point generators
void UpdateSettings(CPDetectorConfig *cpdet_config, int index)
return inputed settings
void OnOk(wxCommandEvent &e)
check inputs
declaration of CPDetectorDialog class, which are for storing and changing settings of different autop...
const bool ContainsStacks()