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 "base_wx/wxutils.h"
37 #include "hugin/config_defaults.h"
38 #include "hugin/huginApp.h"
39 
40 #if defined MAC_SELF_CONTAINED_BUNDLE
41  #include "base_wx/platform.h"
42  #include <wx/dir.h>
43  #include <CoreFoundation/CFBundle.h>
44 #endif
45 
46 // dialog for showing settings of one autopano setting
48 {
49  wxXmlResource::Get()->LoadDialog(this, parent, wxT("cpdetector_dialog"));
50 
51  //restore frame position and size
52  RestoreFramePosition(this,wxT("CPDetectorDialog"));
53 
54  m_edit_desc = XRCCTRL(*this, "prefs_cpdetector_desc", wxTextCtrl);
55  m_edit_prog = XRCCTRL(*this, "prefs_cpdetector_program", wxTextCtrl);
56  m_edit_args = XRCCTRL(*this, "prefs_cpdetector_args", wxTextCtrl);
57  m_label_args_cleanup = XRCCTRL(*this, "prefs_cpdetector_args_label_cleanup", wxStaticText);
58  m_edit_args_cleanup = XRCCTRL(*this, "prefs_cpdetector_args_cleanup", wxTextCtrl);
59  m_edit_prog_descriptor = XRCCTRL(*this, "prefs_cpdetector_program_descriptor", wxTextCtrl);
60  m_edit_args_descriptor = XRCCTRL(*this, "prefs_cpdetector_args_descriptor", wxTextCtrl);
61  m_edit_prog_matcher = XRCCTRL(*this, "prefs_cpdetector_program_matcher", wxTextCtrl);
62  m_edit_args_matcher = XRCCTRL(*this, "prefs_cpdetector_args_matcher", wxTextCtrl);
63  m_edit_prog_stack = XRCCTRL(*this, "prefs_cpdetector_program_stack", wxTextCtrl);
64  m_edit_args_stack = XRCCTRL(*this, "prefs_cpdetector_args_stack", wxTextCtrl);
65  m_check_option = XRCCTRL(*this, "prefs_cpdetector_option", wxCheckBox);
66  m_cpdetector_type = XRCCTRL(*this, "prefs_cpdetector_type", wxChoice);
67  m_choice_step = XRCCTRL(*this, "choicebook_steps", wxChoicebook);
68  // enable auto completion
69  m_edit_prog->AutoCompleteFileNames();
70  m_edit_prog_descriptor->AutoCompleteFileNames();
71  m_edit_prog_matcher->AutoCompleteFileNames();
72  m_edit_prog_stack->AutoCompleteFileNames();
73  m_cpdetector_type->SetSelection(1);
74  ChangeType();
75  // bind events
76  m_cpdetector_type->Bind(wxEVT_CHOICE, &CPDetectorDialog::OnTypeChange, this);
77  m_choice_step->Bind(wxEVT_CHOICEBOOK_PAGE_CHANGING, &CPDetectorDialog::OnStepChanging, this);
78  Bind(wxEVT_BUTTON, &CPDetectorDialog::OnSelectPath, this, XRCID("prefs_cpdetector_program_select"));
79  Bind(wxEVT_BUTTON, &CPDetectorDialog::OnSelectPathDescriptor, this, XRCID("prefs_cpdetector_program_descriptor_select"));
80  Bind(wxEVT_BUTTON, &CPDetectorDialog::OnSelectPathMatcher, this, XRCID("prefs_cpdetector_program_matcher_select"));
81  Bind(wxEVT_BUTTON, &CPDetectorDialog::OnSelectPathStack, this, XRCID("prefs_cpdetector_program_stack_select"));
82  Bind(wxEVT_BUTTON, &CPDetectorDialog::OnOk, this, wxID_OK);
83 };
84 
86 {
87  StoreFramePosition(this,wxT("CPDetectorDialog"));
88 };
89 
90 void CPDetectorDialog::OnOk(wxCommandEvent & e)
91 {
92 #ifdef __WXMAC__
93  if(m_cpdetector_type->GetSelection()==0)
94  {
95  wxMessageBox(_("Autopano from http://autopano.kolor.com is not available for OS X"),
96  _("Using Autopano-Sift instead"),wxOK|wxICON_EXCLAMATION, this);
97  m_cpdetector_type->SetSelection(1);
98  };
99 #endif
100  bool valid=true;
101  valid=valid && (m_edit_desc->GetValue().Trim().Len()>0);
102  if(m_choice_step->GetSelection()==0)
103  {
104  //detector with one step
105  valid=valid && (m_edit_prog->GetValue().Trim().Len()>0);
106  valid=valid && (m_edit_args->GetValue().Trim().Len()>0);
107  }
108  else
109  {
110  //detector with two steps
111  valid=valid && (m_edit_prog_descriptor->GetValue().Trim().Len()>0);
112  valid=valid && (m_edit_prog_matcher->GetValue().Trim().Len()>0);
113  valid=valid && (m_edit_args_descriptor->GetValue().Trim().Len()>0);
114  valid=valid && (m_edit_args_matcher->GetValue().Trim().Len()>0);
115  };
117  if(m_edit_prog_stack->GetValue().Trim().Len()>0)
118  valid=valid && (m_edit_args_stack->GetValue().Trim().Len()>0);
119  if(valid)
120  this->EndModal(wxOK);
121  else
122  wxMessageBox(_("At least one input field is empty.\nPlease check your inputs."),
123  _("Warning"),wxOK | wxICON_ERROR,this);
124 };
125 
127 {
128  m_edit_desc->SetValue(cpdet_config->settings[index].GetCPDetectorDesc());
129  //program names and arguments
130  if(cpdet_config->settings[index].IsTwoStepDetector())
131  {
132  m_choice_step->SetSelection(1);
133  m_edit_prog_descriptor->SetValue(cpdet_config->settings[index].GetProg());
134  m_edit_prog_matcher->SetValue(cpdet_config->settings[index].GetProgMatcher());
135  m_edit_args_descriptor->SetValue(cpdet_config->settings[index].GetArgs());
136  m_edit_args_matcher->SetValue(cpdet_config->settings[index].GetArgsMatcher());
137  }
138  else
139  {
140  m_choice_step->SetSelection(0);
141  m_edit_prog->SetValue(cpdet_config->settings[index].GetProg());
142  m_edit_args->SetValue(cpdet_config->settings[index].GetArgs());
143  if(cpdet_config->settings[index].IsCleanupPossible())
144  {
145  m_edit_args_cleanup->SetValue(cpdet_config->settings[index].GetArgsCleanup());
146  };
147  };
148  if(cpdet_config->settings[index].ContainsStacks())
149  {
150  m_edit_prog_stack->SetValue(cpdet_config->settings[index].GetProgStack());
151  m_edit_args_stack->SetValue(cpdet_config->settings[index].GetArgsStack());
152  };
153  m_cpdetector_type->SetSelection(cpdet_config->settings[index].GetType());
154  m_check_option->SetValue(cpdet_config->settings[index].GetOption());
155  ChangeType();
156 };
157 
159 {
160  cpdet_config->settings[index].SetCPDetectorDesc(m_edit_desc->GetValue().Trim());
161  cpdet_config->settings[index].SetType((CPDetectorType)m_cpdetector_type->GetSelection());
162  if(m_choice_step->GetSelection()==0)
163  {
164  cpdet_config->settings[index].SetProg(m_edit_prog->GetValue().Trim());
165  cpdet_config->settings[index].SetArgs(m_edit_args->GetValue().Trim());
166  if(cpdet_config->settings[index].IsCleanupPossible())
167  {
168  cpdet_config->settings[index].SetArgsCleanup(m_edit_args_cleanup->GetValue().Trim());
169  }
170  else
171  {
172  cpdet_config->settings[index].SetArgsCleanup(wxEmptyString);
173  };
174  }
175  else
176  {
177  cpdet_config->settings[index].SetProg(m_edit_prog_descriptor->GetValue().Trim());
178  cpdet_config->settings[index].SetArgs(m_edit_args_descriptor->GetValue().Trim());
179  cpdet_config->settings[index].SetProgMatcher(m_edit_prog_matcher->GetValue().Trim());
180  cpdet_config->settings[index].SetArgsMatcher(m_edit_args_matcher->GetValue().Trim());
181  };
182  if(cpdet_config->settings[index].ContainsStacks())
183  {
184  cpdet_config->settings[index].SetProgStack(m_edit_prog_stack->GetValue().Trim());
185  cpdet_config->settings[index].SetArgsStack(m_edit_args_stack->GetValue().Trim());
186  }
187  else
188  {
189  cpdet_config->settings[index].SetProgStack(wxEmptyString);
190  cpdet_config->settings[index].SetArgsStack(wxEmptyString);
191  }
192  cpdet_config->settings[index].SetOption(m_check_option->IsChecked());
193 };
194 
195 void CPDetectorDialog::OnTypeChange(wxCommandEvent &e)
196 {
197  ChangeType();
198 };
199 
201 {
202  CPDetectorType type=(CPDetectorType)m_cpdetector_type->GetSelection();
203  if(type==CPDetector_AutoPano)
204  {
205  m_choice_step->SetSelection(0);
206  twoStepAllowed=false;
207  }
208  else
209  {
210  twoStepAllowed=true;
211  }
212  XRCCTRL(*this,"panel_stack",wxPanel)->Enable(CPDetectorSetting::ContainsStacks(type));
213  switch(type)
214  {
217  m_check_option->SetLabel(_("Try to connect all overlapping images."));
218  m_check_option->Enable(true);
219  m_check_option->Show(true);
220  XRCCTRL(*this, "prefs_cpdetector_no_option",wxStaticText)->Show(false);
221  break;
223  m_check_option->SetLabel(_("Only work on image pairs without control points."));
224  m_check_option->Enable(true);
225  m_check_option->Show(true);
226  XRCCTRL(*this, "prefs_cpdetector_no_option",wxStaticText)->Show(false);
227  break;
228  default:
229  XRCCTRL(*this, "prefs_cpdetector_no_option",wxStaticText)->Show(true);
230  m_check_option->Enable(false);
231  m_check_option->Show(false);
232  break;
233  };
234  m_check_option->GetParent()->Layout();
235  bool cleanup_possible=CPDetectorSetting::IsCleanupPossible(type);
236  m_label_args_cleanup->Enable(cleanup_possible);
237  m_label_args_cleanup->Show(cleanup_possible);
238  m_edit_args_cleanup->Enable(cleanup_possible);
239  m_edit_args_cleanup->Show(cleanup_possible);
240  m_label_args_cleanup->GetParent()->Layout();
241  Layout();
242 };
243 
244 
245 bool CPDetectorDialog::ShowFileDialog(wxString & prog)
246 {
247  wxFileName executable(prog);
248 #ifdef MAC_SELF_CONTAINED_BUNDLE
249  wxString autopanoPath = MacGetPathToUserAppSupportAutoPanoFolder();
250 #endif
251  wxFileDialog dlg(this,_("Select control point detector program"),
252 #ifdef MAC_SELF_CONTAINED_BUNDLE
253  autopanoPath,
254 #else
255  executable.GetPath(),
256 #endif
257  executable.GetFullName(),
258 #ifdef __WXMSW__
259  _("Executables (*.exe,*.vbs,*.cmd, *.bat)|*.exe;*.vbs;*.cmd;*.bat"),
260 #else
261  wxT(""),
262 #endif
263  wxFD_OPEN, wxDefaultPosition);
264  if (dlg.ShowModal() == wxID_OK)
265  {
266  prog=dlg.GetPath();
267  return true;
268  }
269  else
270  return false;
271 };
272 
273 void CPDetectorDialog::OnSelectPath(wxCommandEvent &e)
274 {
275  wxString prog=m_edit_prog->GetValue();
276  if (ShowFileDialog(prog))
277  m_edit_prog->SetValue(prog);
278 };
279 
281 {
282  wxString prog=m_edit_prog_descriptor->GetValue();
283  if (ShowFileDialog(prog))
284  m_edit_prog_descriptor->SetValue(prog);
285 };
286 
288 {
289  wxString prog=m_edit_prog_matcher->GetValue();
290  if (ShowFileDialog(prog))
291  m_edit_prog_matcher->SetValue(prog);
292 };
293 
294 void CPDetectorDialog::OnSelectPathStack(wxCommandEvent &e)
295 {
296  wxString prog=m_edit_prog_stack->GetValue();
297  if (ShowFileDialog(prog))
298  m_edit_prog_stack->SetValue(prog);
299 };
300 
301 void CPDetectorDialog::OnStepChanging(wxChoicebookEvent &e)
302 {
303  if(!twoStepAllowed && e.GetOldSelection()==0)
304  {
305  wxBell();
306  e.Veto();
307  };
308 };
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
CPDetectorDialog(wxWindow *parent)
constructor
CPDetectorType
wxTextCtrl * m_edit_prog_stack
void OnSelectPathStack(wxCommandEvent &e)
select program for stack with file open dialog
wxChoicebook * m_choice_step
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
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
wxTextCtrl * m_edit_args_descriptor
void StoreFramePosition(wxTopLevelWindow *frame, const wxString &basename)
Store window size and position in configfile/registry.
Definition: wxutils.cpp:133
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()
void RestoreFramePosition(wxTopLevelWindow *frame, const wxString &basename)
Restore window size and position from configfile/registry.
Definition: wxutils.cpp:65