LensCalApp.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00010 /* 
00011  *  This program is free software; you can redistribute it and/or
00012  *  modify it under the terms of the GNU General Public
00013  *  License as published by the Free Software Foundation; either
00014  *  version 2 of the License, or (at your option) any later version.
00015  *
00016  *  This software is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019  *  General Public License for more details.
00020  *
00021  *  You should have received a copy of the GNU General Public
00022  *  License along with this software. If not, see
00023  *  <http://www.gnu.org/licenses/>.
00024  *
00025  */
00026 
00027 #include "panoinc_WX.h"
00028 #include "panoinc.h"
00029 #include <wx/stdpaths.h>
00030 #include "base_wx/platform.h"
00031 
00032 #include "LensCalApp.h"
00033 #include "LensCalImageCtrl.h"
00034 #include "base_wx/huginConfig.h"
00035 #include "hugin/config_defaults.h"
00036 #include "base_wx/PTWXDlg.h"
00037 
00038 #include <tiffio.h>
00039 
00040 
00041 // make wxwindows use this class as the main application
00042 IMPLEMENT_APP(LensCalApp)
00043 BEGIN_EVENT_TABLE(LensCalApp, wxApp)
00044 END_EVENT_TABLE()
00045 
00046 bool LensCalApp::OnInit()
00047 {
00048 #if wxUSE_ON_FATAL_EXCEPTION
00049     wxHandleFatalExceptions();
00050 #endif
00051     SetAppName(wxT("hugin"));
00052     // register our custom pano tools dialog handlers
00053     registerPTWXDlgFcn();
00054 
00055 #if defined __WXMSW__
00056     wxFileName exeDir(wxStandardPaths::Get().GetExecutablePath());
00057     exeDir.RemoveLastDir();
00058     m_xrcPrefix = exeDir.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR) + wxT("share\\hugin\\xrc\\");
00059     // locale setup
00060     locale.AddCatalogLookupPathPrefix(exeDir.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR) + wxT("share\\locale"));
00061 #elif defined __WXMAC__ && defined MAC_SELF_CONTAINED_BUNDLE
00062     // initialize paths
00063     wxString thePath = MacGetPathToBundledResourceFile(CFSTR("xrc"));
00064     if (thePath == wxT("")) {
00065         wxMessageBox(_("xrc directory not found in bundle"), _("Fatal Error"));
00066         return false;
00067     }
00068     m_xrcPrefix = thePath + wxT("/");
00069     thePath = MacGetPathToBundledResourceFile(CFSTR("locale"));
00070     if(thePath != wxT(""))
00071         locale.AddCatalogLookupPathPrefix(thePath);
00072     else {
00073         wxMessageBox(_("Translations not found in bundle"), _("Fatal Error"));
00074         return false;
00075     }
00076 #else
00077     // add the locale directory specified during configure
00078     m_xrcPrefix = wxT(INSTALL_XRC_DIR);
00079     locale.AddCatalogLookupPathPrefix(wxT(INSTALL_LOCALE_DIR));
00080 #endif
00081 
00082     if ( ! wxFile::Exists(m_xrcPrefix + wxT("/lenscal_frame.xrc")) )
00083     {
00084         wxMessageBox(_("xrc directory not found, hugin needs to be properly installed\nTried Path:" + m_xrcPrefix ), _("Fatal Error"));
00085         return false;
00086     }
00087 
00088     // here goes and comes configuration
00089     wxConfigBase * config = wxConfigBase::Get();
00090     // do not record default values in the preferences file
00091     config->SetRecordDefaults(false);
00092     config->Flush();
00093 
00094     // initialize i18n
00095 #if defined _MSC_VER && defined Hugin_shared
00096     setlocale(LC_NUMERIC, "");
00097 #endif
00098     int localeID = config->Read(wxT("language"), (long) HUGIN_LANGUAGE);
00099     DEBUG_TRACE("localeID: " << localeID);
00100     {
00101         bool bLInit;
00102             bLInit = locale.Init(localeID);
00103             if (bLInit) {
00104                 DEBUG_TRACE("locale init OK");
00105                 DEBUG_TRACE("System Locale: " << locale.GetSysName().mb_str(wxConvLocal))
00106                 DEBUG_TRACE("Canonical Locale: " << locale.GetCanonicalName().mb_str(wxConvLocal))
00107         } else {
00108           DEBUG_TRACE("locale init failed");
00109         }
00110         }
00111         
00112     // set the name of locale recource to look for
00113     locale.AddCatalog(wxT("hugin"));
00114 
00115     // initialize image handlers
00116     wxInitAllImageHandlers();
00117 
00118     // Initialize all the XRC handlers.
00119     wxXmlResource::Get()->InitAllHandlers();
00120     wxXmlResource::Get()->AddHandler(new LensCalImageCtrlXmlHandler());
00121     // load XRC files
00122     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("lenscal_frame.xrc"));
00123     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("lensdb_dialogs.xrc"));
00124     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("dlg_warning.xrc"));
00125 
00126     // create main frame
00127     m_frame = new LensCalFrame(NULL);
00128     SetTopWindow(m_frame);
00129 
00130     // setup main frame size, after it has been created.
00131     RestoreFramePosition(m_frame, wxT("LensCalFrame"));
00132 
00133     // show the frame.
00134     m_frame->Show(TRUE);
00135 
00136     // suppress tiff warnings
00137     TIFFSetWarningHandler(0);
00138 
00139     return true;
00140 }
00141 
00142 #if wxUSE_ON_FATAL_EXCEPTION
00143 void LensCalApp::OnFatalException()
00144 {
00145     GenerateReport(wxDebugReport::Context_Exception);
00146 };
00147 #endif
00148 
00149 // utility functions
00150 void RestoreFramePosition(wxTopLevelWindow * frame, const wxString & basename)
00151 {
00152     DEBUG_TRACE(basename.mb_str(wxConvLocal));
00153     wxConfigBase * config = wxConfigBase::Get();
00154 
00155     // get display size
00156     int dx,dy;
00157     wxDisplaySize(&dx,&dy);
00158 
00159 #if ( __WXGTK__ )
00160 // restoring the splitter positions properly when maximising doesn't work.
00161 // Disabling maximise on wxWidgets >= 2.6.0 and gtk
00162         //size
00163         int w = config->Read(wxT("/") + basename + wxT("/width"),-1l);
00164         int h = config->Read(wxT("/") + basename + wxT("/height"),-1l);
00165         if (w > 0 && w <= dx) {
00166             frame->SetClientSize(w,h);
00167         } else {
00168             frame->Fit();
00169         }
00170         //position
00171         int x = config->Read(wxT("/") + basename + wxT("/positionX"),-1l);
00172         int y = config->Read(wxT("/") + basename + wxT("/positionY"),-1l);
00173         if ( y >= 0 && x >= 0 && x < dx && y < dy) {
00174             frame->Move(x, y);
00175         } else {
00176             frame->Move(0, 44);
00177         }
00178 #else
00179     bool maximized = config->Read(wxT("/") + basename + wxT("/maximized"), 0l) != 0;
00180     if (maximized) {
00181         frame->Maximize();
00182         } else {
00183         //size
00184         int w = config->Read(wxT("/") + basename + wxT("/width"),-1l);
00185         int h = config->Read(wxT("/") + basename + wxT("/height"),-1l);
00186         if (w > 0 && w <= dx) {
00187             frame->SetClientSize(w,h);
00188         } else {
00189             frame->Fit();
00190         }
00191         //position
00192         int x = config->Read(wxT("/") + basename + wxT("/positionX"),-1l);
00193         int y = config->Read(wxT("/") + basename + wxT("/positionY"),-1l);
00194         if ( y >= 0 && x >= 0 && x < dx && y < dy) {
00195             frame->Move(x, y);
00196         } else {
00197             frame->Move(0, 44);
00198         }
00199     }
00200 #endif
00201 }
00202 
00203 
00204 void StoreFramePosition(wxTopLevelWindow * frame, const wxString & basename)
00205 {
00206     DEBUG_TRACE(basename);
00207 
00208     wxConfigBase * config = wxConfigBase::Get();
00209 
00210 #if ( __WXGTK__ )
00211 // restoring the splitter positions properly when maximising doesn't work.
00212 // Disabling maximise on wxWidgets >= 2.6.0 and gtk
00213     
00214         wxSize sz = frame->GetClientSize();
00215         config->Write(wxT("/") + basename + wxT("/width"), sz.GetWidth());
00216         config->Write(wxT("/") + basename + wxT("/height"), sz.GetHeight());
00217         wxPoint ps = frame->GetPosition();
00218         config->Write(wxT("/") + basename + wxT("/positionX"), ps.x);
00219         config->Write(wxT("/") + basename + wxT("/positionY"), ps.y);
00220         config->Write(wxT("/") + basename + wxT("/maximized"), 0);
00221 #else
00222     if ( (! frame->IsMaximized()) && (! frame->IsIconized()) ) {
00223         wxSize sz = frame->GetClientSize();
00224         config->Write(wxT("/") + basename + wxT("/width"), sz.GetWidth());
00225         config->Write(wxT("/") + basename + wxT("/height"), sz.GetHeight());
00226         wxPoint ps = frame->GetPosition();
00227         config->Write(wxT("/") + basename + wxT("/positionX"), ps.x);
00228         config->Write(wxT("/") + basename + wxT("/positionY"), ps.y);
00229         config->Write(wxT("/") + basename + wxT("/maximized"), 0);
00230     } else if (frame->IsMaximized()){
00231         config->Write(wxT("/") + basename + wxT("/maximized"), 1l);
00232     }
00233 #endif
00234 }

Generated on 31 May 2016 for Hugintrunk by  doxygen 1.4.7