00001
00002
00027 #include "huginConfig.h"
00028 #include "hugin_version.h"
00029
00030 #include "hugin/config_defaults.h"
00031 #include "platform.h"
00032
00033
00034 using namespace PT;
00035
00036 std::string getProgram(wxConfigBase * config, wxString bindir, wxString file, wxString name) throw (wxString)
00037 {
00038 std::string pname;
00039 #if defined __WXMAC__ && defined MAC_SELF_CONTAINED_BUNDLE
00040
00041 if (config->Read(name + wxT("/Custom"), 0l)) {
00042 wxString fn = config->Read(name + wxT("/Exe"),wxT(""));
00043 if (wxFileName::FileExists(fn)) {
00044 pname = fn.mb_str(HUGIN_CONV_FILENAME);
00045 return pname;
00046 } else {
00047 wxMessageBox(wxString::Format(_("External program %s not found as specified in preferences, reverting to bundled version"), file.c_str()), _("Error"));
00048 }
00049 }
00050
00051 if(name == wxT("Exiftool")) {
00052 wxString exiftoolDirPath = MacGetPathToBundledResourceFile(CFSTR("ExifTool"));
00053 if(exiftoolDirPath != wxT(""))
00054 {
00055 pname = (exiftoolDirPath+wxT("/")+file).mb_str(HUGIN_CONV_FILENAME);
00056 } else {
00057 wxMessageBox(wxString::Format(_("External program %s not found in the bundle, reverting to system path"), file.c_str()), _("Error"));
00058 pname = file.mb_str(HUGIN_CONV_FILENAME);
00059 }
00060 return pname;
00061 }
00062
00063 CFStringRef filename = MacCreateCFStringWithWxString(file);
00064 wxString fn = MacGetPathToBundledExecutableFile(filename);
00065 CFRelease(filename);
00066
00067 if(fn == wxT(""))
00068 {
00069 wxMessageBox(wxString::Format(_("External program %s not found in the bundle, reverting to system path"), file.c_str()), _("Error"));
00070 pname = file.mb_str(HUGIN_CONV_FILENAME);
00071 } else {
00072 pname = fn.mb_str(HUGIN_CONV_FILENAME);
00073 }
00074 return pname;
00075
00076 #elif defined __WXMSW__
00077 if (config->Read(name + wxT("/Custom"), 0l)) {
00078 wxString fn = config->Read(name + wxT("/Exe"),wxT(""));
00079 if (wxFileName::FileExists(fn)) {
00080 pname = fn.mb_str(HUGIN_CONV_FILENAME);
00081 } else {
00082 wxMessageBox(wxString::Format(_("External program %s not found as specified in preferences, reverting to bundled version"), file.c_str()), _("Error"));
00083 pname = (bindir + wxT("\\") + file).mb_str(HUGIN_CONV_FILENAME);
00084 }
00085 } else {
00086 pname = (bindir + wxT("\\") + file).mb_str(HUGIN_CONV_FILENAME);
00087 }
00088 return pname;
00089 #else
00090
00091 if (config->Read(name + wxT("/Custom"), 0l)) {
00092 wxString fn = config->Read(name + wxT("/Exe"),wxT(""));
00093 pname = fn.mb_str(HUGIN_CONV_FILENAME);
00094 if (pname == "")
00095 throw wxString::Format(_("Program %s not found in preferences, reverting to default value"), file.c_str());
00096 return pname;
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 }
00107 pname = file.mb_str(HUGIN_CONV_FILENAME);
00108 if (pname == "")
00109 throw wxString::Format(_("Program %s not found in preferences, reverting to default value"), file.c_str());
00110 return pname;
00111 #endif
00112 }
00113
00114
00115 PTPrograms getPTProgramsConfig(wxString bundledBinDir, wxConfigBase * config)
00116 {
00117 PTPrograms progs;
00118
00119 wxString bindir;
00120 #ifndef __WXGTK__
00121
00122 wxFileName bindirFN = wxFileName::DirName(bundledBinDir);
00123 bindir = bindirFN.GetPath();
00124 #endif
00125
00126 try {
00127 progs.nona = getProgram(config,bindir, wxT("nona"), wxT("nona"));
00128 } catch (wxString s) {
00129 wxMessageBox(s, _("Warning"));
00130 }
00131 try {
00132 progs.hdrmerge= getProgram(config,bindir, wxT("hugin_hdrmerge"), wxT("hugin_hdrmerge"));
00133 } catch (wxString s) {
00134 wxMessageBox(s, _("Warning"));
00135 }
00136
00137 try {
00138 progs.PTmender = getProgram(config,bindir, wxT("PTmender"), wxT("PTmender"));
00139 } catch (wxString s) {
00140 wxMessageBox(s, _("Warning"));
00141 }
00142 try {
00143 progs.PTblender= getProgram(config,bindir, wxT("PTblender"), wxT("PTblender"));
00144 } catch (wxString s) {
00145 wxMessageBox(s, _("Warning"));
00146 }
00147 try {
00148 progs.PTmasker= getProgram(config,bindir, wxT("PTmasker"), wxT("PTmasker"));
00149 } catch (wxString s) {
00150 wxMessageBox(s, _("Warning"));
00151 }
00152 try {
00153 progs.PTroller= getProgram(config,bindir, wxT("PTroller"), wxT("PTroller"));
00154 } catch (wxString s) {
00155 wxMessageBox(s, _("Warning"));
00156 }
00157
00158 try {
00159 progs.enblend = getProgram(config,bindir, wxT("enblend"), wxT("Enblend"));
00160 } catch (wxString s) {
00161 wxMessageBox(s, _("Warning"));
00162 }
00163 try {
00164 progs.enblend_opts = config->Read(wxT("/Enblend/Args"), wxT(HUGIN_ENBLEND_ARGS)).mb_str(wxConvLocal);
00165 } catch (wxString s) {
00166 wxMessageBox(s, _("Warning"));
00167 }
00168 try {
00169 progs.enfuse = getProgram(config,bindir, wxT("enfuse"), wxT("Enfuse"));
00170 } catch (wxString s) {
00171 wxMessageBox(s, _("Warning"));
00172 }
00173 try {
00174 progs.enfuse_opts = config->Read(wxT("/Enfuse/Args"), wxT(HUGIN_ENFUSE_ARGS)).mb_str(wxConvLocal);
00175 } catch (wxString s) {
00176 wxMessageBox(s, _("Warning"));
00177 }
00178
00179 try {
00180 progs.exiftool = getProgram(config,bindir, wxT("exiftool"), wxT("Exiftool"));
00181 } catch (wxString s) {
00182 wxMessageBox(s, _("Warning"));
00183 }
00184 try {
00185 progs.exiftool_opts = config->Read(wxT("/Exiftool/CopyArgs"), wxT(HUGIN_EXIFTOOL_COPY_ARGS)).mb_str(wxConvLocal);
00186 } catch (wxString s) {
00187 wxMessageBox(s, _("Warning"));
00188 }
00189
00190
00191 try {
00192 progs.smartblend = config->Read(wxT("/Smartblend/SmartblendExe"),wxT("smartblend.exe")).mb_str(HUGIN_CONV_FILENAME);
00193 } catch (wxString s) {
00194 wxMessageBox(s, _("Warning"));
00195 }
00196 try {
00197 progs.smartblend_opts = config->Read(wxT("/Smartblend/SmartblendArgs"),wxT(HUGIN_SMARTBLEND_ARGS)).mb_str(wxConvLocal);
00198 } catch (wxString s) {
00199 wxMessageBox(s, _("Warning"));
00200 }
00201
00202 return progs;
00203 }
00204
00205 AssistantPrograms getAssistantProgramsConfig(wxString bundledBinDir, wxConfigBase * config)
00206 {
00207 AssistantPrograms progs;
00208
00209 wxString bindir;
00210 #ifndef __WXGTK__
00211
00212 wxFileName bindirFN = wxFileName::DirName(bundledBinDir);
00213 bindir = bindirFN.GetPath();
00214 #endif
00215
00216 try {
00217 progs.icpfind = getProgram(config,bindir, wxT("icpfind"), wxT("icpfind"));
00218 } catch (wxString s) {
00219 wxMessageBox(s, _("Warning"));
00220 }
00221 try {
00222 progs.celeste= getProgram(config,bindir, wxT("celeste_standalone"), wxT("celeste_standalone"));
00223 } catch (wxString s) {
00224 wxMessageBox(s, _("Warning"));
00225 }
00226
00227 try {
00228 progs.cpclean = getProgram(config,bindir, wxT("cpclean"), wxT("cpclean"));
00229 } catch (wxString s) {
00230 wxMessageBox(s, _("Warning"));
00231 }
00232 try {
00233 progs.autooptimiser= getProgram(config,bindir, wxT("autooptimiser"), wxT("autooptimiser"));
00234 } catch (wxString s) {
00235 wxMessageBox(s, _("Warning"));
00236 }
00237 try {
00238 progs.pano_modify= getProgram(config,bindir, wxT("pano_modify"), wxT("pano_modify"));
00239 } catch (wxString s) {
00240 wxMessageBox(s, _("Warning"));
00241 }
00242 try {
00243 progs.checkpto= getProgram(config,bindir, wxT("checkpto"), wxT("checkpto"));
00244 } catch (wxString s) {
00245 wxMessageBox(s, _("Warning"));
00246 }
00247 try
00248 {
00249 progs.linefind= getProgram(config,bindir, wxT("linefind"), wxT("linefind"));
00250 }
00251 catch (wxString s)
00252 {
00253 wxMessageBox(s, _("Warning"));
00254 }
00255 return progs;
00256 }
00257
00258 wxString getExePath(wxString argv0)
00259 {
00260 wxString huginPath;
00261 #ifdef __WXMSW__
00262
00263 #if wxUSE_UNICODE
00264 WCHAR tpath[MAX_PATH];
00265 #else //ANSI
00266 char tpath[MAX_PATH];
00267 #endif
00268 tpath[0] = 0;
00269 GetModuleFileName(0,tpath,sizeof(tpath)-1);
00270
00271 #ifdef wxUSE_UNICODE
00272 wxString path(tpath);
00273 #else
00274 wxString path(tpath, wxConvLocal);
00275 #endif
00276 wxFileName::SplitPath( path, &huginPath, NULL, NULL );
00277 #else
00278 wxFileName::SplitPath( argv0, &huginPath, NULL, NULL );
00279 #endif
00280 return huginPath;
00281 }
00282
00283
00284 typedef std::map<wxString, wxString> Placeholdersmap;
00285
00286 void FillDefaultPlaceholders(Placeholdersmap & placeholder)
00287 {
00288 placeholder[wxT("%firstimage")]=_("first image");
00289 placeholder[wxT("%lastimage")]=_("last image");
00290 placeholder[wxT("%#images")]=wxT("0");
00291 placeholder[wxT("%directory")]=_("directory");
00292 placeholder[wxT("%projection")]=_("Equirectangular");
00293 placeholder[wxT("%focallength")]=wxT("28");
00294 wxDateTime datetime=wxDateTime(13,wxDateTime::May,2012,11,35);
00295 placeholder[wxT("%date")]=datetime.FormatDate();
00296 placeholder[wxT("%time")]=datetime.FormatTime();
00297 placeholder[wxT("%maker")]=_("Camera maker");
00298 placeholder[wxT("%model")]=_("Camera model");
00299 placeholder[wxT("%lens")]=_("Lens");
00300 };
00301
00302 void FillPlaceholders(Placeholdersmap & placeholder, const HuginBase::Panorama & pano)
00303 {
00304 const HuginBase::SrcPanoImage & img0=pano.getImage(0);
00305 wxFileName firstImg(wxString(img0.getFilename().c_str(),HUGIN_CONV_FILENAME));
00306 placeholder[wxT("%firstimage")]=firstImg.GetName();
00307 if(firstImg.GetDirCount()>0)
00308 {
00309 placeholder[wxT("%directory")]=firstImg.GetDirs().Last();
00310 };
00311 placeholder[wxT("%focallength")]=wxString::Format(wxT("%.0f"), img0.getExifFocalLength());
00312 struct tm exifdatetime;
00313 if(img0.getExifDateTime(&exifdatetime)==0)
00314 {
00315 wxDateTime datetime=wxDateTime(exifdatetime);
00316 placeholder[wxT("%date")]=datetime.FormatDate();
00317 placeholder[wxT("%time")]=datetime.FormatTime();
00318 };
00319 placeholder[wxT("%maker")]=wxString(img0.getExifMake().c_str(), wxConvLocal);
00320 placeholder[wxT("%model")]=wxString(img0.getExifModel().c_str(), wxConvLocal);
00321 placeholder[wxT("%lens")]=wxString(img0.getExifLens().c_str(), wxConvLocal);
00322
00323 wxFileName lastImg(wxString(pano.getImage(pano.getNrOfImages()-1).getFilename().c_str(),HUGIN_CONV_FILENAME));
00324 placeholder[wxT("%lastimage")]=lastImg.GetName();
00325 placeholder[wxT("%#images")]=wxString::Format(wxT("%d"), pano.getNrOfImages());
00326 PanoramaOptions opts=pano.getOptions();
00327 pano_projection_features proj;
00328 if (panoProjectionFeaturesQuery(opts.getProjection(), &proj))
00329 {
00330 wxString str2(proj.name, wxConvLocal);
00331 placeholder[wxT("%projection")]=wxGetTranslation(str2);
00332 }
00333 else
00334 {
00335 placeholder[wxT("%projection")]=_("unknown projection");
00336 };
00337 };
00338
00339 wxString getDefaultProjectName(const HuginBase::Panorama & pano,const wxString filenameTemplate)
00340 {
00341 wxString filename;
00342 if(filenameTemplate.IsEmpty())
00343 {
00344 filename=wxConfigBase::Get()->Read(wxT("ProjectFilename"), wxT(HUGIN_DEFAULT_PROJECT_NAME));
00345 #ifdef __WXMSW__
00346 filename.Replace(wxT("/"), wxT("\\"), true);
00347 #endif
00348 }
00349 else
00350 {
00351 filename=filenameTemplate;
00352 };
00353 wxString pathPrefix;
00354 Placeholdersmap placeholder;
00355 if(pano.getNrOfImages()>0)
00356 {
00357 FillPlaceholders(placeholder, pano);
00358 wxFileName firstImg(wxString(pano.getImage(0).getFilename().c_str(),HUGIN_CONV_FILENAME));
00359 pathPrefix=firstImg.GetPathWithSep();
00360 }
00361 else
00362 {
00363 FillDefaultPlaceholders(placeholder);
00364 };
00365
00366 for(Placeholdersmap::const_iterator it=placeholder.begin(); it!=placeholder.end(); it++)
00367 {
00368 filename.Replace(it->first, it->second, true);
00369 };
00370 if(filename.empty())
00371 {
00372 filename=wxT("pano");
00373 };
00374 return pathPrefix+filename;
00375 };
00376
00379 wxString getDefaultOutputName(const wxString projectname, const HuginBase::Panorama & pano, const wxString filenameTemplate)
00380 {
00381 wxFileName project;
00382 if (projectname.IsEmpty())
00383 {
00384 project=getDefaultProjectName(pano);
00385 }
00386 else
00387 {
00388 project=projectname;
00389 }
00390 if(project.HasExt())
00391 {
00392 project.ClearExt();
00393 };
00394
00395 wxString filename;
00396 if(filenameTemplate.IsEmpty())
00397 {
00398 filename=wxConfigBase::Get()->Read(wxT("OutputFilename"), wxT(HUGIN_DEFAULT_PROJECT_NAME));
00399 #ifdef __WXMSW__
00400 filename.Replace(wxT("/"), wxT("\\"), true);
00401 #endif
00402 }
00403 else
00404 {
00405 filename=filenameTemplate;
00406 };
00407 wxString pathPrefix=project.GetPathWithSep();
00408 Placeholdersmap placeholder;
00409 if(pano.getNrOfImages()>0)
00410 {
00411 FillPlaceholders(placeholder, pano);
00412 wxFileName firstImg(wxString(pano.getImage(0).getFilename().c_str(),HUGIN_CONV_FILENAME));
00413 }
00414 else
00415 {
00416 FillDefaultPlaceholders(placeholder);
00417 };
00418 placeholder.insert(std::make_pair(wxT("%projectname"), project.GetName()));
00419
00420 for(Placeholdersmap::const_iterator it=placeholder.begin(); it!=placeholder.end(); it++)
00421 {
00422 filename.Replace(it->first, it->second, true);
00423 };
00424 if(filename.empty())
00425 {
00426 filename=wxT("pano");
00427 };
00428 return pathPrefix+filename;
00429 };