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("[");
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("-");
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(", ");
107  };
108  }
109  else
110  {
111  if (it != comp[i].end())
112  {
113  ret.Append(", ");
114  };
115  };
116  };
117 
118  ret.Append("]");
119  if (i + 1 != comp.size())
120  {
121  ret.Append(", ");
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("hugin");
193 #if defined __WXMSW__ && wxCHECK_VERSION(3,3,0)
194  // automatically switch between light and dark mode
195  SetAppearance(Appearance::System);
196 #endif
197 #if defined __WXGTK__
198  CheckConfigFilename();
199 #endif
200 
201  // Connect to ImageCache: we need to tell it when it is safe to handle UI events.
202  ImageCache::getInstance().asyncLoadCompleteSignal = &huginApp::imageLoadedAsync;
203 
204 #ifdef __WXMAC__
205  // do not use the native list control on OSX (it is very slow with the control point list window)
206  wxSystemOptions::SetOption("mac.listctrl.always_use_generic", 1);
207  // On OS X the file open does by default not show the file type list
208  // Apple means this is not necessary
209  // but the the add images dialog needs this selection, so force to
210  // display always the file type list
211  wxSystemOptions::SetOption(wxOSX_FILEDIALOG_ALWAYS_SHOW_TYPES, 1);
212 #endif
213 
214  // register our custom pano tools dialog handlers
216 
217  // required by wxHtmlHelpController
218  wxFileSystem::AddHandler(new wxZipFSHandler);
219 
220  // initialize help provider
221  wxHelpControllerHelpProvider* provider = new wxHelpControllerHelpProvider;
222  wxHelpProvider::Set(provider);
223 
224 #if defined __WXMSW__
225  wxFileName exePath(wxStandardPaths::Get().GetExecutablePath());
226  m_utilsBinDir = exePath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
227  exePath.RemoveLastDir();
228  const wxString huginRoot=exePath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
229  m_xrcPrefix = huginRoot + "share\\hugin\\xrc\\";
230  m_DataDir = huginRoot + "share\\hugin\\data\\";
231 
232  // locale setup
233  locale.AddCatalogLookupPathPrefix(huginRoot + "share\\locale");
234 
235 #elif defined __WXMAC__ && defined MAC_SELF_CONTAINED_BUNDLE
236  // initialize paths
237  {
238  wxString thePath = MacGetPathToBundledResourceFile(CFSTR("xrc"));
239  if (thePath == wxEmptyString) {
240  hugin_utils::HuginMessageBox(_("xrc directory not found in bundle"), _("Hugin"), wxOK | wxICON_ERROR, wxGetActiveWindow());
241  return false;
242  }
243  m_xrcPrefix = thePath + "/";
244  m_DataDir = thePath + "/";
245  }
246 
247 #ifdef HUGIN_HSI
248  // Set PYTHONHOME for the hsi module
249  {
250  wxString pythonHome = MacGetPathToBundledFrameworksDirectory() + "/Python27.framework/Versions/Current";
251  if(! wxDir::Exists(pythonHome)){
252  hugin_utils::HuginMessageBox(wxString::Format(_("Directory '%s' does not exists"), pythonHome), _("Hugin"), wxOK | wxICON_ERROR, wxGetActiveWindow());
253  } else {
254  wxUnsetEnv("PYTHONPATH");
255  if(! wxSetEnv("PYTHONHOME", pythonHome)){
256  hugin_utils::HuginMessageBox(_("Could not set environment variable PYTHONHOME"), _("Hugin"), wxOK | wxICON_ERROR, wxGetActiveWindow());
257  } else {
258  DEBUG_TRACE("PYTHONHOME set to " << pythonHome);
259  }
260  }
261  }
262 #endif
263 
264 #elif defined UNIX_SELF_CONTAINED_BUNDLE
265  // initialize paths
266  {
267  wxFileName exePath(wxStandardPaths::Get().GetExecutablePath());
268  m_utilsBinDir = exePath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
269  exePath.RemoveLastDir();
270  const wxString huginRoot=exePath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
271  m_xrcPrefix = huginRoot + "share/hugin/xrc/";
272  m_DataDir = huginRoot + "share/hugin/data/";
273 
274  // locale setup
275  locale.AddCatalogLookupPathPrefix(huginRoot + "share/locale");
276  }
277 
278 #else
279  // add the locale directory specified during configure
280  m_xrcPrefix = INSTALL_XRC_DIR;
281  m_DataDir = INSTALL_DATA_DIR;
282  locale.AddCatalogLookupPathPrefix(INSTALL_LOCALE_DIR);
283 #endif
284 
285  if ( ! wxFile::Exists(m_xrcPrefix + "/main_frame.xrc") ) {
286  hugin_utils::HuginMessageBox(wxString::Format(_("xrc directory not found, hugin needs to be properly installed\nTried Path: %s"), m_xrcPrefix), _("Hugin"), wxOK | wxICON_ERROR, wxGetActiveWindow());
287  return false;
288  }
289 
290  // here goes and comes configuration
291  wxConfigBase * config = wxConfigBase::Get();
292  // do not record default values in the preferences file
293  config->SetRecordDefaults(false);
294 
295  config->Flush();
296 
297  // need to explicitly initialize locale for C++ library/runtime
298  setlocale(LC_ALL, "");
299  // initialize i18n
300  int localeID = config->Read("language", (long) HUGIN_LANGUAGE);
301  DEBUG_TRACE("localeID: " << localeID);
302  {
303  bool bLInit;
304  bLInit = locale.Init(localeID);
305  if (bLInit) {
306  DEBUG_TRACE("locale init OK");
307  DEBUG_TRACE("System Locale: " << locale.GetSysName().mb_str(wxConvLocal))
308  DEBUG_TRACE("Canonical Locale: " << locale.GetCanonicalName().mb_str(wxConvLocal))
309  } else {
310  DEBUG_TRACE("locale init failed");
311  }
312  }
313 
314  // set the name of locale recource to look for
315  locale.AddCatalog("hugin");
316 
317  // initialize image handlers
318  wxInitAllImageHandlers();
319 
320  // Initialize all the XRC handlers.
321  wxXmlResource::Get()->InitAllHandlers();
322 
323  // load all XRC files.
324  #ifdef _INCLUDE_UI_RESOURCES
325  InitXmlResource();
326  #else
327 
328  // add custom XRC handlers
329  wxXmlResource::Get()->AddHandler(new ImagesPanelXmlHandler());
330  wxXmlResource::Get()->AddHandler(new CPEditorPanelXmlHandler());
331  wxXmlResource::Get()->AddHandler(new CPImageCtrlXmlHandler());
332  wxXmlResource::Get()->AddHandler(new CPImagesComboBoxXmlHandler());
333  wxXmlResource::Get()->AddHandler(new MaskEditorPanelXmlHandler());
334  wxXmlResource::Get()->AddHandler(new MaskImageCtrlXmlHandler());
335  wxXmlResource::Get()->AddHandler(new OptimizePanelXmlHandler());
336  wxXmlResource::Get()->AddHandler(new OptimizePhotometricPanelXmlHandler());
337  wxXmlResource::Get()->AddHandler(new PanoPanelXmlHandler());
338  wxXmlResource::Get()->AddHandler(new PreviewPanelXmlHandler());
339  wxXmlResource::Get()->AddHandler(new HtmlWindowXmlHandler());
340  wxXmlResource::Get()->AddHandler(new wxcode::wxTreeListCtrlXmlHandler());
341  wxXmlResource::Get()->AddHandler(new ImagesTreeCtrlXmlHandler());
342  wxXmlResource::Get()->AddHandler(new CPListCtrlXmlHandler());
343  wxXmlResource::Get()->AddHandler(new SplitButtonXmlHandler());
344 
345  // load XRC files
346  wxXmlResource::Get()->Load(m_xrcPrefix + "cp_list_frame.xrc");
347  wxXmlResource::Get()->Load(m_xrcPrefix + "preview_frame.xrc");
348  wxXmlResource::Get()->Load(m_xrcPrefix + "edit_script_dialog.xrc");
349  wxXmlResource::Get()->Load(m_xrcPrefix + "main_menu.xrc");
350  wxXmlResource::Get()->Load(m_xrcPrefix + "main_tool.xrc");
351  wxXmlResource::Get()->Load(m_xrcPrefix + "about.xrc");
352  wxXmlResource::Get()->Load(m_xrcPrefix + "pref_dialog.xrc");
353  wxXmlResource::Get()->Load(m_xrcPrefix + "cpdetector_dialog.xrc");
354  wxXmlResource::Get()->Load(m_xrcPrefix + "reset_dialog.xrc");
355  wxXmlResource::Get()->Load(m_xrcPrefix + "optimize_photo_panel.xrc");
356  wxXmlResource::Get()->Load(m_xrcPrefix + "cp_editor_panel.xrc");
357  wxXmlResource::Get()->Load(m_xrcPrefix + "images_panel.xrc");
358  wxXmlResource::Get()->Load(m_xrcPrefix + "main_frame.xrc");
359  wxXmlResource::Get()->Load(m_xrcPrefix + "optimize_panel.xrc");
360  wxXmlResource::Get()->Load(m_xrcPrefix + "pano_panel.xrc");
361  wxXmlResource::Get()->Load(m_xrcPrefix + "mask_editor_panel.xrc");
362  wxXmlResource::Get()->Load(m_xrcPrefix + "lensdb_dialogs.xrc");
363  wxXmlResource::Get()->Load(m_xrcPrefix + "image_variable_dlg.xrc");
364  wxXmlResource::Get()->Load(m_xrcPrefix + "dlg_warning.xrc");
365  wxXmlResource::Get()->Load(m_xrcPrefix + "import_raw_dialog.xrc");
366 #endif
367 
368 #ifdef __WXMAC__
369  // If hugin is starting with file opening AppleEvent, MacOpenFile will be called on first wxYield().
370  // Those need to be initialised before first call of Yield which happens in Mainframe constructor.
371  m_macInitDone=false;
372  m_macOpenFileOnStart=false;
373 #endif
374  // read monitor profile
376  // create main frame
377  frame = new MainFrame(NULL, pano);
378  SetTopWindow(frame);
379 
380  // setup main frame size, after it has been created.
382 #ifdef __WXMSW__
383  frame->SendSizeEvent();
384 // wxUSE_TASKBARBUTTON 1 is default, nevertheless check that the feature has not been deactivated by the user, otherwise issue a warning
385 #if wxUSE_TASKBARBUTTON
386  wxTaskBarJumpList jumpList;
387  wxFileName exeFile(wxStandardPaths::Get().GetExecutablePath());
388  exeFile.SetName("PTBatcherGUI");
389  wxTaskBarJumpListItem *item1 = new wxTaskBarJumpListItem(
390  NULL, wxTASKBAR_JUMP_LIST_TASK, _("Open Batch Processor"), exeFile.GetFullPath(), wxEmptyString,
391  _("Opens PTBatcherGUI, the batch processor for Hugin's project files"),
392  exeFile.GetFullPath(), 0);
393  jumpList.GetTasks().Append(item1);
394  exeFile.SetName("calibrate_lens_gui");
395  item1 = new wxTaskBarJumpListItem(
396  NULL, wxTASKBAR_JUMP_LIST_TASK, _("Open Lens calibrate tool"), exeFile.GetFullPath(), wxEmptyString,
397  _("Opens Calibrate_lens_gui, a simple GUI for lens calibration"),
398  exeFile.GetFullPath(), 0);
399  jumpList.GetTasks().Append(item1);
400  exeFile.SetName("Hugin_toolbox");
401  item1 = new wxTaskBarJumpListItem(
402  NULL, wxTASKBAR_JUMP_LIST_TASK, _("Open Hugin toolbox"), exeFile.GetFullPath(), wxEmptyString,
403  _("Opens Hugin_toolbox, a GUI for several small helper programs"),
404  exeFile.GetFullPath(), 0);
405  jumpList.GetTasks().Append(item1);
406 #else
407  #if defined _MSC_VER
408  #pragma message("Warning: huginApp.cpp - wxWidgets is compiled without support for taskbar buttons. Some features have therefore disabled.")
409  #else
410  #warning "Warning: huginApp.cpp - wxWidgets is compiled without support for taskbar buttons. Some features have therefore disabled."
411  #endif
412 #endif
413 #endif
414  // init help system
415  provider->SetHelpController(&frame->GetHelpController());
416 #ifdef __WXMSW__
417  frame->GetHelpController().Initialize(m_xrcPrefix + "data/hugin_help_en_EN.chm");
418 #else
419 #if wxUSE_WXHTML_HELP
420  // using wxHtmlHelpController
421 #if defined __WXMAC__ && defined MAC_SELF_CONTAINED_BUNDLE
422  // On Mac, xrc/data/help_LOCALE should be in the bundle as LOCALE.lproj/help
423  // which we can rely on the operating sytem to pick the right locale's.
424  wxString strFile = MacGetPathToBundledResourceFile(CFSTR("help"));
425  if (!strFile.IsEmpty())
426  {
427  frame->GetHelpController().AddBook(wxFileName(strFile + "/hugin_help_en_EN.hhp"));
428  }
429  else
430  {
431  wxLogError(wxString::Format("Could not find help directory in the bundle", strFile.c_str()));
432  return false;
433  }
434 #else
435  frame->GetHelpController().AddBook(wxFileName(m_xrcPrefix + "data/help_en_EN/hugin_help_en_EN.hhp"));
436 #endif
437 #else
438  // using wxExtHelpController
439  frame->GetHelpController().Initialize(Initialize(m_xrcPrefix + "data/help_en_EN"));
440 #endif
441 #endif
442 
443  // we are closing Hugin, if the top level window is deleted
444  SetExitOnFrameDelete(true);
445  // show the frame.
447  {
448  SetTopWindow(frame->getGLPreview());
449  }
450  else
451  {
452  frame->Show(TRUE);
453  };
454 
455  wxString cwd = wxFileName::GetCwd();
456 
457  m_workDir = config->Read("tempDir",wxEmptyString);
458  // FIXME, make secure against some symlink attacks
459  // get a temp dir
460  if (m_workDir == wxEmptyString) {
461 #if (defined __WXMSW__)
462  DEBUG_DEBUG("figuring out windows temp dir");
463  /* added by Yili Zhao */
464  wxChar buffer[MAX_PATH];
465  GetTempPath(MAX_PATH, buffer);
466  m_workDir = buffer;
467 #elif (defined __WXMAC__) && (defined MAC_SELF_CONTAINED_BUNDLE)
468  DEBUG_DEBUG("temp dir on Mac");
469  m_workDir = MacGetPathToUserDomainTempDir();
470  if(m_workDir == wxEmptyString)
471  m_workDir = "/tmp";
472 #else //UNIX
473  DEBUG_DEBUG("temp dir on unix");
474  // try to read environment variable
475  if (!wxGetEnv("TMPDIR", &m_workDir)) {
476  // still no tempdir, use /tmp
477  m_workDir = "/tmp";
478  }
479 #endif
480 
481  }
482 
483  if (!wxFileName::DirExists(m_workDir)) {
484  DEBUG_DEBUG("creating temp dir: " << m_workDir.mb_str(wxConvLocal));
485  if (!wxMkdir(m_workDir)) {
486  DEBUG_ERROR("Tempdir could not be created: " << m_workDir.mb_str(wxConvLocal));
487  }
488  }
489  if (!wxSetWorkingDirectory(m_workDir)) {
490  DEBUG_ERROR("could not change to temp. dir: " << m_workDir.mb_str(wxConvLocal));
491  }
492  DEBUG_DEBUG("using temp dir: " << m_workDir.mb_str(wxConvLocal));
493 
494  // set some suitable defaults
497 
498  // suppress tiff warnings
499  TIFFSetWarningHandler(0);
500 
501  if (argc > 1)
502  {
503 #ifdef __WXMSW__
504  //on Windows we need to update the fast preview first
505  //otherwise there is an infinite loop when starting with a project file
506  //and closed panorama editor aka mainframe
508  {
509  frame->getGLPreview()->Update();
510  };
511 #endif
512  wxFileName file(argv[1]);
513  // if the first file is a project file, open it
514  if (file.GetExt().CmpNoCase("pto") == 0 ||
515  file.GetExt().CmpNoCase("pts") == 0 ||
516  file.GetExt().CmpNoCase("ptp") == 0 )
517  {
518  if(file.IsRelative())
519  file.MakeAbsolute(cwd);
520  // Loading the project file with set actualPath to its
521  // parent directory. (actualPath is used as starting
522  // directory by many subsequent file selection dialogs.)
523  frame->LoadProjectFile(file.GetFullPath());
524  } else {
525  std::vector<std::string> filesv;
526  std::vector<std::string> rawFilesv;
527  bool actualPathSet = false;
528  for (int i=1; i< argc; i++)
529  {
530 #if defined __WXMSW__
531  //expand wildcards
532  wxFileName fileList(argv[i]);
533  if(fileList.IsRelative())
534  fileList.MakeAbsolute(cwd);
535  wxDir dir;
536  wxString foundFile;
537  wxFileName file;
538  if(fileList.DirExists())
539  if(dir.Open(fileList.GetPath()))
540  if(dir.GetFirst(&foundFile,fileList.GetFullName(),wxDIR_FILES | wxDIR_HIDDEN))
541  do
542  {
543  file=foundFile;
544  file.MakeAbsolute(dir.GetName());
545 #else
546  wxFileName file(argv[i]);
547 #endif
548  if (file.IsRelative())
549  {
550  file.MakeAbsolute(cwd);
551  };
552  if (IsRawExtension(file.GetExt()))
553  {
554  // we got a raw file from command line
555  if (!containsInvalidCharacters(file.GetFullPath()))
556  {
557  rawFilesv.push_back((const char*)file.GetFullPath().mb_str(HUGIN_CONV_FILENAME));
558  // Use the first filename to set actualPath.
559  if (!actualPathSet)
560  {
561  config->Write("/actualPath", file.GetPath());
562  actualPathSet = true;
563  };
564  };
565  }
566  else
567  {
568  if (vigra::isImage(file.GetFullPath().mb_str(HUGIN_CONV_FILENAME)))
569  {
570  if (!containsInvalidCharacters(file.GetFullPath()))
571  {
572  filesv.push_back((const char *)(file.GetFullPath().mb_str(HUGIN_CONV_FILENAME)));
573  // Use the first filename to set actualPath.
574  if (!actualPathSet)
575  {
576  config->Write("/actualPath", file.GetPath());
577  actualPathSet = true;
578  };
579  };
580  };
581  };
582 #if defined __WXMSW__
583  } while (dir.GetNext(&foundFile));
584 #endif
585  }
586  if(!filesv.empty())
587  {
588  std::vector<PanoCommand::PanoCommand*> cmds;
589  cmds.push_back(new PanoCommand::wxAddImagesCmd(pano,filesv));
590  cmds.push_back(new PanoCommand::DistributeImagesCmd(pano));
591  cmds.push_back(new PanoCommand::CenterPanoCmd(pano));
593  };
594  if (!rawFilesv.empty())
595  {
596  if (rawFilesv.size() == 1)
597  {
598  hugin_utils::MessageDialog message=hugin_utils::GetMessageDialog(_("You selected only one raw file. This is not recommended.\nAll raw files should be converted at once."),
599  _("Hugin"), wxICON_EXCLAMATION | wxOK | wxCANCEL, wxGetActiveWindow());
600  message->SetOKLabel(_("Convert anyway."));
601  if (message->ShowModal() != wxID_OK)
602  {
603  return true;
604  };
605  };
606  RawImportDialog dlg(GetTopWindow(), &pano, rawFilesv);
607  // check that raw files are from same camera and that all can be read
608  if (dlg.CheckRawFiles())
609  {
610  // now show dialog
611  if (dlg.ShowModal() == wxID_OK)
612  {
614  };
615  };
616  };
617  };
618  }
619 #ifdef __WXMAC__
620  m_macInitDone = true;
621  if(m_macOpenFileOnStart) {frame->LoadProjectFile(m_macFileNameToOpenOnStart);}
622  m_macOpenFileOnStart = false;
623 #endif
624 
625  //check for no tip switch, needed by PTBatcher
626  wxString secondParam = argc > 2 ? wxString(argv[2]) : wxString();
627  if(secondParam.Cmp(_T("-notips"))!=0)
628  {
629  //load tip startup preferences (tips will be started after splash terminates)
630  int nValue = config->Read("/MainFrame/ShowStartTip", 1l);
631 
632  //show tips if needed now
633  if(nValue > 0)
634  {
635  wxCommandEvent dummy;
636  frame->OnTipOfDay(dummy);
637  }
638  }
639 
640  DEBUG_TRACE("=========================== huginApp::OnInit() end ===================");
641  return true;
642 }
643 
645 {
646  DEBUG_TRACE("");
647  delete wxHelpProvider::Set(NULL);
648  return 0;
649 }
650 
652 {
653  if (m_this) {
654  return m_this;
655  } else {
656  DEBUG_FATAL("huginApp not yet created");
658  return 0;
659  }
660 }
661 
663 {
664  if (m_this) {
665  return m_this->frame;
666  } else {
667  return 0;
668  }
669 }
670 
672 {
673  if (event.entry.get())
674  {
675  ImageCache::getInstance().postEvent(event.request, event.entry);
676  }
677  else
678  {
679  // loading failed, first remove request from image cache list
680  ImageCache::getInstance().removeRequest(event.request);
681  // now notify main frame to remove the failed image from project
682  wxCommandEvent e(EVT_LOADING_FAILED);
683  e.SetString(wxString(event.request->getFilename().c_str(), HUGIN_CONV_FILENAME));
684  frame->GetEventHandler()->AddPendingEvent(e);
685  };
686 }
687 
688 void huginApp::imageLoadedAsync(ImageCache::RequestPtr request, ImageCache::EntryPtr entry)
689 {
690  ImageReadyEvent event(request, entry);
691  // AddPendingEvent adds the event to the event queue and returns without
692  // processing it. This is necessary since we are probably not in the
693  // UI thread, but the event handler must be run in the UI thread since it
694  // could update image views.
695  Get()->AddPendingEvent(event);
696 }
697 
698 #ifdef __WXMAC__
699 void huginApp::MacOpenFile(const wxString &fileName)
700 {
701  if(!m_macInitDone)
702  {
703  m_macOpenFileOnStart=true;
704  m_macFileNameToOpenOnStart = fileName;
705  return;
706  }
707 
708  if(frame) frame->MacOnOpenFile(fileName);
709 }
710 #endif
711 
712 #if wxUSE_ON_FATAL_EXCEPTION
713 void huginApp::OnFatalException()
714 {
715  GenerateReport(wxDebugReport::Context_Exception);
716 };
717 #endif
718 
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
void RestoreFramePosition(wxTopLevelWindow *frame, const wxString &basename, const bool ignoreMaximize)
Definition: wxutils.cpp:67
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
std::unique_ptr< wxMessageDialogBase > MessageDialog
Definition: wxutils.h:90
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:178
#define HUGIN_LANGUAGE
void relayImageLoaded(ImageReadyEvent &event)
Relay image loaded event when the UI thread is ready to process it.
Definition: huginApp.cpp:671
void OnTipOfDay(wxCommandEvent &e)
Definition: MainFrame.cpp:1471
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
MessageDialog GetMessageDialog(const wxString &message, const wxString &caption, int style, wxWindow *parent)
Definition: wxutils.cpp:212
static huginApp * Get()
hack.. kind of a pseudo singleton...
Definition: huginApp.cpp:651
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:1069
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:625
static MainFrame * getMainFrame()
Definition: huginApp.cpp:662
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:2210
virtual ~huginApp()
dtor.
Definition: huginApp.cpp:169
xrc handler
Definition: PanoPanel.h:225
virtual int OnExit()
just for testing purposes
Definition: huginApp.cpp:644
#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
int HuginMessageBox(const wxString &message, const wxString &caption, int style, wxWindow *parent)
Definition: wxutils.cpp:176
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:688
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:630
void GetMonitorProfile(wxString &profileName, cmsHPROFILE &profile)
retrieve monitor profile from system
Definition: wxcms.cpp:201
int main(int argc, char *argv[])
Definition: Main.cpp:167