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(_("xrc directory not found, hugin needs to be properly installed\nTried Path:" + 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
154 
155 // utility functions
156 void RestoreFramePosition(wxTopLevelWindow * frame, const wxString & basename)
157 {
158  DEBUG_TRACE(basename.mb_str(wxConvLocal));
159  wxConfigBase * config = wxConfigBase::Get();
160 
161  // get display size
162  int dx,dy;
163  wxDisplaySize(&dx,&dy);
164 
165 #if ( __WXGTK__ )
166 // restoring the splitter positions properly when maximising doesn't work.
167 // Disabling maximise on wxWidgets >= 2.6.0 and gtk
168  //size
169  int w = config->Read(wxT("/") + basename + wxT("/width"),-1l);
170  int h = config->Read(wxT("/") + basename + wxT("/height"),-1l);
171  if (w > 0 && w <= dx) {
172  frame->SetClientSize(w,h);
173  } else {
174  frame->Fit();
175  }
176  //position
177  int x = config->Read(wxT("/") + basename + wxT("/positionX"),-1l);
178  int y = config->Read(wxT("/") + basename + wxT("/positionY"),-1l);
179  if ( y >= 0 && x >= 0 && x < dx && y < dy) {
180  frame->Move(x, y);
181  } else {
182  frame->Move(0, 44);
183  }
184 #else
185  bool maximized = config->Read(wxT("/") + basename + wxT("/maximized"), 0l) != 0;
186  if (maximized) {
187  frame->Maximize();
188  } else {
189  //size
190  int w = config->Read(wxT("/") + basename + wxT("/width"),-1l);
191  int h = config->Read(wxT("/") + basename + wxT("/height"),-1l);
192  if (w > 0 && w <= dx) {
193  frame->SetClientSize(w,h);
194  } else {
195  frame->Fit();
196  }
197  //position
198  int x = config->Read(wxT("/") + basename + wxT("/positionX"),-1l);
199  int y = config->Read(wxT("/") + basename + wxT("/positionY"),-1l);
200  if ( y >= 0 && x >= 0 && x < dx && y < dy) {
201  frame->Move(x, y);
202  } else {
203  frame->Move(0, 44);
204  }
205  }
206 #endif
207 }
208 
209 
210 void StoreFramePosition(wxTopLevelWindow * frame, const wxString & basename)
211 {
212  DEBUG_TRACE(basename);
213 
214  wxConfigBase * config = wxConfigBase::Get();
215 
216 #if ( __WXGTK__ )
217 // restoring the splitter positions properly when maximising doesn't work.
218 // Disabling maximise on wxWidgets >= 2.6.0 and gtk
219 
220  wxSize sz = frame->GetClientSize();
221  config->Write(wxT("/") + basename + wxT("/width"), sz.GetWidth());
222  config->Write(wxT("/") + basename + wxT("/height"), sz.GetHeight());
223  wxPoint ps = frame->GetPosition();
224  config->Write(wxT("/") + basename + wxT("/positionX"), ps.x);
225  config->Write(wxT("/") + basename + wxT("/positionY"), ps.y);
226  config->Write(wxT("/") + basename + wxT("/maximized"), 0);
227 #else
228  if ( (! frame->IsMaximized()) && (! frame->IsIconized()) ) {
229  wxSize sz = frame->GetClientSize();
230  config->Write(wxT("/") + basename + wxT("/width"), sz.GetWidth());
231  config->Write(wxT("/") + basename + wxT("/height"), sz.GetHeight());
232  wxPoint ps = frame->GetPosition();
233  config->Write(wxT("/") + basename + wxT("/positionX"), ps.x);
234  config->Write(wxT("/") + basename + wxT("/positionY"), ps.y);
235  config->Write(wxT("/") + basename + wxT("/maximized"), 0);
236  } else if (frame->IsMaximized()){
237  config->Write(wxT("/") + basename + wxT("/maximized"), 1l);
238  }
239 #endif
240 }
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
void StoreFramePosition(wxTopLevelWindow *frame, const wxString &basename)
Store window size and position in configfile/registry.
Definition: LensCalApp.cpp:210
void RestoreFramePosition(wxTopLevelWindow *frame, const wxString &basename)
Restore window size and position from configfile/registry.
Definition: LensCalApp.cpp:156
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