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 #include "base_wx/wxutils.h"
32 
33 #include "LensCalApp.h"
34 #include "LensCalImageCtrl.h"
35 #include "base_wx/huginConfig.h"
36 #include "hugin/config_defaults.h"
37 #include "base_wx/PTWXDlg.h"
38 #if defined __WXGTK__
39 #include "base_wx/wxPlatform.h"
40 #endif
41 
42 #include <tiffio.h>
43 
44 
45 // make wxwindows use this class as the main application
46 IMPLEMENT_APP(LensCalApp)
47 
48 bool LensCalApp::OnInit()
49 {
50 #if wxUSE_ON_FATAL_EXCEPTION
51  wxHandleFatalExceptions();
52 #endif
53  SetAppName("hugin");
54 #if defined __WXMSW__ && wxCHECK_VERSION(3,3,0)
55  // automatically switch between light and dark mode
56  SetAppearance(Appearance::System);
57 #endif
58 #if defined __WXGTK__
59  CheckConfigFilename();
60 #endif
61  // register our custom pano tools dialog handlers
63 
64 #if defined __WXMSW__
65  wxFileName exeDir(wxStandardPaths::Get().GetExecutablePath());
66  exeDir.RemoveLastDir();
67  m_xrcPrefix = exeDir.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR) + "share\\hugin\\xrc\\";
68  // locale setup
69  locale.AddCatalogLookupPathPrefix(exeDir.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR) + "share\\locale");
70 #elif defined __WXMAC__ && defined MAC_SELF_CONTAINED_BUNDLE
71  // initialize paths
72  wxString thePath = MacGetPathToBundledResourceFile(CFSTR("xrc"));
73  if (thePath == wxEmptyString) {
74  hugin_utils::HuginMessageBox(_("xrc directory not found in bundle"), _("Calibrate_lens_GUI"), wxOK | wxICON_ERROR, wxGetActiveWindow());
75  return false;
76  }
77  m_xrcPrefix = thePath + "/";
78 #elif defined UNIX_SELF_CONTAINED_BUNDLE
79  // initialize paths
80  {
81  wxFileName exePath(wxStandardPaths::Get().GetExecutablePath());
82  exePath.RemoveLastDir();
83  const wxString huginRoot=exePath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
84  // add the locale directory specified during configure
85  m_xrcPrefix = huginRoot + "share/hugin/xrc/";
86  locale.AddCatalogLookupPathPrefix(huginRoot + "share/locale");
87  }
88 #else
89  // add the locale directory specified during configure
90  m_xrcPrefix = INSTALL_XRC_DIR;
91  locale.AddCatalogLookupPathPrefix(INSTALL_LOCALE_DIR);
92 #endif
93 
94  if ( ! wxFile::Exists(m_xrcPrefix + "/lenscal_frame.xrc") )
95  {
96  hugin_utils::HuginMessageBox(wxString::Format(_("xrc directory not found, hugin needs to be properly installed\nTried Path: %s"), m_xrcPrefix), _("Calibrate_lens_GUI"), wxOK | wxICON_ERROR, wxGetActiveWindow());
97  return false;
98  }
99 
100  // here goes and comes configuration
101  wxConfigBase * config = wxConfigBase::Get();
102  // do not record default values in the preferences file
103  config->SetRecordDefaults(false);
104  config->Flush();
105 
106  // need to explicitly initialize locale for C++ library/runtime
107  setlocale(LC_ALL, "");
108  // initialize i18n
109  int localeID = config->Read("language", (long) HUGIN_LANGUAGE);
110  DEBUG_TRACE("localeID: " << localeID);
111  {
112  bool bLInit;
113  bLInit = locale.Init(localeID);
114  if (bLInit) {
115  DEBUG_TRACE("locale init OK");
116  DEBUG_TRACE("System Locale: " << locale.GetSysName().mb_str(wxConvLocal))
117  DEBUG_TRACE("Canonical Locale: " << locale.GetCanonicalName().mb_str(wxConvLocal))
118  } else {
119  DEBUG_TRACE("locale init failed");
120  }
121  }
122 
123  // set the name of locale recource to look for
124  locale.AddCatalog("hugin");
125 
126  // initialize image handlers
127  wxInitAllImageHandlers();
128 
129  // Initialize all the XRC handlers.
130  wxXmlResource::Get()->InitAllHandlers();
131  wxXmlResource::Get()->AddHandler(new LensCalImageCtrlXmlHandler());
132  // load XRC files
133  wxXmlResource::Get()->Load(m_xrcPrefix + "lenscal_frame.xrc");
134  wxXmlResource::Get()->Load(m_xrcPrefix + "lensdb_dialogs.xrc");
135  wxXmlResource::Get()->Load(m_xrcPrefix + "dlg_warning.xrc");
136 
137  // create main frame
138  m_frame = new LensCalFrame(NULL);
139  SetTopWindow(m_frame);
140 
141  // setup main frame size, after it has been created.
142  hugin_utils::RestoreFramePosition(m_frame, "LensCalFrame");
143 
144  // show the frame.
145  m_frame->Show(TRUE);
146 
147  // suppress tiff warnings
148  TIFFSetWarningHandler(0);
149 
150  return true;
151 }
152 
153 #if wxUSE_ON_FATAL_EXCEPTION
154 void LensCalApp::OnFatalException()
155 {
156  GenerateReport(wxDebugReport::Context_Exception);
157 };
158 #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:178
#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:37
functions for interaction with the hugin configuration file
platform/compiler specific stuff.
declaration of application class for lens calibrate application
int HuginMessageBox(const wxString &message, const wxString &caption, int style, wxWindow *parent)
Definition: wxutils.cpp:176
void RestoreFramePosition(wxTopLevelWindow *frame, const wxString &basename)
Definition: wxutils.cpp:67