00001
00002
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "hugin/CPDetectorDialog.h"
00029 #include <config.h>
00030 #include "base_wx/huginConfig.h"
00031 #include "hugin/config_defaults.h"
00032 #include "hugin/huginApp.h"
00033
00034 #if defined MAC_SELF_CONTAINED_BUNDLE
00035 #include "base_wx/platform.h"
00036 #include <wx/dir.h>
00037 #include <CoreFoundation/CFBundle.h>
00038 #endif
00039
00040
00041
00042 BEGIN_EVENT_TABLE(CPDetectorDialog,wxDialog)
00043 EVT_BUTTON(wxID_OK, CPDetectorDialog::OnOk)
00044 EVT_BUTTON(XRCID("prefs_cpdetector_program_select"),CPDetectorDialog::OnSelectPath)
00045 EVT_BUTTON(XRCID("prefs_cpdetector_program_descriptor_select"),CPDetectorDialog::OnSelectPathDescriptor)
00046 EVT_BUTTON(XRCID("prefs_cpdetector_program_matcher_select"),CPDetectorDialog::OnSelectPathMatcher)
00047 EVT_BUTTON(XRCID("prefs_cpdetector_program_stack_select"),CPDetectorDialog::OnSelectPathStack)
00048 EVT_CHOICE(XRCID("prefs_cpdetector_type"),CPDetectorDialog::OnTypeChange)
00049 EVT_CHOICEBOOK_PAGE_CHANGING(XRCID("choicebook_steps"),CPDetectorDialog::OnStepChanging)
00050 END_EVENT_TABLE()
00051
00052 CPDetectorDialog::CPDetectorDialog(wxWindow* parent)
00053 {
00054 wxXmlResource::Get()->LoadDialog(this, parent, wxT("cpdetector_dialog"));
00055 #ifdef __WXMSW__
00056 wxIcon myIcon(huginApp::Get()->GetXRCPath() + wxT("data/hugin.ico"),wxBITMAP_TYPE_ICO);
00057 #else
00058 wxIcon myIcon(huginApp::Get()->GetXRCPath() + wxT("data/hugin.png"),wxBITMAP_TYPE_PNG);
00059 #endif
00060 SetIcon(myIcon);
00061
00062
00063 RestoreFramePosition(this,wxT("CPDetectorDialog"));
00064
00065 m_edit_desc = XRCCTRL(*this, "prefs_cpdetector_desc", wxTextCtrl);
00066 m_edit_prog = XRCCTRL(*this, "prefs_cpdetector_program", wxTextCtrl);
00067 m_edit_args = XRCCTRL(*this, "prefs_cpdetector_args", wxTextCtrl);
00068 m_label_args_cleanup = XRCCTRL(*this, "prefs_cpdetector_args_label_cleanup", wxStaticText);
00069 m_edit_args_cleanup = XRCCTRL(*this, "prefs_cpdetector_args_cleanup", wxTextCtrl);
00070 m_edit_prog_descriptor = XRCCTRL(*this, "prefs_cpdetector_program_descriptor", wxTextCtrl);
00071 m_edit_args_descriptor = XRCCTRL(*this, "prefs_cpdetector_args_descriptor", wxTextCtrl);
00072 m_edit_prog_matcher = XRCCTRL(*this, "prefs_cpdetector_program_matcher", wxTextCtrl);
00073 m_edit_args_matcher = XRCCTRL(*this, "prefs_cpdetector_args_matcher", wxTextCtrl);
00074 m_edit_prog_stack = XRCCTRL(*this, "prefs_cpdetector_program_stack", wxTextCtrl);
00075 m_edit_args_stack = XRCCTRL(*this, "prefs_cpdetector_args_stack", wxTextCtrl);
00076 m_check_option = XRCCTRL(*this, "prefs_cpdetector_option", wxCheckBox);
00077 m_cpdetector_type = XRCCTRL(*this, "prefs_cpdetector_type", wxChoice);
00078 m_choice_step = XRCCTRL(*this, "choicebook_steps", wxChoicebook);
00079 m_cpdetector_type->SetSelection(1);
00080 ChangeType();
00081 };
00082
00083 CPDetectorDialog::~CPDetectorDialog()
00084 {
00085 StoreFramePosition(this,wxT("CPDetectorDialog"));
00086 };
00087
00088 void CPDetectorDialog::OnOk(wxCommandEvent & e)
00089 {
00090 #ifdef __WXMAC__
00091 if(m_cpdetector_type->GetSelection()==0)
00092 {
00093 wxMessageBox(_("Autopano from http://autopano.kolor.com is not available for OS X"),
00094 _("Using Autopano-Sift instead"),wxOK|wxICON_EXCLAMATION, this);
00095 m_cpdetector_type->SetSelection(1);
00096 };
00097 #endif
00098 bool valid=true;
00099 valid=valid && (m_edit_desc->GetValue().Trim().Len()>0);
00100 if(m_choice_step->GetSelection()==0)
00101 {
00102
00103 valid=valid && (m_edit_prog->GetValue().Trim().Len()>0);
00104 valid=valid && (m_edit_args->GetValue().Trim().Len()>0);
00105 }
00106 else
00107 {
00108
00109 valid=valid && (m_edit_prog_descriptor->GetValue().Trim().Len()>0);
00110 valid=valid && (m_edit_prog_matcher->GetValue().Trim().Len()>0);
00111 valid=valid && (m_edit_args_descriptor->GetValue().Trim().Len()>0);
00112 valid=valid && (m_edit_args_matcher->GetValue().Trim().Len()>0);
00113 };
00114 if(CPDetectorSetting::ContainsStacks((CPDetectorType)(m_cpdetector_type->GetSelection())))
00115 if(m_edit_prog_stack->GetValue().Trim().Len()>0)
00116 valid=valid && (m_edit_args_stack->GetValue().Trim().Len()>0);
00117 if(valid)
00118 this->EndModal(wxOK);
00119 else
00120 wxMessageBox(_("At least one input field is empty.\nPlease check your inputs."),
00121 _("Warning"),wxOK | wxICON_ERROR,this);
00122 };
00123
00124 void CPDetectorDialog::UpdateFields(CPDetectorConfig* cpdet_config,int index)
00125 {
00126 m_edit_desc->SetValue(cpdet_config->settings[index].GetCPDetectorDesc());
00127
00128 if(cpdet_config->settings[index].IsTwoStepDetector())
00129 {
00130 m_choice_step->SetSelection(1);
00131 m_edit_prog_descriptor->SetValue(cpdet_config->settings[index].GetProg());
00132 m_edit_prog_matcher->SetValue(cpdet_config->settings[index].GetProgMatcher());
00133 m_edit_args_descriptor->SetValue(cpdet_config->settings[index].GetArgs());
00134 m_edit_args_matcher->SetValue(cpdet_config->settings[index].GetArgsMatcher());
00135 }
00136 else
00137 {
00138 m_choice_step->SetSelection(0);
00139 m_edit_prog->SetValue(cpdet_config->settings[index].GetProg());
00140 m_edit_args->SetValue(cpdet_config->settings[index].GetArgs());
00141 if(cpdet_config->settings[index].IsCleanupPossible())
00142 {
00143 m_edit_args_cleanup->SetValue(cpdet_config->settings[index].GetArgsCleanup());
00144 };
00145 };
00146 if(cpdet_config->settings[index].ContainsStacks())
00147 {
00148 m_edit_prog_stack->SetValue(cpdet_config->settings[index].GetProgStack());
00149 m_edit_args_stack->SetValue(cpdet_config->settings[index].GetArgsStack());
00150 };
00151 m_cpdetector_type->SetSelection(cpdet_config->settings[index].GetType());
00152 m_check_option->SetValue(cpdet_config->settings[index].GetOption());
00153 ChangeType();
00154 };
00155
00156 void CPDetectorDialog::UpdateSettings(CPDetectorConfig* cpdet_config,int index)
00157 {
00158 cpdet_config->settings[index].SetCPDetectorDesc(m_edit_desc->GetValue().Trim());
00159 cpdet_config->settings[index].SetType((CPDetectorType)m_cpdetector_type->GetSelection());
00160 if(m_choice_step->GetSelection()==0)
00161 {
00162 cpdet_config->settings[index].SetProg(m_edit_prog->GetValue().Trim());
00163 cpdet_config->settings[index].SetArgs(m_edit_args->GetValue().Trim());
00164 if(cpdet_config->settings[index].IsCleanupPossible())
00165 {
00166 cpdet_config->settings[index].SetArgsCleanup(m_edit_args_cleanup->GetValue().Trim());
00167 }
00168 else
00169 {
00170 cpdet_config->settings[index].SetArgsCleanup(wxEmptyString);
00171 };
00172 }
00173 else
00174 {
00175 cpdet_config->settings[index].SetProg(m_edit_prog_descriptor->GetValue().Trim());
00176 cpdet_config->settings[index].SetArgs(m_edit_args_descriptor->GetValue().Trim());
00177 cpdet_config->settings[index].SetProgMatcher(m_edit_prog_matcher->GetValue().Trim());
00178 cpdet_config->settings[index].SetArgsMatcher(m_edit_args_matcher->GetValue().Trim());
00179 };
00180 if(cpdet_config->settings[index].ContainsStacks())
00181 {
00182 cpdet_config->settings[index].SetProgStack(m_edit_prog_stack->GetValue().Trim());
00183 cpdet_config->settings[index].SetArgsStack(m_edit_args_stack->GetValue().Trim());
00184 }
00185 else
00186 {
00187 cpdet_config->settings[index].SetProgStack(wxEmptyString);
00188 cpdet_config->settings[index].SetArgsStack(wxEmptyString);
00189 }
00190 cpdet_config->settings[index].SetOption(m_check_option->IsChecked());
00191 };
00192
00193 void CPDetectorDialog::OnTypeChange(wxCommandEvent &e)
00194 {
00195 ChangeType();
00196 };
00197
00198 void CPDetectorDialog::ChangeType()
00199 {
00200 CPDetectorType type=(CPDetectorType)m_cpdetector_type->GetSelection();
00201 if(type==CPDetector_AutoPano)
00202 {
00203 m_choice_step->SetSelection(0);
00204 twoStepAllowed=false;
00205 }
00206 else
00207 {
00208 twoStepAllowed=true;
00209 }
00210 XRCCTRL(*this,"panel_stack",wxPanel)->Enable(CPDetectorSetting::ContainsStacks(type));
00211 switch(type)
00212 {
00213 case CPDetector_AutoPanoSiftMultiRow:
00214 case CPDetector_AutoPanoSiftMultiRowStack:
00215 m_check_option->SetLabel(_("Try to connect all overlapping images."));
00216 m_check_option->Enable(true);
00217 m_check_option->Show(true);
00218 XRCCTRL(*this, "prefs_cpdetector_no_option",wxStaticText)->Show(false);
00219 break;
00220 case CPDetector_AutoPanoSiftPreAlign:
00221 m_check_option->SetLabel(_("Only work on image pairs without control points."));
00222 m_check_option->Enable(true);
00223 m_check_option->Show(true);
00224 XRCCTRL(*this, "prefs_cpdetector_no_option",wxStaticText)->Show(false);
00225 break;
00226 default:
00227 XRCCTRL(*this, "prefs_cpdetector_no_option",wxStaticText)->Show(true);
00228 m_check_option->Enable(false);
00229 m_check_option->Show(false);
00230 break;
00231 };
00232 m_check_option->GetParent()->Layout();
00233 bool cleanup_possible=CPDetectorSetting::IsCleanupPossible(type);
00234 m_label_args_cleanup->Enable(cleanup_possible);
00235 m_label_args_cleanup->Show(cleanup_possible);
00236 m_edit_args_cleanup->Enable(cleanup_possible);
00237 m_edit_args_cleanup->Show(cleanup_possible);
00238 m_label_args_cleanup->GetParent()->Layout();
00239 Layout();
00240 };
00241
00242
00243 bool CPDetectorDialog::ShowFileDialog(wxString & prog)
00244 {
00245 wxFileName executable(prog);
00246 #ifdef MAC_SELF_CONTAINED_BUNDLE
00247 wxString autopanoPath = MacGetPathToUserAppSupportAutoPanoFolder();
00248 #endif
00249 wxFileDialog dlg(this,_("Select control point detector program"),
00250 #ifdef MAC_SELF_CONTAINED_BUNDLE
00251 autopanoPath,
00252 #else
00253 executable.GetPath(),
00254 #endif
00255 executable.GetFullName(),
00256 #ifdef __WXMSW__
00257 _("Executables (*.exe,*.vbs,*.cmd, *.bat)|*.exe;*.vbs;*.cmd;*.bat"),
00258 #else
00259 wxT(""),
00260 #endif
00261 wxFD_OPEN, wxDefaultPosition);
00262 if (dlg.ShowModal() == wxID_OK)
00263 {
00264 prog=dlg.GetPath();
00265 return true;
00266 }
00267 else
00268 return false;
00269 };
00270
00271 void CPDetectorDialog::OnSelectPath(wxCommandEvent &e)
00272 {
00273 wxString prog=m_edit_prog->GetValue();
00274 if (ShowFileDialog(prog))
00275 m_edit_prog->SetValue(prog);
00276 };
00277
00278 void CPDetectorDialog::OnSelectPathDescriptor(wxCommandEvent &e)
00279 {
00280 wxString prog=m_edit_prog_descriptor->GetValue();
00281 if (ShowFileDialog(prog))
00282 m_edit_prog_descriptor->SetValue(prog);
00283 };
00284
00285 void CPDetectorDialog::OnSelectPathMatcher(wxCommandEvent &e)
00286 {
00287 wxString prog=m_edit_prog_matcher->GetValue();
00288 if (ShowFileDialog(prog))
00289 m_edit_prog_matcher->SetValue(prog);
00290 };
00291
00292 void CPDetectorDialog::OnSelectPathStack(wxCommandEvent &e)
00293 {
00294 wxString prog=m_edit_prog_stack->GetValue();
00295 if (ShowFileDialog(prog))
00296 m_edit_prog_stack->SetValue(prog);
00297 };
00298
00299 void CPDetectorDialog::OnStepChanging(wxChoicebookEvent &e)
00300 {
00301 if(!twoStepAllowed && e.GetOldSelection()==0)
00302 {
00303 wxBell();
00304 e.Veto();
00305 };
00306 };