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