Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
huginApp.cpp
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
2 
27 #include "hugin_config.h"
28 
29 #include "panoinc_WX.h"
30 
31 #ifdef __WXMAC__
32 #include <wx/sysopt.h>
33 #include <wx/dir.h>
34 #endif
35 
36 #include "panoinc.h"
37 
38 #include "hugin/config_defaults.h"
39 #include "hugin/huginApp.h"
40 #include "hugin/ImagesPanel.h"
41 #include "hugin/MaskEditorPanel.h"
42 #include "hugin/CPEditorPanel.h"
44 #include "hugin/PanoPanel.h"
45 #include "hugin/CPListFrame.h"
46 #include "hugin/PreviewPanel.h"
47 #include "hugin/GLPreviewFrame.h"
48 #include "hugin/RawImport.h"
49 #include "base_wx/PTWXDlg.h"
50 #include "base_wx/CommandHistory.h"
51 #include "base_wx/wxcms.h"
52 #include "base_wx/wxPanoCommand.h"
53 #include "base_wx/wxutils.h"
54 #include "hugin/HtmlWindow.h"
55 #include "hugin/treelistctrl.h"
56 #include "hugin/ImagesTree.h"
57 #include "hugin/SplitButton.h"
58 
59 #include "base_wx/platform.h"
60 #include "base_wx/huginConfig.h"
61 #include <wx/cshelp.h>
62 #include <wx/stdpaths.h>
63 #ifdef __WXMSW__
64 #include <wx/dir.h>
65 #include <wx/taskbarbutton.h>
66 #endif
67 #if defined __WXGTK__
68 #include "base_wx/wxPlatform.h"
69 #endif
70 
71 #include <tiffio.h>
72 
73 #include "AboutDialog.h"
74 
75 //for natural sorting
76 #include "hugin_utils/alphanum.h"
77 #include "lensdb/LensDB.h"
78 
79 bool checkVersion(wxString v1, wxString v2)
80 {
81  return doj::alphanum_comp(std::string(v1.mb_str(wxConvLocal)),std::string(v2.mb_str(wxConvLocal))) < 0;
82 };
83 
85 {
86  wxString ret;
87  for (unsigned i=0; i < comp.size(); i++) {
88  ret.Append(wxT("["));
89  HuginGraph::ImageGraph::Components::value_type::const_iterator it = comp[i].begin();
90  while (it != comp[i].end())
91  {
92  unsigned int imgNr = *it;
93  ret << imgNr;
94  it++;
95  if (it != comp[i].end() && *it == imgNr + 1)
96  {
97  ret.Append(wxT("-"));
98  while (it != comp[i].end() && *it == imgNr + 1)
99  {
100  ++it;
101  ++imgNr;
102  };
103  ret << imgNr;
104  if (it != comp[i].end())
105  {
106  ret.Append(wxT(", "));
107  };
108  }
109  else
110  {
111  if (it != comp[i].end())
112  {
113  ret.Append(wxT(", "));
114  };
115  };
116  };
117 
118  ret.Append(wxT("]"));
119  if (i + 1 != comp.size())
120  {
121  ret.Append(wxT(", "));
122  };
123  }
124  return ret;
125 }
126 
127 // make wxwindows use this class as the main application
128 #if defined USE_GDKBACKEND_X11
129 // wxWidgets does not support wxGLCanvas on Wayland
130 // so until it is fixed upstream enforce using x11 backend
131 // see ticket http://trac.wxwidgets.org/ticket/17702
132 #warning Using Hugin with hard coded GDK_BACKEND=x11
133 wxIMPLEMENT_WX_THEME_SUPPORT
134 wxIMPLEMENT_APP_NO_MAIN(huginApp);
135 #include <stdlib.h>
136 int main(int argc, char **argv)
137 {
138  wxDISABLE_DEBUG_SUPPORT();
139  char backend[]="GDK_BACKEND=x11";
140  putenv(backend);
141  return wxEntry(argc, argv);
142 };
143 #else
145 #endif
146 
147 wxDEFINE_EVENT(EVT_IMAGE_READY, ImageReadyEvent);
148 
149 ImageReadyEvent::ImageReadyEvent(HuginBase::ImageCache::RequestPtr request, HuginBase::ImageCache::EntryPtr entry) : wxEvent(0, EVT_IMAGE_READY), request(request), entry(entry)
150 {
151 }
152 
153 wxEvent* ImageReadyEvent::Clone() const
154 {
155  return new ImageReadyEvent(request, entry);
156 }
157 
159 {
160  DEBUG_TRACE("ctor");
161  m_this=this;
162  m_monitorProfile = NULL;
163 #if wxUSE_ON_FATAL_EXCEPTION
164  wxHandleFatalExceptions();
165 #endif
166  Bind(EVT_IMAGE_READY, &huginApp::relayImageLoaded, this);
167 }
168 
170 {
171  DEBUG_TRACE("dtor");
172  // delete temporary dir
173 // if (!wxRmdir(m_workDir)) {
174 // DEBUG_ERROR("Could not remove temporary directory");
175 // }
176 
177  // todo: remove all listeners from the panorama object
178 
179 // delete frame;
181  // delete monitor profile
182  if (m_monitorProfile)
183  {
184  cmsCloseProfile(m_monitorProfile);
185  };
186  DEBUG_TRACE("dtor end");
187 }
188 
190 {
191  DEBUG_TRACE("=========================== huginApp::OnInit() begin ===================");
192  SetAppName(wxT("hugin"));
193 #if defined __WXGTK__
194  CheckConfigFilename();
195 #endif
196 
197  // Connect to ImageCache: we need to tell it when it is safe to handle UI events.
198  ImageCache::getInstance().asyncLoadCompleteSignal = &huginApp::imageLoadedAsync;
199 
200 #ifdef __WXMAC__
201  // do not use the native list control on OSX (it is very slow with the control point list window)
202  wxSystemOptions::SetOption(wxT("mac.listctrl.always_use_generic"), 1);
203  // On OS X the file open does by default not show the file type list
204  // Apple means this is not necessary
205  // but the the add images dialog needs this selection, so force to
206  // display always the file type list
207  wxSystemOptions::SetOption(wxOSX_FILEDIALOG_ALWAYS_SHOW_TYPES, 1);
208 #endif
209 
210  // register our custom pano tools dialog handlers
212 
213  // required by wxHtmlHelpController
214  wxFileSystem::AddHandler(new wxZipFSHandler);
215 
216  // initialize help provider
217  wxHelpControllerHelpProvider* provider = new wxHelpControllerHelpProvider;
218  wxHelpProvider::Set(provider);
219 
220 #if defined __WXMSW__
221  wxFileName exePath(wxStandardPaths::Get().GetExecutablePath());
222  m_utilsBinDir = exePath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
223  exePath.RemoveLastDir();
224  const wxString huginRoot=exePath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
225  m_xrcPrefix = huginRoot + wxT("share\\hugin\\xrc\\");
226  m_DataDir = huginRoot + wxT("share\\hugin\\data\\");
227 
228  // locale setup
229  locale.AddCatalogLookupPathPrefix(huginRoot + wxT("share\\locale"));
230 
231 #elif defined __WXMAC__ && defined MAC_SELF_CONTAINED_BUNDLE
232  // initialize paths
233  {
234  wxString thePath = MacGetPathToBundledResourceFile(CFSTR("xrc"));
235  if (thePath == wxT("")) {
236  wxMessageBox(_("xrc directory not found in bundle"), _("Fatal Error"));
237  return false;
238  }
239  m_xrcPrefix = thePath + wxT("/");
240  m_DataDir = thePath + wxT("/");
241  }
242 
243 #ifdef HUGIN_HSI
244  // Set PYTHONHOME for the hsi module
245  {
246  wxString pythonHome = MacGetPathToBundledFrameworksDirectory() + wxT("/Python27.framework/Versions/Current");
247  if(! wxDir::Exists(pythonHome)){
248  wxMessageBox(wxString::Format(_("Directory '%s' does not exists"), pythonHome.c_str()));
249  } else {
250  wxUnsetEnv(wxT("PYTHONPATH"));
251  if(! wxSetEnv(wxT("PYTHONHOME"), pythonHome)){
252  wxMessageBox(_("Could not set environment variable PYTHONHOME"));
253  } else {
254  DEBUG_TRACE("PYTHONHOME set to " << pythonHome);
255  }
256  }
257  }
258 #endif
259 
260 #elif defined UNIX_SELF_CONTAINED_BUNDLE
261  // initialize paths
262  {
263  wxFileName exePath(wxStandardPaths::Get().GetExecutablePath());
264  m_utilsBinDir = exePath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
265  exePath.RemoveLastDir();
266  const wxString huginRoot=exePath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
267  m_xrcPrefix = huginRoot + wxT("share/hugin/xrc/");
268  m_DataDir = huginRoot + wxT("share/hugin/data/");
269 
270  // locale setup
271  locale.AddCatalogLookupPathPrefix(huginRoot + wxT("share/locale"));
272  }
273 
274 #else
275  // add the locale directory specified during configure
276  m_xrcPrefix = wxT(INSTALL_XRC_DIR);
277  m_DataDir = wxT(INSTALL_DATA_DIR);
278  locale.AddCatalogLookupPathPrefix(wxT(INSTALL_LOCALE_DIR));
279 #endif
280 
281  if ( ! wxFile::Exists(m_xrcPrefix + wxT("/main_frame.xrc")) ) {
282  wxMessageBox(wxString::Format(_("xrc directory not found, hugin needs to be properly installed\nTried Path: %s"), m_xrcPrefix), _("Fatal Error"));
283  return false;
284  }
285 
286  // here goes and comes configuration
287  wxConfigBase * config = wxConfigBase::Get();
288  // do not record default values in the preferences file
289  config->SetRecordDefaults(false);
290 
291  config->Flush();
292 
293  // need to explicitly initialize locale for C++ library/runtime
294  setlocale(LC_ALL, "");
295  // initialize i18n
296  int localeID = config->Read(wxT("language"), (long) HUGIN_LANGUAGE);
297  DEBUG_TRACE("localeID: " << localeID);
298  {
299  bool bLInit;
300  bLInit = locale.Init(localeID);
301  if (bLInit) {
302  DEBUG_TRACE("locale init OK");
303  DEBUG_TRACE("System Locale: " << locale.GetSysName().mb_str(wxConvLocal))
304  DEBUG_TRACE("Canonical Locale: " << locale.GetCanonicalName().mb_str(wxConvLocal))
305  } else {
306  DEBUG_TRACE("locale init failed");
307  }
308  }
309 
310  // set the name of locale recource to look for
311  locale.AddCatalog(wxT("hugin"));
312 
313  // initialize image handlers
314  wxInitAllImageHandlers();
315 
316  // Initialize all the XRC handlers.
317  wxXmlResource::Get()->InitAllHandlers();
318 
319  // load all XRC files.
320  #ifdef _INCLUDE_UI_RESOURCES
321  InitXmlResource();
322  #else
323 
324  // add custom XRC handlers
325  wxXmlResource::Get()->AddHandler(new ImagesPanelXmlHandler());
326  wxXmlResource::Get()->AddHandler(new CPEditorPanelXmlHandler());
327  wxXmlResource::Get()->AddHandler(new CPImageCtrlXmlHandler());
328  wxXmlResource::Get()->AddHandler(new CPImagesComboBoxXmlHandler());
329  wxXmlResource::Get()->AddHandler(new MaskEditorPanelXmlHandler());
330  wxXmlResource::Get()->AddHandler(new MaskImageCtrlXmlHandler());
331  wxXmlResource::Get()->AddHandler(new OptimizePanelXmlHandler());
332  wxXmlResource::Get()->AddHandler(new OptimizePhotometricPanelXmlHandler());
333  wxXmlResource::Get()->AddHandler(new PanoPanelXmlHandler());
334  wxXmlResource::Get()->AddHandler(new PreviewPanelXmlHandler());
335  wxXmlResource::Get()->AddHandler(new HtmlWindowXmlHandler());
336  wxXmlResource::Get()->AddHandler(new wxcode::wxTreeListCtrlXmlHandler());
337  wxXmlResource::Get()->AddHandler(new ImagesTreeCtrlXmlHandler());
338  wxXmlResource::Get()->AddHandler(new CPListCtrlXmlHandler());
339  wxXmlResource::Get()->AddHandler(new SplitButtonXmlHandler());
340 
341  // load XRC files
342  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("cp_list_frame.xrc"));
343  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("preview_frame.xrc"));
344  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("edit_script_dialog.xrc"));
345  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("main_menu.xrc"));
346  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("main_tool.xrc"));
347  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("about.xrc"));
348  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("pref_dialog.xrc"));
349  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("cpdetector_dialog.xrc"));
350  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("reset_dialog.xrc"));
351  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("optimize_photo_panel.xrc"));
352  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("cp_editor_panel.xrc"));
353  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("images_panel.xrc"));
354  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("main_frame.xrc"));
355  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("optimize_panel.xrc"));
356  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("pano_panel.xrc"));
357  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("mask_editor_panel.xrc"));
358  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("lensdb_dialogs.xrc"));
359  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("image_variable_dlg.xrc"));
360  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("dlg_warning.xrc"));
361  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("import_raw_dialog.xrc"));
362 #endif
363 
364 #ifdef __WXMAC__
365  // If hugin is starting with file opening AppleEvent, MacOpenFile will be called on first wxYield().
366  // Those need to be initialised before first call of Yield which happens in Mainframe constructor.
367  m_macInitDone=false;
368  m_macOpenFileOnStart=false;
369 #endif
370  // read monitor profile
372  // create main frame
373  frame = new MainFrame(NULL, pano);
374  SetTopWindow(frame);
375 
376  // setup main frame size, after it has been created.
377  RestoreFramePosition(frame, wxT("MainFrame"));
378 #ifdef __WXMSW__
379  frame->SendSizeEvent();
380 // wxUSE_TASKBARBUTTON 1 is default, nevertheless check that the feature has not been deactivated by the user, otherwise issue a warning
381 #if wxUSE_TASKBARBUTTON
382  wxTaskBarJumpList jumpList;
383  wxFileName exeFile(wxStandardPaths::Get().GetExecutablePath());
384  exeFile.SetName("PTBatcherGUI");
385  wxTaskBarJumpListItem *item1 = new wxTaskBarJumpListItem(
386  NULL, wxTASKBAR_JUMP_LIST_TASK, _("Open Batch Processor"), exeFile.GetFullPath(), wxEmptyString,
387  _("Opens PTBatcherGUI, the batch processor for Hugin's project files"),
388  exeFile.GetFullPath(), 0);
389  jumpList.GetTasks().Append(item1);
390  exeFile.SetName("calibrate_lens_gui");
391  item1 = new wxTaskBarJumpListItem(
392  NULL, wxTASKBAR_JUMP_LIST_TASK, _("Open Lens calibrate tool"), exeFile.GetFullPath(), wxEmptyString,
393  _("Opens Calibrate_lens_gui, a simple GUI for lens calibration"),
394  exeFile.GetFullPath(), 0);
395  jumpList.GetTasks().Append(item1);
396  exeFile.SetName("Hugin_toolbox");
397  item1 = new wxTaskBarJumpListItem(
398  NULL, wxTASKBAR_JUMP_LIST_TASK, _("Open Hugin toolbox"), exeFile.GetFullPath(), wxEmptyString,
399  _("Opens Hugin_toolbox, a GUI for several small helper programs"),
400  exeFile.GetFullPath(), 0);
401  jumpList.GetTasks().Append(item1);
402 #else
403  #if defined _MSC_VER
404  #pragma message("Warning: huginApp.cpp - wxWidgets is compiled without support for taskbar buttons. Some features have therefore disabled.")
405  #else
406  #warning "Warning: huginApp.cpp - wxWidgets is compiled without support for taskbar buttons. Some features have therefore disabled."
407  #endif
408 #endif
409 #endif
410  // init help system
411  provider->SetHelpController(&frame->GetHelpController());
412 #ifdef __WXMSW__
413  frame->GetHelpController().Initialize(m_xrcPrefix + wxT("data/hugin_help_en_EN.chm"));
414 #else
415 #if wxUSE_WXHTML_HELP
416  // using wxHtmlHelpController
417 #if defined __WXMAC__ && defined MAC_SELF_CONTAINED_BUNDLE
418  // On Mac, xrc/data/help_LOCALE should be in the bundle as LOCALE.lproj/help
419  // which we can rely on the operating sytem to pick the right locale's.
420  wxString strFile = MacGetPathToBundledResourceFile(CFSTR("help"));
421  if (!strFile.IsEmpty())
422  {
423  frame->GetHelpController().AddBook(wxFileName(strFile + wxT("/hugin_help_en_EN.hhp")));
424  }
425  else
426  {
427  wxLogError(wxString::Format(wxT("Could not find help directory in the bundle"), strFile.c_str()));
428  return false;
429  }
430 #else
431  frame->GetHelpController().AddBook(wxFileName(m_xrcPrefix + wxT("data/help_en_EN/hugin_help_en_EN.hhp")));
432 #endif
433 #else
434  // using wxExtHelpController
435  frame->GetHelpController().Initialize(Initialize(m_xrcPrefix + wxT("data/help_en_EN")));
436 #endif
437 #endif
438 
439  // we are closing Hugin, if the top level window is deleted
440  SetExitOnFrameDelete(true);
441  // show the frame.
443  {
444  SetTopWindow(frame->getGLPreview());
445  }
446  else
447  {
448  frame->Show(TRUE);
449  };
450 
451  wxString cwd = wxFileName::GetCwd();
452 
453  m_workDir = config->Read(wxT("tempDir"),wxT(""));
454  // FIXME, make secure against some symlink attacks
455  // get a temp dir
456  if (m_workDir == wxT("")) {
457 #if (defined __WXMSW__)
458  DEBUG_DEBUG("figuring out windows temp dir");
459  /* added by Yili Zhao */
460  wxChar buffer[MAX_PATH];
461  GetTempPath(MAX_PATH, buffer);
462  m_workDir = buffer;
463 #elif (defined __WXMAC__) && (defined MAC_SELF_CONTAINED_BUNDLE)
464  DEBUG_DEBUG("temp dir on Mac");
465  m_workDir = MacGetPathToUserDomainTempDir();
466  if(m_workDir == wxT(""))
467  m_workDir = wxT("/tmp");
468 #else //UNIX
469  DEBUG_DEBUG("temp dir on unix");
470  // try to read environment variable
471  if (!wxGetEnv(wxT("TMPDIR"), &m_workDir)) {
472  // still no tempdir, use /tmp
473  m_workDir = wxT("/tmp");
474  }
475 #endif
476 
477  }
478 
479  if (!wxFileName::DirExists(m_workDir)) {
480  DEBUG_DEBUG("creating temp dir: " << m_workDir.mb_str(wxConvLocal));
481  if (!wxMkdir(m_workDir)) {
482  DEBUG_ERROR("Tempdir could not be created: " << m_workDir.mb_str(wxConvLocal));
483  }
484  }
485  if (!wxSetWorkingDirectory(m_workDir)) {
486  DEBUG_ERROR("could not change to temp. dir: " << m_workDir.mb_str(wxConvLocal));
487  }
488  DEBUG_DEBUG("using temp dir: " << m_workDir.mb_str(wxConvLocal));
489 
490  // set some suitable defaults
493 
494  // suppress tiff warnings
495  TIFFSetWarningHandler(0);
496 
497  if (argc > 1)
498  {
499 #ifdef __WXMSW__
500  //on Windows we need to update the fast preview first
501  //otherwise there is an infinite loop when starting with a project file
502  //and closed panorama editor aka mainframe
504  {
505  frame->getGLPreview()->Update();
506  };
507 #endif
508  wxFileName file(argv[1]);
509  // if the first file is a project file, open it
510  if (file.GetExt().CmpNoCase(wxT("pto")) == 0 ||
511  file.GetExt().CmpNoCase(wxT("pts")) == 0 ||
512  file.GetExt().CmpNoCase(wxT("ptp")) == 0 )
513  {
514  if(file.IsRelative())
515  file.MakeAbsolute(cwd);
516  // Loading the project file with set actualPath to its
517  // parent directory. (actualPath is used as starting
518  // directory by many subsequent file selection dialogs.)
519  frame->LoadProjectFile(file.GetFullPath());
520  } else {
521  std::vector<std::string> filesv;
522  std::vector<std::string> rawFilesv;
523  bool actualPathSet = false;
524  for (int i=1; i< argc; i++)
525  {
526 #if defined __WXMSW__
527  //expand wildcards
528  wxFileName fileList(argv[i]);
529  if(fileList.IsRelative())
530  fileList.MakeAbsolute(cwd);
531  wxDir dir;
532  wxString foundFile;
533  wxFileName file;
534  if(fileList.DirExists())
535  if(dir.Open(fileList.GetPath()))
536  if(dir.GetFirst(&foundFile,fileList.GetFullName(),wxDIR_FILES | wxDIR_HIDDEN))
537  do
538  {
539  file=foundFile;
540  file.MakeAbsolute(dir.GetName());
541 #else
542  wxFileName file(argv[i]);
543 #endif
544  if (file.IsRelative())
545  {
546  file.MakeAbsolute(cwd);
547  };
548  if (IsRawExtension(file.GetExt()))
549  {
550  // we got a raw file from command line
551  if (!containsInvalidCharacters(file.GetFullPath()))
552  {
553  rawFilesv.push_back((const char*)file.GetFullPath().mb_str(HUGIN_CONV_FILENAME));
554  // Use the first filename to set actualPath.
555  if (!actualPathSet)
556  {
557  config->Write(wxT("/actualPath"), file.GetPath());
558  actualPathSet = true;
559  };
560  };
561  }
562  else
563  {
564  if (vigra::isImage(file.GetFullPath().mb_str(HUGIN_CONV_FILENAME)))
565  {
566  if (!containsInvalidCharacters(file.GetFullPath()))
567  {
568  filesv.push_back((const char *)(file.GetFullPath().mb_str(HUGIN_CONV_FILENAME)));
569  // Use the first filename to set actualPath.
570  if (!actualPathSet)
571  {
572  config->Write(wxT("/actualPath"), file.GetPath());
573  actualPathSet = true;
574  };
575  };
576  };
577  };
578 #if defined __WXMSW__
579  } while (dir.GetNext(&foundFile));
580 #endif
581  }
582  if(!filesv.empty())
583  {
584  std::vector<PanoCommand::PanoCommand*> cmds;
585  cmds.push_back(new PanoCommand::wxAddImagesCmd(pano,filesv));
586  cmds.push_back(new PanoCommand::DistributeImagesCmd(pano));
587  cmds.push_back(new PanoCommand::CenterPanoCmd(pano));
589  };
590  if (!rawFilesv.empty())
591  {
592  if (rawFilesv.size() == 1)
593  {
594  wxMessageDialog message(GetTopWindow(), _("You selected only one raw file. This is not recommended.\nAll raw files should be converted at once."),
595 #ifdef _WIN32
596  _("Hugin"),
597 #else
598  wxT(""),
599 #endif
600  wxICON_EXCLAMATION | wxOK | wxCANCEL);
601  message.SetOKLabel(_("Convert anyway."));
602  if (message.ShowModal() != wxID_OK)
603  {
604  return true;
605  };
606  };
607  RawImportDialog dlg(GetTopWindow(), &pano, rawFilesv);
608  // check that raw files are from same camera and that all can be read
609  if (dlg.CheckRawFiles())
610  {
611  // now show dialog
612  if (dlg.ShowModal() == wxID_OK)
613  {
615  };
616  };
617  };
618  };
619  }
620 #ifdef __WXMAC__
621  m_macInitDone = true;
622  if(m_macOpenFileOnStart) {frame->LoadProjectFile(m_macFileNameToOpenOnStart);}
623  m_macOpenFileOnStart = false;
624 #endif
625 
626  //check for no tip switch, needed by PTBatcher
627  wxString secondParam = argc > 2 ? wxString(argv[2]) : wxString();
628  if(secondParam.Cmp(_T("-notips"))!=0)
629  {
630  //load tip startup preferences (tips will be started after splash terminates)
631  int nValue = config->Read(wxT("/MainFrame/ShowStartTip"), 1l);
632 
633  //show tips if needed now
634  if(nValue > 0)
635  {
636  wxCommandEvent dummy;
637  frame->OnTipOfDay(dummy);
638  }
639  }
640 
641  DEBUG_TRACE("=========================== huginApp::OnInit() end ===================");
642  return true;
643 }
644 
646 {
647  DEBUG_TRACE("");
648  delete wxHelpProvider::Set(NULL);
649  return 0;
650 }
651 
653 {
654  if (m_this) {
655  return m_this;
656  } else {
657  DEBUG_FATAL("huginApp not yet created");
659  return 0;
660  }
661 }
662 
664 {
665  if (m_this) {
666  return m_this->frame;
667  } else {
668  return 0;
669  }
670 }
671 
673 {
674  if (event.entry.get())
675  {
676  ImageCache::getInstance().postEvent(event.request, event.entry);
677  }
678  else
679  {
680  // loading failed, first remove request from image cache list
681  ImageCache::getInstance().removeRequest(event.request);
682  // now notify main frame to remove the failed image from project
683  wxCommandEvent e(EVT_LOADING_FAILED);
684  e.SetString(wxString(event.request->getFilename().c_str(), HUGIN_CONV_FILENAME));
685  frame->GetEventHandler()->AddPendingEvent(e);
686  };
687 }
688 
689 void huginApp::imageLoadedAsync(ImageCache::RequestPtr request, ImageCache::EntryPtr entry)
690 {
691  ImageReadyEvent event(request, entry);
692  // AddPendingEvent adds the event to the event queue and returns without
693  // processing it. This is necessary since we are probably not in the
694  // UI thread, but the event handler must be run in the UI thread since it
695  // could update image views.
696  Get()->AddPendingEvent(event);
697 }
698 
699 #ifdef __WXMAC__
700 void huginApp::MacOpenFile(const wxString &fileName)
701 {
702  if(!m_macInitDone)
703  {
704  m_macOpenFileOnStart=true;
705  m_macFileNameToOpenOnStart = fileName;
706  return;
707  }
708 
709  if(frame) frame->MacOnOpenFile(fileName);
710 }
711 #endif
712 
713 #if wxUSE_ON_FATAL_EXCEPTION
714 void huginApp::OnFatalException()
715 {
716  GenerateReport(wxDebugReport::Context_Exception);
717 };
718 #endif
719 
wxDEFINE_EVENT(EVT_QUEUE_PROGRESS, wxCommandEvent)
bool checkVersion(wxString v1, wxString v2)
Definition: huginApp.cpp:79
int alphanum_comp(const std::string &l, const std::string &r)
Compare l and r with the same semantics as strcmp(), but with the &quot;Alphanum Algorithm&quot; which produces...
Definition: alphanum.cpp:119
static huginApp * m_this
Definition: huginApp.h:149
The application class for hugin.
Definition: huginApp.h:56
implementation of huginApp Class
virtual bool OnInit()
pseudo constructor.
Definition: huginApp.cpp:189
HuginBase::Panorama pano
Definition: huginApp.h:152
start a new project, reset options to values in preferences
Definition: wxPanoCommand.h:85
center panorama horizontically
Definition: PanoCommand.h:250
declaration of main image tree control
wxIMPLEMENT_APP(huginApp)
#define HUGIN_CONV_FILENAME
Definition: platform.h:40
xrc handler for split button
Definition: SplitButton.h:94
#define DEBUG_TRACE(msg)
Definition: utils.h:67
cmsHPROFILE m_monitorProfile
Definition: huginApp.h:162
xrc handler for handling mask editor panel
void registerPTWXDlgFcn()
Definition: PTWXDlg.cpp:173
#define HUGIN_LANGUAGE
void relayImageLoaded(ImageReadyEvent &event)
Relay image loaded event when the UI thread is ready to process it.
Definition: huginApp.cpp:672
void OnTipOfDay(wxCommandEvent &e)
Definition: MainFrame.cpp:1496
MainFrame * frame
Definition: huginApp.h:146
huginApp()
ctor.
Definition: huginApp.cpp:158
wxString m_DataDir
Definition: huginApp.h:157
#define DEBUG_ASSERT(cond)
Definition: utils.h:80
include file for the hugin project
wxHelpController & GetHelpController()
Definition: MainFrame.h:183
virtual wxEvent * Clone() const
Definition: huginApp.cpp:153
wxString m_monitorProfileName
Definition: huginApp.h:161
std::vector< HuginBase::UIntSet > Components
stores the components of the graph
Definition: ImageGraph.h:50
static void Clean()
cleanup the static LensDB instance, must be called at the end of the program
Definition: LensDB.cpp:2010
static huginApp * Get()
hack.. kind of a pseudo singleton...
Definition: huginApp.cpp:652
Dialog for raw import.
Definition: RawImport.h:34
PanoCommand to combine other PanoCommands.
Definition: PanoCommand.h:39
#define DEBUG_FATAL(msg)
Definition: utils.h:78
class to access Hugins camera and lens database
The main window frame.
Definition: MainFrame.h:83
xrc handler for mask editor
wxString m_xrcPrefix
Definition: huginApp.h:155
void LoadProjectFile(const wxString &filename)
Definition: MainFrame.cpp:1079
Definition of dialog and functions to import RAW images to project file.
HuginBase::ImageCache::EntryPtr entry
Definition: huginApp.h:45
std::shared_ptr< Entry > EntryPtr
a shared pointer to the entry
Definition: ImageCache.h:112
PanoCommand::PanoCommand * GetPanoCommand()
return PanoCommand for adding converted raw files to Panorama
Definition: RawImport.cpp:645
static MainFrame * getMainFrame()
Definition: huginApp.cpp:663
Definition of dialog for numeric transforms.
std::shared_ptr< Request > RequestPtr
Reference counted request for an image to load.
Definition: ImageCache.h:151
wxString m_utilsBinDir
Definition: huginApp.h:159
wxwindows specific panorama commands
distributes all images above the sphere, for the assistant
Definition: PanoCommand.h:649
xrc handler for CPImagesComboBox
Definition: CPListFrame.h:94
static GlobalCmdHist & getInstance()
void addCommand(PanoCommand *command, bool execute=true)
Adds a command to the history.
void clear()
Erases all the undo/redo history.
#define DEBUG_ERROR(msg)
Definition: utils.h:76
xrc handler for CPImagesComboBox
ImageReadyEvent(HuginBase::ImageCache::RequestPtr request, HuginBase::ImageCache::EntryPtr entry)
Definition: huginApp.cpp:149
wxString m_workDir
temporary working directory
Definition: huginApp.h:144
include file for the hugin project
const GuiLevel GetGuiLevel() const
Definition: MainFrame.h:185
GLPreviewFrame * getGLPreview()
Definition: MainFrame.cpp:2235
virtual ~huginApp()
dtor.
Definition: huginApp.cpp:169
xrc handler
Definition: PanoPanel.h:225
virtual int OnExit()
just for testing purposes
Definition: huginApp.cpp:645
#define DEBUG_DEBUG(msg)
Definition: utils.h:68
bool containsInvalidCharacters(const wxString stringToTest)
returns true, if the given strings contains invalid characters
Definition: platform.cpp:510
add image(s) to a panorama
Definition: wxPanoCommand.h:50
functions for interaction with the hugin configuration file
platform/compiler specific stuff.
xrc handler for HTMLWindow
Definition: HtmlWindow.h:53
bool IsRawExtension(const wxString &testExt)
return true, if given extension is in list of known raw extension (comparision is case insensitive ...
Definition: platform.cpp:111
Definition of HTMLWindow class which supports opening external links in default web browser...
HuginBase::ImageCache::RequestPtr request
Definition: huginApp.h:44
wxString Components2Str(const HuginGraph::ImageGraph::Components &comp)
Definition: huginApp.cpp:84
Event for when a requested image finished loading.
Definition: huginApp.h:41
static void imageLoadedAsync(HuginBase::ImageCache::RequestPtr request, HuginBase::ImageCache::EntryPtr entry)
Queue up an image loaded event when an image has just loaded.
Definition: huginApp.cpp:689
wxLocale locale
locale for internationalisation
Definition: huginApp.h:128
bool CheckRawFiles()
return true, if all raw files are from the same camera
Definition: RawImport.cpp:650
void GetMonitorProfile(wxString &profileName, cmsHPROFILE &profile)
retrieve monitor profile from system
Definition: wxcms.cpp:201
void RestoreFramePosition(wxTopLevelWindow *frame, const wxString &basename)
Restore window size and position from configfile/registry.
Definition: wxutils.cpp:65
int main(int argc, char *argv[])
Definition: Main.cpp:167