CPDetectorDialog.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00002 
00012 /*  This is free software; you can redistribute it and/or
00013  *  modify it under the terms of the GNU General Public
00014  *  License as published by the Free Software Foundation; either
00015  *  version 2 of the License, or (at your option) any later version.
00016  *
00017  *  This software is distributed in the hope that it will be useful,
00018  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020  *  Lesser General Public License for more details.
00021  *
00022  *  You should have received a copy of the GNU General Public
00023  *  License along with this software. If not, see
00024  *  <http://www.gnu.org/licenses/>.
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 // dialog for showing settings of one autopano setting
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     //restore frame position and size
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 #if wxCHECK_VERSION(2,9,3)
00080     // enable auto completion
00081     m_edit_prog->AutoCompleteFileNames();
00082     m_edit_prog_descriptor->AutoCompleteFileNames();
00083     m_edit_prog_matcher->AutoCompleteFileNames();
00084     m_edit_prog_stack->AutoCompleteFileNames();
00085 #endif
00086     m_cpdetector_type->SetSelection(1);
00087     ChangeType();
00088 };
00089 
00090 CPDetectorDialog::~CPDetectorDialog()
00091 {
00092     StoreFramePosition(this,wxT("CPDetectorDialog"));
00093 };
00094 
00095 void CPDetectorDialog::OnOk(wxCommandEvent & e)
00096 {
00097 #ifdef __WXMAC__
00098     if(m_cpdetector_type->GetSelection()==0)
00099     {
00100         wxMessageBox(_("Autopano from http://autopano.kolor.com is not available for OS X"), 
00101                      _("Using Autopano-Sift instead"),wxOK|wxICON_EXCLAMATION, this); 
00102         m_cpdetector_type->SetSelection(1);
00103     };
00104 #endif
00105     bool valid=true;
00106     valid=valid && (m_edit_desc->GetValue().Trim().Len()>0);
00107     if(m_choice_step->GetSelection()==0)
00108     {
00109         //detector with one step
00110         valid=valid && (m_edit_prog->GetValue().Trim().Len()>0);
00111         valid=valid && (m_edit_args->GetValue().Trim().Len()>0);
00112     }
00113     else
00114     {
00115         //detector with two steps
00116         valid=valid && (m_edit_prog_descriptor->GetValue().Trim().Len()>0);
00117         valid=valid && (m_edit_prog_matcher->GetValue().Trim().Len()>0);
00118         valid=valid && (m_edit_args_descriptor->GetValue().Trim().Len()>0);
00119         valid=valid && (m_edit_args_matcher->GetValue().Trim().Len()>0);
00120     };
00121     if(CPDetectorSetting::ContainsStacks((CPDetectorType)(m_cpdetector_type->GetSelection())))
00122         if(m_edit_prog_stack->GetValue().Trim().Len()>0)
00123             valid=valid && (m_edit_args_stack->GetValue().Trim().Len()>0);
00124     if(valid)        
00125         this->EndModal(wxOK);
00126     else
00127         wxMessageBox(_("At least one input field is empty.\nPlease check your inputs."),
00128             _("Warning"),wxOK | wxICON_ERROR,this);
00129 };
00130 
00131 void CPDetectorDialog::UpdateFields(CPDetectorConfig* cpdet_config,int index)
00132 {
00133     m_edit_desc->SetValue(cpdet_config->settings[index].GetCPDetectorDesc());
00134     //program names and arguments
00135     if(cpdet_config->settings[index].IsTwoStepDetector())
00136     {
00137         m_choice_step->SetSelection(1);
00138         m_edit_prog_descriptor->SetValue(cpdet_config->settings[index].GetProg());
00139         m_edit_prog_matcher->SetValue(cpdet_config->settings[index].GetProgMatcher());
00140         m_edit_args_descriptor->SetValue(cpdet_config->settings[index].GetArgs());
00141         m_edit_args_matcher->SetValue(cpdet_config->settings[index].GetArgsMatcher());
00142     }
00143     else
00144     {
00145         m_choice_step->SetSelection(0);
00146         m_edit_prog->SetValue(cpdet_config->settings[index].GetProg());
00147         m_edit_args->SetValue(cpdet_config->settings[index].GetArgs());
00148         if(cpdet_config->settings[index].IsCleanupPossible())
00149         {
00150             m_edit_args_cleanup->SetValue(cpdet_config->settings[index].GetArgsCleanup());
00151         };
00152     };
00153     if(cpdet_config->settings[index].ContainsStacks())
00154     {
00155         m_edit_prog_stack->SetValue(cpdet_config->settings[index].GetProgStack());
00156         m_edit_args_stack->SetValue(cpdet_config->settings[index].GetArgsStack());
00157     };
00158     m_cpdetector_type->SetSelection(cpdet_config->settings[index].GetType());
00159     m_check_option->SetValue(cpdet_config->settings[index].GetOption());
00160     ChangeType();
00161 };
00162 
00163 void CPDetectorDialog::UpdateSettings(CPDetectorConfig* cpdet_config,int index)
00164 {
00165     cpdet_config->settings[index].SetCPDetectorDesc(m_edit_desc->GetValue().Trim());
00166     cpdet_config->settings[index].SetType((CPDetectorType)m_cpdetector_type->GetSelection());
00167     if(m_choice_step->GetSelection()==0)
00168     {
00169         cpdet_config->settings[index].SetProg(m_edit_prog->GetValue().Trim());
00170         cpdet_config->settings[index].SetArgs(m_edit_args->GetValue().Trim());
00171         if(cpdet_config->settings[index].IsCleanupPossible())
00172         {
00173             cpdet_config->settings[index].SetArgsCleanup(m_edit_args_cleanup->GetValue().Trim());
00174         }
00175         else
00176         {
00177             cpdet_config->settings[index].SetArgsCleanup(wxEmptyString);
00178         };
00179     }
00180     else
00181     {
00182         cpdet_config->settings[index].SetProg(m_edit_prog_descriptor->GetValue().Trim());
00183         cpdet_config->settings[index].SetArgs(m_edit_args_descriptor->GetValue().Trim());
00184         cpdet_config->settings[index].SetProgMatcher(m_edit_prog_matcher->GetValue().Trim());
00185         cpdet_config->settings[index].SetArgsMatcher(m_edit_args_matcher->GetValue().Trim());
00186     };
00187     if(cpdet_config->settings[index].ContainsStacks())
00188     {
00189         cpdet_config->settings[index].SetProgStack(m_edit_prog_stack->GetValue().Trim());
00190         cpdet_config->settings[index].SetArgsStack(m_edit_args_stack->GetValue().Trim());
00191     }
00192     else
00193     {
00194         cpdet_config->settings[index].SetProgStack(wxEmptyString);
00195         cpdet_config->settings[index].SetArgsStack(wxEmptyString);
00196     }
00197     cpdet_config->settings[index].SetOption(m_check_option->IsChecked());
00198 };
00199 
00200 void CPDetectorDialog::OnTypeChange(wxCommandEvent &e)
00201 {
00202     ChangeType();
00203 };
00204 
00205 void CPDetectorDialog::ChangeType()
00206 {
00207     CPDetectorType type=(CPDetectorType)m_cpdetector_type->GetSelection();
00208     if(type==CPDetector_AutoPano)
00209     {
00210         m_choice_step->SetSelection(0);
00211         twoStepAllowed=false;
00212     }
00213     else
00214     {
00215         twoStepAllowed=true;
00216     }
00217     XRCCTRL(*this,"panel_stack",wxPanel)->Enable(CPDetectorSetting::ContainsStacks(type));
00218     switch(type)
00219     {
00220         case CPDetector_AutoPanoSiftMultiRow:
00221         case CPDetector_AutoPanoSiftMultiRowStack:
00222             m_check_option->SetLabel(_("Try to connect all overlapping images."));
00223             m_check_option->Enable(true);
00224             m_check_option->Show(true);
00225             XRCCTRL(*this, "prefs_cpdetector_no_option",wxStaticText)->Show(false);
00226             break;
00227         case CPDetector_AutoPanoSiftPreAlign:
00228             m_check_option->SetLabel(_("Only work on image pairs without control points."));
00229             m_check_option->Enable(true);
00230             m_check_option->Show(true);
00231             XRCCTRL(*this, "prefs_cpdetector_no_option",wxStaticText)->Show(false);
00232             break;
00233         default:
00234             XRCCTRL(*this, "prefs_cpdetector_no_option",wxStaticText)->Show(true);
00235             m_check_option->Enable(false);
00236             m_check_option->Show(false);
00237             break;
00238     };
00239     m_check_option->GetParent()->Layout();
00240     bool cleanup_possible=CPDetectorSetting::IsCleanupPossible(type);
00241     m_label_args_cleanup->Enable(cleanup_possible);
00242     m_label_args_cleanup->Show(cleanup_possible);
00243     m_edit_args_cleanup->Enable(cleanup_possible);
00244     m_edit_args_cleanup->Show(cleanup_possible);
00245     m_label_args_cleanup->GetParent()->Layout();
00246     Layout();
00247 };
00248 
00249 
00250 bool CPDetectorDialog::ShowFileDialog(wxString & prog)
00251 {
00252     wxFileName executable(prog);
00253 #ifdef MAC_SELF_CONTAINED_BUNDLE
00254     wxString autopanoPath = MacGetPathToUserAppSupportAutoPanoFolder();
00255 #endif
00256     wxFileDialog dlg(this,_("Select control point detector program"), 
00257 #ifdef MAC_SELF_CONTAINED_BUNDLE
00258             autopanoPath,
00259 #else
00260             executable.GetPath(),
00261 #endif
00262             executable.GetFullName(),
00263 #ifdef __WXMSW__
00264             _("Executables (*.exe,*.vbs,*.cmd, *.bat)|*.exe;*.vbs;*.cmd;*.bat"),
00265 #else
00266             wxT(""),
00267 #endif
00268             wxFD_OPEN, wxDefaultPosition);
00269     if (dlg.ShowModal() == wxID_OK)
00270     {
00271         prog=dlg.GetPath();
00272         return true;
00273     }
00274     else
00275         return false;
00276 };
00277 
00278 void CPDetectorDialog::OnSelectPath(wxCommandEvent &e)
00279 {
00280     wxString prog=m_edit_prog->GetValue();
00281     if (ShowFileDialog(prog))
00282         m_edit_prog->SetValue(prog);
00283 };
00284 
00285 void CPDetectorDialog::OnSelectPathDescriptor(wxCommandEvent &e)
00286 {
00287     wxString prog=m_edit_prog_descriptor->GetValue();
00288     if (ShowFileDialog(prog))
00289         m_edit_prog_descriptor->SetValue(prog);
00290 };
00291 
00292 void CPDetectorDialog::OnSelectPathMatcher(wxCommandEvent &e)
00293 {
00294     wxString prog=m_edit_prog_matcher->GetValue();
00295     if (ShowFileDialog(prog))
00296         m_edit_prog_matcher->SetValue(prog);
00297 };
00298 
00299 void CPDetectorDialog::OnSelectPathStack(wxCommandEvent &e)
00300 {
00301     wxString prog=m_edit_prog_stack->GetValue();
00302     if (ShowFileDialog(prog))
00303         m_edit_prog_stack->SetValue(prog);
00304 };
00305 
00306 void CPDetectorDialog::OnStepChanging(wxChoicebookEvent &e)
00307 {
00308     if(!twoStepAllowed && e.GetOldSelection()==0)
00309     {
00310         wxBell();
00311         e.Veto();
00312     };
00313 };

Generated on 29 Aug 2015 for Hugintrunk by  doxygen 1.4.7