Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ToolboxApp.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 "ToolboxApp.h"
34 #include "ToolboxFrame.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 IMPLEMENT_APP(ToolboxApp)
45 
46 bool ToolboxApp::OnInit()
47 {
48 #if wxUSE_ON_FATAL_EXCEPTION
49  wxHandleFatalExceptions();
50 #endif
51  SetAppName("hugin");
52 #if defined __WXGTK__
53  CheckConfigFilename();
54 #endif
55  // register our custom pano tools dialog handlers
57 
58 #if defined __WXMSW__
59  wxFileName exeDir(wxStandardPaths::Get().GetExecutablePath());
60  exeDir.RemoveLastDir();
61  m_xrcPrefix = exeDir.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR) + "share\\hugin\\xrc\\";
62  // locale setup
63  locale.AddCatalogLookupPathPrefix(exeDir.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR) + "share\\locale");
64 #elif defined __WXMAC__ && defined MAC_SELF_CONTAINED_BUNDLE
65  // initialize paths
66  wxString thePath = MacGetPathToBundledResourceFile(CFSTR("xrc"));
67  if (thePath == "")
68  {
69  wxMessageBox(_("xrc directory not found in bundle"), _("Fatal Error"));
70  return false;
71  }
72  m_xrcPrefix = thePath + "/";
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 + "share/hugin/xrc/";
81  locale.AddCatalogLookupPathPrefix(huginRoot + "share/locale");
82  }
83 #else
84  // add the locale directory specified during configure
85  m_xrcPrefix = INSTALL_XRC_DIR;
86  locale.AddCatalogLookupPathPrefix(INSTALL_LOCALE_DIR);
87 #endif
88 
89  if ( ! wxFile::Exists(m_xrcPrefix + "/toolbox_panel.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("language", (long) HUGIN_LANGUAGE);
105  DEBUG_TRACE("localeID: " << localeID);
106  {
107  bool bLInit = locale.Init(localeID);
108  if (bLInit)
109  {
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  }
114  else
115  {
116  DEBUG_TRACE("locale init failed");
117  }
118  }
119 
120  // set the name of locale recource to look for
121  locale.AddCatalog("hugin");
122 
123  // initialize image handlers
124  wxInitAllImageHandlers();
125 
126  // Initialize all the XRC handlers.
127  wxXmlResource::Get()->InitAllHandlers();
128  // load XRC files
129  wxXmlResource::Get()->Load(m_xrcPrefix + "toolbox_panel.xrc");
130 
131  // create main frame
132  m_frame = new ToolboxFrame(NULL);
133  SetTopWindow(m_frame);
134  // show the frame.
135  m_frame->Show(TRUE);
136 
137  // suppress tiff warnings
138  TIFFSetWarningHandler(0);
139 
140  return true;
141 }
142 
143 #if wxUSE_ON_FATAL_EXCEPTION
144 void ToolboxApp::OnFatalException()
145 {
146  GenerateReport(wxDebugReport::Context_Exception);
147 };
148 #endif
implementation of huginApp Class
#define DEBUG_TRACE(msg)
Definition: utils.h:67
void registerPTWXDlgFcn()
Definition: PTWXDlg.cpp:173
#define HUGIN_LANGUAGE
include file for the hugin project
declaration of main frame class for toolbox GUI
include file for the hugin project
functions for interaction with the hugin configuration file
platform/compiler specific stuff.
The main window frame.
Definition: ToolboxFrame.h:42
The application class for toolbox app.
Definition: ToolboxApp.h:34