Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
huginConfig.cpp
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
2 
27 #include "platform.h"
28 #include "huginConfig.h"
29 #include "hugin/config_defaults.h"
30 
31 // functions to handle with default project/output filenames
32 typedef std::map<wxString, wxString> Placeholdersmap;
33 
34 wxString CleanDateTime(const wxString& input)
35 {
36  // replace invalid characters in format string
37  // which are not allowed in filenames
38  wxString result(input);
39  result.Replace("/", "_");
40  result.Replace("\\", "_");
41  result.Replace(":", "-");
42  result.Replace("*", ".");
43  result.Replace("?", ".");
44  result.Replace("<", ".");
45  result.Replace(">", ".");
46  result.Replace("|", ".");
47  return result;
48 }
50 {
51  placeholder[wxT("%firstimage")]=_("first image");
52  placeholder[wxT("%lastimage")]=_("last image");
53  placeholder[wxT("%#images")]=wxT("0");
54  placeholder[wxT("%directory")]=_("directory");
55  placeholder[wxT("%projection")]=_("Equirectangular");
56  placeholder[wxT("%focallength")]=wxT("28");
57  wxDateTime datetime=wxDateTime(13,wxDateTime::May,2012,11,35);
58  placeholder[wxT("%date")] = CleanDateTime(datetime.FormatDate());
59  placeholder[wxT("%time")] = CleanDateTime(datetime.FormatTime());
60  placeholder[wxT("%maker")]=_("Camera maker");
61  placeholder[wxT("%model")]=_("Camera model");
62  placeholder[wxT("%lens")]=_("Lens");
63 };
64 
65 void FillPlaceholders(Placeholdersmap & placeholder, const HuginBase::Panorama & pano)
66 {
67  const HuginBase::SrcPanoImage & img0=pano.getImage(0);
68  wxFileName firstImg(wxString(img0.getFilename().c_str(),HUGIN_CONV_FILENAME));
69  placeholder[wxT("%firstimage")]=firstImg.GetName();
70  if (firstImg.GetDirCount() > 0)
71  {
72  placeholder[wxT("%directory")] = firstImg.GetDirs().Last();
73  }
74  else
75  {
76  placeholder[wxT("%directory")] = wxEmptyString;
77  };
78  placeholder[wxT("%focallength")]=wxString::Format(wxT("%.0f"), img0.getExifFocalLength());
79  struct tm exifdatetime;
80  if (img0.getExifDateTime(&exifdatetime) == 0)
81  {
82  wxDateTime datetime = wxDateTime(exifdatetime);
83  placeholder[wxT("%date")] = CleanDateTime(datetime.FormatDate());
84  placeholder[wxT("%time")] = CleanDateTime(datetime.FormatTime());
85  }
86  else
87  {
88  // no date found, use file create date
89  const wxFileName firstFile(img0.getFilename());
90  wxDateTime createTime;
91  firstFile.GetTimes(NULL, NULL, &createTime);
92  placeholder[wxT("%date")] = CleanDateTime(createTime.FormatDate());
93  placeholder[wxT("%time")] = CleanDateTime(createTime.FormatTime());
94  };
95  placeholder[wxT("%maker")]=wxString(img0.getExifMake().c_str(), wxConvLocal);
96  placeholder[wxT("%model")]=wxString(img0.getExifModel().c_str(), wxConvLocal);
97  placeholder[wxT("%lens")]=wxString(img0.getExifLens().c_str(), wxConvLocal);
98 
99  wxFileName lastImg(wxString(pano.getImage(pano.getNrOfImages()-1).getFilename().c_str(),HUGIN_CONV_FILENAME));
100  placeholder[wxT("%lastimage")]=lastImg.GetName();
101  placeholder[wxT("%#images")]=wxString::Format(wxT("%lu"), (unsigned long)pano.getNrOfImages());
103  pano_projection_features proj;
104  if (panoProjectionFeaturesQuery(opts.getProjection(), &proj))
105  {
106  wxString str2(proj.name, wxConvLocal);
107  placeholder[wxT("%projection")]=wxGetTranslation(str2);
108  }
109  else
110  {
111  placeholder[wxT("%projection")]=_("unknown projection");
112  };
113 };
114 
115 wxString getDefaultProjectName(const HuginBase::Panorama & pano,const wxString filenameTemplate)
116 {
117  wxString filename;
118  if(filenameTemplate.IsEmpty())
119  {
120  filename=wxConfigBase::Get()->Read(wxT("ProjectFilename"), wxT(HUGIN_DEFAULT_PROJECT_NAME));
121 #ifdef __WXMSW__
122  filename.Replace(wxT("/"), wxT("\\"), true);
123 #endif
124  }
125  else
126  {
127  filename=filenameTemplate;
128  };
129  wxString pathPrefix;
130  Placeholdersmap placeholder;
131  if(pano.getNrOfImages()>0)
132  {
133  FillPlaceholders(placeholder, pano);
134  wxFileName firstImg(wxString(pano.getImage(0).getFilename().c_str(),HUGIN_CONV_FILENAME));
135  pathPrefix=firstImg.GetPathWithSep();
136  }
137  else
138  {
139  FillDefaultPlaceholders(placeholder);
140  };
141  // now replace all placeholder
142  for(Placeholdersmap::const_iterator it=placeholder.begin(); it!=placeholder.end(); ++it)
143  {
144  filename.Replace(it->first, it->second, true);
145  };
146  if(filename.empty())
147  {
148  filename=wxT("pano");
149  };
150  // check if template is an absolute path, if so ignore path from first image
151  wxFileName fileName(filename);
152  if (fileName.IsAbsolute())
153  {
154  return filename;
155  };
156  return pathPrefix+filename;
157 };
158 
161 wxString getDefaultOutputName(const wxString projectname, const HuginBase::Panorama & pano, const wxString filenameTemplate)
162 {
163  wxFileName project;
164  if (projectname.IsEmpty())
165  {
166  project=getDefaultProjectName(pano);
167  }
168  else
169  {
170  project=projectname;
171  }
172  if(project.HasExt())
173  {
174  project.ClearExt();
175  };
176 
177  wxString filename;
178  if(filenameTemplate.IsEmpty())
179  {
180  filename=wxConfigBase::Get()->Read(wxT("OutputFilename"), wxT(HUGIN_DEFAULT_PROJECT_NAME));
181 #ifdef __WXMSW__
182  filename.Replace(wxT("/"), wxT("\\"), true);
183 #endif
184  }
185  else
186  {
187  filename=filenameTemplate;
188  };
189  wxString pathPrefix=project.GetPathWithSep();
190  Placeholdersmap placeholder;
191  if(pano.getNrOfImages()>0)
192  {
193  FillPlaceholders(placeholder, pano);
194  wxFileName firstImg(wxString(pano.getImage(0).getFilename().c_str(),HUGIN_CONV_FILENAME));
195  }
196  else
197  {
198  FillDefaultPlaceholders(placeholder);
199  };
200  placeholder.insert(std::make_pair(wxT("%projectname"), project.GetName()));
201  // now replace all placeholder
202  for(Placeholdersmap::const_iterator it=placeholder.begin(); it!=placeholder.end(); ++it)
203  {
204  filename.Replace(it->first, it->second, true);
205  };
206  if(filename.empty())
207  {
208  filename=wxT("pano");
209  };
210  // check if template is an absolute path, if so ignore path from first image
211  wxFileName fileName(filename);
212  if (fileName.IsAbsolute())
213  {
214  return filename;
215  };
216  return pathPrefix+filename;
217 };
implementation of huginApp Class
std::map< wxString, wxString > Placeholdersmap
Definition: huginConfig.cpp:32
#define HUGIN_CONV_FILENAME
Definition: platform.h:40
void FillDefaultPlaceholders(Placeholdersmap &placeholder)
Definition: huginConfig.cpp:49
void FillPlaceholders(Placeholdersmap &placeholder, const HuginBase::Panorama &pano)
Definition: huginConfig.cpp:65
Model for a panorama.
Definition: Panorama.h:152
std::size_t getNrOfImages() const
number of images.
Definition: Panorama.h:205
const int getExifDateTime(struct tm *datetime) const
try to convert Exif date time string to struct tm
#define HUGIN_DEFAULT_PROJECT_NAME
const PanoramaOptions & getOptions() const
returns the options for this panorama
Definition: Panorama.h:481
functions for interaction with the hugin configuration file
const SrcPanoImage & getImage(std::size_t nr) const
get a panorama image, counting starts with 0
Definition: Panorama.h:211
wxString CleanDateTime(const wxString &input)
Definition: huginConfig.cpp:34
wxString getDefaultOutputName(const wxString projectname, const HuginBase::Panorama &pano, const wxString filenameTemplate)
gets the default output prefix, based on filename and images in project the setting is read from the ...
All variables of a source image.
Definition: SrcPanoImage.h:194
Panorama image options.
wxString getDefaultProjectName(const HuginBase::Panorama &pano, const wxString filenameTemplate)
gets the default project name, as defined in the preferences