27 #include <hugin_config.h>
31 #include <wx/wfstream.h>
32 #if defined __WXMSW__ || defined UNIX_SELF_CONTAINED_BUNDLE
33 #include <wx/stdpaths.h>
51 #include <wx/cmdline.h>
56 RunStitchFrame(wxWindow * parent,
const wxString& title,
const wxPoint& pos,
const wxSize& size);
58 bool StitchProject(
const wxString& scriptFile,
const wxString& outname,
const wxString& userDefinedOutput,
bool doDeleteOnExit);
60 void OnQuit(wxCommandEvent& event);
61 void OnAbout(wxCommandEvent& event);
74 void OnCancel(wxCommandEvent & event);
87 : wxFrame(parent, -1, title, pos, size), m_isStitching(false)
89 wxBoxSizer * topsizer =
new wxBoxSizer( wxVERTICAL );
92 topsizer->Add(m_stitchPanel, 1, wxEXPAND | wxALL, 2);
94 wxBoxSizer* bottomsizer =
new wxBoxSizer(wxHORIZONTAL);
95 m_progress =
new wxGauge(
this, wxID_ANY, 100, wxDefaultPosition, wxDefaultSize, wxGA_HORIZONTAL | wxGA_PROGRESS);
96 bottomsizer->Add(m_progress, 1, wxEXPAND | wxALL, 10);
97 bottomsizer->Add(
new wxButton(
this, wxID_CANCEL, _(
"Cancel")),
99 topsizer->Add(bottomsizer, 0, wxEXPAND);
103 this->SetBackgroundColour(m_stitchPanel->GetBackgroundColour());
107 wxInitAllImageHandlers();
108 #if defined __WXMSW__
109 wxFileName exePath(wxStandardPaths::Get().GetExecutablePath());
110 exePath.RemoveLastDir();
111 wxIconBundle myIcons(exePath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR) +
"share\\hugin\\xrc\\data\\hugin.ico", wxBITMAP_TYPE_ICO);
115 #if defined __WXMAC__ && defined MAC_SELF_CONTAINED_BUNDLE
117 wxString exec_path = MacGetPathToBundledResourceFile(CFSTR(
"xrc"));
118 if (!exec_path.IsEmpty())
120 xrcPrefix = exec_path +
"/";
124 wxMessageBox(_(
"xrc directory not found in bundle"), _(
"Fatal Error"));
128 #elif defined UNIX_SELF_CONTAINED_BUNDLE
131 wxFileName exePath(wxStandardPaths::Get().GetExecutablePath());
132 exePath.RemoveLastDir();
133 const wxString huginRoot(exePath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR));
134 xrcPrefix = huginRoot +
"share/hugin/xrc/";
138 xrcPrefix = INSTALL_XRC_DIR;
140 wxIcon myIcon(xrcPrefix +
"data/hugin.png", wxBITMAP_TYPE_PNG);
144 SetSizer( topsizer );
146 m_deleteOnExit=
false;
158 wxMessageBox(wxString::Format(_(
"HuginStitchProject. Application to stitch hugin project files.\n Version: %s"),
hugin_utils::GetHuginVersion().c_str()),
159 wxT(
"About hugin_stitch_project"),
160 wxOK | wxICON_INFORMATION );
191 if (event.GetExitCode() != 0)
193 if(wxMessageBox(_(
"Error during stitching\nPlease report the complete text to the bug tracker on https://bugs.launchpad.net/hugin.\n\nDo you want to save the log file?"),
194 _(
"Error during stitching"), wxICON_ERROR | wxYES_NO )==wxYES)
196 wxString defaultdir = wxConfigBase::Get()->Read(wxT(
"/actualPath"),wxT(
""));
197 wxFileDialog dlg(
this,
198 _(
"Specify log file"),
200 _(
"Log files (*.log)|*.log|All files (*)|*"),
201 wxFD_SAVE | wxFD_OVERWRITE_PROMPT, wxDefaultPosition);
202 dlg.SetDirectory(wxConfigBase::Get()->Read(wxT(
"/actualPath"),wxT(
"")));
203 if (dlg.ShowModal() == wxID_OK)
205 wxConfig::Get()->Write(wxT(
"/actualPath"), dlg.GetDirectory());
221 if (event.GetInt() >= 0)
271 void MacOpenFile(
const wxString &fileName);
277 wxString m_macFileNameToOpenOnStart;
284 TIFFSetWarningHandler(0);
298 SetAppName(wxT(
"hugin"));
299 #if defined __WXGTK__
300 CheckConfigFilename();
304 setlocale(LC_ALL,
"");
306 #if defined __WXMSW__
307 int localeID = wxConfigBase::Get()->Read(wxT(
"language"), (
long) wxLANGUAGE_DEFAULT);
314 #if defined __WXMSW__
315 wxFileName exePath(wxStandardPaths::Get().GetExecutablePath());
316 exePath.RemoveLastDir();
318 m_locale.AddCatalogLookupPathPrefix(exePath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR) + wxT(
"share\\locale"));
320 #elif defined UNIX_SELF_CONTAINED_BUNDLE
323 wxFileName exePath(wxStandardPaths::Get().GetExecutablePath());
324 exePath.RemoveLastDir();
325 const wxString huginRoot=exePath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
327 m_locale.AddCatalogLookupPathPrefix(huginRoot + wxT(
"share/locale"));
331 m_locale.AddCatalogLookupPathPrefix(wxT(INSTALL_LOCALE_DIR));
338 static const wxCmdLineEntryDesc cmdLineDesc[] =
342 { wxCMD_LINE_SWITCH,
"h",
"help",
"show this help message",
343 wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP },
344 { wxCMD_LINE_OPTION,
"o",
"output",
"output prefix" },
345 { wxCMD_LINE_SWITCH,
"d",
"delete",
"delete pto file after stitching" },
346 { wxCMD_LINE_SWITCH,
"w",
"overwrite",
"overwrite existing files" },
347 { wxCMD_LINE_OPTION,
"u",
"user-defined-output",
"use user defined output" },
348 { wxCMD_LINE_PARAM, NULL, NULL,
"<project>",
349 wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
353 wxCmdLineParser parser(cmdLineDesc, argc, argv);
355 switch ( parser.Parse() ) {
362 wxLogError(_(
"Syntax error in parameters detected, aborting."));
369 m_macFileNameToOpenOnStart = wxT(
"");
371 scriptFile = m_macFileNameToOpenOnStart;
375 ProcessSerialNumber selfPSN;
376 OSErr err = GetCurrentProcess(&selfPSN);
379 SetFrontProcess(&selfPSN);
384 wxString userDefinedOutput;
385 parser.Found(wxT(
"u"), &userDefinedOutput);
386 if (!userDefinedOutput.IsEmpty())
390 wxMessageBox(wxString::Format(_(
"Could not find the specified user output file \"%s\"."), userDefinedOutput.c_str()),
391 _(
"Error"), wxOK | wxICON_EXCLAMATION);
395 if( parser.GetParamCount() == 0 && wxIsEmpty(scriptFile))
397 wxString defaultdir = wxConfigBase::Get()->Read(wxT(
"/actualPath"),wxT(
""));
399 _(
"Specify project source project file"),
401 _(
"Project files (*.pto)|*.pto|All files (*)|*"),
402 wxFD_OPEN, wxDefaultPosition);
404 dlg.SetDirectory(wxConfigBase::Get()->Read(wxT(
"/actualPath"),wxT(
"")));
405 if (dlg.ShowModal() == wxID_OK) {
406 wxConfig::Get()->Write(wxT(
"/actualPath"), dlg.GetDirectory());
407 scriptFile = dlg.GetPath();
411 }
else if(wxIsEmpty(scriptFile)) {
412 scriptFile = parser.GetParam(0);
413 std::cout <<
"********************* script file: " << (
const char *)scriptFile.mb_str(wxConvLocal) << std::endl;
414 if (! wxIsAbsolutePath(scriptFile)) {
415 scriptFile = wxGetCwd() + wxFileName::GetPathSeparator() + scriptFile;
419 std::cout <<
"input file is " << (
const char *)scriptFile.mb_str(wxConvLocal) << std::endl;
423 if ( !parser.Found(wxT(
"o"), &outname) ) {
425 wxFileDialog dlg(0,_(
"Specify output prefix"),
426 wxConfigBase::Get()->Read(wxT(
"/actualPath"),wxT(
"")),
428 wxFD_SAVE, wxDefaultPosition);
429 dlg.SetDirectory(wxConfigBase::Get()->Read(wxT(
"/actualPath"),wxT(
"")));
430 if (dlg.ShowModal() == wxID_OK) {
433 wxMessageBox(wxString::Format(_(
"The given filename contains one of the following invalid characters: %s\nHugin can not work with this filename. Please enter a valid filename."),
getInvalidCharacters().c_str()),
434 _(
"Error"),wxOK | wxICON_EXCLAMATION);
435 if(dlg.ShowModal()!=wxID_OK)
438 wxFileName prefix(dlg.GetPath());
439 while (!prefix.IsDirWritable())
441 wxMessageBox(wxString::Format(_(
"You have no permissions to write in folder \"%s\".\nPlease select another folder for the final output."), prefix.GetPath().c_str()),
443 wxT(
"Hugin_stitch_project"),
447 wxOK | wxICON_INFORMATION);
448 if (dlg.ShowModal() != wxID_OK)
452 prefix = dlg.GetPath();
455 wxConfig::Get()->Write(wxT(
"/actualPath"), dlg.GetDirectory());
456 outname = dlg.GetPath();
464 wxFileName outfn(outname);
465 wxString ext = outfn.GetExt();
467 if (ext.CmpNoCase(wxT(
"jpg")) == 0 || ext.CmpNoCase(wxT(
"jpeg")) == 0||
468 ext.CmpNoCase(wxT(
"tif")) == 0|| ext.CmpNoCase(wxT(
"tiff")) == 0 ||
469 ext.CmpNoCase(wxT(
"png")) == 0 || ext.CmpNoCase(wxT(
"exr")) == 0 ||
470 ext.CmpNoCase(wxT(
"pnm")) == 0 || ext.CmpNoCase(wxT(
"hdr")))
473 outname = outfn.GetFullPath();
478 SetTopWindow( frame );
480 wxFileName basename(scriptFile);
481 frame->SetTitle(wxString::Format(_(
"%s - Stitching"), basename.GetName().c_str()));
483 bool n = frame->
StitchProject(scriptFile, outname, userDefinedOutput, parser.Found(wxT(
"d")));
497 void stitchApp::MacOpenFile(
const wxString &fileName)
499 m_macFileNameToOpenOnStart = fileName;
RunStitchFrame(wxWindow *parent, const wxString &title, const wxPoint &pos, const wxSize &size)
bool FileExists(const std::string &filename)
checks if file exists
void OnCancel(wxCommandEvent &event)
Cancels project execution - kills process.
void OnProcessTerminate(wxProcessEvent &event)
RunStitchPanel * m_stitchPanel
bool StitchProject(const wxString &scriptFile, const wxString &outname, const wxString &userDefinedOutput=wxEmptyString)
include file for the hugin project
virtual ~stitchApp()
dtor.
bool StitchProject(wxString scriptFile, wxString outname, wxString userDefinedOutput=wxEmptyString)
Starts stitching of project file.
bool SaveLog(const wxString &filename)
save the content of the window into a given log file
void OnAbout(wxCommandEvent &event)
void OnQuit(wxCommandEvent &event)
The application class for hugin_stitch_project.
include file for the hugin project
void SetOverwrite(bool over=true)
std::string GetHuginVersion()
return a string with version numbers
functions for interaction with the hugin configuration file
virtual bool OnInit()
pseudo constructor.
virtual int OnExit()
just for testing purposes
void SetOverwrite(bool doOverwrite)
sets, if existing output file should be automatic overwritten
void OnProgress(wxCommandEvent &event)