Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GenerateSequenceDialog.cpp
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
10 /* This is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public
12  * License as published by the Free Software Foundation; either
13  * version 2 of the License, or (at your option) any later version.
14  *
15  * This software is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public
21  * License along with this software. If not, see
22  * <http://www.gnu.org/licenses/>.
23  *
24  */
25 
26 #include "GenerateSequenceDialog.h"
27 #include "base_wx/wxPlatform.h"
28 #include <wx/busyinfo.h>
29 #include "panoinc.h"
30 
32 wxArrayString GetAllSubDirectories(const wxString baseDir)
33 {
34  wxArrayString subDirs;
35  wxDir dir(baseDir);
36  if (!dir.IsOpened())
37  {
38  // could not open given directories
39  return subDirs;
40  }
41  wxString filename;
42  bool cont = dir.GetFirst(&filename, wxEmptyString, wxDIR_DIRS);
43  while (cont)
44  {
45  subDirs.Add(filename);
46  cont = dir.GetNext(&filename);
47  };
48  return subDirs;
49 }
50 
52 wxString GetNumberString(size_t x, size_t width)
53 {
54  const wxString formatString = wxString::Format("%%0%dd", width);
55  return wxString::Format(formatString, x);
56 }
57 
58 BEGIN_EVENT_TABLE(GenerateSequenceDialog, wxDialog)
59  EVT_BUTTON(XRCID("sequence_select_base_path"), GenerateSequenceDialog::OnSelectBasePath)
60  EVT_CHOICE(XRCID("sequence_choice_subdirectory"), GenerateSequenceDialog::OnSelectSubDir)
61  EVT_LIST_ITEM_SELECTED(XRCID("sequence_images_list"), GenerateSequenceDialog::OnImageListSelected)
62  EVT_LIST_ITEM_DESELECTED(XRCID("sequence_images_list"), GenerateSequenceDialog::OnImageListSelected)
63  EVT_BUTTON(XRCID("sequence_change_image"), GenerateSequenceDialog::OnUpdateImageTemplate)
64  EVT_BUTTON(XRCID("sequence_change_all_images"), GenerateSequenceDialog::OnUpdateAllImagesTemplate)
65  EVT_SPINCTRL(XRCID("sequence_p_offset"), GenerateSequenceDialog::OnUpdateCounters)
66  EVT_SPINCTRL(XRCID("sequence_p_step"), GenerateSequenceDialog::OnUpdateCounters)
67  EVT_SPINCTRL(XRCID("sequence_p_end"), GenerateSequenceDialog::OnUpdateCounters)
68  EVT_SPINCTRL(XRCID("sequence_i_offset"), GenerateSequenceDialog::OnUpdateCounters)
69  EVT_SPINCTRL(XRCID("sequence_i_step"), GenerateSequenceDialog::OnUpdateCounters)
70  EVT_SPINCTRL(XRCID("sequence_i_end"), GenerateSequenceDialog::OnUpdateCounters)
71  EVT_SPINCTRL(XRCID("sequence_x_offset"), GenerateSequenceDialog::OnUpdateCounters)
72  EVT_SPINCTRL(XRCID("sequence_x_step"), GenerateSequenceDialog::OnUpdateCounters)
73  EVT_SPINCTRL(XRCID("sequence_x_end"), GenerateSequenceDialog::OnUpdateCounters)
74  EVT_BUTTON(XRCID("sequence_generate_preview"), GenerateSequenceDialog::OnGeneratePreview)
75  EVT_BUTTON(XRCID("sequence_generate_stitching"), GenerateSequenceDialog::OnGenerateStitchingPanorama)
76  EVT_BUTTON(XRCID("sequence_generate_assistant"), GenerateSequenceDialog::OnGenerateAssistantPanorama)
78 
79 GenerateSequenceDialog::GenerateSequenceDialog(BatchFrame* batchframe, wxString xrcPrefix, wxString ptoFilename)
80 {
81  // load our children. some children might need special
82  // initialization. this will be done later.
83  wxXmlResource::Get()->LoadDialog(this,batchframe, "generate_sequence_dialog");
84 
85 #ifdef __WXMSW__
86  wxIconBundle myIcons(xrcPrefix+ "data/ptbatcher.ico",wxBITMAP_TYPE_ICO);
87  SetIcons(myIcons);
88 #else
89  wxIcon myIcon(xrcPrefix + "data/ptbatcher.png",wxBITMAP_TYPE_PNG);
90  SetIcon(myIcon);
91 #endif
92  m_batchframe=batchframe;
93  m_filename = ptoFilename;
94  ReadPTOFile();
95  if (IsValidPanorama())
96  {
97  this->SetLabel(wxString::Format(_("Generating sequence from %s"), m_filename.c_str()));
98  m_basepath = XRCCTRL(*this, "sequence_base_path", wxTextCtrl);
99  m_basepath->SetValue(wxPathOnly(m_filename));
100 
101  m_choiceSubDir = XRCCTRL(*this, "sequence_choice_subdirectory", wxChoice);
102  m_subDirTextCtrl = XRCCTRL(*this, "sequence_directory_name", wxTextCtrl);
103 
104  m_imagesListCtrl = XRCCTRL(*this, "sequence_images_list", wxListCtrl);
105  m_imagesListCtrl->InsertColumn(0, _("Template image name"));
106  m_imagesListCtrl->InsertColumn(1, _("Sequence image name"));
107  FillImagesList();
108 
109  m_originalImage = XRCCTRL(*this, "sequence_orignal_image_text", wxStaticText);
110  m_imageTemplate = XRCCTRL(*this, "sequence_image_text", wxTextCtrl);
111  m_changeImageTemplate = XRCCTRL(*this, "sequence_change_image", wxButton);
112  m_changeAllImagesTemplate = XRCCTRL(*this, "sequence_change_all_images", wxButton);
113 
114  m_spinCounterP_offset = XRCCTRL(*this, "sequence_p_offset", wxSpinCtrl);
115  m_spinCounterP_step = XRCCTRL(*this, "sequence_p_step", wxSpinCtrl);
116  m_spinCounterP_end = XRCCTRL(*this, "sequence_p_end", wxSpinCtrl);
117  m_spinCounterI_offset = XRCCTRL(*this, "sequence_i_offset", wxSpinCtrl);
118  m_spinCounterI_step = XRCCTRL(*this, "sequence_i_step", wxSpinCtrl);
119  m_spinCounterI_end = XRCCTRL(*this, "sequence_i_end", wxSpinCtrl);
120  m_spinCounterX_offset = XRCCTRL(*this, "sequence_x_offset", wxSpinCtrl);
121  m_spinCounterX_step = XRCCTRL(*this, "sequence_x_step", wxSpinCtrl);
122  m_spinCounterX_end = XRCCTRL(*this, "sequence_x_end", wxSpinCtrl);
123 
124  wxCommandEvent dummy;
125  OnSelectSubDir(dummy);
126  // UpdateCounters();
127 
128  //set parameters
129  wxConfigBase* config = wxConfigBase::Get();
130  // restore position and size
131  int dx, dy;
132  wxDisplaySize(&dx, &dy);
133  bool maximized = config->Read("/GenerateSequenceDialog/maximized", 0l) != 0;
134  if (maximized)
135  {
136  this->Maximize();
137  }
138  else
139  {
140  //size
141  int w = config->Read("/GenerateSequenceDialog/width", -1l);
142  int h = config->Read("/GenerateSequenceDialog/height", -1l);
143  if (w > 0 && w <= dx)
144  {
145  this->SetClientSize(w, h);
146  }
147  else
148  {
149  this->Fit();
150  }
151  //position
152  int x = config->Read("/GenerateSequenceDialog/positionX", -1l);
153  int y = config->Read("/GenerateSequenceDialog/positionY", -1l);
154  if (y >= 0 && x >= 0 && x < dx && y < dy)
155  {
156  this->Move(x, y);
157  }
158  else
159  {
160  this->Move(0, 44);
161  }
162  }
163 
164  m_imagesListCtrl->SetColumnWidth(0, config->Read("/GenerateSequenceDialog/ImageListColumn0Width", 200l));
165  m_imagesListCtrl->SetColumnWidth(1, config->Read("/GenerateSequenceDialog/ImageListColumn1Width", 200l));
166  XRCCTRL(*this, "sequence_naming", wxChoice)->SetSelection(config->Read("/GenerateSequenceDialog/NamingConvention", 0l));
167  };
168  XRCCTRL(*this, "sequence_counter_help", wxTextCtrl)->SetBackgroundColour(this->GetBackgroundColour());
169 };
170 
172 {
173  wxConfigBase* config=wxConfigBase::Get();
174  if(!this->IsMaximized())
175  {
176  wxSize sz = this->GetClientSize();
177  config->Write("/GenerateSequenceDialog/width", sz.GetWidth());
178  config->Write("/GenerateSequenceDialog/height", sz.GetHeight());
179  wxPoint ps = this->GetPosition();
180  config->Write("/GenerateSequenceDialog/positionX", ps.x);
181  config->Write("/GenerateSequenceDialog/positionY", ps.y);
182  config->Write("/GenerateSequenceDialog/maximized", 0);
183  }
184  else
185  {
186  config->Write(wxT("/GenerateSequenceDialog/maximized"), 1l);
187  };
188  config->Write("/GenerateSequenceDialog/ImageListColumn0Width", m_imagesListCtrl->GetColumnWidth(0));
189  config->Write("/GenerateSequenceDialog/ImageListColumn1Width", m_imagesListCtrl->GetColumnWidth(1));
190  config->Write("/GenerateSequenceDialog/NamingConvention", XRCCTRL(*this, "sequence_naming", wxChoice)->GetSelection());
191 }
192 
194 {
195  return m_validPTO && m_pano.getNrOfImages() > 0;
196 }
197 
199 {
200  std::ifstream prjfile((const char*)m_filename.mb_str(HUGIN_CONV_FILENAME));
201  if (prjfile.good())
202  {
204  int ptoVersion = 0;
205  if (newPano.loadPTScript(prjfile, ptoVersion, ""))
206  {
207  m_pano.setMemento(newPano);
208  m_validPTO = true;
209  for (size_t i = 0; i < m_pano.getNrOfImages(); ++i)
210  {
211  const wxString imageFilename(wxString(m_pano.getImage(i).getFilename().c_str(), HUGIN_CONV_FILENAME));
212  m_orignalFilenames.Add(imageFilename);
213  m_mappedFilenames.Add(imageFilename);
214  };
215  };
216  };
217 }
218 
220 {
221  long selItem = -1;
222  if (m_imagesListCtrl->GetSelectedItemCount() > 0)
223  {
224  // remember selected item
225  selItem = m_imagesListCtrl->GetNextItem(selItem, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
226  };
227  m_imagesListCtrl->DeleteAllItems();
229  for (size_t i = 0; i < m_orignalFilenames.size(); ++i)
230  {
231  const size_t index = m_imagesListCtrl->GetItemCount();
232  m_imagesListCtrl->InsertItem(index, m_orignalFilenames[i]);
233  m_imagesListCtrl->SetItem(index, 1, m_mappedFilenames[i]);
234  };
235  // restore selected item
236  if (selItem != -1)
237  {
238  m_imagesListCtrl->SetItemState(selItem, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
239  };
240 }
241 
243 {
244  wxDirDialog dlg(this, _("Specify a directory to search for projects in"),
245  m_basepath->GetValue(), wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST);
246  if (dlg.ShowModal() == wxID_OK)
247  {
248  m_basepath->SetValue(dlg.GetPath());
249  OnSelectSubDir(e);
250  };
251 }
252 
254 {
255  // show text ctrl only when "use name template" use selected
256  m_subDirTextCtrl->Enable(m_choiceSubDir->GetSelection() == 2);
257  if (m_choiceSubDir->GetSelection() != 2)
258  {
259  // clear input wxTextCtrl if not used
260  m_subDirTextCtrl->Clear();
261  };
262  if (m_choiceSubDir->GetSelection() == 1)
263  {
264  // get list of all sub-directories
265  wxArrayString subDirs = GetAllSubDirectories(m_basepath->GetValue());
266  m_subDirCount = subDirs.size();
267  }
268  else
269  {
270  m_subDirCount = 0;
271  };
272  UpdateCounters();
273 }
274 
276 {
277  if (m_imagesListCtrl->GetSelectedItemCount() > 0)
278  {
279  // enable all controls
280  // if one image is selected in list control
281  m_imageTemplate->Enable(true);
282  m_changeImageTemplate->Enable(true);
283  m_changeAllImagesTemplate->Enable(true);
284  // set text
285  long item = -1;
286  item = m_imagesListCtrl->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
287  m_originalImage->SetLabel(m_orignalFilenames[item]);
288  m_imageTemplate->SetValue(m_mappedFilenames[item]);
289  }
290  else
291  {
292  // no item selected, disable all related ctrl
293  m_imageTemplate->Enable(false);
294  m_changeImageTemplate->Enable(false);
295  m_changeAllImagesTemplate->Enable(false);
296  }
297 }
298 
300 {
301  if (m_imagesListCtrl->GetSelectedItemCount() > 0)
302  {
303  // find selected item
304  long item = -1;
305  item = m_imagesListCtrl->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
306  // now update value
307  m_mappedFilenames[item] = m_imageTemplate->GetValue();
308  FillImagesList();
309  }
310  else
311  {
312  wxBell();
313  };
314 }
315 
317 {
318  for (size_t i = 0; i < m_mappedFilenames.size(); ++i)
319  {
320  // update values
321  m_mappedFilenames[i] = m_imageTemplate->GetValue();
322  };
323  FillImagesList();
324 }
325 
327 {
328  UpdateCounters();
329 }
330 
332 {
333  // update %p counter
334  size_t pano_count;
335  if (m_choiceSubDir->GetSelection() == 1)
336  {
337  // iterate all sub-directories selected
338  m_spinCounterP_end->Enable(false);
339  pano_count = m_subDirCount;
340  if (pano_count > 0)
341  {
342  m_spinCounterP_end->SetValue(m_spinCounterP_offset->GetValue() + m_spinCounterI_step->GetValue() * (pano_count - 1));
343  }
344  else
345  {
346  m_spinCounterP_end->SetValue(m_spinCounterP_offset->GetValue());
347  };
348  }
349  else
350  {
351  m_spinCounterP_end->Enable(true);
352  m_spinCounterP_end->SetRange(m_spinCounterP_offset->GetValue(), m_spinCounterP_end->GetMax());
353  if (m_spinCounterP_end->GetValue() < m_spinCounterP_offset->GetValue())
354  {
355  m_spinCounterP_end->SetValue(m_spinCounterP_offset->GetValue());
356  };
357  pano_count = (m_spinCounterP_end->GetValue() - m_spinCounterP_offset->GetValue()) / m_spinCounterP_step->GetValue() + 1;
358  };
359  // update end value for image counter
360  m_spinCounterI_end->Enable(false);
361  m_spinCounterI_end->SetValue(m_spinCounterI_offset->GetValue() + m_spinCounterI_step->GetValue() * (m_pano.getNrOfImages() - 1));
362  // update end value for x counter
363  m_spinCounterX_end->Enable(false);
364  m_spinCounterX_end->SetValue(m_spinCounterX_offset->GetValue() + m_spinCounterX_step->GetValue() * (m_pano.getNrOfImages() * pano_count - 1));
365 }
366 
367 void GenerateSequenceDialog::GenerateFileList(wxArrayString& panoSubDirs, std::vector<wxArrayString>& fileList)
368 {
369  // read all counter values
370  // first update all counters if necessary
371  UpdateCounters();
372  const size_t pano_offset = m_spinCounterP_offset->GetValue();
373  const size_t pano_step = m_spinCounterP_step->GetValue();
374  const size_t pano_end = m_spinCounterP_end->GetValue();
375  const size_t pano_width = XRCCTRL(*this, "sequence_p_width", wxSpinCtrl)->GetValue();
376  const size_t img_offset = m_spinCounterI_offset->GetValue();
377  const size_t img_step = m_spinCounterI_step->GetValue();
378  const size_t img_width = XRCCTRL(*this, "sequence_i_width", wxSpinCtrl)->GetValue();
379  const size_t x_offset = m_spinCounterX_offset->GetValue();
380  const size_t x_step = m_spinCounterX_step->GetValue();
381  const size_t x_width = XRCCTRL(*this, "sequence_x_width", wxSpinCtrl)->GetValue();
382  const size_t pano_count = (pano_end - pano_offset) / pano_step + 1;
383  const size_t img_count = m_pano.getNrOfImages();
384  // generate list of all sub-directories
385  if (m_choiceSubDir->GetSelection() == 1)
386  {
387  panoSubDirs = GetAllSubDirectories(m_basepath->GetValue());
388  if (panoSubDirs.IsEmpty())
389  {
390  wxBell();
391  return;
392  };
393  }
394  else
395  {
396  wxString panoNameTemplate = m_subDirTextCtrl->GetValue();
397  panoSubDirs.resize(pano_count);
398  if (!panoNameTemplate.IsEmpty())
399  {
400  size_t panoCounter = pano_offset;
401  for (size_t i = 0; i < pano_count; ++i, panoCounter += pano_step)
402  {
403  panoSubDirs[i] = panoNameTemplate;
404  // replace placeholder
405  panoSubDirs[i].Replace("%p", GetNumberString(panoCounter, pano_width), true);
406  };
407  };
408  };
409  // now iterate all panoramas and generate file list
410  size_t panoCounter = pano_offset;
411  size_t xCounter = x_offset;
412  for (size_t i = 0; i < pano_count; ++i, panoCounter += pano_step)
413  {
414  wxFileName currentPath;
415  currentPath.SetPath(m_basepath->GetValue());
416  if (!panoSubDirs[i].IsEmpty())
417  {
418  currentPath.AppendDir(panoSubDirs[i]);
419  };
420  size_t imgCounter = img_offset;
421  wxArrayString panoFileList;
422  for (size_t j = 0; j < m_pano.getNrOfImages(); ++j, imgCounter += img_step, xCounter += x_step)
423  {
424  // replace all counter variables
425  wxString file = m_mappedFilenames[j];
426  // replace all placeholders
427  file.Replace("%p", GetNumberString(panoCounter, pano_width), true);
428  file.Replace("%i", GetNumberString(imgCounter, img_width), true);
429  file.Replace("%x", GetNumberString(xCounter, x_width), true);
430  wxFileName fileName(file);
431  fileName.MakeAbsolute(currentPath.GetPath());
432  panoFileList.Add(fileName.GetFullPath());
433  }
434  fileList.push_back(panoFileList);
435  };
436 }
437 
439 {
440  wxWindowDisabler winDisable;
441  wxBusyInfo waitInfo(
442  wxBusyInfoFlags()
443  .Parent(this)
444  .Text(_("Generating preview list. Please wait..."))
445  .Icon(GetIcon())
446  );
447  // generate a preview of all images in text form
448  wxArrayString subDirList;
449  std::vector<wxArrayString> fileList;
450  GenerateFileList(subDirList, fileList);
451  wxTextCtrl* preview = XRCCTRL(*this, "sequence_preview", wxTextCtrl);
452  preview->Clear();
453  wxString text;
454 #ifdef __WXMSW__
455  const wxString linebreak("\r\n");
456 #else
457  const wxString linebreak("\n");
458 #endif
459  if (fileList.empty())
460  {
461  text.Append(_("No matching sub-directories found."));
462  }
463  else
464  {
465  // iterate above all panoramas
466  for (size_t i = 0; i < fileList.size(); ++i)
467  {
468  text.Append(wxString::Format(_("Panorama %d"), i));
469  text.Append(linebreak);
470  if (!subDirList[i].IsEmpty())
471  {
472  text.Append(wxString::Format(_("Sub-directory: %s"), subDirList[i].c_str()));
473  text.Append(linebreak);
474  };
475  // iterate above all files in current pano
476  bool missingFiles = false;
477  for (size_t j = 0; j < m_pano.getNrOfImages(); ++j)
478  {
479  text.Append("\t");
480  text.Append(fileList[i][j]);
481  if (!wxFileName::FileExists(fileList[i][j]))
482  {
483  missingFiles = true;
484  text.Append(" <-- ");
485  text.Append(_("File not found"));
486  };
487  text.Append(linebreak);
488  };
489  if (missingFiles)
490  {
491  text.Append("\t");
492  text.Append(_("This panorama will be skipped becaused of missing files."));
493  text.Append(linebreak);
494  };
495  };
496  };
497  preview->SetValue(text);
498 }
499 
504 {
505  // check image sizes, and correct parameters if required.
507  for (unsigned int i = 0; i < newPano.getNrOfImages(); i++)
508  {
509  // check if image size is correct
510  const HuginBase::SrcPanoImage& oldSrcImg = pano.getImage(i);
511  HuginBase::SrcPanoImage newSrcImg = newPano.getSrcImage(i);
512 
513  // just keep the file name
514  newSrcImg.setFilename(oldSrcImg.getFilename());
515  if (oldSrcImg.getSize() != newSrcImg.getSize())
516  {
517  // adjust size properly.
518  newSrcImg.resize(oldSrcImg.getSize(), &vars[i]);
519  }
520  newPano.setSrcImage(i, newSrcImg);
521  }
522  // now update all possible linked variables
523  for (unsigned int i = 0; i < newPano.getNrOfImages(); ++i)
524  {
525  if (!vars[i].empty())
526  {
527  newPano.updateVariables(i, vars[i]);
528  };
529  };
530  // remove all control points, they are only valid for the original template
532 }
533 
536 bool GetNewProjectFilename(long index, const HuginBase::Panorama& pano, const wxString basePath, wxFileName& projectFile, unsigned int currentIndex)
537 {
538  wxString mask;
539  projectFile.SetPath(basePath);
540  projectFile.SetExt(wxT("pto"));
541  if (!projectFile.IsDirWritable())
542  {
543  return false;
544  };
545  switch (index)
546  {
547  case 0:
548  // panoramaXX.pto
549  mask = wxString::Format("panorama%d", currentIndex);
550  break;
551  case 1:
552  // First file - last file.pto
553  {
554  const wxFileName f1(wxString(pano.getImage(0).getFilename().c_str(), HUGIN_CONV_FILENAME));
555  const wxFileName f2(wxString(pano.getImage(pano.getNrOfImages() - 1).getFilename().c_str(), HUGIN_CONV_FILENAME));
556  mask = f1.GetName() + wxT("-") + f2.GetName();
557  }
558  break;
559  case 2:
560  // Foldername.pto
561  {
562  wxArrayString folders = projectFile.GetDirs();
563  if (folders.GetCount() == 0)
564  {
565  return false;
566  }
567  mask = folders.Last();
568  }
569  break;
570  case 3:
571  // Template from preferences
572  {
573  wxFileName newProject(getDefaultProjectName(pano));
574  mask = newProject.GetName();
575  projectFile.SetName(mask);
576  };
577  break;
578  default:
579  mask = wxString::Format("panorama%d", currentIndex);
580  };
581 
582  projectFile.SetName(mask);
583  if (projectFile.FileExists())
584  {
585  unsigned int i = 1;
586  mask = mask.Append("_%d");
587  projectFile.SetName(wxString::Format(mask, i));
588  while (projectFile.FileExists())
589  {
590  i++;
591  projectFile.SetName(wxString::Format(mask, i));
592  //security fall through
593  if (i > 1000)
594  {
595  return false;
596  };
597  };
598  };
599  return true;
600 }
601 
603 {
604  wxWindowDisabler winDisable;
605  wxBusyInfo waitInfo(
606  wxBusyInfoFlags()
607  .Parent(this)
608  .Text(_("Generating panorama files. Please wait..."))
609  .Icon(GetIcon())
610  );
611  wxArrayString subDirList;
612  std::vector<wxArrayString> fileList;
613  GenerateFileList(subDirList, fileList);
614  if (fileList.empty())
615  {
616  wxMessageBox(_("No matching sub-directories found."),
617 #ifdef __WXMSW__
618  wxT("PTBatcherGUI"),
619 #else
620  wxEmptyString,
621 #endif
622  wxOK | wxICON_EXCLAMATION, NULL);
623  }
624  else
625  {
626  const wxString basePath = m_basepath->GetValue();
627  wxArrayString ptoFileList;
628 
629  for (size_t i = 0; i < fileList.size(); ++i)
630  {
631  // check that all files exists
632  bool missingFiles = false;
633  for (size_t j = 0; j < m_pano.getNrOfImages(); ++j)
634  {
635  if (!wxFileName::FileExists(fileList[i][j]))
636  {
637  missingFiles = true;
638  break;
639  };
640  };
641  if (!missingFiles)
642  {
643  // now build the new panorama object
644  HuginBase::Panorama newPano;
645  bool allFilesReadable = true;
646  for (size_t j = 0; j < m_pano.getNrOfImages(); ++j)
647  {
649  image.setFilename(std::string(fileList[i][j].mb_str(HUGIN_CONV_FILENAME)));
650  if (!image.checkImageSizeKnown())
651  {
652  allFilesReadable = false;
653  break;
654  };
655  newPano.addImage(image);
656  };
657  if (allFilesReadable)
658  {
659  HuginBase::Panorama newGeneratedPano = m_pano.duplicate();
660  ApplyTemplate(newPano, newGeneratedPano);
661  // write to disc
662  wxFileName projectFile;
663  if (!GetNewProjectFilename(XRCCTRL(*this, "sequence_naming", wxChoice)->GetSelection(), newGeneratedPano, basePath, projectFile, i))
664  {
665  break;
666  };
667  const std::string scriptString(projectFile.GetFullPath().mb_str(HUGIN_CONV_FILENAME));
668  newGeneratedPano.WritePTOFile(scriptString, hugin_utils::getPathPrefix(scriptString));
669  // all done, remember pto file name
670  ptoFileList.Add(projectFile.GetFullPath());
671  };
672  };
673  };
674  // all done, now add the pto files to queue
675  if (!ptoFileList.IsEmpty())
676  {
677  m_batchframe->AddArrayToList(ptoFileList, target);
678  };
679  EndModal(wxID_OK);
680  };
681 }
682 
684 {
686 }
687 
689 {
691 }
bool FileExists(const std::string &filename)
checks if file exists
Definition: utils.cpp:362
wxString GetNumberString(size_t x, size_t width)
return given number as string with given number of digits
Definition of GenerateSequenceDialog class.
void setMemento(const PanoramaMemento &memento)
set the internal state
Definition: Panorama.cpp:1507
void OnGenerateAssistantPanorama(wxCommandEvent &e)
generate assistant sequence button
SrcPanoImage getSrcImage(unsigned imgNr) const
get a description of a source image
Definition: Panorama.cpp:1620
HuginBase::Panorama m_pano
#define HUGIN_CONV_FILENAME
Definition: platform.h:40
bool checkImageSizeKnown()
check if the image size is known, if try to load the information from the file
void OnUpdateImageTemplate(wxCommandEvent &e)
update image filename template on selected image
Dialog for generate panoramas from a sequence of images.
void OnGenerateStitchingPanorama(wxCommandEvent &e)
generate stitching sequence button
#define DEBUG_ASSERT(cond)
Definition: utils.h:80
END_EVENT_TABLE()
include file for the hugin project
void ApplyTemplate(const HuginBase::Panorama &pano, HuginBase::Panorama &newPano)
copy the image files from pano to newPano -&gt; this corresponds to apply the template newPano to pano t...
virtual void updateVariables(const VariableMapVector &vars)
Set the variables.
Definition: Panorama.cpp:171
Panorama duplicate() const
duplicate the panorama
Definition: Panorama.cpp:1653
std::vector< VariableMap > VariableMapVector
Model for a panorama.
Definition: Panorama.h:152
std::string getPathPrefix(const std::string &filename)
Get the path to a filename.
Definition: utils.cpp:184
bool loadPTScript(std::istream &i, int &ptoVersion, const std::string &prefix="")
load a Hugin file
std::size_t getNrOfImages() const
number of images.
Definition: Panorama.h:205
void setCtrlPoints(const CPVector &points)
set all control points (Ippei: Is this supposed to be &#39;add&#39; method?)
Definition: Panorama.cpp:449
void OnSelectBasePath(wxCommandEvent &e)
show select directory dialog
void OnUpdateAllImagesTemplate(wxCommandEvent &e)
update images filename template for all images
void FillImagesList()
fill the images list with current values
void GenerateFileList(wxArrayString &panoSubDirs, std::vector< wxArrayString > &fileList)
generate a list of all panorama and images in panoramas
void OnImageListSelected(wxListEvent &e)
image in list ctrl selected
void resize(const vigra::Size2D &size, VariableMap *potentialLinkedVars)
&quot;resize&quot; image, adjusts all distortion coefficients for usage with a source image of size size potent...
IMPEX double h[25][1024]
Definition: emor.cpp:169
void OnUpdateCounters(wxSpinEvent &e)
update all spin controls with current numbers
unsigned int addImage(const SrcPanoImage &img)
the the number for a specific image
Definition: Panorama.cpp:319
bool GetNewProjectFilename(long index, const HuginBase::Panorama &pano, const wxString basePath, wxFileName &projectFile, unsigned int currentIndex)
generate filename from given settings and panorama append a number if file already exists ...
wxArrayString GetAllSubDirectories(const wxString baseDir)
return a list of all sub-directories
void DoGeneratePanorama(const Project::Target target)
generates all panoramas and add them to the batch queue with given queue target
void OnSelectSubDir(wxCommandEvent &e)
select which sub-directory should be used
void UpdateCounters()
update all counters, enable/disable end value and calculate end values
~GenerateSequenceDialog()
destructor, saves size and position
Memento class for a Panorama object.
Definition: Panorama.h:49
void OnGeneratePreview(wxCommandEvent &e)
generate preview
void ReadPTOFile()
read pto template from file
std::vector< ControlPoint > CPVector
Definition: ControlPoint.h:99
platform/compiler specific stuff.
bool WritePTOFile(const std::string &filename, const std::string &prefix="")
write data to given pto file
Definition: Panorama.cpp:2059
const SrcPanoImage & getImage(std::size_t nr) const
get a panorama image, counting starts with 0
Definition: Panorama.h:211
bool IsValidPanorama() const
return true if given template is a valid pto file, if not the dialog should not be used ...
void setSrcImage(unsigned int nr, const SrcPanoImage &img)
set input image parameters
All variables of a source image.
Definition: SrcPanoImage.h:194
wxString getDefaultProjectName(const HuginBase::Panorama &pano, const wxString filenameTemplate)
gets the default project name, as defined in the preferences
void AddArrayToList(const wxArrayString &fileList, Project::Target target)
Definition: BatchFrame.cpp:509