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, write to the Free Software
00025  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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     // wxT is required previous to wxWidgets 2.9, and not recommended after it.
00084     // Here it causes errors converting between const wchar_t * and const char*.
00085 #if wxCHECK_VERSION(2,9,0)
00086         { wxCMD_LINE_OPTION, "m", NULL, NULL, wxCMD_LINE_VAL_STRING },
00087         { wxCMD_LINE_SWITCH, "c", NULL, NULL},
00088         { wxCMD_LINE_OPTION, "i", NULL, NULL, wxCMD_LINE_VAL_NUMBER },
00089         { wxCMD_LINE_OPTION, "s", NULL, NULL, wxCMD_LINE_VAL_STRING },
00090         { wxCMD_LINE_OPTION, "a", NULL, NULL, wxCMD_LINE_VAL_STRING },
00091 #else
00092         { wxCMD_LINE_OPTION, wxT("m"), NULL, NULL, wxCMD_LINE_VAL_STRING },
00093         { wxCMD_LINE_SWITCH, wxT("c"), NULL, NULL},
00094         { wxCMD_LINE_OPTION, wxT("i"), NULL, NULL, wxCMD_LINE_VAL_NUMBER },
00095         { wxCMD_LINE_OPTION, wxT("s"), NULL, NULL, wxCMD_LINE_VAL_STRING },
00096         { wxCMD_LINE_OPTION, wxT("a"), NULL, NULL, wxCMD_LINE_VAL_STRING },
00097 #endif
00098         { wxCMD_LINE_NONE }
00099     };
00100     wxCmdLineParser parser;
00101     parser.SetDesc(cmdLineDesc);
00102     parser.SetCmdLine(m_cmd);
00103     parser.Parse(false);
00104     wxString param;
00105     if(parser.Found(wxT("m"),&param))
00106     {
00107         if(param.CmpNoCase(wxT("avg_slow"))==0)
00108             m_mode->SetSelection(1);
00109         else
00110         {
00111             if(param.CmpNoCase(wxT("khan"))==0)
00112                 m_mode->SetSelection(2);
00113             else
00114                 m_mode->SetSelection(0);
00115         };
00116     }
00117     else
00118         m_mode->SetSelection(0);
00119     m_option_c->SetValue(parser.Found(wxT("c")));
00120     long i;
00121     if(parser.Found(wxT("i"),&i))
00122         m_khan_iter->SetValue(i);
00123     else
00124         m_khan_iter->SetValue(4);
00125     if(parser.Found(wxT("s"),&param))
00126     {
00127         //change locale for correct numeric output
00128         char * p = setlocale(LC_NUMERIC,NULL);
00129         char * old_locale = strdup(p);
00130         setlocale(LC_NUMERIC,"C");
00131         double sigma=0.0;
00132         param.ToDouble(&sigma);
00133         //reset locale
00134         setlocale(LC_NUMERIC,old_locale);
00135         free(old_locale);
00136         //using current locale for value in GUI
00137         m_khan_sigma->SetValue(wxString::Format(wxT("%.2f"),sigma));
00138     }
00139     else
00140         m_khan_sigma->SetValue(wxT("30"));
00141     if(parser.Found(wxT("a"),&param))
00142     {
00143         m_option_khan_af->SetValue(param.Contains(wxT("f")));
00144         m_option_khan_ag->SetValue(param.Contains(wxT("g")));
00145         m_option_khan_am->SetValue(param.Contains(wxT("m")));
00146     }
00147     wxCommandEvent dummy;
00148     OnModeChanged(dummy);
00149 };
00150 
00151 bool HDRMergeOptionsDialog::BuildCommandLineArgument()
00152 {
00153     int selection=m_mode->GetSelection();
00154     m_cmd.Clear();
00155     bool correct_input=true;
00156     double i = 0;
00157     wxString errorstring(_("Invalid input\n"));
00158     switch(selection)
00159     {
00160         case 0:
00161             m_cmd.Append(wxT("-m avg"));
00162             if(m_option_c->IsChecked())
00163                 m_cmd.Append(wxT(" -c"));
00164             break;
00165         case 1:
00166             m_cmd.Append(wxT("-m avg_slow"));
00167             break;
00168         case 2:
00169             m_cmd.Append(wxT("-m khan"));
00170             if(m_khan_iter->GetValue())
00171             {
00172                 m_cmd.Append(wxString::Format(wxT(" -i %d"),m_khan_iter->GetValue()));
00173             }
00174             else
00175             {
00176                 correct_input=false;
00177                 errorstring.Append(wxString::Format(_("Input \"%s\" for %s is not a valid number\n"),
00178                     m_khan_iter->GetValue(),_("Iteration")));
00179             };
00180             if(m_khan_sigma->GetValue().ToDouble(&i))
00181             {
00182                 //change locale for correct numeric output
00183                 char * p = setlocale(LC_NUMERIC,NULL);
00184                 char * old_locale = strdup(p);
00185                 setlocale(LC_NUMERIC,"C");
00186                 m_cmd.Append(wxString::Format(wxT(" -s %f"),i));
00187                 //reset locale
00188                 setlocale(LC_NUMERIC,old_locale);
00189                 free(old_locale);
00190             }
00191             else
00192             {
00193                 correct_input=false;
00194                 errorstring.Append(wxString::Format(_("Input \"%s\" for %s is not a valid number\n"),
00195                     m_khan_iter->GetValue(),_("Sigma")));
00196             };
00197             if(m_option_khan_af->IsChecked() || m_option_khan_ag->IsChecked() || 
00198                 m_option_khan_am->IsChecked())
00199             {
00200                 m_cmd.Append(wxT(" -a "));
00201                 if(m_option_khan_af->IsChecked())
00202                     m_cmd.Append(wxT("f"));
00203                 if(m_option_khan_ag->IsChecked())
00204                     m_cmd.Append(wxT("g"));
00205                 if(m_option_khan_am->IsChecked())
00206                     m_cmd.Append(wxT("m"));
00207             }
00208             break;
00209     };
00210     if(!correct_input)
00211         wxMessageBox(errorstring,_("Wrong input"),wxOK | wxICON_INFORMATION);
00212     return correct_input;
00213 };
00214 
00215 void HDRMergeOptionsDialog::OnModeChanged(wxCommandEvent & e)
00216 {
00217     int selection=m_mode->GetSelection();
00218     m_panel_avg->Show(selection==0);
00219     m_panel_avgslow->Show(selection==1);
00220     m_panel_khan->Show(selection==2);
00221     GetSizer()->Fit(this);
00222 };
00223 
00224 void HDRMergeOptionsDialog::OnOk(wxCommandEvent & e)
00225 {
00226     if(BuildCommandLineArgument())
00227         this->EndModal(wxOK);
00228 };
00229 

Generated on 5 Dec 2014 for Hugintrunk by  doxygen 1.4.7