Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BatchFrame.cpp
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
2 
27 #include "BatchFrame.h"
28 #include <wx/stdpaths.h>
29 #include "PTBatcherGUI.h"
30 #include "FindPanoDialog.h"
31 #include "FailedProjectsDialog.h"
33 #include "GenerateSequenceDialog.h"
34 #ifdef __WXMSW__
35 #include <powrprof.h>
36 #ifdef _MSC_VER
37 #pragma comment(lib, "PowrProf.lib")
38 #endif
39 #include <wx/taskbarbutton.h>
40 #endif
41 #include "base_wx/wxutils.h"
42 
43 /* file drag and drop handler method */
44 bool BatchDropTarget::OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames)
45 {
46  BatchFrame* MyBatchFrame = wxGetApp().GetFrame();
47  if (!MyBatchFrame)
48  {
49  return false;
50  }
51  if(filenames.GetCount()==0)
52  {
53  return false;
54  }
55  for(unsigned int i=0; i< filenames.GetCount(); i++)
56  {
57  wxFileName file(filenames[i]);
58  if(file.HasExt())
59  {
60  if (file.GetExt().CmpNoCase("pto") == 0 ||
61  file.GetExt().CmpNoCase("ptp") == 0 ||
62  file.GetExt().CmpNoCase("pts") == 0 )
63  {
64  if(file.FileExists())
65  {
66  MyBatchFrame->AddToList(filenames[i]);
67  }
68  };
69  }
70  else
71  {
72  if(file.DirExists())
73  {
74  MyBatchFrame->AddDirToList(filenames[i]);
75  }
76  };
77  };
78  return true;
79 };
80 
81 enum
82 {
84 };
85 
86 BatchFrame::BatchFrame(wxLocale* locale, wxString xrc)
87 {
88  this->SetLocaleAndXRC(locale,xrc);
89  m_cancelled = false;
90 
91  //load xrc resources
92  wxXmlResource::Get()->LoadFrame(this, (wxWindow* )NULL, "batch_frame");
93  // load our menu bar
94 #ifdef __WXMAC__
95  wxApp::s_macExitMenuItemId = XRCID("menu_exit");
96  wxApp::s_macHelpMenuTitleName = _("&Help");
97 #endif
98  SetMenuBar(wxXmlResource::Get()->LoadMenuBar(this, "batch_menu"));
99 
100  // create tool bar
101  SetToolBar(wxXmlResource::Get()->LoadToolBar(this, "batch_toolbar"));
102 
103  int widths[2] = { -1, 150 };
104  CreateStatusBar(2);
105  SetStatusWidths(2, widths);
106  SetStatusText(_("Not doing much..."));
107 
108  // set the minimize icon
109 #ifdef __WXMSW__
110  m_iconNormal = wxIcon(m_xrcPrefix + "data/ptbatcher.ico", wxBITMAP_TYPE_ICO);
111  m_iconRunning = wxIcon(m_xrcPrefix + "data/ptbatcher_running.ico", wxBITMAP_TYPE_ICO);
112  m_iconPaused = wxIcon(m_xrcPrefix + "data/ptbatcher_pause.ico", wxBITMAP_TYPE_ICO);
113  wxIconBundle myIcons(m_xrcPrefix + "data/ptbatcher.ico", wxBITMAP_TYPE_ICO);
114  SetIcons(myIcons);
115 #else
116  m_iconNormal = wxIcon(m_xrcPrefix + "data/ptbatcher.png", wxBITMAP_TYPE_PNG);
117  m_iconRunning = wxIcon(m_xrcPrefix + "data/ptbatcher_running.png", wxBITMAP_TYPE_PNG);
118  m_iconPaused = wxIcon(m_xrcPrefix + "data/ptbatcher_pause.png", wxBITMAP_TYPE_PNG);
119  SetIcon(m_iconNormal);
120 #endif
121 
122  m_batch = new Batch(this);
123  if(wxGetKeyState(WXK_COMMAND))
124  {
125 #ifdef __WXMAC__
126  wxString text(_("You have pressed the Command key."));
127 #else
128  wxString text(_("You have pressed the Control key."));
129 #endif
130  text.Append("\n");
131  text.Append(_("Should the loading of the batch queue be skipped?"));
132  if (hugin_utils::HuginMessageBox(text, _("PTBatcherGUI"), wxYES_NO | wxICON_EXCLAMATION, this) == wxNO)
133  {
134  m_batch->LoadTemp();
135  }
136  else
137  {
138  // save empty batch queue
139  m_batch->SaveTemp();
140  };
141  }
142  else
143  {
144  m_batch->LoadTemp();
145  };
146  projListBox = XRCCTRL(*this,"project_listbox",ProjectListBox);
147  projListBox->Bind(wxEVT_LIST_ITEM_ACTIVATED, &BatchFrame::OnButtonOpenWithHugin, this);
148  // fill at end list box, check which options are available
149  m_endChoice = XRCCTRL(*this, "choice_end", wxChoice);
150  m_endChoice->Clear();
151  m_endChoice->Append(_("Do nothing"), (void*)Batch::DO_NOTHING);
152  m_endChoice->Append(_("Close PTBatcherGUI"), (void*)Batch::CLOSE_PTBATCHERGUI);
153 #if !defined __WXMAC__ && !defined __WXOSX_COCOA__
154  // there is no wxShutdown for wxMac
155  m_endChoice->Append(_("Shutdown computer"), (void*)Batch::SHUTDOWN);
156 #endif
157  m_endChoice->Bind(wxEVT_CHOICE, &BatchFrame::OnChoiceEnd, this);
158 #ifdef __WXMSW__
159  SYSTEM_POWER_CAPABILITIES pwrCap;
160  if (GetPwrCapabilities(&pwrCap))
161  {
162  if (pwrCap.SystemS3)
163  {
164  m_endChoice->Append(_("Suspend computer"), (void*)Batch::SUSPEND);
165  };
166  if (pwrCap.SystemS4 && pwrCap.HiberFilePresent)
167  {
168  m_endChoice->Append(_("Hibernate computer"), (void*)Batch::HIBERNATE);
169  };
170  };
171 #endif
172 
173  //TO-DO: include a batch or project progress gauge?
175  SetDropTarget(new BatchDropTarget());
176 
177  m_tray = NULL;
178  if (wxTaskBarIcon::IsAvailable())
179  {
180  // minimize to tray is by default disabled
181  // activate only if task bar icon is available
182  GetMenuBar()->Enable(XRCID("menu_tray"), true);
183  bool minTray;
184  // tray icon is disabled by default
185  wxConfigBase::Get()->Read("/BatchFrame/minimizeTray", &minTray, false);
186  GetMenuBar()->Check(XRCID("menu_tray"), minTray);
187  UpdateTrayIcon(minTray);
188  }
189 
191 
192 #ifndef __WXMSW__
193  // check settings of help window and fix when needed
194  FixHelpSettings();
195 #endif
196  m_updateProjectsTimer = new wxTimer(this, EVT_TIMER_UPDATE_LISTBOX);
197  // start timer for check for updates in project files
198  m_updateProjectsTimer->StartOnce(5000);
199  // connect all events
200  // tool buttons
201  Bind(wxEVT_TOOL, &BatchFrame::OnButtonClear, this, XRCID("tool_clear"));
202  Bind(wxEVT_TOOL, &BatchFrame::OnButtonOpenBatch, this, XRCID("tool_open"));
203  Bind(wxEVT_TOOL, &BatchFrame::OnButtonSaveBatch, this, XRCID("tool_save"));
204  Bind(wxEVT_TOOL, &BatchFrame::OnButtonRunBatch, this, XRCID("tool_start"));
205  Bind(wxEVT_TOOL, &BatchFrame::OnButtonSkip, this, XRCID("tool_skip"));
206  Bind(wxEVT_TOOL, &BatchFrame::OnButtonPause, this, XRCID("tool_pause"));
207  Bind(wxEVT_TOOL, &BatchFrame::OnButtonCancel, this, XRCID("tool_cancel"));
208  Bind(wxEVT_TOOL, &BatchFrame::OnButtonAddToStitchingQueue, this, XRCID("tool_add"));
209  Bind(wxEVT_TOOL, &BatchFrame::OnButtonRemoveFromList, this, XRCID("tool_remove"));
210  Bind(wxEVT_TOOL, &BatchFrame::OnButtonAddDir, this, XRCID("tool_adddir"));
211  // menu items
212  Bind(wxEVT_MENU, &BatchFrame::OnButtonAddToStitchingQueue, this, XRCID("menu_add"));
213  Bind(wxEVT_MENU, &BatchFrame::OnButtonAddToAssistantQueue, this, XRCID("menu_add_assistant"));
214  Bind(wxEVT_MENU, &BatchFrame::OnButtonRemoveFromList, this, XRCID("menu_remove"));
215  Bind(wxEVT_MENU, &BatchFrame::OnButtonAddDir, this, XRCID("menu_adddir"));
216  Bind(wxEVT_MENU, &BatchFrame::OnButtonSearchPano, this, XRCID("menu_searchpano"));
217  Bind(wxEVT_MENU, &BatchFrame::OnButtonGenerateSequence, this, XRCID("menu_generate_sequence"));
218  Bind(wxEVT_MENU, &BatchFrame::OnButtonOpenBatch, this, XRCID("menu_open"));
219  Bind(wxEVT_MENU, &BatchFrame::OnButtonSaveBatch, this, XRCID("menu_save"));
220  Bind(wxEVT_MENU, &BatchFrame::OnButtonClear, this, XRCID("menu_clear"));
221  Bind(wxEVT_MENU, &BatchFrame::OnMinimizeTrayMenu, this, XRCID("menu_tray"));
222  Bind(wxEVT_MENU, &BatchFrame::OnUserExit, this, XRCID("menu_exit"));
223  Bind(wxEVT_MENU, &BatchFrame::OnButtonHelp, this, XRCID("menu_help"));
224  // buttons
225  Bind(wxEVT_BUTTON, &BatchFrame::OnButtonAddCommand, this, XRCID("button_addcommand"));
226  Bind(wxEVT_BUTTON, &BatchFrame::OnButtonRemoveComplete, this, XRCID("button_remove"));
227  Bind(wxEVT_BUTTON, &BatchFrame::OnButtonChangePrefix, this, XRCID("button_prefix"));
228  Bind(wxEVT_BUTTON, &BatchFrame::OnButtonChangeUserDefinedSequence, this, XRCID("button_user_defined"));
229  Bind(wxEVT_BUTTON, &BatchFrame::OnButtonReset, this, XRCID("button_reset"));
230  Bind(wxEVT_BUTTON, &BatchFrame::OnButtonResetAll, this, XRCID("button_resetall"));
231  Bind(wxEVT_BUTTON, &BatchFrame::OnButtonOpenWithHugin, this, XRCID("button_edit"));
232  Bind(wxEVT_BUTTON, &BatchFrame::OnButtonMoveUp, this, XRCID("button_move_up"));
233  Bind(wxEVT_BUTTON, &BatchFrame::OnButtonMoveDown, this, XRCID("button_move_down"));
234  // checkboxes
235  Bind(wxEVT_CHECKBOX, &BatchFrame::OnCheckOverwrite, this, XRCID("cb_overwrite"));
236  Bind(wxEVT_CHECKBOX, &BatchFrame::OnCheckVerbose, this, XRCID("cb_verbose"));
237  Bind(wxEVT_CHECKBOX, &BatchFrame::OnCheckAutoRemove, this, XRCID("cb_autoremove"));
238  Bind(wxEVT_CHECKBOX, &BatchFrame::OnCheckAutoStitch, this, XRCID("cb_autostitch"));
239  Bind(wxEVT_CHECKBOX, &BatchFrame::OnCheckSaveLog, this, XRCID("cb_savelog"));
240  // some general flow events
241  Bind(wxEVT_END_PROCESS, &BatchFrame::OnProcessTerminate, this);
242  Bind(wxEVT_CLOSE_WINDOW, &BatchFrame::OnClose, this);
243  Bind(wxEVT_TIMER, &BatchFrame::OnUpdateListBox, this, EVT_TIMER_UPDATE_LISTBOX);
244  Bind(EVT_BATCH_FAILED, &BatchFrame::OnBatchFailed, this);
245  Bind(EVT_INFORMATION, &BatchFrame::OnBatchInformation, this);
246  Bind(EVT_UPDATE_PARENT, &BatchFrame::OnRefillListBox, this);
247  Bind(EVT_QUEUE_PROGRESS, &BatchFrame::OnProgress, this);
248  Bind(wxEVT_ICONIZE, &BatchFrame::OnMinimize, this);
249 }
250 
251 wxStatusBar* BatchFrame::OnCreateStatusBar(int number, long style, wxWindowID id, const wxString& name)
252 {
253  m_progStatusBar = new ProgressStatusBar(this, id, style, name);
254  m_progStatusBar->SetFieldsCount(number);
255  return m_progStatusBar;
256 }
257 
259 {
260  return m_batch->IsRunning();
261 };
262 
264 {
265  return m_batch->IsPaused();
266 };
267 
268 void BatchFrame::OnUpdateListBox(wxTimerEvent& event)
269 {
270  wxFileName tempFile;
271  bool change = false;
272  for(int i = 0; i< m_batch->GetProjectCount(); i++)
273  {
275  {
276  tempFile.Assign(m_batch->GetProject(i)->path);
277  if(tempFile.FileExists())
278  {
279  wxDateTime modify;
280  modify=tempFile.GetModificationTime();
281  if(m_batch->GetProject(i)->skip)
282  {
283  change = true;
284  m_batch->GetProject(i)->skip = false;
287  }
288  else if(!modify.IsEqualTo(m_batch->GetProject(i)->modDate))
289  {
290  change = true;
291  m_batch->GetProject(i)->modDate = modify;
294  {
296  };
298  }
299  if (!m_batch->GetProject(i)->userDefindSequence.empty())
300  {
301  // check for existence of user defined sequence
303  {
304  change = true;
305  m_batch->GetProject(i)->skip = true;
308  };
309  };
310  }
311  else
312  {
314  {
315  change = true;
316  m_batch->GetProject(i)->skip = true;
319  }
320  }
321  }
323  {
324  change = true;
325  }
326  }
327  if(change)
328  {
329  m_batch->SaveTemp();
330  };
331  // start timer again
332  m_updateProjectsTimer->StartOnce(2000);
333 };
334 
335 void BatchFrame::OnUserExit(wxCommandEvent& event)
336 {
337  Close(true);
338 };
339 
340 void BatchFrame::OnButtonAddCommand(wxCommandEvent& event)
341 {
342  wxTextEntryDialog dlg(this,_("Please enter the command-line application to execute:"),_("Enter application"));
343  wxTheApp->SetEvtHandlerEnabled(false);
344  if(dlg.ShowModal() == wxID_OK)
345  {
346  wxString line = dlg.GetValue();
347  m_batch->AddAppToBatch(line);
348  //SetStatusText(_T("Added application"));
350  m_batch->SaveTemp();
351  }
352  wxTheApp->SetEvtHandlerEnabled(true);
353 }
354 
355 void BatchFrame::OnButtonAddDir(wxCommandEvent& event)
356 {
357  wxString defaultdir = wxConfigBase::Get()->Read("/BatchFrame/actualPath",wxEmptyString);
358  wxDirDialog dlg(this,
359  _("Specify a directory to search for projects in"),
360  defaultdir, wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST);
361  dlg.SetPath(wxConfigBase::Get()->Read("/BatchFrame/actualPath",wxEmptyString));
362  if (dlg.ShowModal() == wxID_OK)
363  {
364  wxConfig::Get()->Write("/BatchFrame/actualPath", dlg.GetPath()); // remember for later
365  AddDirToList(dlg.GetPath());
366  };
367 }
368 
369 void BatchFrame::OnButtonSearchPano(wxCommandEvent& e)
370 {
371  FindPanoDialog findpano_dlg(this,m_xrcPrefix);
372  findpano_dlg.ShowModal();
373 };
374 
376 {
377  wxString defaultdir = wxConfigBase::Get()->Read("/BatchFrame/actualPath", wxEmptyString);
378  wxFileDialog dlg(0,
379  _("Specify project source file(s)"),
380  defaultdir, wxEmptyString,
381  _("Project files (*.pto)|*.pto|All files (*)|*"),
382  wxFD_OPEN , wxDefaultPosition);
383  dlg.SetDirectory(defaultdir);
384 
385  if (dlg.ShowModal() == wxID_OK)
386  {
387  wxConfig::Get()->Write("/BatchFrame/actualPath", wxPathOnly(dlg.GetPath()));
388  GenerateSequenceDialog sequenceDialog(this, m_xrcPrefix, dlg.GetPath());
389  if (sequenceDialog.IsValidPanorama())
390  {
391  if (sequenceDialog.ShowModal())
392  {
393  };
394  }
395  else
396  {
397  hugin_utils::HuginMessageBox(wxString::Format(_("Could not read file %s as valid Hugin pto file."), dlg.GetPath()), _("PTBatcherGUI"),
398  wxOK | wxICON_EXCLAMATION, this);
399  };
400  };
401 };
402 
403 void BatchFrame::OnButtonAddToStitchingQueue(wxCommandEvent& event)
404 {
405  wxString defaultdir = wxConfigBase::Get()->Read("/BatchFrame/actualPath",wxEmptyString);
406  wxFileDialog dlg(0,
407  _("Specify project source file(s)"),
408  defaultdir, wxEmptyString,
409  _("Project files (*.pto)|*.pto|All files (*)|*"),
410  wxFD_OPEN | wxFD_MULTIPLE, wxDefaultPosition);
411  dlg.SetDirectory(defaultdir);
412 
413  if (dlg.ShowModal() == wxID_OK)
414  {
415  wxArrayString paths;
416  dlg.GetPaths(paths);
417 #ifdef __WXGTK__
418  //workaround a bug in GTK, see https://bugzilla.redhat.com/show_bug.cgi?id=849692 and http://trac.wxwidgets.org/ticket/14525
419  wxConfig::Get()->Write("/BatchFrame/actualPath", wxPathOnly(paths[0])); // remember for later
420 #else
421  wxConfig::Get()->Write("/BatchFrame/actualPath", dlg.GetDirectory()); // remember for later
422 #endif
423  for(unsigned int i=0; i<paths.GetCount(); i++)
424  {
425  AddToList(paths.Item(i));
426  }
427  m_batch->SaveTemp();
428  };
429 }
430 
431 void BatchFrame::OnButtonAddToAssistantQueue(wxCommandEvent& event)
432 {
433  wxString defaultdir = wxConfigBase::Get()->Read("/BatchFrame/actualPath",wxEmptyString);
434  wxFileDialog dlg(0,
435  _("Specify project source file(s)"),
436  defaultdir, wxEmptyString,
437  _("Project files (*.pto)|*.pto|All files (*)|*"),
438  wxFD_OPEN | wxFD_MULTIPLE, wxDefaultPosition);
439  dlg.SetDirectory(defaultdir);
440 
441  if (dlg.ShowModal() == wxID_OK)
442  {
443  wxArrayString paths;
444  dlg.GetPaths(paths);
445 #ifdef __WXGTK__
446  //workaround a bug in GTK, see https://bugzilla.redhat.com/show_bug.cgi?id=849692 and http://trac.wxwidgets.org/ticket/14525
447  wxConfig::Get()->Write("/BatchFrame/actualPath", wxPathOnly(paths[0])); // remember for later
448 #else
449  wxConfig::Get()->Write("/BatchFrame/actualPath", dlg.GetDirectory()); // remember for later
450 #endif
451 
452  for(unsigned int i=0; i<paths.GetCount(); i++)
453  {
454  AddToList(paths.Item(i),Project::DETECTING);
455  }
456  m_batch->SaveTemp();
457  };
458 }
459 
460 void BatchFrame::AddDirToList(wxString aDir)
461 {
462  //we traverse all subdirectories of chosen path
463  DirTraverser traverser;
464  wxDir dir(aDir);
465  dir.Traverse(traverser);
466  wxArrayString projects = traverser.GetProjectFiles();
467  for(unsigned int i=0; i<projects.GetCount(); i++)
468  {
469  m_batch->AddProjectToBatch(projects.Item(i));
471  if(!proj->isAligned)
472  {
474  };
475  projListBox->AppendProject(proj);
476  };
477  m_batch->SaveTemp();
478  SetStatusText(wxString::Format(_("Added projects from dir %s"), aDir.c_str()));
479 };
480 
481 void BatchFrame::AddToList(wxString aFile, Project::Target target, wxString userDefined)
482 {
483  m_batch->AddProjectToBatch(aFile, wxEmptyString, userDefined, target);
484  wxString s;
485  switch(target)
486  {
487  case Project::STITCHING:
488  s=wxString::Format(_("Add project %s to stitching queue."),aFile.c_str());
489  break;
490  case Project::DETECTING:
491  s=wxString::Format(_("Add project %s to assistant queue."),aFile.c_str());
492  break;
493  };
494  SetStatusText(s);
496  m_batch->SaveTemp();
497 }
498 
499 void BatchFrame::AddArrayToList(const wxArrayString& fileList, Project::Target target)
500 {
501  for (size_t i = 0; i < fileList.GetCount(); ++i)
502  {
503  m_batch->AddProjectToBatch(fileList[i], wxEmptyString, wxEmptyString, target);
505  };
506  m_batch->SaveTemp();
507 }
508 
509 void BatchFrame::OnButtonCancel(wxCommandEvent& event)
510 {
511  GetToolBar()->ToggleTool(XRCID("tool_pause"),false);
512  m_cancelled = true;
513  m_batch->CancelBatch();
514  SetStatusText(_("Batch stopped"));
515  if (m_tray)
516  {
517  m_tray->SetIcon(m_iconNormal, _("Hugin's Batch processor"));
518  };
519 }
520 
521 void BatchFrame::OnButtonChangePrefix(wxCommandEvent& event)
522 {
524  if(selected.size()== 1)
525  {
526  Project* project = m_batch->GetProject(*selected.begin());
527  if (project->id < 0)
528  {
529  SetStatusText(_("The prefix of command cannot be changed."));
530  wxBell();
531  return;
532  }
533  if (project->target == Project::STITCHING)
534  {
535  wxFileName prefix(project->prefix);
536  wxFileDialog dlg(0, wxString::Format(_("Specify output prefix for project %s"), project->path),
537  prefix.GetPath(),
538  prefix.GetFullName(), wxEmptyString,
539  wxFD_SAVE, wxDefaultPosition);
540  if (dlg.ShowModal() == wxID_OK)
541  {
542  while(containsInvalidCharacters(dlg.GetPath()))
543  {
544  wxArrayString list;
545  list.Add(dlg.GetPath());
546  ShowFilenameWarning(this, list);
547  if(dlg.ShowModal()!=wxID_OK)
548  {
549  return;
550  }
551  };
552  wxFileName prefix(dlg.GetPath());
553  while (!prefix.IsDirWritable())
554  {
555  hugin_utils::HuginMessageBox(wxString::Format(_("You have no permissions to write in folder \"%s\".\nPlease select another folder for the final output."), prefix.GetPath()),
556  _("PTBatcherGUI"), wxOK | wxICON_INFORMATION, this);
557  if (dlg.ShowModal() != wxID_OK)
558  {
559  return;
560  };
561  prefix = dlg.GetPath();
562  };
563 
564  wxString outname(dlg.GetPath());
565  ChangePrefix(*selected.begin(), outname);
566  //SetStatusText(_T("Changed prefix for "+projListBox->GetSelectedProject()));
567  m_batch->SaveTemp();
568  }
569  }
570  else
571  {
572  SetStatusText(_("The prefix of an assistant target cannot be changed."));
573  wxBell();
574  };
575  }
576  else
577  {
578  if (selected.empty())
579  {
580  SetStatusText(_("Please select a project"));
581  }
582  else
583  {
584  wxBell();
585  SetStatusText(_("Please select only one project"));
586  };
587  };
588 }
589 
590 void BatchFrame::ChangePrefix(int index,wxString newPrefix)
591 {
592  int i;
593  if(index!=-1)
594  {
595  i=index;
596  }
597  else
598  {
599  i=m_batch->GetProjectCount()-1;
600  }
601  m_batch->ChangePrefix(i,newPrefix);
602  projListBox->ChangePrefix(i,newPrefix);
603 }
604 
605 void BatchFrame::ChangeUserDefined(int index, wxString newUserDefined)
606 {
607  int i;
608  if (index != -1)
609  {
610  i = index;
611  }
612  else
613  {
614  i = m_batch->GetProjectCount() - 1;
615  }
616  m_batch->ChangeUserDefined(i, newUserDefined);
617  projListBox->ChangeUserDefined(i, newUserDefined);
618 }
619 
621 {
622  HuginBase::UIntSet selectedProjects = projListBox->GetSelectedProjects();
623  if (selectedProjects.empty())
624  {
625  SetStatusText(_("Please select a project"));
626  }
627  else
628  {
629  Project* project = m_batch->GetProject(*selectedProjects.begin());
630  const Project::Target target = project->target;
631  for (auto& i : selectedProjects)
632  {
633  const Project* projectI = m_batch->GetProject(i);
634  if (projectI->id < 0)
635  {
636  wxBell();
637  SetStatusText(_("Changing user defined sequence is not possible for application entries."));
638  return;
639  };
640  if (target != projectI->target)
641  {
642  wxBell();
643  SetStatusText(_("You can change the user defined sequence only for the same type of operation (either stitching or assistant)."));
644  return;
645  }
646  };
648  if (dialog.ShowModal() == wxID_OK)
649  {
650  const wxString newUserDefined = dialog.GetNewSequence();
651  for (auto& i : selectedProjects)
652  {
653  m_batch->ChangeUserDefined(i, newUserDefined);
654  projListBox->ChangeUserDefined(i, newUserDefined);
655  };
656  };
657  };
658 }
659 
660 void BatchFrame::OnButtonClear(wxCommandEvent& event)
661 {
662  int returnCode = m_batch->ClearBatch();
663  if(returnCode == 0)
664  {
665  projListBox->DeleteAllItems();
666  }
667  else if(returnCode == 2)
668  {
669  m_cancelled = true;
670  projListBox->DeleteAllItems();
671  if(GetToolBar()->GetToolState(XRCID("tool_pause")))
672  {
673  GetToolBar()->ToggleTool(XRCID("tool_pause"),false);
674  }
675  }
676  m_batch->SaveTemp();
677 }
678 
679 void BatchFrame::OnButtonHelp(wxCommandEvent& event)
680 {
681  DEBUG_TRACE("");
682  GetHelpController().DisplaySection("Hugin_Batch_Processor.html");
683 }
684 
685 void BatchFrame::OnButtonMoveDown(wxCommandEvent& event)
686 {
688  if (selected.size() == 1)
689  {
690  SwapProject(*selected.begin(), true);
691  m_batch->SaveTemp();
692  }
693  else
694  {
695  wxBell();
696  };
697 }
698 
699 void BatchFrame::OnButtonMoveUp(wxCommandEvent& event)
700 {
702  if (selected.size() == 1)
703  {
704  SwapProject(*selected.begin() - 1, false);
705  m_batch->SaveTemp();
706  }
707  else
708  {
709  wxBell();
710  };
711 }
712 
713 void BatchFrame::OnButtonOpenBatch(wxCommandEvent& event)
714 {
715  wxString defaultdir = wxConfigBase::Get()->Read("/BatchFrame/batchPath",wxEmptyString);
716  wxFileDialog dlg(0,
717  _("Specify batch file to open"),
718  defaultdir, wxEmptyString,
719  _("Batch file (*.ptq)|*.ptq;|All files (*)|*"),
720  wxFD_OPEN, wxDefaultPosition);
721  if (dlg.ShowModal() == wxID_OK)
722  {
723  wxConfig::Get()->Write("/BatchFrame/batchPath", dlg.GetDirectory()); // remember for later
724  int clearCode = m_batch->LoadBatchFile(dlg.GetPath());
725  //1 is error code for not clearing batch
726  if(clearCode!=1)
727  {
728  /*if(clearCode==2) //we just cancelled the batch, so we need to try loading again
729  m_batch->LoadBatchFile(dlg.GetPath());*/
730  projListBox->DeleteAllItems();
732  m_batch->SaveTemp();
733  }
734  }
735 }
736 
737 void BatchFrame::OnButtonOpenWithHugin(wxCommandEvent& event)
738 {
739  const wxFileName exePath(wxStandardPaths::Get().GetExecutablePath());
741  if (selected.size() == 1)
742  {
743  if (projListBox->GetText(*selected.begin(), 0).Cmp(_T("")) != 0)
744 #ifdef __WXMAC__
745  wxExecute(_T("open -b net.sourceforge.Hugin \"" + m_batch->GetProject(*selected.begin())->path + _T("\"")));
746 #else
747  wxExecute(exePath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR) + _T("hugin \"" + m_batch->GetProject(*selected.begin())->path + _T("\" -notips")));
748 #endif
749  else
750  {
751  SetStatusText(_("Cannot open app in Hugin."));
752  };
753  }
754  else
755  {
756  if (selected.empty())
757  {
758  //ask user if he/she wants to load an empty project
759  if (hugin_utils::HuginMessageBox(_("No project selected. Open Hugin without project?"), _("PTBatcherGUI"), wxYES_NO|wxICON_INFORMATION, this) == wxYES)
760  {
761 #ifdef __WXMAC__
762  wxExecute(_T("open -b net.sourceforge.Hugin"));
763 #else
764  wxExecute(exePath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR) + _T("hugin"));
765 #endif
766  }
767  }
768  else
769  {
770  wxBell();
771  SetStatusText(_("Please select only one project"));
772  };
773  };
774 }
775 
776 void BatchFrame::OnButtonPause(wxCommandEvent& event)
777 {
778  if(m_batch->GetRunningCount()>0)
779  {
780  if(!m_batch->IsPaused())
781  {
782  m_batch->PauseBatch();
783  GetToolBar()->ToggleTool(XRCID("tool_pause"),true);
784  SetStatusText(_("Batch paused"));
785  if (m_tray)
786  {
787  m_tray->SetIcon(m_iconPaused, _("Pausing processing Hugin's batch queue"));
788  };
789  }
790  else
791  {
792  m_batch->PauseBatch();
793  GetToolBar()->ToggleTool(XRCID("tool_pause"),false);
794  SetStatusText(_("Continuing batch..."));
795  if (m_tray)
796  {
797  m_tray->SetIcon(m_iconRunning, _("Processing Hugin's batch queue"));
798  };
799  }
800  }
801  else //if no projects are running, we deactivate the button
802  {
803  GetToolBar()->ToggleTool(XRCID("tool_pause"),false);
804  }
806 }
807 
808 void BatchFrame::OnButtonRemoveComplete(wxCommandEvent& event)
809 {
810  bool removeErrors=false;
811  if(!m_batch->NoErrors())
812  {
813  if (hugin_utils::HuginMessageBox(_("There are failed projects in the list.\nRemove them too?"), _("PTBatcherGUI"), wxYES_NO | wxICON_INFORMATION, this) == wxYES)
814  {
815  removeErrors=true;
816  }
817  }
818  for(int i=projListBox->GetItemCount()-1; i>=0; i--)
819  {
821  (removeErrors && m_batch->GetStatus(i)==Project::FAILED))
822  {
823  projListBox->Deselect(i);
824  projListBox->DeleteItem(i);
826  }
827  }
828  m_batch->SaveTemp();
829 }
830 
831 void BatchFrame::OnButtonRemoveFromList(wxCommandEvent& event)
832 {
833 
835  if(!selected.empty())
836  {
837  for (auto i = selected.rbegin(); i != selected.rend(); ++i)
838  {
839  const int selIndex = *i;
840  if (m_batch->GetStatus(selIndex) == Project::RUNNING || m_batch->GetStatus(selIndex) == Project::PAUSED)
841  {
842  if (hugin_utils::HuginMessageBox(_("Cannot remove project in progress.\nDo you want to cancel it?"), _("PTBatcherGUI"), wxYES_NO | wxICON_INFORMATION, this) == wxYES)
843  {
844  OnButtonSkip(event);
845  };
846  }
847  else
848  {
849  SetStatusText(wxString::Format(_("Removed project %s"), m_batch->GetProject(selIndex)->path.c_str()));
850  projListBox->Deselect(selIndex);
851  projListBox->DeleteItem(selIndex);
852  m_batch->RemoveProjectAtIndex(selIndex);
853  m_batch->SaveTemp();
854  };
855  };
856  }
857  else
858  {
859  SetStatusText(_("Please select a project to remove"));
860  }
861 }
862 
863 
864 void BatchFrame::OnButtonReset(wxCommandEvent& event)
865 {
867  if(!selected.empty())
868  {
869  for (auto selIndex : selected)
870  {
871  if (m_batch->GetStatus(selIndex) == Project::RUNNING || m_batch->GetStatus(selIndex) == Project::PAUSED)
872  {
873  if (hugin_utils::HuginMessageBox(_("Cannot reset project in progress.\nDo you want to cancel it?"), _("PTBatcherGUI"), wxYES_NO | wxICON_INFORMATION, this) == wxYES)
874  {
875  OnButtonSkip(event);
876  }
877  }
878  else
879  {
880  m_batch->SetStatus(selIndex, Project::WAITING);
881  SetStatusText(wxString::Format(_("Reset project %s"), m_batch->GetProject(selIndex)->path.c_str()));
882  };
883  };
884  }
885  else
886  {
887  SetStatusText(_("Please select a project to reset"));
888  }
889  m_batch->SaveTemp();
890 }
891 
892 void BatchFrame::OnButtonResetAll(wxCommandEvent& event)
893 {
894  if(m_batch->GetRunningCount()!=0)
895  {
896  if (hugin_utils::HuginMessageBox(_("Cannot reset projects in progress.\nDo you want to cancel the batch?"), _("PTBatcherGUI"), wxYES_NO | wxICON_INFORMATION, this) == wxYES)
897  {
898  OnButtonCancel(event);
899  }
900  }
901  else
902  {
903  for(int i=projListBox->GetItemCount()-1; i>=0; i--)
904  {
906  }
907  }
908  m_batch->SaveTemp();
909 }
910 
911 void BatchFrame::OnButtonRunBatch(wxCommandEvent& event)
912 {
913  if(m_batch->IsPaused())
914  {
915  //m_batch->paused = false;
916  OnButtonPause(event);
917  }
918  else
919  {
920  RunBatch();
921  }
922 }
923 
924 void BatchFrame::OnButtonSaveBatch(wxCommandEvent& event)
925 {
926  wxString defaultdir = wxConfigBase::Get()->Read("/BatchFrame/batchPath",wxEmptyString);
927  wxFileDialog dlg(0,
928  _("Specify batch file to save"),
929  defaultdir, wxEmptyString,
930  _("Batch file (*.ptq)|*.ptq;|All files (*)|*"),
931  wxFD_SAVE | wxFD_OVERWRITE_PROMPT, wxDefaultPosition);
932  if (dlg.ShowModal() == wxID_OK)
933  {
934  wxConfig::Get()->Write("/BatchFrame/batchPath", dlg.GetDirectory()); // remember for later
935  m_batch->SaveBatchFile(dlg.GetPath());
936  }
937 }
938 
939 void BatchFrame::OnButtonSkip(wxCommandEvent& event)
940 {
942  if(!selected.empty())
943  {
944  for (auto selIndex : selected)
945  {
946  if (m_batch->GetStatus(selIndex) == Project::RUNNING
947  || m_batch->GetStatus(selIndex) == Project::PAUSED)
948  {
949  if (m_batch->GetStatus(selIndex) == Project::PAUSED)
950  {
951  if (m_batch->GetRunningCount() == 1)
952  {
953  GetToolBar()->ToggleTool(XRCID("tool_pause"), false);
954  }
955  for (int i = 0; i < m_batch->GetRunningCount(); i++)
956  {
957  if (m_batch->GetStatus(selIndex) == Project::PAUSED
958  && m_batch->CompareProjectsInLists(i, selIndex))
959  {
961  }
962  }
963  }
964  else
965  {
966  //we go through all running projects to find the one with the same id as chosen one
967  for (int i = 0; i < m_batch->GetRunningCount(); i++)
968  {
969  if (m_batch->GetStatus(selIndex) == Project::RUNNING
970  && m_batch->CompareProjectsInLists(i, selIndex))
971  {
973  }
974  }
975  }
976  }
977  else
978  {
979  m_batch->SetStatus(selIndex, Project::FAILED);
980  };
981  };
982  }
983 }
984 
985 void SelectEndTask(wxControlWithItems* list, const Batch::EndTask endTask)
986 {
987  for (unsigned int i = 0; i<list->GetCount(); i++)
988  {
989  if (static_cast<Batch::EndTask>((size_t)list->GetClientData(i)) == endTask)
990  {
991  list->SetSelection(i);
992  return;
993  };
994  };
995  list->SetSelection(0);
996 };
997 
999 {
1000  wxConfigBase* config=wxConfigBase::Get();
1001  int i;
1002  // read older version
1003 #if defined __WXMAC__ || defined __WXOSX_COCOA__
1004  i = 0;
1005 #else
1006  i=config->Read("/BatchFrame/ShutdownCheck", 0l);
1007 #endif
1008  if (i != 0)
1009  {
1012  };
1013  config->DeleteEntry("/BatchFrame/ShutdownCheck");
1014  // now read current version
1015  i = config->Read("/BatchFrame/AtEnd", 0l);
1016 #if defined __WXMAC__ || defined __WXOSX_COCOA__
1017  // wxWidgets for MacOS does not support wxShutdown
1018  if (i == Batch::SHUTDOWN)
1019  {
1020  i = 0;
1021  };
1022 #endif
1023  m_batch->atEnd = static_cast<Batch::EndTask>(i);
1025  i=config->Read("/BatchFrame/OverwriteCheck", 0l);
1026  XRCCTRL(*this,"cb_overwrite",wxCheckBox)->SetValue(i!=0);
1027  m_batch->overwrite=(i!=0);
1028  i=config->Read("/BatchFrame/VerboseCheck", 0l);
1029  XRCCTRL(*this,"cb_verbose",wxCheckBox)->SetValue(i!=0);
1030  m_batch->verbose=(i!=0);
1031  i=config->Read("/BatchFrame/AutoRemoveCheck", 1l);
1032  XRCCTRL(*this,"cb_autoremove",wxCheckBox)->SetValue(i!=0);
1033  m_batch->autoremove=(i!=0);
1034  i=config->Read("/BatchFrame/AutoStitchCheck", 0l);
1035  XRCCTRL(*this,"cb_autostitch",wxCheckBox)->SetValue(i!=0);
1036  m_batch->autostitch=(i!=0);
1037  i=config->Read("/BatchFrame/SaveLog", 0l);
1038  XRCCTRL(*this, "cb_savelog",wxCheckBox)->SetValue(i!=0);
1039  m_batch->saveLog=(i!=0);
1040 };
1041 
1043 {
1044  return static_cast<Batch::EndTask>((size_t)m_endChoice->GetClientData(m_endChoice->GetSelection()));
1045 };
1046 
1048 {
1049  return XRCCTRL(*this,"cb_overwrite",wxCheckBox)->IsChecked();
1050 };
1051 
1053 {
1054  return XRCCTRL(*this,"cb_verbose",wxCheckBox)->IsChecked();
1055 };
1056 
1058 {
1059  return XRCCTRL(*this,"cb_autoremove",wxCheckBox)->IsChecked();
1060 };
1061 
1063 {
1064  return XRCCTRL(*this,"cb_autostitch",wxCheckBox)->IsChecked();
1065 };
1066 
1068 {
1069  return XRCCTRL(*this,"cb_savelog",wxCheckBox)->IsChecked();
1070 };
1071 
1072 void BatchFrame::OnCheckOverwrite(wxCommandEvent& event)
1073 {
1074  wxConfigBase* config=wxConfigBase::Get();
1075  if(event.IsChecked())
1076  {
1077  m_batch->overwrite = true;
1078  config->Write("/BatchFrame/OverwriteCheck", 1l);
1079  }
1080  else
1081  {
1082  m_batch->overwrite = false;
1083  config->Write("/BatchFrame/OverwriteCheck", 0l);
1084  }
1085  config->Flush();
1086 }
1087 
1088 void BatchFrame::OnChoiceEnd(wxCommandEvent& event)
1089 {
1090  m_batch->atEnd = static_cast<Batch::EndTask>((size_t)m_endChoice->GetClientData(event.GetSelection()));
1091  wxConfigBase* config=wxConfigBase::Get();
1092  config->Write("/BatchFrame/AtEnd", static_cast<long>(m_batch->atEnd));
1093  config->Flush();
1094 }
1095 
1096 void BatchFrame::OnCheckVerbose(wxCommandEvent& event)
1097 {
1098  wxConfigBase* config=wxConfigBase::Get();
1099  if(event.IsChecked())
1100  {
1101  m_batch->verbose = true;
1102  config->Write("/BatchFrame/VerboseCheck", 1l);
1103  }
1104  else
1105  {
1106  m_batch->verbose = false;
1107  config->Write("/BatchFrame/VerboseCheck", 0l);
1108  };
1109  config->Flush();
1111 }
1112 
1113 void BatchFrame::SetInternalVerbose(bool newVerbose)
1114 {
1115  m_batch->verbose=newVerbose;
1116 };
1117 
1118 void BatchFrame::OnCheckAutoRemove(wxCommandEvent& event)
1119 {
1120  m_batch->autoremove=event.IsChecked();
1121  wxConfigBase* config=wxConfigBase::Get();
1122  if(m_batch->autoremove)
1123  {
1124  config->Write("/BatchFrame/AutoRemoveCheck", 1l);
1125  }
1126  else
1127  {
1128  config->Write("/BatchFrame/AutoRemoveCheck", 0l);
1129  }
1130  config->Flush();
1131 };
1132 
1133 void BatchFrame::OnCheckAutoStitch(wxCommandEvent& event)
1134 {
1135  m_batch->autostitch=event.IsChecked();
1136  wxConfigBase* config=wxConfigBase::Get();
1137  if(m_batch->autostitch)
1138  {
1139  config->Write("/BatchFrame/AutoStitchCheck", 1l);
1140  }
1141  else
1142  {
1143  config->Write("/BatchFrame/AutoStitchCheck", 0l);
1144  }
1145  config->Flush();
1146 };
1147 
1148 void BatchFrame::OnCheckSaveLog(wxCommandEvent& event)
1149 {
1150  m_batch->saveLog=event.IsChecked();
1151  wxConfigBase* config=wxConfigBase::Get();
1152  if(m_batch->saveLog)
1153  {
1154  config->Write("/BatchFrame/SaveLog", 1l);
1155  }
1156  else
1157  {
1158  config->Write("/BatchFrame/SaveLog", 0l);
1159  }
1160  config->Flush();
1161 };
1162 
1163 void BatchFrame::OnClose(wxCloseEvent& event)
1164 {
1165  // check size of batch queue
1166  if (m_batch->GetProjectCount() > 500)
1167  {
1168  hugin_utils::MessageDialog message = hugin_utils::GetMessageDialog(_("The batch queue contains many items.\nThis can have negative effects on performance.\nShould the batch queue be cleared now?"),
1169  _("PTBatcherGUI"), wxYES_NO | wxICON_INFORMATION, this);
1170  message->SetYesNoLabels(_("Clear batch queue now"), _("Keep batch queue"));
1171  if (message->ShowModal() == wxID_YES)
1172  {
1173  m_batch->ClearBatch();
1174  m_batch->SaveTemp();
1175  };
1176  };
1177  //save windows position
1178  wxConfigBase* config=wxConfigBase::Get();
1179  if(IsMaximized())
1180  {
1181  config->Write("/BatchFrame/Max", 1l);
1182  config->Write("/BatchFrame/Minimized", 0l);
1183  }
1184  else
1185  {
1186  config->Write("/BatchFrame/Max", 0l);
1187  if(m_tray!=NULL && !IsShown())
1188  {
1189  config->Write("/BatchFrame/Minimized", 1l);
1190  }
1191  else
1192  {
1193  config->Write("/BatchFrame/Minimized", 0l);
1194  config->Write("/BatchFrame/Width", GetSize().GetWidth());
1195  config->Write("/BatchFrame/Height", GetSize().GetHeight());
1196  };
1197  }
1198  config->Flush();
1199  if(m_tray!=NULL)
1200  {
1201  delete m_tray;
1202  m_tray = NULL;
1203  }
1204  delete m_updateProjectsTimer;
1205  this->Destroy();
1206 }
1207 
1209 {
1210  m_batch->atEnd = GetEndTask();
1215 }
1216 
1218 {
1219  if(!IsRunning())
1220  {
1221  SetStatusText(_("Starting batch"));
1222  if (m_tray)
1223  {
1224  m_tray->SetIcon(m_iconRunning, _("Processing Hugin's batch queue"));
1225  };
1226  }
1227  m_batch->RunBatch();
1228 }
1229 
1230 void BatchFrame::SetLocaleAndXRC(wxLocale* locale, wxString xrc)
1231 {
1232  m_locale = locale;
1233  m_xrcPrefix = xrc;
1234 }
1235 
1236 void BatchFrame::SwapProject(int index, bool down)
1237 {
1238  if(index>=0 && index<(projListBox->GetItemCount()-1))
1239  {
1240  projListBox->SwapProject(index);
1241  m_batch->SwapProject(index);
1242  if(down)
1243  {
1244  projListBox->Deselect(index);
1245  projListBox->Select(index + 1);
1246  }
1247  else
1248  {
1249  projListBox->Select(index);
1250  projListBox->Deselect(index + 1);
1251  };
1252  }
1253 }
1254 
1255 
1256 void BatchFrame::OnProcessTerminate(wxProcessEvent& event)
1257 {
1258  if(m_batch->GetRunningCount()==1)
1259  {
1260  GetToolBar()->ToggleTool(XRCID("tool_pause"),false);
1261  if (m_tray)
1262  {
1263  m_tray->SetIcon(m_iconNormal, _("Hugin's Batch processor"));
1264  };
1265  }
1266  event.Skip();
1267 }
1268 
1270 {
1271  //get saved size
1272  wxConfigBase* config=wxConfigBase::Get();
1273  int width = config->Read("/BatchFrame/Width", -1l);
1274  int height = config->Read("/BatchFrame/Height", -1l);
1275  int max = config->Read("/BatchFrame/Max", -1l);
1276  int min = config->Read("/BatchFrame/Minimized", -1l);
1277  if((width != -1) && (height != -1))
1278  {
1279  SetSize(width,height);
1280  }
1281  else
1282  {
1283  SetSize(this->FromDIP(wxSize(600,400)));
1284  }
1285 
1286  if(max==1)
1287  {
1288  Maximize();
1289  };
1290  m_startedMinimized=(m_tray!=NULL) && (min==1);
1291 }
1292 
1293 void BatchFrame::OnBatchFailed(wxCommandEvent& event)
1294 {
1296  {
1297  if (m_tray)
1298  {
1299  m_tray->SetIcon(m_iconNormal, _("Hugin's Batch processor"));
1300  };
1301  FailedProjectsDialog failedProjects_dlg(this, m_batch, m_xrcPrefix);
1302  failedProjects_dlg.ShowModal();
1303  };
1304 };
1305 
1306 void BatchFrame::OnBatchInformation(wxCommandEvent& e)
1307 {
1308  SetStatusText(e.GetString());
1309  if (m_tray && e.GetInt() == 1)
1310  {
1311  // batch finished, reset icon in task bar
1312  m_tray->SetIcon(m_iconNormal, _("Hugin's Batch processor"));
1313  };
1314 };
1315 
1316 void BatchFrame::OnProgress(wxCommandEvent& e)
1317 {
1318  m_progStatusBar->SetProgress(e.GetInt());
1320 };
1321 
1323 {
1324 #if defined __WXMSW__ && wxUSE_TASKBARBUTTON
1325  // provide also a feedback in task bar if available
1326  if (IsShown())
1327  {
1328  wxTaskBarButton* taskBarButton = MSWGetTaskBarButton();
1329  if (taskBarButton != NULL)
1330  {
1331  if (m_progStatusBar->GetProgress() < 0)
1332  {
1333  taskBarButton->SetProgressValue(wxTASKBAR_BUTTON_NO_PROGRESS);
1334  }
1335  else
1336  {
1337  taskBarButton->SetProgressRange(100);
1338  taskBarButton->SetProgressState(m_batch->IsPaused() ? wxTASKBAR_BUTTON_PAUSED : wxTASKBAR_BUTTON_NORMAL);
1339  taskBarButton->SetProgressValue(m_progStatusBar->GetProgress());
1340  };
1341  };
1342  };
1343 #endif
1344 };
1345 
1346 void BatchFrame::OnMinimize(wxIconizeEvent& e)
1347 {
1348  //hide/show window in taskbar when minimizing
1349  if(m_tray!=NULL)
1350  {
1351  Show(!e.IsIconized());
1352  //switch off verbose output if PTBatcherGUI is in tray/taskbar
1353  if(e.IsIconized())
1354  {
1355  m_batch->verbose=false;
1356  }
1357  else
1358  {
1359  m_batch->verbose=XRCCTRL(*this,"cb_verbose",wxCheckBox)->IsChecked();
1361  };
1363  }
1364  else //don't hide window if no tray icon
1365  {
1366  if (!e.IsIconized())
1367  {
1368  // window is restored, update progress indicators
1370  };
1371  e.Skip();
1372  };
1373 };
1374 
1376 {
1377  m_batch->verbose=XRCCTRL(*this,"cb_verbose",wxCheckBox)->IsChecked();
1379 };
1380 
1381 void BatchFrame::OnRefillListBox(wxCommandEvent& event)
1382 {
1384  std::set<long> selectedID;
1385  for (auto index : selected)
1386  {
1387  selectedID.insert(m_batch->GetProject(index)->id);
1388  };
1389  projListBox->DeleteAllItems();
1391  for(auto id:selectedID)
1392  {
1393  int index=projListBox->GetIndex(id);
1394  if(index!=-1)
1395  {
1396  projListBox->Select(index);
1397  };
1398  };
1399 };
1400 
1401 void BatchFrame::OnMinimizeTrayMenu(wxCommandEvent& event)
1402 {
1403  UpdateTrayIcon(event.IsChecked());
1404  wxConfigBase* config=wxConfigBase::Get();
1405  config->Write("/BatchFrame/minimizeTray", event.IsChecked());
1406  config->Flush();
1407 }
1408 
1409 void BatchFrame::UpdateTrayIcon(const bool createTrayIcon)
1410 {
1411  if (createTrayIcon)
1412  {
1413  // create tray icon only if it not exists
1414  if (m_tray)
1415  {
1416  delete m_tray;
1417  m_tray = NULL;
1418  }
1419  m_tray = new BatchTaskBarIcon();
1420  if (m_batch->IsRunning())
1421  {
1422  m_tray->SetIcon(m_iconRunning, _("Processing Hugin's batch queue"));
1423  }
1424  else
1425  {
1426  if (m_batch->IsPaused())
1427  {
1428  m_tray->SetIcon(m_iconPaused, _("Pausing processing Hugin's batch queue"));
1429  }
1430  else
1431  {
1432  m_tray->SetIcon(m_iconNormal, _("Hugin's Batch processor"));
1433  }
1434  }
1435  }
1436  else
1437  {
1438  // destroy tray icon
1439  if (m_tray)
1440  {
1441  delete m_tray;
1442  m_tray = NULL;
1443  }
1444  }
1445 }
bool NoErrors()
Returns true if there are no failed projects in batch.
Definition: Batch.cpp:372
int GetRunningCount()
Returns number of projects currently in progress.
Definition: Batch.cpp:313
int ClearBatch()
Clears batch list and returns 0 if succesful.
Definition: Batch.cpp:221
void PropagateDefaults()
void SetLocaleAndXRC(wxLocale *locale, wxString xrc)
void OnButtonChangePrefix(wxCommandEvent &event)
Definition: BatchFrame.cpp:521
bool FileExists(const std::string &filename)
checks if file exists
Definition: utils.cpp:362
void ChangePrefix(int index, wxString newPrefix)
Definition: BatchFrame.cpp:590
bool GetCheckAutoRemove()
return if auto remove checkbox is checked
Definition of GenerateSequenceDialog class.
void SwapProject(int index)
Swaps position in batch of project at index with project at index+1.
Definition: Batch.cpp:917
void RemoveProjectAtIndex(int selIndex)
Removes project at index from batch list.
Definition: Batch.cpp:741
int GetProjectCount()
Returns number of projects in batch list.
Definition: Batch.cpp:295
bool verbose
Definition: Batch.h:60
wxString userDefindSequence
Definition: ProjectArray.h:73
bool GetCheckSaveLog()
return if always save log is checked
wxIcon m_iconNormal
Definition: BatchFrame.h:171
void AddDirToList(wxString aDir)
Definition: BatchFrame.cpp:460
class for showing a status bar with progress, the progress bar is always in the last field of the sta...
bool saveLog
Definition: Batch.h:63
void SetMissing(int index)
wxDateTime modDate
Definition: ProjectArray.h:75
std::unique_ptr< wxMessageDialogBase > MessageDialog
Definition: wxutils.h:87
Definition of failed projects dialog.
void OnButtonReset(wxCommandEvent &event)
Definition: BatchFrame.cpp:864
ProgressStatusBar * m_progStatusBar
Definition: BatchFrame.h:170
#define DEBUG_TRACE(msg)
Definition: utils.h:67
void SetStatus(int index, Project::Status status)
Used internally to set status of selected project.
Definition: Batch.cpp:905
size_t GetFailedProjectsCount()
returns number of failed projects
Definition: Batch.h:145
Batch::EndTask GetEndTask()
return which task should be executed at end
void OnButtonOpenBatch(wxCommandEvent &event)
Definition: BatchFrame.cpp:713
void RunBatch()
void Deselect(int index)
void AddToList(wxString aFile, Project::Target target=Project::STITCHING, wxString userDefined=wxEmptyString)
Definition: BatchFrame.cpp:481
void CancelBatch()
Stops batch run, failing projects in progress.
Definition: Batch.cpp:184
void OnButtonGenerateSequence(wxCommandEvent &e)
generate a sequence of panoramas
Definition: BatchFrame.cpp:375
void OnButtonPause(wxCommandEvent &event)
Definition: BatchFrame.cpp:776
wxLocale * m_locale
Definition: BatchFrame.h:161
void OnProcessTerminate(wxProcessEvent &event)
Dialog for generate panoramas from a sequence of images.
void AppendProject(Project *project)
void OnButtonHelp(wxCommandEvent &event)
Definition: BatchFrame.cpp:679
void OnButtonChangeUserDefinedSequence(wxCommandEvent &event)
Definition: BatchFrame.cpp:620
void OnClose(wxCloseEvent &event)
bool autostitch
Definition: Batch.h:61
bool GetCheckOverwrite()
return if overwrite checkbox is checked
void AddProjectToBatch(wxString projectFile, wxString outputFile=wxEmptyString, wxString userDefinedSequence=wxEmptyString, Project::Target target=Project::STITCHING)
Adds a project entry in the batch list.
Definition: Batch.cpp:80
void OnButtonSaveBatch(wxCommandEvent &event)
Definition: BatchFrame.cpp:924
wxString GetText(int row, int column)
wxString GetNewSequence()
returns the newly selected sequence
void AddAppToBatch(wxString app)
Adds an application entry in the batch list.
Definition: Batch.cpp:74
static char * line
Definition: svm.cpp:2784
int LoadBatchFile(wxString file)
Clears current batch list and loads projects from batch file.
Definition: Batch.cpp:341
wxString m_xrcPrefix
Definition: BatchFrame.h:162
bool IsPaused()
Returns true if batch execution is currently paused.
Definition: Batch.cpp:336
wxIcon m_iconPaused
Definition: BatchFrame.h:173
void UpdateBatchVerboseStatus()
update visibility of verbose output window depending on status of verbose checkbox ...
MessageDialog GetMessageDialog(const wxString &message, const wxString &caption, int style, wxWindow *parent)
Definition: wxutils.cpp:212
void ShowFilenameWarning(wxWindow *parent, const wxArrayString filelist)
shows a dialog about filename with invalid characters, all names in filelist will be show in list ...
Definition: platform.cpp:523
void ChangePrefix(int index, wxString newPrefix)
Changes output prefix for project at index.
Definition: Batch.cpp:211
Batch processor for Hugin with GUI.
void OnUpdateListBox(wxTimerEvent &event)
called by thread to update listbox
Definition: BatchFrame.cpp:268
void ChangePrefix(int index, wxString newPrefix)
WXIMPEX void FixHelpSettings()
helper function to check window position settings of help window
Definition: wxPlatform.cpp:53
void ChangeUserDefined(int index, wxString newUserDefined)
std::set< unsigned int > UIntSet
Definition: PanoramaData.h:51
void OnButtonSkip(wxCommandEvent &event)
Definition: BatchFrame.cpp:939
Project::Status GetStatus(int index)
Returns current status of project at index.
Definition: Batch.cpp:318
void RestoreSize()
bool IsRunning()
return true, if batch is running
Definition: Batch.cpp:331
int GetIndex(int id)
void OnRefillListBox(wxCommandEvent &e)
called if the project box needs to be updated, because projects were added or deleted ...
void Select(int index)
void UpdateTaskBarProgressBar()
update the progress bar in the task bar
void PauseBatch()
Pauses and continues batch execution.
Definition: Batch.cpp:695
void OnButtonAddCommand(wxCommandEvent &event)
Definition: BatchFrame.cpp:340
EndTask atEnd
Definition: Batch.h:58
void OnButtonMoveUp(wxCommandEvent &event)
Definition: BatchFrame.cpp:699
Dialog for finding panorama in given directory.
class for showing a taskbar/tray icon
Definition: BatchTrayIcon.h:33
Target target
Definition: ProjectArray.h:67
Definition of dialog to change user defined sequence.
void ChangeUserDefined(int index, wxString newUserDefined)
Definition: BatchFrame.cpp:605
bool isAligned
Definition: ProjectArray.h:81
int GetProgress()
return current progress value, should be in range 0 - 100, or -1 if the progress gauge is hidden ...
bool UpdateStatus(int index, Project *project)
void UpdateTrayIcon(const bool createTrayIcon)
create or destroy the tray icon
void OnMinimizeTrayMenu(wxCommandEvent &e)
void SaveTemp()
Saves batch list to temporary file.
Definition: Batch.cpp:900
void OnButtonClear(wxCommandEvent &event)
Definition: BatchFrame.cpp:660
Project * GetProject(int index)
Returns project at index.
Definition: Batch.cpp:290
Definition: Batch.h:46
void OnCheckVerbose(wxCommandEvent &event)
wxStatusBar * OnCreateStatusBar(int number, long style, wxWindowID id, const wxString &name)
Definition: BatchFrame.cpp:251
Dialog for changing the user defined sequence.
void ShowOutput(bool isVisible=true)
Set visibility of all running projects.
Definition: Batch.cpp:923
bool m_cancelled
Definition: BatchFrame.h:164
void OnButtonSearchPano(wxCommandEvent &e)
Definition: BatchFrame.cpp:369
void OnButtonAddToStitchingQueue(wxCommandEvent &event)
let the user select a project file which should be added to the stitching queue
Definition: BatchFrame.cpp:403
wxArrayString GetProjectFiles()
Definition: DirTraverser.h:58
BatchTaskBarIcon * m_tray
Definition: BatchFrame.h:169
void OnCheckOverwrite(wxCommandEvent &event)
void OnButtonOpenWithHugin(wxCommandEvent &event)
Definition: BatchFrame.cpp:737
void OnMinimize(wxIconizeEvent &e)
handle when minimize or restore image
void OnButtonResetAll(wxCommandEvent &event)
Definition: BatchFrame.cpp:892
Batch processor for Hugin with GUI.
wxString path
Definition: ProjectArray.h:69
void OnButtonMoveDown(wxCommandEvent &event)
Definition: BatchFrame.cpp:685
wxHelpController & GetHelpController()
return help controller for open help
Definition: BatchFrame.h:155
bool IsRunning()
returns true, if batch is running
Definition: BatchFrame.cpp:258
void RunBatch()
Starts batch execution.
Definition: Batch.cpp:764
void SwapProject(int index, bool down)
bool autoremove
Definition: Batch.h:62
bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString &filenames)
File/directory drag and drop handler method.
Definition: BatchFrame.cpp:44
void SetProgress(int progress)
update progress bar
void OnButtonCancel(wxCommandEvent &event)
Definition: BatchFrame.cpp:509
HuginBase::UIntSet GetSelectedProjects()
void OnChoiceEnd(wxCommandEvent &event)
Batch * m_batch
Definition: BatchFrame.h:163
void OnButtonRemoveComplete(wxCommandEvent &event)
Definition: BatchFrame.cpp:808
wxTimer * m_updateProjectsTimer
Definition: BatchFrame.h:175
void CancelProject(int index)
Cancels project at index in batch, failing it.
Definition: Batch.cpp:198
wxChoice * m_endChoice
Definition: BatchFrame.h:166
void OnBatchInformation(wxCommandEvent &e)
called when batch wants to show some progress message
void SaveBatchFile(wxString file)
Saves batch list to file.
Definition: Batch.cpp:851
EndTask
Definition: Batch.h:49
static T max(T x, T y)
Definition: svm.cpp:65
wxIcon m_iconRunning
Definition: BatchFrame.h:172
bool CompareProjectsInLists(int stitchListIndex, int batchListIndex)
Compares two project at indexes in both lists and returns true if they have identical project ids...
Definition: Batch.cpp:248
void SetCheckboxes()
Definition: BatchFrame.cpp:998
void OnUserExit(wxCommandEvent &event)
Definition: BatchFrame.cpp:335
bool GetCheckAutoStitch()
return if auto stitch checkbox is checked
bool containsInvalidCharacters(const wxString stringToTest)
returns true, if the given strings contains invalid characters
Definition: platform.cpp:510
void OnCheckAutoRemove(wxCommandEvent &event)
event handler called when auto remove checkbox was changed
Simple class that forward the drop to the mainframe.
Definition: BatchFrame.h:44
void SelectEndTask(wxControlWithItems *list, const Batch::EndTask endTask)
Definition: BatchFrame.cpp:985
void OnBatchFailed(wxCommandEvent &event)
called when batch was finished and there are failed projects
bool IsPaused()
returns true, if batch is paused
Definition: BatchFrame.cpp:263
void OnCheckAutoStitch(wxCommandEvent &event)
event handler called when auto stitch checkbox was changed
void ReloadProject(int index, Project *project)
Dialog for finding panorama in given directory.
void OnCheckSaveLog(wxCommandEvent &event)
event handler called when always save log checkbox was changed
void OnButtonRemoveFromList(wxCommandEvent &event)
Definition: BatchFrame.cpp:831
ProjectListBox * projListBox
Definition: BatchFrame.h:158
void Fill(Batch *batch)
void OnProgress(wxCommandEvent &event)
event handler for update progress controls
void OnButtonAddDir(wxCommandEvent &event)
Definition: BatchFrame.cpp:355
wxString prefix
Definition: ProjectArray.h:71
bool overwrite
Definition: Batch.h:59
int LoadTemp()
Loads temporary batch file.
Definition: Batch.cpp:361
bool GetCheckVerbose()
return if verbose checkbox is checked
void OnButtonRunBatch(wxCommandEvent &event)
Definition: BatchFrame.cpp:911
void ResetOptions()
static T min(T x, T y)
Definition: svm.cpp:62
void SetInternalVerbose(bool newVerbose)
sets the current verbose status, does not update the checkbox
int HuginMessageBox(const wxString &message, const wxString &caption, int style, wxWindow *parent)
Definition: wxutils.cpp:176
BatchFrame(wxLocale *locale, wxString xrc)
Definition: BatchFrame.cpp:86
void ChangeUserDefined(int index, wxString newUserDefined)
Changes user defined sequence for project at index.
Definition: Batch.cpp:216
bool skip
Definition: ProjectArray.h:79
bool m_startedMinimized
Definition: BatchFrame.h:176
long id
Definition: ProjectArray.h:63
void SwapProject(int index)
void OnButtonAddToAssistantQueue(wxCommandEvent &event)
let the user select a project file which should be added to the stitching queue
Definition: BatchFrame.cpp:431
void AddArrayToList(const wxArrayString &fileList, Project::Target target)
Definition: BatchFrame.cpp:499