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 #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 wxDEFINE_EVENT(EVT_IMAGE_READY, wxCommandEvent);
128 
129 BEGIN_EVENT_TABLE(huginApp, wxApp)
130  EVT_IMAGE_READY2(-1, huginApp::relayImageLoaded)
132 
133 // make wxwindows use this class as the main application
134 #if defined USE_GDKBACKEND_X11
135 // wxWidgets does not support wxGLCanvas on Wayland
136 // so until it is fixed upstream enforce using x11 backend
137 // see ticket http://trac.wxwidgets.org/ticket/17702
138 #warning Using Hugin with hard coded GDK_BACKEND=x11
139 wxIMPLEMENT_WX_THEME_SUPPORT
140 wxIMPLEMENT_APP_NO_MAIN(huginApp);
141 #include <stdlib.h>
142 int main(int argc, char **argv)
143 {
144  wxDISABLE_DEBUG_SUPPORT();
145  char backend[]="GDK_BACKEND=x11";
146  putenv(backend);
147  return wxEntry(argc, argv);
148 };
149 #else
151 #endif
152 
154 {
155  DEBUG_TRACE("ctor");
156  m_this=this;
157  m_monitorProfile = NULL;
158 #if wxUSE_ON_FATAL_EXCEPTION
159  wxHandleFatalExceptions();
160 #endif
161 }
162 
164 {
165  DEBUG_TRACE("dtor");
166  // delete temporary dir
167 // if (!wxRmdir(m_workDir)) {
168 // DEBUG_ERROR("Could not remove temporary directory");
169 // }
170 
171  // todo: remove all listeners from the panorama object
172 
173 // delete frame;
175  // delete monitor profile
176  if (m_monitorProfile)
177  {
178  cmsCloseProfile(m_monitorProfile);
179  };
180  DEBUG_TRACE("dtor end");
181 }
182 
184 {
185  DEBUG_TRACE("=========================== huginApp::OnInit() begin ===================");
186  SetAppName(wxT("hugin"));
187 #if defined __WXGTK__
188  CheckConfigFilename();
189 #endif
190 
191  // Connect to ImageCache: we need to tell it when it is safe to handle UI events.
192  ImageCache::getInstance().asyncLoadCompleteSignal = &huginApp::imageLoadedAsync;
193 
194 #ifdef __WXMAC__
195  // do not use the native list control on OSX (it is very slow with the control point list window)
196  wxSystemOptions::SetOption(wxT("mac.listctrl.always_use_generic"), 1);
197  // On OS X the file open does by default not show the file type list
198  // Apple means this is not necessary
199  // but the the add images dialog needs this selection, so force to
200  // display always the file type list
201  wxSystemOptions::SetOption(wxOSX_FILEDIALOG_ALWAYS_SHOW_TYPES, 1);
202 #endif
203 
204  // register our custom pano tools dialog handlers
206 
207  // required by wxHtmlHelpController
208  wxFileSystem::AddHandler(new wxZipFSHandler);
209 
210  // initialize help provider
211  wxHelpControllerHelpProvider* provider = new wxHelpControllerHelpProvider;
212  wxHelpProvider::Set(provider);
213 
214 #if defined __WXMSW__
215  wxFileName exePath(wxStandardPaths::Get().GetExecutablePath());
216  m_utilsBinDir = exePath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
217  exePath.RemoveLastDir();
218  const wxString huginRoot=exePath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
219  m_xrcPrefix = huginRoot + wxT("share\\hugin\\xrc\\");
220  m_DataDir = huginRoot + wxT("share\\hugin\\data\\");
221 
222  // locale setup
223  locale.AddCatalogLookupPathPrefix(huginRoot + wxT("share\\locale"));
224 
225 #elif defined __WXMAC__ && defined MAC_SELF_CONTAINED_BUNDLE
226  // initialize paths
227  {
228  wxString thePath = MacGetPathToBundledResourceFile(CFSTR("xrc"));
229  if (thePath == wxT("")) {
230  wxMessageBox(_("xrc directory not found in bundle"), _("Fatal Error"));
231  return false;
232  }
233  m_xrcPrefix = thePath + wxT("/");
234  m_DataDir = thePath + wxT("/");
235  }
236 
237 #ifdef HUGIN_HSI
238  // Set PYTHONHOME for the hsi module
239  {
240  wxString pythonHome = MacGetPathToBundledFrameworksDirectory() + wxT("/Python27.framework/Versions/Current");
241  if(! wxDir::Exists(pythonHome)){
242  wxMessageBox(wxString::Format(_("Directory '%s' does not exists"), pythonHome.c_str()));
243  } else {
244  wxUnsetEnv(wxT("PYTHONPATH"));
245  if(! wxSetEnv(wxT("PYTHONHOME"), pythonHome)){
246  wxMessageBox(_("Could not set environment variable PYTHONHOME"));
247  } else {
248  DEBUG_TRACE("PYTHONHOME set to " << pythonHome);
249  }
250  }
251  }
252 #endif
253 
254 #elif defined UNIX_SELF_CONTAINED_BUNDLE
255  // initialize paths
256  {
257  wxFileName exePath(wxStandardPaths::Get().GetExecutablePath());
258  m_utilsBinDir = exePath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
259  exePath.RemoveLastDir();
260  const wxString huginRoot=exePath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
261  m_xrcPrefix = huginRoot + wxT("share/hugin/xrc/");
262  m_DataDir = huginRoot + wxT("share/hugin/data/");
263 
264  // locale setup
265  locale.AddCatalogLookupPathPrefix(huginRoot + wxT("share/locale"));
266  }
267 
268 #else
269  // add the locale directory specified during configure
270  m_xrcPrefix = wxT(INSTALL_XRC_DIR);
271  m_DataDir = wxT(INSTALL_DATA_DIR);
272  locale.AddCatalogLookupPathPrefix(wxT(INSTALL_LOCALE_DIR));
273 #endif
274 
275  if ( ! wxFile::Exists(m_xrcPrefix + wxT("/main_frame.xrc")) ) {
276  wxMessageBox(_("xrc directory not found, hugin needs to be properly installed\nTried Path:" + m_xrcPrefix ), _("Fatal Error"));
277  return false;
278  }
279 
280  // here goes and comes configuration
281  wxConfigBase * config = wxConfigBase::Get();
282  // do not record default values in the preferences file
283  config->SetRecordDefaults(false);
284 
285  config->Flush();
286 
287  // need to explicitly initialize locale for C++ library/runtime
288  setlocale(LC_ALL, "");
289  // initialize i18n
290  int localeID = config->Read(wxT("language"), (long) HUGIN_LANGUAGE);
291  DEBUG_TRACE("localeID: " << localeID);
292  {
293  bool bLInit;
294  bLInit = locale.Init(localeID);
295  if (bLInit) {
296  DEBUG_TRACE("locale init OK");
297  DEBUG_TRACE("System Locale: " << locale.GetSysName().mb_str(wxConvLocal))
298  DEBUG_TRACE("Canonical Locale: " << locale.GetCanonicalName().mb_str(wxConvLocal))
299  } else {
300  DEBUG_TRACE("locale init failed");
301  }
302  }
303 
304  // set the name of locale recource to look for
305  locale.AddCatalog(wxT("hugin"));
306 
307  // initialize image handlers
308  wxInitAllImageHandlers();
309 
310  // Initialize all the XRC handlers.
311  wxXmlResource::Get()->InitAllHandlers();
312 
313  // load all XRC files.
314  #ifdef _INCLUDE_UI_RESOURCES
315  InitXmlResource();
316  #else
317 
318  // add custom XRC handlers
319  wxXmlResource::Get()->AddHandler(new ImagesPanelXmlHandler());
320  wxXmlResource::Get()->AddHandler(new CPEditorPanelXmlHandler());
321  wxXmlResource::Get()->AddHandler(new CPImageCtrlXmlHandler());
322  wxXmlResource::Get()->AddHandler(new CPImagesComboBoxXmlHandler());
323  wxXmlResource::Get()->AddHandler(new MaskEditorPanelXmlHandler());
324  wxXmlResource::Get()->AddHandler(new ImagesListMaskXmlHandler());
325  wxXmlResource::Get()->AddHandler(new MaskImageCtrlXmlHandler());
326  wxXmlResource::Get()->AddHandler(new OptimizePanelXmlHandler());
327  wxXmlResource::Get()->AddHandler(new OptimizePhotometricPanelXmlHandler());
328  wxXmlResource::Get()->AddHandler(new PanoPanelXmlHandler());
329  wxXmlResource::Get()->AddHandler(new PreviewPanelXmlHandler());
330  wxXmlResource::Get()->AddHandler(new HtmlWindowXmlHandler());
331  wxXmlResource::Get()->AddHandler(new wxcode::wxTreeListCtrlXmlHandler());
332  wxXmlResource::Get()->AddHandler(new ImagesTreeCtrlXmlHandler());
333  wxXmlResource::Get()->AddHandler(new CPListCtrlXmlHandler());
334  wxXmlResource::Get()->AddHandler(new SplitButtonXmlHandler());
335 
336  // load XRC files
337  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("cp_list_frame.xrc"));
338  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("preview_frame.xrc"));
339  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("edit_script_dialog.xrc"));
340  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("main_menu.xrc"));
341  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("main_tool.xrc"));
342  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("about.xrc"));
343  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("pref_dialog.xrc"));
344  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("cpdetector_dialog.xrc"));
345  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("reset_dialog.xrc"));
346  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("optimize_photo_panel.xrc"));
347  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("cp_editor_panel.xrc"));
348  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("images_panel.xrc"));
349  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("main_frame.xrc"));
350  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("optimize_panel.xrc"));
351  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("pano_panel.xrc"));
352  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("mask_editor_panel.xrc"));
353  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("lensdb_dialogs.xrc"));
354  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("image_variable_dlg.xrc"));
355  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("dlg_warning.xrc"));
356  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("import_raw_dialog.xrc"));
357 #endif
358 
359 #ifdef __WXMAC__
360  // If hugin is starting with file opening AppleEvent, MacOpenFile will be called on first wxYield().
361  // Those need to be initialised before first call of Yield which happens in Mainframe constructor.
362  m_macInitDone=false;
363  m_macOpenFileOnStart=false;
364 #endif
365  // read monitor profile
367  // create main frame
368  frame = new MainFrame(NULL, pano);
369  SetTopWindow(frame);
370 
371  // setup main frame size, after it has been created.
372  RestoreFramePosition(frame, wxT("MainFrame"));
373 #ifdef __WXMSW__
374  frame->SendSizeEvent();
375 // wxUSE_TASKBARBUTTON 1 is default, nevertheless check that the feature has not been deactivated by the user, otherwise issue a warning
376 #if wxUSE_TASKBARBUTTON
377  wxTaskBarJumpList jumpList;
378  wxFileName exeFile(wxStandardPaths::Get().GetExecutablePath());
379  exeFile.SetName("PTBatcherGUI");
380  wxTaskBarJumpListItem *item1 = new wxTaskBarJumpListItem(
381  NULL, wxTASKBAR_JUMP_LIST_TASK, _("Open Batch Processor"), exeFile.GetFullPath(), wxEmptyString,
382  _("Opens PTBatcherGUI, the batch processor for Hugin's project files"),
383  exeFile.GetFullPath(), 0);
384  jumpList.GetTasks().Append(item1);
385  exeFile.SetName("calibrate_lens_gui");
386  wxTaskBarJumpListItem *item2 = new wxTaskBarJumpListItem(
387  NULL, wxTASKBAR_JUMP_LIST_TASK, _("Open Lens calibrate tool"), exeFile.GetFullPath(), wxEmptyString,
388  _("Opens Calibrate_lens_gui, a simple GUI for lens calibration"),
389  exeFile.GetFullPath(), 0);
390  jumpList.GetTasks().Append(item2);
391 #else
392  #if defined _MSC_VER
393  #pragma message("Warning: huginApp.cpp - wxWidgets is compiled without support for taskbar buttons. Some features have therefore disabled.")
394  #else
395  #warning "Warning: huginApp.cpp - wxWidgets is compiled without support for taskbar buttons. Some features have therefore disabled."
396  #endif
397 #endif
398 #endif
399  // init help system
400  provider->SetHelpController(&frame->GetHelpController());
401 #ifdef __WXMSW__
402  frame->GetHelpController().Initialize(m_xrcPrefix + wxT("data/hugin_help_en_EN.chm"));
403 #else
404 #if wxUSE_WXHTML_HELP
405  // using wxHtmlHelpController
406 #if defined __WXMAC__ && defined MAC_SELF_CONTAINED_BUNDLE
407  // On Mac, xrc/data/help_LOCALE should be in the bundle as LOCALE.lproj/help
408  // which we can rely on the operating sytem to pick the right locale's.
409  wxString strFile = MacGetPathToBundledResourceFile(CFSTR("help"));
410  if (!strFile.IsEmpty())
411  {
412  frame->GetHelpController().AddBook(wxFileName(strFile + wxT("/hugin_help_en_EN.hhp")));
413  }
414  else
415  {
416  wxLogError(wxString::Format(wxT("Could not find help directory in the bundle"), strFile.c_str()));
417  return false;
418  }
419 #else
420  frame->GetHelpController().AddBook(wxFileName(m_xrcPrefix + wxT("data/help_en_EN/hugin_help_en_EN.hhp")));
421 #endif
422 #else
423  // using wxExtHelpController
424  frame->GetHelpController().Initialize(Initialize(m_xrcPrefix + wxT("data/help_en_EN")));
425 #endif
426 #endif
427 
428  // we are closing Hugin, if the top level window is deleted
429  SetExitOnFrameDelete(true);
430  // show the frame.
432  {
433  SetTopWindow(frame->getGLPreview());
434  }
435  else
436  {
437  frame->Show(TRUE);
438  };
439 
440  wxString cwd = wxFileName::GetCwd();
441 
442  m_workDir = config->Read(wxT("tempDir"),wxT(""));
443  // FIXME, make secure against some symlink attacks
444  // get a temp dir
445  if (m_workDir == wxT("")) {
446 #if (defined __WXMSW__)
447  DEBUG_DEBUG("figuring out windows temp dir");
448  /* added by Yili Zhao */
449  wxChar buffer[MAX_PATH];
450  GetTempPath(MAX_PATH, buffer);
451  m_workDir = buffer;
452 #elif (defined __WXMAC__) && (defined MAC_SELF_CONTAINED_BUNDLE)
453  DEBUG_DEBUG("temp dir on Mac");
454  m_workDir = MacGetPathToUserDomainTempDir();
455  if(m_workDir == wxT(""))
456  m_workDir = wxT("/tmp");
457 #else //UNIX
458  DEBUG_DEBUG("temp dir on unix");
459  // try to read environment variable
460  if (!wxGetEnv(wxT("TMPDIR"), &m_workDir)) {
461  // still no tempdir, use /tmp
462  m_workDir = wxT("/tmp");
463  }
464 #endif
465 
466  }
467 
468  if (!wxFileName::DirExists(m_workDir)) {
469  DEBUG_DEBUG("creating temp dir: " << m_workDir.mb_str(wxConvLocal));
470  if (!wxMkdir(m_workDir)) {
471  DEBUG_ERROR("Tempdir could not be created: " << m_workDir.mb_str(wxConvLocal));
472  }
473  }
474  if (!wxSetWorkingDirectory(m_workDir)) {
475  DEBUG_ERROR("could not change to temp. dir: " << m_workDir.mb_str(wxConvLocal));
476  }
477  DEBUG_DEBUG("using temp dir: " << m_workDir.mb_str(wxConvLocal));
478 
479  // set some suitable defaults
482 
483  // suppress tiff warnings
484  TIFFSetWarningHandler(0);
485 
486  if (argc > 1)
487  {
488 #ifdef __WXMSW__
489  //on Windows we need to update the fast preview first
490  //otherwise there is an infinite loop when starting with a project file
491  //and closed panorama editor aka mainframe
493  {
494  frame->getGLPreview()->Update();
495  };
496 #endif
497  wxFileName file(argv[1]);
498  // if the first file is a project file, open it
499  if (file.GetExt().CmpNoCase(wxT("pto")) == 0 ||
500  file.GetExt().CmpNoCase(wxT("pts")) == 0 ||
501  file.GetExt().CmpNoCase(wxT("ptp")) == 0 )
502  {
503  if(file.IsRelative())
504  file.MakeAbsolute(cwd);
505  // Loading the project file with set actualPath to its
506  // parent directory. (actualPath is used as starting
507  // directory by many subsequent file selection dialogs.)
508  frame->LoadProjectFile(file.GetFullPath());
509  } else {
510  std::vector<std::string> filesv;
511  std::vector<std::string> rawFilesv;
512  bool actualPathSet = false;
513  for (int i=1; i< argc; i++)
514  {
515 #if defined __WXMSW__
516  //expand wildcards
517  wxFileName fileList(argv[i]);
518  if(fileList.IsRelative())
519  fileList.MakeAbsolute(cwd);
520  wxDir dir;
521  wxString foundFile;
522  wxFileName file;
523  if(fileList.DirExists())
524  if(dir.Open(fileList.GetPath()))
525  if(dir.GetFirst(&foundFile,fileList.GetFullName(),wxDIR_FILES | wxDIR_HIDDEN))
526  do
527  {
528  file=foundFile;
529  file.MakeAbsolute(dir.GetName());
530 #else
531  wxFileName file(argv[i]);
532 #endif
533  if (file.IsRelative())
534  {
535  file.MakeAbsolute(cwd);
536  };
537  if (IsRawExtension(file.GetExt()))
538  {
539  // we got a raw file from command line
540  if (!containsInvalidCharacters(file.GetFullPath()))
541  {
542  rawFilesv.push_back((const char*)file.GetFullPath().mb_str(HUGIN_CONV_FILENAME));
543  // Use the first filename to set actualPath.
544  if (!actualPathSet)
545  {
546  config->Write(wxT("/actualPath"), file.GetPath());
547  actualPathSet = true;
548  };
549  };
550  }
551  else
552  {
553  if (vigra::isImage(file.GetFullPath().mb_str(HUGIN_CONV_FILENAME)))
554  {
555  if (!containsInvalidCharacters(file.GetFullPath()))
556  {
557  filesv.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(wxT("/actualPath"), file.GetPath());
562  actualPathSet = true;
563  };
564  };
565  };
566  };
567 #if defined __WXMSW__
568  } while (dir.GetNext(&foundFile));
569 #endif
570  }
571  if(!filesv.empty())
572  {
573  std::vector<PanoCommand::PanoCommand*> cmds;
574  cmds.push_back(new PanoCommand::wxAddImagesCmd(pano,filesv));
575  cmds.push_back(new PanoCommand::DistributeImagesCmd(pano));
576  cmds.push_back(new PanoCommand::CenterPanoCmd(pano));
578  };
579  if (!rawFilesv.empty())
580  {
581  if (rawFilesv.size() == 1)
582  {
583  wxMessageDialog message(GetTopWindow(), _("You selected only one raw file. This is not recommended.\nAll raw files should be converted at once."),
584 #ifdef _WIN32
585  _("Hugin"),
586 #else
587  wxT(""),
588 #endif
589  wxICON_EXCLAMATION | wxOK | wxCANCEL);
590  message.SetOKLabel(_("Convert anyway."));
591  if (message.ShowModal() != wxID_OK)
592  {
593  return true;
594  };
595  };
596  RawImportDialog dlg(GetTopWindow(), &pano, rawFilesv);
597  // check that raw files are from same camera and that all can be read
598  if (dlg.CheckRawFiles())
599  {
600  // now show dialog
601  if (dlg.ShowModal() == wxID_OK)
602  {
604  };
605  };
606  };
607  };
608  }
609 #ifdef __WXMAC__
610  m_macInitDone = true;
611  if(m_macOpenFileOnStart) {frame->LoadProjectFile(m_macFileNameToOpenOnStart);}
612  m_macOpenFileOnStart = false;
613 #endif
614 
615  //check for no tip switch, needed by PTBatcher
616  wxString secondParam = argc > 2 ? wxString(argv[2]) : wxString();
617  if(secondParam.Cmp(_T("-notips"))!=0)
618  {
619  //load tip startup preferences (tips will be started after splash terminates)
620  int nValue = config->Read(wxT("/MainFrame/ShowStartTip"), 1l);
621 
622  //show tips if needed now
623  if(nValue > 0)
624  {
625  wxCommandEvent dummy;
626  frame->OnTipOfDay(dummy);
627  }
628  }
629 
630  DEBUG_TRACE("=========================== huginApp::OnInit() end ===================");
631  return true;
632 }
633 
635 {
636  DEBUG_TRACE("");
637  delete wxHelpProvider::Set(NULL);
638  return 0;
639 }
640 
642 {
643  if (m_this) {
644  return m_this;
645  } else {
646  DEBUG_FATAL("huginApp not yet created");
648  return 0;
649  }
650 }
651 
653 {
654  if (m_this) {
655  return m_this->frame;
656  } else {
657  return 0;
658  }
659 }
660 
662 {
663  if (event.entry.get())
664  {
665  ImageCache::getInstance().postEvent(event.request, event.entry);
666  }
667  else
668  {
669  // loading failed, first remove request from image cache list
670  ImageCache::getInstance().removeRequest(event.request);
671  // now notify main frame to remove the failed image from project
672  wxCommandEvent e(EVT_LOADING_FAILED);
673  e.SetString(wxString(event.request->getFilename().c_str(), HUGIN_CONV_FILENAME));
674  frame->GetEventHandler()->AddPendingEvent(e);
675  };
676 }
677 
678 void huginApp::imageLoadedAsync(ImageCache::RequestPtr request, ImageCache::EntryPtr entry)
679 {
680  ImageReadyEvent event(request, entry);
681  // AddPendingEvent adds the event to the event queue and returns without
682  // processing it. This is necessary since we are probably not in the
683  // UI thread, but the event handler must be run in the UI thread since it
684  // could update image views.
685  Get()->AddPendingEvent(event);
686 }
687 
688 #ifdef __WXMAC__
689 void huginApp::MacOpenFile(const wxString &fileName)
690 {
691  if(!m_macInitDone)
692  {
693  m_macOpenFileOnStart=true;
694  m_macFileNameToOpenOnStart = fileName;
695  return;
696  }
697 
698  if(frame) frame->MacOnOpenFile(fileName);
699 }
700 #endif
701 
702 #if wxUSE_ON_FATAL_EXCEPTION
703 void huginApp::OnFatalException()
704 {
705  GenerateReport(wxDebugReport::Context_Exception);
706 };
707 #endif
708 
710 
711 
712 // utility functions
713 
714 void RestoreFramePosition(wxTopLevelWindow * frame, const wxString & basename)
715 {
716  DEBUG_TRACE(basename.mb_str(wxConvLocal));
717 
718  wxConfigBase * config = wxConfigBase::Get();
719 
720  // get display size
721  int dx,dy;
722  wxDisplaySize(&dx,&dy);
723 
724 #if ( __WXGTK__ )
725 // restoring the splitter positions properly when maximising doesn't work.
726 // Disabling maximise on wxWidgets >= 2.6.0 and gtk
727  //size
728  int w = config->Read(wxT("/") + basename + wxT("/width"),-1l);
729  int h = config->Read(wxT("/") + basename + wxT("/height"),-1l);
730  if (w > 0 && w <= dx) {
731  frame->SetClientSize(w,h);
732  } else {
733  frame->Fit();
734  }
735  //position
736  int x = config->Read(wxT("/") + basename + wxT("/positionX"),-1l);
737  int y = config->Read(wxT("/") + basename + wxT("/positionY"),-1l);
738  if ( y >= 0 && x >= 0 && x < dx && y < dy) {
739  frame->Move(x, y);
740  } else {
741  frame->Move(0, 44);
742  }
743 #else
744  bool maximized = config->Read(wxT("/") + basename + wxT("/maximized"), 0l) != 0;
745  if (maximized) {
746  frame->Maximize();
747  } else {
748  //size
749  int w = config->Read(wxT("/") + basename + wxT("/width"),-1l);
750  int h = config->Read(wxT("/") + basename + wxT("/height"),-1l);
751  if (w > 0 && w <= dx) {
752  frame->SetClientSize(w,h);
753  } else {
754  frame->Fit();
755  }
756  //position
757  int x = config->Read(wxT("/") + basename + wxT("/positionX"),-1l);
758  int y = config->Read(wxT("/") + basename + wxT("/positionY"),-1l);
759  if ( y >= 0 && x >= 0 && x < dx && y < dy) {
760  frame->Move(x, y);
761  } else {
762  frame->Move(0, 44);
763  }
764  }
765 #endif
766 }
767 
768 
769 void StoreFramePosition(wxTopLevelWindow * frame, const wxString & basename)
770 {
771  DEBUG_TRACE(basename);
772 
773  wxConfigBase * config = wxConfigBase::Get();
774 
775 #if ( __WXGTK__ )
776 // restoring the splitter positions properly when maximising doesn't work.
777 // Disabling maximise on wxWidgets >= 2.6.0 and gtk
778 
779  wxSize sz = frame->GetClientSize();
780  config->Write(wxT("/") + basename + wxT("/width"), sz.GetWidth());
781  config->Write(wxT("/") + basename + wxT("/height"), sz.GetHeight());
782  wxPoint ps = frame->GetPosition();
783  config->Write(wxT("/") + basename + wxT("/positionX"), ps.x);
784  config->Write(wxT("/") + basename + wxT("/positionY"), ps.y);
785  config->Write(wxT("/") + basename + wxT("/maximized"), 0);
786 #else
787  if ( (! frame->IsMaximized()) && (! frame->IsIconized()) ) {
788  wxSize sz = frame->GetClientSize();
789  config->Write(wxT("/") + basename + wxT("/width"), sz.GetWidth());
790  config->Write(wxT("/") + basename + wxT("/height"), sz.GetHeight());
791  wxPoint ps = frame->GetPosition();
792  config->Write(wxT("/") + basename + wxT("/positionX"), ps.x);
793  config->Write(wxT("/") + basename + wxT("/positionY"), ps.y);
794  config->Write(wxT("/") + basename + wxT("/maximized"), 0);
795  } else if (frame->IsMaximized()){
796  config->Write(wxT("/") + basename + wxT("/maximized"), 1l);
797  }
798 #endif
799 }
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:181
The application class for hugin.
Definition: huginApp.h:88
implementation of huginApp Class
virtual bool OnInit()
pseudo constructor.
Definition: huginApp.cpp:183
#define EVT_IMAGE_READY2(id, fn)
Definition: huginApp.h:79
HuginBase::Panorama pano
Definition: huginApp.h:184
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:194
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:661
void OnTipOfDay(wxCommandEvent &e)
Definition: MainFrame.cpp:1511
MainFrame * frame
Definition: huginApp.h:178
huginApp()
ctor.
Definition: huginApp.cpp:153
wxString m_DataDir
Definition: huginApp.h:189
#define DEBUG_ASSERT(cond)
Definition: utils.h:80
END_EVENT_TABLE()
include file for the hugin project
wxHelpController & GetHelpController()
Definition: MainFrame.h:183
wxString m_monitorProfileName
Definition: huginApp.h:193
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:641
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:187
void LoadProjectFile(const wxString &filename)
Definition: MainFrame.cpp:1094
Definition of dialog and functions to import RAW images to project file.
HuginBase::ImageCache::EntryPtr entry
Definition: huginApp.h:61
PanoCommand::PanoCommand * GetPanoCommand()
return PanoCommand for adding converted raw files to Panorama
Definition: RawImport.cpp:656
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:652
Definition of dialog for numeric transforms.
wxString m_utilsBinDir
Definition: huginApp.h:191
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:176
include file for the hugin project
const GuiLevel GetGuiLevel() const
Definition: MainFrame.h:185
GLPreviewFrame * getGLPreview()
Definition: MainFrame.cpp:2250
virtual ~huginApp()
dtor.
Definition: huginApp.cpp:163
xrc handler
Definition: PanoPanel.h:226
virtual int OnExit()
just for testing purposes
Definition: huginApp.cpp:634
#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:60
wxString Components2Str(const HuginGraph::ImageGraph::Components &comp)
Definition: huginApp.cpp:84
Event for when a requested image finished loading.
Definition: huginApp.h:56
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:678
wxLocale locale
locale for internationalisation
Definition: huginApp.h:160
bool CheckRawFiles()
return true, if all raw files are from the same camera
Definition: RawImport.cpp:661
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