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

Generated on 28 Jul 2016 for Hugintrunk by  doxygen 1.4.7