huginConfig.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00002 
00027 #include "huginConfig.h"
00028 
00029 #include "hugin/config_defaults.h"
00030 #include "platform.h"
00031 
00032 // functions to handle with default project/output filenames
00033 typedef std::map<wxString, wxString> Placeholdersmap;
00034 
00035 void FillDefaultPlaceholders(Placeholdersmap & placeholder)
00036 {
00037     placeholder[wxT("%firstimage")]=_("first image");
00038     placeholder[wxT("%lastimage")]=_("last image");
00039     placeholder[wxT("%#images")]=wxT("0");
00040     placeholder[wxT("%directory")]=_("directory");
00041     placeholder[wxT("%projection")]=_("Equirectangular");
00042     placeholder[wxT("%focallength")]=wxT("28");
00043     wxDateTime datetime=wxDateTime(13,wxDateTime::May,2012,11,35);
00044     placeholder[wxT("%date")]=datetime.FormatDate();
00045     placeholder[wxT("%time")]=datetime.FormatTime();
00046     placeholder[wxT("%maker")]=_("Camera maker");
00047     placeholder[wxT("%model")]=_("Camera model");
00048     placeholder[wxT("%lens")]=_("Lens");
00049 };
00050 
00051 void FillPlaceholders(Placeholdersmap & placeholder, const HuginBase::Panorama & pano)
00052 {
00053     const HuginBase::SrcPanoImage & img0=pano.getImage(0);
00054     wxFileName firstImg(wxString(img0.getFilename().c_str(),HUGIN_CONV_FILENAME));
00055     placeholder[wxT("%firstimage")]=firstImg.GetName();
00056     if(firstImg.GetDirCount()>0)
00057     {
00058         placeholder[wxT("%directory")]=firstImg.GetDirs().Last();
00059     };
00060     placeholder[wxT("%focallength")]=wxString::Format(wxT("%.0f"), img0.getExifFocalLength());
00061     struct tm exifdatetime;
00062     if(img0.getExifDateTime(&exifdatetime)==0)
00063     {
00064         wxDateTime datetime=wxDateTime(exifdatetime);
00065         placeholder[wxT("%date")]=datetime.FormatDate();
00066         placeholder[wxT("%time")]=datetime.FormatTime();
00067     };
00068     placeholder[wxT("%maker")]=wxString(img0.getExifMake().c_str(), wxConvLocal);
00069     placeholder[wxT("%model")]=wxString(img0.getExifModel().c_str(), wxConvLocal);
00070     placeholder[wxT("%lens")]=wxString(img0.getExifLens().c_str(), wxConvLocal);
00071 
00072     wxFileName lastImg(wxString(pano.getImage(pano.getNrOfImages()-1).getFilename().c_str(),HUGIN_CONV_FILENAME));
00073     placeholder[wxT("%lastimage")]=lastImg.GetName();
00074     placeholder[wxT("%#images")]=wxString::Format(wxT("%lu"), (unsigned long)pano.getNrOfImages());
00075     HuginBase::PanoramaOptions opts = pano.getOptions();
00076     pano_projection_features proj;
00077     if (panoProjectionFeaturesQuery(opts.getProjection(), &proj))
00078     {
00079         wxString str2(proj.name, wxConvLocal);
00080         placeholder[wxT("%projection")]=wxGetTranslation(str2);
00081     }
00082     else
00083     {
00084         placeholder[wxT("%projection")]=_("unknown projection");
00085     };
00086 };
00087 
00088 wxString getDefaultProjectName(const HuginBase::Panorama & pano,const wxString filenameTemplate)
00089 {
00090     wxString filename;
00091     if(filenameTemplate.IsEmpty())
00092     {
00093         filename=wxConfigBase::Get()->Read(wxT("ProjectFilename"), wxT(HUGIN_DEFAULT_PROJECT_NAME));
00094 #ifdef __WXMSW__
00095         filename.Replace(wxT("/"), wxT("\\"), true);
00096 #endif
00097     }
00098     else
00099     {
00100         filename=filenameTemplate;
00101     };
00102     wxString pathPrefix;
00103     Placeholdersmap placeholder;
00104     if(pano.getNrOfImages()>0)
00105     {
00106         FillPlaceholders(placeholder, pano);
00107         wxFileName firstImg(wxString(pano.getImage(0).getFilename().c_str(),HUGIN_CONV_FILENAME));
00108         pathPrefix=firstImg.GetPathWithSep();
00109     }
00110     else
00111     {
00112         FillDefaultPlaceholders(placeholder);
00113     };
00114     // now replace all placeholder
00115     for(Placeholdersmap::const_iterator it=placeholder.begin(); it!=placeholder.end(); ++it)
00116     {
00117         filename.Replace(it->first, it->second, true);
00118     };
00119     if(filename.empty())
00120     {
00121         filename=wxT("pano");
00122     };
00123     // check if template is an absolute path, if so ignore path from first image
00124     wxFileName fileName(filename);
00125     if (fileName.IsAbsolute())
00126     {
00127         return filename;
00128     };
00129     return pathPrefix+filename;
00130 };
00131 
00134 wxString getDefaultOutputName(const wxString projectname, const HuginBase::Panorama & pano, const wxString filenameTemplate)
00135 {
00136     wxFileName project;
00137     if (projectname.IsEmpty())
00138     {
00139         project=getDefaultProjectName(pano);
00140     }
00141     else
00142     {
00143         project=projectname;
00144     }
00145     if(project.HasExt())
00146     {
00147         project.ClearExt();
00148     };
00149 
00150     wxString filename;
00151     if(filenameTemplate.IsEmpty())
00152     {
00153         filename=wxConfigBase::Get()->Read(wxT("OutputFilename"), wxT(HUGIN_DEFAULT_PROJECT_NAME));
00154 #ifdef __WXMSW__
00155         filename.Replace(wxT("/"), wxT("\\"), true);
00156 #endif
00157     }
00158     else
00159     {
00160         filename=filenameTemplate;
00161     };
00162     wxString pathPrefix=project.GetPathWithSep();
00163     Placeholdersmap placeholder;
00164     if(pano.getNrOfImages()>0)
00165     {
00166         FillPlaceholders(placeholder, pano);
00167         wxFileName firstImg(wxString(pano.getImage(0).getFilename().c_str(),HUGIN_CONV_FILENAME));
00168     }
00169     else
00170     {
00171         FillDefaultPlaceholders(placeholder);
00172     };
00173     placeholder.insert(std::make_pair(wxT("%projectname"), project.GetName()));
00174     // now replace all placeholder
00175     for(Placeholdersmap::const_iterator it=placeholder.begin(); it!=placeholder.end(); ++it)
00176     {
00177         filename.Replace(it->first, it->second, true);
00178     };
00179     if(filename.empty())
00180     {
00181         filename=wxT("pano");
00182     };
00183     // check if template is an absolute path, if so ignore path from first image
00184     wxFileName fileName(filename);
00185     if (fileName.IsAbsolute())
00186     {
00187         return filename;
00188     };
00189     return pathPrefix+filename;
00190 };

Generated on 29 Aug 2015 for Hugintrunk by  doxygen 1.4.7