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/ImagesList.h"
46 #include "hugin/CPListFrame.h"
47 #include "hugin/PreviewPanel.h"
48 #include "hugin/GLPreviewFrame.h"
49 #include "hugin/RawImport.h"
50 #include "base_wx/PTWXDlg.h"
51 #include "base_wx/CommandHistory.h"
52 #include "base_wx/wxcms.h"
53 #include "base_wx/wxPanoCommand.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 #if wxCHECK_VERSION(3,1,0)
66 #include <wx/taskbarbutton.h>
67 #endif
68 #endif
69 #if defined __WXGTK__ && wxCHECK_VERSION(3,1,1)
70 #include "base_wx/wxPlatform.h"
71 #endif
72 
73 #include <tiffio.h>
74 
75 #include "AboutDialog.h"
76 
77 //for natural sorting
78 #include "hugin_utils/alphanum.h"
79 #include "lensdb/LensDB.h"
80 
81 bool checkVersion(wxString v1, wxString v2)
82 {
83  return doj::alphanum_comp(std::string(v1.mb_str(wxConvLocal)),std::string(v2.mb_str(wxConvLocal))) < 0;
84 };
85 
87 {
88  wxString ret;
89  for (unsigned i=0; i < comp.size(); i++) {
90  ret.Append(wxT("["));
91  HuginGraph::ImageGraph::Components::value_type::const_iterator it = comp[i].begin();
92  while (it != comp[i].end())
93  {
94  unsigned int imgNr = *it;
95  ret << imgNr;
96  it++;
97  if (it != comp[i].end() && *it == imgNr + 1)
98  {
99  ret.Append(wxT("-"));
100  while (it != comp[i].end() && *it == imgNr + 1)
101  {
102  ++it;
103  ++imgNr;
104  };
105  ret << imgNr;
106  if (it != comp[i].end())
107  {
108  ret.Append(wxT(", "));
109  };
110  }
111  else
112  {
113  if (it != comp[i].end())
114  {
115  ret.Append(wxT(", "));
116  };
117  };
118  };
119 
120  ret.Append(wxT("]"));
121  if (i + 1 != comp.size())
122  {
123  ret.Append(wxT(", "));
124  };
125  }
126  return ret;
127 }
128 
129 #if defined _WIN32 && defined Hugin_shared
130 DEFINE_LOCAL_EVENT_TYPE( EVT_IMAGE_READY )
131 #else
132 DEFINE_EVENT_TYPE( EVT_IMAGE_READY )
133 #endif
134 
135 BEGIN_EVENT_TABLE(huginApp, wxApp)
136  EVT_IMAGE_READY2(-1, huginApp::relayImageLoaded)
138 
139 // make wxwindows use this class as the main application
140 #if defined USE_GDKBACKEND_X11
141 // wxWidgets does not support wxGLCanvas on Wayland
142 // so until it is fixed upstream enforce using x11 backend
143 // see ticket http://trac.wxwidgets.org/ticket/17702
144 #warning Using Hugin with hard coded GDK_BACKEND=x11
145 wxIMPLEMENT_WX_THEME_SUPPORT
146 wxIMPLEMENT_APP_NO_MAIN(huginApp);
147 #include <stdlib.h>
148 int main(int argc, char **argv)
149 {
150  wxDISABLE_DEBUG_SUPPORT();
151  char backend[]="GDK_BACKEND=x11";
152  putenv(backend);
153  return wxEntry(argc, argv);
154 };
155 #else
157 #endif
158 
160 {
161  DEBUG_TRACE("ctor");
162  m_this=this;
163  m_monitorProfile = NULL;
164 #if wxUSE_ON_FATAL_EXCEPTION
165  wxHandleFatalExceptions();
166 #endif
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__ && wxCHECK_VERSION(3,1,1)
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(_("xrc directory not found, hugin needs to be properly installed\nTried Path:" + 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 ImagesListMaskXmlHandler());
331  wxXmlResource::Get()->AddHandler(new MaskImageCtrlXmlHandler());
332  wxXmlResource::Get()->AddHandler(new OptimizePanelXmlHandler());
333  wxXmlResource::Get()->AddHandler(new OptimizePhotometricPanelXmlHandler());
334  wxXmlResource::Get()->AddHandler(new PanoPanelXmlHandler());
335  wxXmlResource::Get()->AddHandler(new PreviewPanelXmlHandler());
336  wxXmlResource::Get()->AddHandler(new HtmlWindowXmlHandler());
337  wxXmlResource::Get()->AddHandler(new wxcode::wxTreeListCtrlXmlHandler());
338  wxXmlResource::Get()->AddHandler(new ImagesTreeCtrlXmlHandler());
339  wxXmlResource::Get()->AddHandler(new CPListCtrlXmlHandler());
340  wxXmlResource::Get()->AddHandler(new SplitButtonXmlHandler());
341 
342  // load XRC files
343  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("cp_list_frame.xrc"));
344  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("preview_frame.xrc"));
345  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("edit_script_dialog.xrc"));
346  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("main_menu.xrc"));
347  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("main_tool.xrc"));
348  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("about.xrc"));
349  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("pref_dialog.xrc"));
350  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("cpdetector_dialog.xrc"));
351  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("reset_dialog.xrc"));
352  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("optimize_photo_panel.xrc"));
353  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("cp_editor_panel.xrc"));
354  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("images_panel.xrc"));
355  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("main_frame.xrc"));
356  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("optimize_panel.xrc"));
357  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("pano_panel.xrc"));
358  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("mask_editor_panel.xrc"));
359  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("lensdb_dialogs.xrc"));
360  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("image_variable_dlg.xrc"));
361  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("dlg_warning.xrc"));
362  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("import_raw_dialog.xrc"));
363 #endif
364 
365 #ifdef __WXMAC__
366  // If hugin is starting with file opening AppleEvent, MacOpenFile will be called on first wxYield().
367  // Those need to be initialised before first call of Yield which happens in Mainframe constructor.
368  m_macInitDone=false;
369  m_macOpenFileOnStart=false;
370 #endif
371  // read monitor profile
373  // create main frame
374  frame = new MainFrame(NULL, pano);
375  SetTopWindow(frame);
376 
377  // setup main frame size, after it has been created.
378  RestoreFramePosition(frame, wxT("MainFrame"));
379 #ifdef __WXMSW__
380  frame->SendSizeEvent();
381 #if wxCHECK_VERSION(3,1,0)
382 // wxUSE_TASKBARBUTTON 1 is default, nevertheless check that the feature has not been deactivated by the user, otherwise issue a warning
383 #if wxUSE_TASKBARBUTTON
384  wxTaskBarJumpList jumpList;
385  wxFileName exeFile(wxStandardPaths::Get().GetExecutablePath());
386  exeFile.SetName("PTBatcherGUI");
387  wxTaskBarJumpListItem *item1 = new wxTaskBarJumpListItem(
388  NULL, wxTASKBAR_JUMP_LIST_TASK, _("Open Batch Processor"), exeFile.GetFullPath(), wxEmptyString,
389  _("Opens PTBatcherGUI, the batch processor for Hugin's project files"),
390  exeFile.GetFullPath(), 0);
391  jumpList.GetTasks().Append(item1);
392  exeFile.SetName("calibrate_lens_gui");
393  wxTaskBarJumpListItem *item2 = new wxTaskBarJumpListItem(
394  NULL, wxTASKBAR_JUMP_LIST_TASK, _("Open Lens calibrate tool"), exeFile.GetFullPath(), wxEmptyString,
395  _("Opens Calibrate_lens_gui, a simple GUI for lens calibration"),
396  exeFile.GetFullPath(), 0);
397  jumpList.GetTasks().Append(item2);
398 #else
399  #if defined _MSC_VER
400  #pragma message("Warning: huginApp.cpp - wxWidgets is compiled without support for taskbar buttons. Some features have therefore disabled.")
401  #else
402  #warning "Warning: huginApp.cpp - wxWidgets is compiled without support for taskbar buttons. Some features have therefore disabled."
403  #endif
404 #endif
405 #endif
406 #endif
407  // init help system
408  provider->SetHelpController(&frame->GetHelpController());
409 #ifdef __WXMSW__
410  frame->GetHelpController().Initialize(m_xrcPrefix + wxT("data/hugin_help_en_EN.chm"));
411 #else
412 #if wxUSE_WXHTML_HELP
413  // using wxHtmlHelpController
414 #if defined __WXMAC__ && defined MAC_SELF_CONTAINED_BUNDLE
415  // On Mac, xrc/data/help_LOCALE should be in the bundle as LOCALE.lproj/help
416  // which we can rely on the operating sytem to pick the right locale's.
417  wxString strFile = MacGetPathToBundledResourceFile(CFSTR("help"));
418  if (!strFile.IsEmpty())
419  {
420  frame->GetHelpController().AddBook(wxFileName(strFile + wxT("/hugin_help_en_EN.hhp")));
421  }
422  else
423  {
424  wxLogError(wxString::Format(wxT("Could not find help directory in the bundle"), strFile.c_str()));
425  return false;
426  }
427 #else
428  frame->GetHelpController().AddBook(wxFileName(m_xrcPrefix + wxT("data/help_en_EN/hugin_help_en_EN.hhp")));
429 #endif
430 #else
431  // using wxExtHelpController
432  frame->GetHelpController().Initialize(Initialize(m_xrcPrefix + wxT("data/help_en_EN")));
433 #endif
434 #endif
435 
436  // we are closing Hugin, if the top level window is deleted
437  SetExitOnFrameDelete(true);
438  // show the frame.
440  {
441  SetTopWindow(frame->getGLPreview());
442  }
443  else
444  {
445  frame->Show(TRUE);
446  };
447 
448  wxString cwd = wxFileName::GetCwd();
449 
450  m_workDir = config->Read(wxT("tempDir"),wxT(""));
451  // FIXME, make secure against some symlink attacks
452  // get a temp dir
453  if (m_workDir == wxT("")) {
454 #if (defined __WXMSW__)
455  DEBUG_DEBUG("figuring out windows temp dir");
456  /* added by Yili Zhao */
457  wxChar buffer[MAX_PATH];
458  GetTempPath(MAX_PATH, buffer);
459  m_workDir = buffer;
460 #elif (defined __WXMAC__) && (defined MAC_SELF_CONTAINED_BUNDLE)
461  DEBUG_DEBUG("temp dir on Mac");
462  m_workDir = MacGetPathToUserDomainTempDir();
463  if(m_workDir == wxT(""))
464  m_workDir = wxT("/tmp");
465 #else //UNIX
466  DEBUG_DEBUG("temp dir on unix");
467  // try to read environment variable
468  if (!wxGetEnv(wxT("TMPDIR"), &m_workDir)) {
469  // still no tempdir, use /tmp
470  m_workDir = wxT("/tmp");
471  }
472 #endif
473 
474  }
475 
476  if (!wxFileName::DirExists(m_workDir)) {
477  DEBUG_DEBUG("creating temp dir: " << m_workDir.mb_str(wxConvLocal));
478  if (!wxMkdir(m_workDir)) {
479  DEBUG_ERROR("Tempdir could not be created: " << m_workDir.mb_str(wxConvLocal));
480  }
481  }
482  if (!wxSetWorkingDirectory(m_workDir)) {
483  DEBUG_ERROR("could not change to temp. dir: " << m_workDir.mb_str(wxConvLocal));
484  }
485  DEBUG_DEBUG("using temp dir: " << m_workDir.mb_str(wxConvLocal));
486 
487  // set some suitable defaults
490 
491  // suppress tiff warnings
492  TIFFSetWarningHandler(0);
493 
494  if (argc > 1)
495  {
496 #ifdef __WXMSW__
497  //on Windows we need to update the fast preview first
498  //otherwise there is an infinite loop when starting with a project file
499  //and closed panorama editor aka mainframe
501  {
502  frame->getGLPreview()->Update();
503  };
504 #endif
505  wxFileName file(argv[1]);
506  // if the first file is a project file, open it
507  if (file.GetExt().CmpNoCase(wxT("pto")) == 0 ||
508  file.GetExt().CmpNoCase(wxT("pts")) == 0 ||
509  file.GetExt().CmpNoCase(wxT("ptp")) == 0 )
510  {
511  if(file.IsRelative())
512  file.MakeAbsolute(cwd);
513  // Loading the project file with set actualPath to its
514  // parent directory. (actualPath is used as starting
515  // directory by many subsequent file selection dialogs.)
516  frame->LoadProjectFile(file.GetFullPath());
517  } else {
518  std::vector<std::string> filesv;
519  std::vector<std::string> rawFilesv;
520  bool actualPathSet = false;
521  for (int i=1; i< argc; i++)
522  {
523 #if defined __WXMSW__
524  //expand wildcards
525  wxFileName fileList(argv[i]);
526  if(fileList.IsRelative())
527  fileList.MakeAbsolute(cwd);
528  wxDir dir;
529  wxString foundFile;
530  wxFileName file;
531  if(fileList.DirExists())
532  if(dir.Open(fileList.GetPath()))
533  if(dir.GetFirst(&foundFile,fileList.GetFullName(),wxDIR_FILES | wxDIR_HIDDEN))
534  do
535  {
536  file=foundFile;
537  file.MakeAbsolute(dir.GetName());
538 #else
539  wxFileName file(argv[i]);
540 #endif
541  if (file.IsRelative())
542  {
543  file.MakeAbsolute(cwd);
544  };
545  if (IsRawExtension(file.GetExt()))
546  {
547  // we got a raw file from command line
548  if (!containsInvalidCharacters(file.GetFullPath()))
549  {
550  rawFilesv.push_back((const char*)file.GetFullPath().mb_str(HUGIN_CONV_FILENAME));
551  // Use the first filename to set actualPath.
552  if (!actualPathSet)
553  {
554  config->Write(wxT("/actualPath"), file.GetPath());
555  actualPathSet = true;
556  };
557  };
558  }
559  else
560  {
561  if (vigra::isImage(file.GetFullPath().mb_str(HUGIN_CONV_FILENAME)))
562  {
563  if (!containsInvalidCharacters(file.GetFullPath()))
564  {
565  filesv.push_back((const char *)(file.GetFullPath().mb_str(HUGIN_CONV_FILENAME)));
566  // Use the first filename to set actualPath.
567  if (!actualPathSet)
568  {
569  config->Write(wxT("/actualPath"), file.GetPath());
570  actualPathSet = true;
571  };
572  };
573  };
574  };
575 #if defined __WXMSW__
576  } while (dir.GetNext(&foundFile));
577 #endif
578  }
579  if(!filesv.empty())
580  {
581  std::vector<PanoCommand::PanoCommand*> cmds;
582  cmds.push_back(new PanoCommand::wxAddImagesCmd(pano,filesv));
583  cmds.push_back(new PanoCommand::DistributeImagesCmd(pano));
584  cmds.push_back(new PanoCommand::CenterPanoCmd(pano));
586  };
587  if (!rawFilesv.empty())
588  {
589  if (rawFilesv.size() == 1)
590  {
591  wxMessageDialog message(GetTopWindow(), _("You selected only one raw file. This is not recommended.\nAll raw files should be converted at once."),
592 #ifdef _WIN32
593  _("Hugin"),
594 #else
595  wxT(""),
596 #endif
597  wxICON_EXCLAMATION | wxOK | wxCANCEL);
598  message.SetOKLabel(_("Convert anyway."));
599  if (message.ShowModal() != wxID_OK)
600  {
601  return true;
602  };
603  };
604  RawImportDialog dlg(GetTopWindow(), &pano, rawFilesv);
605  // check that raw files are from same camera and that all can be read
606  if (dlg.CheckRawFiles())
607  {
608  // now show dialog
609  if (dlg.ShowModal() == wxID_OK)
610  {
612  };
613  };
614  };
615  };
616  }
617 #ifdef __WXMAC__
618  m_macInitDone = true;
619  if(m_macOpenFileOnStart) {frame->LoadProjectFile(m_macFileNameToOpenOnStart);}
620  m_macOpenFileOnStart = false;
621 #endif
622 
623  //check for no tip switch, needed by PTBatcher
624  wxString secondParam = argc > 2 ? wxString(argv[2]) : wxString();
625  if(secondParam.Cmp(_T("-notips"))!=0)
626  {
627  //load tip startup preferences (tips will be started after splash terminates)
628  int nValue = config->Read(wxT("/MainFrame/ShowStartTip"), 1l);
629 
630  //show tips if needed now
631  if(nValue > 0)
632  {
633  wxCommandEvent dummy;
634  frame->OnTipOfDay(dummy);
635  }
636  }
637 
638  DEBUG_TRACE("=========================== huginApp::OnInit() end ===================");
639  return true;
640 }
641 
643 {
644  DEBUG_TRACE("");
645  delete wxHelpProvider::Set(NULL);
646  return 0;
647 }
648 
650 {
651  if (m_this) {
652  return m_this;
653  } else {
654  DEBUG_FATAL("huginApp not yet created");
656  return 0;
657  }
658 }
659 
661 {
662  if (m_this) {
663  return m_this->frame;
664  } else {
665  return 0;
666  }
667 }
668 
670 {
671  if (event.entry.get())
672  {
673  ImageCache::getInstance().postEvent(event.request, event.entry);
674  }
675  else
676  {
677  // loading failed, first remove request from image cache list
678  ImageCache::getInstance().removeRequest(event.request);
679  // now notify main frame to remove the failed image from project
680  wxCommandEvent e(EVT_LOADING_FAILED);
681  e.SetString(wxString(event.request->getFilename().c_str(), HUGIN_CONV_FILENAME));
682  frame->GetEventHandler()->AddPendingEvent(e);
683  };
684 }
685 
686 void huginApp::imageLoadedAsync(ImageCache::RequestPtr request, ImageCache::EntryPtr entry)
687 {
688  ImageReadyEvent event(request, entry);
689  // AddPendingEvent adds the event to the event queue and returns without
690  // processing it. This is necessary since we are probably not in the
691  // UI thread, but the event handler must be run in the UI thread since it
692  // could update image views.
693  Get()->AddPendingEvent(event);
694 }
695 
696 #ifdef __WXMAC__
697 void huginApp::MacOpenFile(const wxString &fileName)
698 {
699  if(!m_macInitDone)
700  {
701  m_macOpenFileOnStart=true;
702  m_macFileNameToOpenOnStart = fileName;
703  return;
704  }
705 
706  if(frame) frame->MacOnOpenFile(fileName);
707 }
708 #endif
709 
710 #if wxUSE_ON_FATAL_EXCEPTION
711 void huginApp::OnFatalException()
712 {
713  GenerateReport(wxDebugReport::Context_Exception);
714 };
715 #endif
716 
718 
719 
720 // utility functions
721 
722 void RestoreFramePosition(wxTopLevelWindow * frame, const wxString & basename)
723 {
724  DEBUG_TRACE(basename.mb_str(wxConvLocal));
725 
726  wxConfigBase * config = wxConfigBase::Get();
727 
728  // get display size
729  int dx,dy;
730  wxDisplaySize(&dx,&dy);
731 
732 #if ( __WXGTK__ )
733 // restoring the splitter positions properly when maximising doesn't work.
734 // Disabling maximise on wxWidgets >= 2.6.0 and gtk
735  //size
736  int w = config->Read(wxT("/") + basename + wxT("/width"),-1l);
737  int h = config->Read(wxT("/") + basename + wxT("/height"),-1l);
738  if (w > 0 && w <= dx) {
739  frame->SetClientSize(w,h);
740  } else {
741  frame->Fit();
742  }
743  //position
744  int x = config->Read(wxT("/") + basename + wxT("/positionX"),-1l);
745  int y = config->Read(wxT("/") + basename + wxT("/positionY"),-1l);
746  if ( y >= 0 && x >= 0 && x < dx && y < dy) {
747  frame->Move(x, y);
748  } else {
749  frame->Move(0, 44);
750  }
751 #else
752  bool maximized = config->Read(wxT("/") + basename + wxT("/maximized"), 0l) != 0;
753  if (maximized) {
754  frame->Maximize();
755  } else {
756  //size
757  int w = config->Read(wxT("/") + basename + wxT("/width"),-1l);
758  int h = config->Read(wxT("/") + basename + wxT("/height"),-1l);
759  if (w > 0 && w <= dx) {
760  frame->SetClientSize(w,h);
761  } else {
762  frame->Fit();
763  }
764  //position
765  int x = config->Read(wxT("/") + basename + wxT("/positionX"),-1l);
766  int y = config->Read(wxT("/") + basename + wxT("/positionY"),-1l);
767  if ( y >= 0 && x >= 0 && x < dx && y < dy) {
768  frame->Move(x, y);
769  } else {
770  frame->Move(0, 44);
771  }
772  }
773 #endif
774 }
775 
776 
777 void StoreFramePosition(wxTopLevelWindow * frame, const wxString & basename)
778 {
779  DEBUG_TRACE(basename);
780 
781  wxConfigBase * config = wxConfigBase::Get();
782 
783 #if ( __WXGTK__ )
784 // restoring the splitter positions properly when maximising doesn't work.
785 // Disabling maximise on wxWidgets >= 2.6.0 and gtk
786 
787  wxSize sz = frame->GetClientSize();
788  config->Write(wxT("/") + basename + wxT("/width"), sz.GetWidth());
789  config->Write(wxT("/") + basename + wxT("/height"), sz.GetHeight());
790  wxPoint ps = frame->GetPosition();
791  config->Write(wxT("/") + basename + wxT("/positionX"), ps.x);
792  config->Write(wxT("/") + basename + wxT("/positionY"), ps.y);
793  config->Write(wxT("/") + basename + wxT("/maximized"), 0);
794 #else
795  if ( (! frame->IsMaximized()) && (! frame->IsIconized()) ) {
796  wxSize sz = frame->GetClientSize();
797  config->Write(wxT("/") + basename + wxT("/width"), sz.GetWidth());
798  config->Write(wxT("/") + basename + wxT("/height"), sz.GetHeight());
799  wxPoint ps = frame->GetPosition();
800  config->Write(wxT("/") + basename + wxT("/positionX"), ps.x);
801  config->Write(wxT("/") + basename + wxT("/positionY"), ps.y);
802  config->Write(wxT("/") + basename + wxT("/maximized"), 0);
803  } else if (frame->IsMaximized()){
804  config->Write(wxT("/") + basename + wxT("/maximized"), 1l);
805  }
806 #endif
807 }
bool checkVersion(wxString v1, wxString v2)
Definition: huginApp.cpp:81
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:189
The application class for hugin.
Definition: huginApp.h:92
implementation of huginApp Class
virtual bool OnInit()
pseudo constructor.
Definition: huginApp.cpp:189
#define EVT_IMAGE_READY2(id, fn)
Definition: huginApp.h:83
HuginBase::Panorama pano
Definition: huginApp.h:192
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:202
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:669
void OnTipOfDay(wxCommandEvent &e)
Definition: MainFrame.cpp:1525
MainFrame * frame
Definition: huginApp.h:186
huginApp()
ctor.
Definition: huginApp.cpp:159
wxString m_DataDir
Definition: huginApp.h:197
#define DEBUG_ASSERT(cond)
Definition: utils.h:80
END_EVENT_TABLE()
include file for the hugin project
wxHelpController & GetHelpController()
Definition: MainFrame.h:187
wxString m_monitorProfileName
Definition: huginApp.h:201
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:649
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:87
xrc handler for mask editor
wxString m_xrcPrefix
Definition: huginApp.h:195
void LoadProjectFile(const wxString &filename)
Definition: MainFrame.cpp:1101
Definition of dialog and functions to import RAW images to project file.
HuginBase::ImageCache::EntryPtr entry
Definition: huginApp.h:65
PanoCommand::PanoCommand * GetPanoCommand()
return PanoCommand for adding converted raw files to Panorama
Definition: RawImport.cpp:663
void StoreFramePosition(wxTopLevelWindow *frame, const wxString &basename)
Store window size and position in configfile/registry.
Definition: LensCalApp.cpp:212
static MainFrame * getMainFrame()
Definition: huginApp.cpp:660
Definition of dialog for numeric transforms.
wxString m_utilsBinDir
Definition: huginApp.h:199
wxwindows specific panorama commands
distributes all images above the sphere, for the assistant
Definition: PanoCommand.h:649
void RestoreFramePosition(wxTopLevelWindow *frame, const wxString &basename)
Restore window size and position from configfile/registry.
Definition: LensCalApp.cpp:158
IMPEX double h[25][1024]
Definition: emor.cpp:169
xrc handler for CPImagesComboBox
Definition: CPListFrame.h:95
static GlobalCmdHist & getInstance()
options wxIntPtr item2
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
wxString m_workDir
temporary working directory
Definition: huginApp.h:184
include file for the hugin project
const GuiLevel GetGuiLevel() const
Definition: MainFrame.h:189
GLPreviewFrame * getGLPreview()
Definition: MainFrame.cpp:2264
virtual ~huginApp()
dtor.
Definition: huginApp.cpp:169
xrc handler
Definition: PanoPanel.h:226
virtual int OnExit()
just for testing purposes
Definition: huginApp.cpp:642
#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:502
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:103
Definition of HTMLWindow class which supports opening external links in default web browser...
HuginBase::ImageCache::RequestPtr request
Definition: huginApp.h:64
wxString Components2Str(const HuginGraph::ImageGraph::Components &comp)
Definition: huginApp.cpp:86
Resources Definition.
Definition: huginApp.h:60
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:686
wxLocale locale
locale for internationalisation
Definition: huginApp.h:164
bool CheckRawFiles()
return true, if all raw files are from the same camera
Definition: RawImport.cpp:668
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