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__ && wxCHECK_VERSION(3,1,1)
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 BEGIN_EVENT_TABLE(LensCalApp, wxApp)
48 
49 bool LensCalApp::OnInit()
50 {
51 #if wxUSE_ON_FATAL_EXCEPTION
52  wxHandleFatalExceptions();
53 #endif
54  SetAppName(wxT("hugin"));
55 #if defined __WXGTK__ && wxCHECK_VERSION(3,1,1)
56  CheckConfigFilename();
57 #endif
58  // register our custom pano tools dialog handlers
60 
61 #if defined __WXMSW__
62  wxFileName exeDir(wxStandardPaths::Get().GetExecutablePath());
63  exeDir.RemoveLastDir();
64  m_xrcPrefix = exeDir.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR) + wxT("share\\hugin\\xrc\\");
65  // locale setup
66  locale.AddCatalogLookupPathPrefix(exeDir.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR) + wxT("share\\locale"));
67 #elif defined __WXMAC__ && defined MAC_SELF_CONTAINED_BUNDLE
68  // initialize paths
69  wxString thePath = MacGetPathToBundledResourceFile(CFSTR("xrc"));
70  if (thePath == wxT("")) {
71  wxMessageBox(_("xrc directory not found in bundle"), _("Fatal Error"));
72  return false;
73  }
74  m_xrcPrefix = thePath + wxT("/");
75 #elif defined UNIX_SELF_CONTAINED_BUNDLE
76  // initialize paths
77  {
78  wxFileName exePath(wxStandardPaths::Get().GetExecutablePath());
79  exePath.RemoveLastDir();
80  const wxString huginRoot=exePath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
81  // add the locale directory specified during configure
82  m_xrcPrefix = huginRoot + wxT("share/hugin/xrc/");
83  locale.AddCatalogLookupPathPrefix(huginRoot + wxT("share/locale"));
84  }
85 #else
86  // add the locale directory specified during configure
87  m_xrcPrefix = wxT(INSTALL_XRC_DIR);
88  locale.AddCatalogLookupPathPrefix(wxT(INSTALL_LOCALE_DIR));
89 #endif
90 
91  if ( ! wxFile::Exists(m_xrcPrefix + wxT("/lenscal_frame.xrc")) )
92  {
93  wxMessageBox(_("xrc directory not found, hugin needs to be properly installed\nTried Path:" + m_xrcPrefix ), _("Fatal Error"));
94  return false;
95  }
96 
97  // here goes and comes configuration
98  wxConfigBase * config = wxConfigBase::Get();
99  // do not record default values in the preferences file
100  config->SetRecordDefaults(false);
101  config->Flush();
102 
103  // need to explicitly initialize locale for C++ library/runtime
104  setlocale(LC_ALL, "");
105  // initialize i18n
106  int localeID = config->Read(wxT("language"), (long) HUGIN_LANGUAGE);
107  DEBUG_TRACE("localeID: " << localeID);
108  {
109  bool bLInit;
110  bLInit = locale.Init(localeID);
111  if (bLInit) {
112  DEBUG_TRACE("locale init OK");
113  DEBUG_TRACE("System Locale: " << locale.GetSysName().mb_str(wxConvLocal))
114  DEBUG_TRACE("Canonical Locale: " << locale.GetCanonicalName().mb_str(wxConvLocal))
115  } else {
116  DEBUG_TRACE("locale init failed");
117  }
118  }
119 
120  // set the name of locale recource to look for
121  locale.AddCatalog(wxT("hugin"));
122 
123  // initialize image handlers
124  wxInitAllImageHandlers();
125 
126  // Initialize all the XRC handlers.
127  wxXmlResource::Get()->InitAllHandlers();
128  wxXmlResource::Get()->AddHandler(new LensCalImageCtrlXmlHandler());
129  // load XRC files
130  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("lenscal_frame.xrc"));
131  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("lensdb_dialogs.xrc"));
132  wxXmlResource::Get()->Load(m_xrcPrefix + wxT("dlg_warning.xrc"));
133 
134  // create main frame
135  m_frame = new LensCalFrame(NULL);
136  SetTopWindow(m_frame);
137 
138  // setup main frame size, after it has been created.
139  RestoreFramePosition(m_frame, wxT("LensCalFrame"));
140 
141  // show the frame.
142  m_frame->Show(TRUE);
143 
144  // suppress tiff warnings
145  TIFFSetWarningHandler(0);
146 
147  return true;
148 }
149 
150 #if wxUSE_ON_FATAL_EXCEPTION
151 void LensCalApp::OnFatalException()
152 {
153  GenerateReport(wxDebugReport::Context_Exception);
154 };
155 #endif
156 
157 // utility functions
158 void RestoreFramePosition(wxTopLevelWindow * frame, const wxString & basename)
159 {
160  DEBUG_TRACE(basename.mb_str(wxConvLocal));
161  wxConfigBase * config = wxConfigBase::Get();
162 
163  // get display size
164  int dx,dy;
165  wxDisplaySize(&dx,&dy);
166 
167 #if ( __WXGTK__ )
168 // restoring the splitter positions properly when maximising doesn't work.
169 // Disabling maximise on wxWidgets >= 2.6.0 and gtk
170  //size
171  int w = config->Read(wxT("/") + basename + wxT("/width"),-1l);
172  int h = config->Read(wxT("/") + basename + wxT("/height"),-1l);
173  if (w > 0 && w <= dx) {
174  frame->SetClientSize(w,h);
175  } else {
176  frame->Fit();
177  }
178  //position
179  int x = config->Read(wxT("/") + basename + wxT("/positionX"),-1l);
180  int y = config->Read(wxT("/") + basename + wxT("/positionY"),-1l);
181  if ( y >= 0 && x >= 0 && x < dx && y < dy) {
182  frame->Move(x, y);
183  } else {
184  frame->Move(0, 44);
185  }
186 #else
187  bool maximized = config->Read(wxT("/") + basename + wxT("/maximized"), 0l) != 0;
188  if (maximized) {
189  frame->Maximize();
190  } else {
191  //size
192  int w = config->Read(wxT("/") + basename + wxT("/width"),-1l);
193  int h = config->Read(wxT("/") + basename + wxT("/height"),-1l);
194  if (w > 0 && w <= dx) {
195  frame->SetClientSize(w,h);
196  } else {
197  frame->Fit();
198  }
199  //position
200  int x = config->Read(wxT("/") + basename + wxT("/positionX"),-1l);
201  int y = config->Read(wxT("/") + basename + wxT("/positionY"),-1l);
202  if ( y >= 0 && x >= 0 && x < dx && y < dy) {
203  frame->Move(x, y);
204  } else {
205  frame->Move(0, 44);
206  }
207  }
208 #endif
209 }
210 
211 
212 void StoreFramePosition(wxTopLevelWindow * frame, const wxString & basename)
213 {
214  DEBUG_TRACE(basename);
215 
216  wxConfigBase * config = wxConfigBase::Get();
217 
218 #if ( __WXGTK__ )
219 // restoring the splitter positions properly when maximising doesn't work.
220 // Disabling maximise on wxWidgets >= 2.6.0 and gtk
221 
222  wxSize sz = frame->GetClientSize();
223  config->Write(wxT("/") + basename + wxT("/width"), sz.GetWidth());
224  config->Write(wxT("/") + basename + wxT("/height"), sz.GetHeight());
225  wxPoint ps = frame->GetPosition();
226  config->Write(wxT("/") + basename + wxT("/positionX"), ps.x);
227  config->Write(wxT("/") + basename + wxT("/positionY"), ps.y);
228  config->Write(wxT("/") + basename + wxT("/maximized"), 0);
229 #else
230  if ( (! frame->IsMaximized()) && (! frame->IsIconized()) ) {
231  wxSize sz = frame->GetClientSize();
232  config->Write(wxT("/") + basename + wxT("/width"), sz.GetWidth());
233  config->Write(wxT("/") + basename + wxT("/height"), sz.GetHeight());
234  wxPoint ps = frame->GetPosition();
235  config->Write(wxT("/") + basename + wxT("/positionX"), ps.x);
236  config->Write(wxT("/") + basename + wxT("/positionY"), ps.y);
237  config->Write(wxT("/") + basename + wxT("/maximized"), 0);
238  } else if (frame->IsMaximized()){
239  config->Write(wxT("/") + basename + wxT("/maximized"), 1l);
240  }
241 #endif
242 }
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
END_EVENT_TABLE()
include file for the hugin project
void StoreFramePosition(wxTopLevelWindow *frame, const wxString &basename)
Store window size and position in configfile/registry.
Definition: LensCalApp.cpp:212
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
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