28 #include "wx/msw/wrapwin.h"
31 #include <wx/stdpaths.h>
35 #pragma comment(lib, "PowrProf.lib")
47 Batch::Batch(wxFrame* parent) : wxFrame(parent, wxID_ANY, _T(
"Batch"))
81 wxFileName projectName(projectFile);
82 wxFileName outName(outputFile);
83 projectName.Normalize(wxPATH_NORM_ABSOLUTE | wxPATH_NORM_DOTS | wxPATH_NORM_TILDE | wxPATH_NORM_SHORTCUT);
84 outName.Normalize(wxPATH_NORM_ABSOLUTE | wxPATH_NORM_DOTS | wxPATH_NORM_TILDE | wxPATH_NORM_SHORTCUT);
88 Project* proj =
new Project(projectName.GetFullPath(), outName.GetFullPath(), userDefinedSequence, target);
94 Project* proj =
new Project(projectName.GetFullPath(), wxEmptyString, userDefinedSequence);
101 for(
unsigned int i=0; i<
m_projList.GetCount(); i++)
117 wxFileInputStream fileStream(file);
118 wxFileConfig batchFile(fileStream);
120 const long idGenTemp = batchFile.ReadLong(
"/Main/CurrentID", 1l);
121 const long projCount = batchFile.ReadLong(
"/Main/Count", 0l);
127 for (
long i = 1; i <= projCount; ++i)
129 const wxString group = wxString::Format(
"Project_%ld", i);
130 if (batchFile.HasGroup(group))
132 batchFile.SetPath(group);
133 const wxString projectName = batchFile.Read(
"Project", wxEmptyString);
134 const wxString type = batchFile.Read(
"Type",
"Stitching");
135 const long id = batchFile.ReadLong(
"Id", 1);
137 const bool skip = batchFile.ReadBool(
"Skip",
false);
147 const wxString userDefinedSequence = batchFile.Read(
"UserDefinedSequence", wxEmptyString);
148 if (type.CmpNoCase(
"Stitching") == 0)
150 const wxString prefix = batchFile.Read(
"Prefix", wxEmptyString);
155 if (type.CmpNoCase(
"Detecting") == 0)
173 m_projList.Last().skip = batchFile.ReadBool(
"Skip",
false);
174 batchFile.SetPath(
"/");
199 wxCommandEvent event;
217 m_projList.Item(index).userDefindSequence = newUserDefined;
224 wxMessageDialog message(
this, _(
"Cannot clear batch in progress.\nDo you want to cancel it?"),
230 wxYES_NO | wxICON_INFORMATION);
231 if(message.ShowModal()==wxID_YES)
239 ((wxFrame*)GetParent())->SetStatusText(_(
"Cleared batch."));
249 ((wxFrame*)GetParent())->SetStatusText(_(
"Cleared batch."));
286 for(
unsigned int i=0; i<
m_projList.GetCount(); i++)
309 for(
unsigned int i=0; i<
m_projList.GetCount(); i++)
332 wxMessageBox(wxString::Format(_(
"Error: Could not get status, project with index %d is not in list."),index),_(
"Error!"),wxOK | wxICON_INFORMATION );
355 else if(clearCode==2)
362 wxMessageBox(_(
"Error: Could not load batch file."));
380 for(
unsigned int i=0; i<
m_projList.GetCount(); i++)
417 wxString savedLogfile=wxEmptyString;
418 if(
saveLog || event.GetExitCode() != 0 ||
event.GetTimestamp()==-1)
422 logFile.MakeAbsolute();
423 logFile.SetExt(wxT(
"log"));
424 wxString name=logFile.GetName();
426 while(logFile.FileExists() && i<1000)
428 logFile.SetName(wxString::Format(wxT(
"%s_%d"),name.c_str(),i));
434 if((static_cast<RunStitchFrame*>(event.GetEventObject()))->SaveLog(logFile.GetFullPath()))
436 savedLogfile=logFile.GetFullPath();
440 if (event.GetExitCode() != 0 ||
event.GetTimestamp()==-1)
445 failedProject.
logfile=savedLogfile;
455 bool notifyParent=
false;
470 wxCommandEvent e(EVT_UPDATE_PARENT,wxID_ANY);
471 GetParent()->GetEventHandler()->AddPendingEvent(e);
488 wxCommandEvent e(EVT_INFORMATION,wxID_ANY);
489 e.SetString(_(
"Batch successfully completed."));
492 GetParent()->GetEventHandler()->AddPendingEvent(e);
496 ((wxFrame*)GetParent())->SetStatusText(_(
"Batch completed with errors."));
501 wxCommandEvent e(EVT_BATCH_FAILED,wxID_ANY);
502 GetParent()->GetEventHandler()->AddPendingEvent(e);
511 GetParent()->Close();
515 wxProgressDialog progress(_(
"Initializing shutdown..."), _(
"Shutting down..."), 49,
this,
516 wxPD_AUTO_HIDE | wxPD_SMOOTH | wxPD_APP_MODAL | wxPD_CAN_ABORT | wxPD_CAN_SKIP);
520 while (progress.Update(i, _(
"Shutting down..."), &skip))
524 wxShutdown(wxSHUTDOWN_POWEROFF);
527 #if defined __WXMSW__
540 wxString progressCaption(_(
"Prepare to hibernate..."));
541 wxString progressLabel(_(
"Initializing hibernating..."));
544 progressCaption = wxString(_(
"Prepare to suspend..."));
545 progressLabel = wxString(_(
"Initializing suspend mode..."));
547 wxProgressDialog progress(progressLabel, progressCaption, 49,
this,
548 wxPD_AUTO_HIDE | wxPD_SMOOTH | wxPD_APP_MODAL | wxPD_CAN_ABORT | wxPD_CAN_SKIP);
552 while (progress.Update(i, progressCaption, &skip))
585 bool Batch::OnStitch(wxString scriptFile, wxString outname, wxString userDefinedOutput,
int id)
588 delete wxConfigBase::Set((wxConfigBase*)NULL);
589 wxConfigBase* config = wxConfigBase::Get();
590 if(wxIsEmpty(scriptFile))
592 wxString defaultdir = config->Read(wxT(
"/actualPath"),wxT(
""));
594 _(
"Specify project file"),
596 _(
"Project files (*.pto)|*.pto|All files (*)|*"),
597 wxFD_OPEN, wxDefaultPosition);
599 dlg.SetDirectory(wxConfigBase::Get()->Read(wxT(
"/actualPath"),wxT(
"")));
600 if (dlg.ShowModal() == wxID_OK)
602 config->Write(wxT(
"/actualPath"), dlg.GetDirectory());
604 wxFileDialog dlg2(0,_(
"Specify output prefix"),
605 wxConfigBase::Get()->Read(wxT(
"/actualPath"),wxT(
"")),
607 wxFD_SAVE, wxDefaultPosition);
608 dlg2.SetDirectory(wxConfigBase::Get()->Read(wxT(
"/actualPath"),wxT(
"")));
609 if (dlg2.ShowModal() == wxID_OK)
611 outname = dlg2.GetPath();
615 wxLogError( _(
"No output prefix specified"));
618 scriptFile = dlg.GetPath();
622 wxLogError(_(
"No project files specified"));
628 wxFileName outfn(outname);
629 wxString ext = outfn.GetExt();
631 if (ext.CmpNoCase(wxT(
"jpg")) == 0 || ext.CmpNoCase(wxT(
"jpeg")) == 0 ||
632 ext.CmpNoCase(wxT(
"tif")) == 0 || ext.CmpNoCase(wxT(
"tiff")) == 0 ||
633 ext.CmpNoCase(wxT(
"png")) == 0 || ext.CmpNoCase(wxT(
"exr")) == 0 ||
634 ext.CmpNoCase(wxT(
"pnm")) == 0 || ext.CmpNoCase(wxT(
"hdr")) == 0)
637 outname = outfn.GetFullPath();
644 stitchFrame->Show(
true );
645 wxTheApp->SetTopWindow( stitchFrame );
648 wxFileName basename(scriptFile);
649 stitchFrame->SetTitle(wxString::Format(_(
"%s - Stitching"), basename.GetName().c_str()));
655 bool n = stitchFrame->
StitchProject(scriptFile, outname, userDefinedOutput);
662 stitchFrame->Close();
671 delete wxConfigBase::Set((wxConfigBase*)NULL);
676 stitchFrame->Show(
true );
677 wxTheApp->SetTopWindow( stitchFrame );
680 wxFileName basename(scriptFile);
681 stitchFrame->SetTitle(wxString::Format(_(
"%s - Assistant"), basename.GetName().c_str()));
683 bool n = stitchFrame->
DetectProject(scriptFile, userDefinedAssistant);
690 stitchFrame->Close();
705 for(
unsigned int i=0; i<
m_projList.GetCount(); i++)
720 for(
unsigned int i=0; i<
m_projList.GetCount(); i++)
738 wxMessageBox(wxString::Format(_(
"Error removing, project with id %d is not in list."),
id),_(
"Error!"),wxOK | wxICON_INFORMATION );
749 wxFileName file(
m_projList.Item(selIndex).path);
750 if(file.FileExists())
752 if(!wxRemoveFile(file.GetFullPath()))
754 wxMessageBox(wxString::Format(_(
"Error: Could not delete project file %s"), file.GetFullPath()),_(
"Error!"),wxOK | wxICON_INFORMATION );
770 ((wxFrame*)GetParent())->SetStatusText(_(
"Running batch..."));
772 m_resBlocker =
new wxPowerResourceBlocker(wxPOWER_RESOURCE_SYSTEM, _(
"PTBatcherGUI is stitching"));
777 ((wxFrame*)GetParent())->SetStatusText(_(
"Batch already in progress."));
791 SetStatusText(wxString::Format(_(
"Running command \"%s\""),
m_projList.Item(i).path.c_str()));
794 if(wxExecute(
m_projList.Item(i).path, wxEXEC_SYNC)==0)
810 if (!
m_projList.Item(i).userDefindSequence.empty())
824 wxCommandEvent e(EVT_INFORMATION,wxID_ANY);
825 e.SetString(wxString::Format(_(
"Now stitching: %s"),
m_projList.Item(i).path.c_str()));
826 GetParent()->GetEventHandler()->AddPendingEvent(e);
831 wxCommandEvent e(EVT_INFORMATION,wxID_ANY);
832 e.SetString(wxString::Format(_(
"Now detecting: %s"),
m_projList.Item(i).path.c_str()));
833 GetParent()->GetEventHandler()->AddPendingEvent(e);
854 wxFileConfig batchFile;
857 batchFile.Write(
"/Main/Count",
m_projList.GetCount());
859 for (
unsigned int i = 0; i <
m_projList.GetCount(); i++)
861 batchFile.SetPath(wxString::Format(
"/Project_%u", i + 1));
862 batchFile.Write(
"Project",
m_projList.Item(i).path);
866 batchFile.Write(
"Type",
"Stitching");
867 batchFile.Write(
"Prefix",
m_projList.Item(i).prefix);
870 batchFile.Write(
"Type",
"Detecting");
873 if (!
m_projList.Item(i).userDefindSequence.IsEmpty())
875 batchFile.Write(
"UserDefinedSequence",
m_projList.Item(i).userDefindSequence);
878 batchFile.Write(
"Status", (
long)
m_projList.Item(i).status);
881 batchFile.Write(
"Skip",
m_projList.Item(i).skip);
884 wxFileOutputStream fileStream(file);
885 batchFile.Save(fileStream);
892 if (userDataDir.IsEmpty())
896 userDataDir = wxStandardPaths::Get().GetUserConfigDir();
898 return wxFileName(userDataDir, _T(
"PTBatcherQueue.ptq")).GetFullPath();
914 wxMessageBox(wxString::Format(_(
"Error: Could not set status, project with index %d is not in list."),index),_(
"Error!"),wxOK | wxICON_INFORMATION );
940 return wxEmptyString;
952 return wxEmptyString;
wxDEFINE_EVENT(EVT_QUEUE_PROGRESS, wxCommandEvent)
bool NoErrors()
Returns true if there are no failed projects in batch.
int GetRunningCount()
Returns number of projects currently in progress.
int ClearBatch()
Clears batch list and returns 0 if succesful.
int GetFirstAvailable()
Returns index of first waiting project in batch.
bool FileExists(const std::string &filename)
checks if file exists
void SwapProject(int index)
Swaps position in batch of project at index with project at index+1.
void RemoveProjectAtIndex(int selIndex)
Removes project at index from batch list.
int GetProjectCount()
Returns number of projects in batch list.
FrameArray m_stitchFrames
RunStitchPanel * m_stitchPanel
int GetIndex(int id)
Returns index of project with selected id.
void SetStatus(int index, Project::Status status)
Used internally to set status of selected project.
void CancelBatch()
Stops batch run, failing projects in progress.
bool OnDetect(wxString scriptFile, wxString userDefinedAssistant, int id)
called to start detecting
void RemoveProject(int id)
Removes project with id from batch list.
void AddProjectToBatch(wxString projectFile, wxString outputFile=wxEmptyString, wxString userDefinedSequence=wxEmptyString, Project::Target target=Project::STITCHING)
Adds a project entry in the batch list.
void AddAppToBatch(wxString app)
Adds an application entry in the batch list.
bool StitchProject(wxString scriptFile, wxString outname, wxString userDefinedOutput=wxEmptyString)
Starts stitching of project file.
int LoadBatchFile(wxString file)
Clears current batch list and loads projects from batch file.
bool IsPaused()
Returns true if batch execution is currently paused.
void ChangePrefix(int index, wxString newPrefix)
Changes output prefix for project at index.
void AppendBatchFile(wxString file)
Appends projects from file to batch list.
bool DetectProject(wxString scriptFile, wxString userDefinedAssistant=wxEmptyString)
starts assistant of project file
Project::Status GetStatus(int index)
Returns current status of project at index.
bool IsRunning()
return true, if batch is running
void RunNextInBatch()
Starts execution of next waiting project in batch.
wxString GetFailedProjectName(unsigned int i)
returns project file name of failed project with index i
void PauseBatch()
Pauses and continues batch execution.
wxPowerResourceBlocker * m_resBlocker
void SaveTemp()
Saves batch list to temporary file.
Project * GetProject(int index)
Returns project at index.
void ShowOutput(bool isVisible=true)
Set visibility of all running projects.
int GetProjectCountByPath(wxString path)
Returns number of projects in batch list with the input file path.
void RunBatch()
Starts batch execution.
std::vector< FailedProject > m_failedProjects
Batch(wxFrame *parent)
Main constructor.
void SetOverwrite(bool over=true)
void CancelProject(int index)
Cancels project at index in batch, failing it.
void SaveBatchFile(wxString file)
Saves batch list to file.
bool CompareProjectsInLists(int stitchListIndex, int batchListIndex)
Compares two project at indexes in both lists and returns true if they have identical project ids...
std::string GetUserAppDataDir()
returns the directory for user specific Hugin settings, e.g.
wxString GetBatchFilename()
returns the filename of the default queue file
bool AllDone()
Returns true if there are no more projects pending execution.
Batch processor for Hugin.
void SetProjectId(int id)
Sets project id from batch.
void OnProcessTerminate(wxProcessEvent &event)
Called internally when all running processes have completed and need to be removed from running list...
wxString GetFailedProjectLog(unsigned int i)
returns log file name of failed project with index i
int LoadTemp()
Loads temporary batch file.
bool OnStitch(wxString scriptFile, wxString outname, wxString userDefinedOutput, int id)
Called to start stitch of project with input scriptFile.
void ChangeUserDefined(int index, wxString newUserDefined)
Changes user defined sequence for project at index.