HDRMergeOptionDialog.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00002 
00013 /*  This is free software; you can redistribute it and/or
00014  *  modify it under the terms of the GNU General Public
00015  *  License as published by the Free Software Foundation; either
00016  *  version 2 of the License, or (at your option) any later version.
00017  *
00018  *  This software is distributed in the hope that it will be useful,
00019  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00021  *  Lesser General Public License for more details.
00022  *
00023  *  You should have received a copy of the GNU General Public
00024  *  License along with this software. If not, see
00025  *  <http://www.gnu.org/licenses/>.
00026  *
00027  */
00028 
00029 #include "hugin/HDRMergeOptionDialog.h"
00030 #include "base_wx/wxPlatform.h"
00031 #ifdef __APPLE__
00032 #include "panoinc_WX.h"
00033 #include "panoinc.h"
00034 #endif
00035 #include <hugin/config_defaults.h>
00036 #include "hugin/huginApp.h"
00037 
00038 // somewhere SetDesc gets defined.. this breaks wx/cmdline.h on OSX
00039 #ifdef SetDesc
00040 #undef SetDesc
00041 #endif
00042 
00043 #include <wx/cmdline.h>
00044 
00045 BEGIN_EVENT_TABLE(HDRMergeOptionsDialog,wxDialog)
00046 EVT_CHOICE(XRCID("hdrmerge_option_mode"),HDRMergeOptionsDialog::OnModeChanged)
00047 EVT_BUTTON(wxID_OK, HDRMergeOptionsDialog::OnOk)
00048 END_EVENT_TABLE()
00049 
00050 HDRMergeOptionsDialog::HDRMergeOptionsDialog(wxWindow *parent)
00051 {
00052     wxXmlResource::Get()->LoadDialog(this, parent, wxT("hdrmerge_options_dialog"));
00053 
00054 #ifdef __WXMSW__
00055     wxIcon myIcon(huginApp::Get()->GetXRCPath() + wxT("data/hugin.ico"),wxBITMAP_TYPE_ICO);
00056 #else
00057     wxIcon myIcon(huginApp::Get()->GetXRCPath() + wxT("data/hugin.png"),wxBITMAP_TYPE_PNG);
00058 #endif
00059     SetIcon(myIcon);
00060     m_mode=XRCCTRL(*this,"hdrmerge_option_mode",wxChoice);
00061     m_panel_avg=XRCCTRL(*this,"hdrmerge_option_panel_avg",wxPanel);
00062     m_panel_avgslow=XRCCTRL(*this,"hdrmerge_option_panel_avgslow",wxPanel);
00063     m_panel_khan=XRCCTRL(*this,"hdrmerge_option_panel_khan",wxPanel);
00064     m_option_c=XRCCTRL(*this,"hdrmerge_option_c",wxCheckBox);
00065     m_khan_iter=XRCCTRL(*this,"hdrmerge_option_khan_iter",wxSpinCtrl);
00066     m_khan_iter->SetRange(1,100);
00067     m_khan_sigma=XRCCTRL(*this,"hdrmerge_option_khan_sigma",wxTextCtrl);
00068     m_option_khan_af=XRCCTRL(*this,"hdrmerge_option_khan_af",wxCheckBox);
00069     m_option_khan_ag=XRCCTRL(*this,"hdrmerge_option_khan_ag",wxCheckBox);
00070     m_option_khan_am=XRCCTRL(*this,"hdrmerge_option_khan_am",wxCheckBox);
00071     this->CenterOnParent();
00072 };
00073 
00074 void HDRMergeOptionsDialog::SetCommandLineArgument(wxString cmd)
00075 {
00076     m_cmd=cmd;
00077     if (m_cmd.IsEmpty())
00078         m_cmd=wxT(HUGIN_HDRMERGE_ARGS);
00079     m_cmd.LowerCase();
00080         // parse arguments
00081     static const wxCmdLineEntryDesc cmdLineDesc[] =
00082     {
00083         { wxCMD_LINE_OPTION, "m", NULL, NULL, wxCMD_LINE_VAL_STRING },
00084         { wxCMD_LINE_SWITCH, "c", NULL, NULL},
00085         { wxCMD_LINE_OPTION, "i", NULL, NULL, wxCMD_LINE_VAL_NUMBER },
00086         { wxCMD_LINE_OPTION, "s", NULL, NULL, wxCMD_LINE_VAL_STRING },
00087         { wxCMD_LINE_OPTION, "a", NULL, NULL, wxCMD_LINE_VAL_STRING },
00088         { wxCMD_LINE_NONE }
00089     };
00090     wxCmdLineParser parser;
00091     parser.SetDesc(cmdLineDesc);
00092     parser.SetCmdLine(m_cmd);
00093     parser.Parse(false);
00094     wxString param;
00095     if(parser.Found(wxT("m"),&param))
00096     {
00097         if(param.CmpNoCase(wxT("avg_slow"))==0)
00098             m_mode->SetSelection(1);
00099         else
00100         {
00101             if(param.CmpNoCase(wxT("khan"))==0)
00102                 m_mode->SetSelection(2);
00103             else
00104                 m_mode->SetSelection(0);
00105         };
00106     }
00107     else
00108         m_mode->SetSelection(0);
00109     m_option_c->SetValue(parser.Found(wxT("c")));
00110     long i;
00111     if(parser.Found(wxT("i"),&i))
00112         m_khan_iter->SetValue(i);
00113     else
00114         m_khan_iter->SetValue(4);
00115     if(parser.Found(wxT("s"),&param))
00116     {
00117         //change locale for correct numeric output
00118         char * p = setlocale(LC_NUMERIC,NULL);
00119         char * old_locale = strdup(p);
00120         setlocale(LC_NUMERIC,"C");
00121         double sigma=0.0;
00122         param.ToDouble(&sigma);
00123         //reset locale
00124         setlocale(LC_NUMERIC,old_locale);
00125         free(old_locale);
00126         //using current locale for value in GUI
00127         m_khan_sigma->SetValue(wxString::Format(wxT("%.2f"),sigma));
00128     }
00129     else
00130         m_khan_sigma->SetValue(wxT("30"));
00131     if(parser.Found(wxT("a"),&param))
00132     {
00133         m_option_khan_af->SetValue(param.Contains(wxT("f")));
00134         m_option_khan_ag->SetValue(param.Contains(wxT("g")));
00135         m_option_khan_am->SetValue(param.Contains(wxT("m")));
00136     }
00137     wxCommandEvent dummy;
00138     OnModeChanged(dummy);
00139 };
00140 
00141 bool HDRMergeOptionsDialog::BuildCommandLineArgument()
00142 {
00143     int selection=m_mode->GetSelection();
00144     m_cmd.Clear();
00145     bool correct_input=true;
00146     double i = 0;
00147     wxString errorstring(_("Invalid input\n"));
00148     switch(selection)
00149     {
00150         case 0:
00151             m_cmd.Append(wxT("-m avg"));
00152             if(m_option_c->IsChecked())
00153                 m_cmd.Append(wxT(" -c"));
00154             break;
00155         case 1:
00156             m_cmd.Append(wxT("-m avg_slow"));
00157             break;
00158         case 2:
00159             m_cmd.Append(wxT("-m khan"));
00160             if(m_khan_iter->GetValue())
00161             {
00162                 m_cmd.Append(wxString::Format(wxT(" -i %d"),m_khan_iter->GetValue()));
00163             }
00164             else
00165             {
00166                 correct_input=false;
00167                 errorstring.Append(wxString::Format(_("Input \"%s\" for %s is not a valid number\n"),
00168                     m_khan_iter->GetValue(),_("Iteration")));
00169             };
00170             if(m_khan_sigma->GetValue().ToDouble(&i))
00171             {
00172                 //change locale for correct numeric output
00173                 char * p = setlocale(LC_NUMERIC,NULL);
00174                 char * old_locale = strdup(p);
00175                 setlocale(LC_NUMERIC,"C");
00176                 m_cmd.Append(wxString::Format(wxT(" -s %f"),i));
00177                 //reset locale
00178                 setlocale(LC_NUMERIC,old_locale);
00179                 free(old_locale);
00180             }
00181             else
00182             {
00183                 correct_input=false;
00184                 errorstring.Append(wxString::Format(_("Input \"%s\" for %s is not a valid number\n"),
00185                     m_khan_iter->GetValue(),_("Sigma")));
00186             };
00187             if(m_option_khan_af->IsChecked() || m_option_khan_ag->IsChecked() || 
00188                 m_option_khan_am->IsChecked())
00189             {
00190                 m_cmd.Append(wxT(" -a "));
00191                 if(m_option_khan_af->IsChecked())
00192                     m_cmd.Append(wxT("f"));
00193                 if(m_option_khan_ag->IsChecked())
00194                     m_cmd.Append(wxT("g"));
00195                 if(m_option_khan_am->IsChecked())
00196                     m_cmd.Append(wxT("m"));
00197             }
00198             break;
00199     };
00200     if(!correct_input)
00201         wxMessageBox(errorstring,_("Wrong input"),wxOK | wxICON_INFORMATION);
00202     return correct_input;
00203 };
00204 
00205 void HDRMergeOptionsDialog::OnModeChanged(wxCommandEvent & e)
00206 {
00207     int selection=m_mode->GetSelection();
00208     m_panel_avg->Show(selection==0);
00209     m_panel_avgslow->Show(selection==1);
00210     m_panel_khan->Show(selection==2);
00211     GetSizer()->Fit(this);
00212 };
00213 
00214 void HDRMergeOptionsDialog::OnOk(wxCommandEvent & e)
00215 {
00216     if(BuildCommandLineArgument())
00217         this->EndModal(wxOK);
00218 };
00219 

Generated on 30 Aug 2016 for Hugintrunk by  doxygen 1.4.7