Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LensCalApp.cpp
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
10 /*
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public
13  * License as published by the Free Software Foundation; either
14  * version 2 of the License, or (at your option) any later version.
15  *
16  * This software is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public
22  * License along with this software. If not, see
23  * <http://www.gnu.org/licenses/>.
24  *
25  */
26 
27 #include "panoinc_WX.h"
28 #include "panoinc.h"
29 #include <wx/stdpaths.h>
30 #include "base_wx/platform.h"
31 
32 #include "LensCalApp.h"
33 #include "LensCalImageCtrl.h"
34 #include "base_wx/huginConfig.h"
35 #include "hugin/config_defaults.h"
36 #include "base_wx/PTWXDlg.h"
37 #if defined __WXGTK__
38 #include "base_wx/wxPlatform.h"
39 #endif
40 
41 #include <tiffio.h>
42 
43 
44 // make wxwindows use this class as the main application
45 IMPLEMENT_APP(LensCalApp)
46 
47 bool LensCalApp::OnInit()
48 {
49 #if wxUSE_ON_FATAL_EXCEPTION
50  wxHandleFatalExceptions();
51 #endif
52  SetAppName(wxT("hugin"));
53 #if defined __WXGTK__
54  CheckConfigFilename();
55 #endif
56  // register our custom pano tools dialog handlers
58 
59 #if defined __WXMSW__
60  wxFileName exeDir(wxStandardPaths::Get().GetExecutablePath());
61  exeDir.RemoveLastDir();
62  m_xrcPrefix = exeDir.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR) + wxT("share\\hugin\\xrc\\");
63  // locale setup
64  locale.AddCatalogLookupPathPrefix(exeDir.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR) + wxT("share\\locale"));
65 #elif defined __WXMAC__ && defined MAC_SELF_CONTAINED_BUNDLE
66  // initialize paths
67  wxString thePath = MacGetPathToBundledResourceFile(CFSTR("xrc"));
68  if (thePath == wxT("")) {
69  wxMessageBox(_("xrc directory not found in bundle"), _("Fatal Error"));
70  return false;
71  }
72  m_xrcPrefix = thePath + wxT("/");
73 #elif defined UNIX_SELF_CONTAINED_BUNDLE
74  // initialize paths
75  {
76  wxFileName exePath(wxStandardPaths::Get().GetExecutablePath());
77  exePath.RemoveLastDir();
78  const wxString huginRoot=exePath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
79  // add the locale directory specified during configure
80  m_xrcPrefix = huginRoot + wxT("share/hugin/xrc/");
81  locale.AddCatalogLookupPathPrefix(huginRoot + wxT("share/locale"));
82  }
83 #else
84  // add the locale directory specified during configure
85  m_xrcPrefix = wxT(INSTALL_XRC_DIR);
86  locale.AddCatalogLookupPathPrefix(wxT(INSTALL_LOCALE_DIR));
87 #endif
88 
89  if ( ! wxFile::Exists(m_xrcPrefix + wxT("/lenscal_frame.xrc")) )
90  {
91  wxMessageBox(wxString::Format(_("xrc directory not found, hugin needs to be properly installed\nTried Path: %s"), m_xrcPrefix), _("Fatal Error"));
92  return false;
93  }
94 
95  // here goes and comes configuration
96  wxConfigBase * config = wxConfigBase::Get();
97  // do not record default values in the preferences file
98  config->SetRecordDefaults(false);
99  config->Flush();
100 
101  // need to explicitly initialize locale for C++ library/runtime
102  setlocale(LC_ALL, "");
103  // initialize i18n
104  int localeID = config->Read(wxT("language"), (long) HUGIN_LANGUAGE);
105  DEBUG_TRACE("localeID: " << localeID);
106  {
107  bool bLInit;
108  bLInit = locale.Init(localeID);
109  if (bLInit) {
110  DEBUG_TRACE("locale init OK");
111  DEBUG_TRACE("System Locale: " << locale.GetSysName().mb_str(wxConvLocal))
112  DEBUG_TRACE("Canonical Locale: " << locale.GetCanonicalName().mb_str(wxConvLocal))
113  } else {
114  DEBUG_TRACE("locale init failed");
115  }
116  }
117 
118  // set the name of locale recource to look for
119  locale.AddCatalog(wxT("hugin"));
120 
121  // initialize image handlers
122  wxInitAllImageHandlers();
123 
124  // Initialize all the XRC handlers.
125  wxXmlResource::Get()->InitAllHandlers();
126  wxXmlResource::Get()->AddHandler(new LensCalImageCtrlXmlHandler());
127  // load XRC files
128  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("lenscal_frame.xrc"));
129  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("lensdb_dialogs.xrc"));
130  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("dlg_warning.xrc"));
131 
132  // create main frame
133  m_frame = new LensCalFrame(NULL);
134  SetTopWindow(m_frame);
135 
136  // setup main frame size, after it has been created.
137  RestoreFramePosition(m_frame, wxT("LensCalFrame"));
138 
139  // show the frame.
140  m_frame->Show(TRUE);
141 
142  // suppress tiff warnings
143  TIFFSetWarningHandler(0);
144 
145  return true;
146 }
147 
148 #if wxUSE_ON_FATAL_EXCEPTION
149 void LensCalApp::OnFatalException()
150 {
151  GenerateReport(wxDebugReport::Context_Exception);
152 };
153 #endif
implementation of huginApp Class
xrc handler for LensCalImageCtrl
#define DEBUG_TRACE(msg)
Definition: utils.h:67
The main window frame.
Definition: LensCalFrame.h:56
void registerPTWXDlgFcn()
Definition: PTWXDlg.cpp:173
#define HUGIN_LANGUAGE
include file for the hugin project
declaration of preview for lens calibration gui
include file for the hugin project
The application class for lens_calibrate_gui .
Definition: LensCalApp.h:42
functions for interaction with the hugin configuration file
platform/compiler specific stuff.
declaration of application class for lens calibrate application
void RestoreFramePosition(wxTopLevelWindow *frame, const wxString &basename)
Restore window size and position from configfile/registry.
Definition: wxutils.cpp:65