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     int localeID = config->Read(wxT("language"), (long) HUGIN_LANGUAGE);
00096     DEBUG_TRACE("localeID: " << localeID);
00097     {
00098         bool bLInit;
00099             bLInit = locale.Init(localeID);
00100             if (bLInit) {
00101                 DEBUG_TRACE("locale init OK");
00102                 DEBUG_TRACE("System Locale: " << locale.GetSysName().mb_str(wxConvLocal))
00103                 DEBUG_TRACE("Canonical Locale: " << locale.GetCanonicalName().mb_str(wxConvLocal))
00104         } else {
00105           DEBUG_TRACE("locale init failed");
00106         }
00107         }
00108         
00109     // set the name of locale recource to look for
00110     locale.AddCatalog(wxT("hugin"));
00111 
00112     // initialize image handlers
00113     wxInitAllImageHandlers();
00114 
00115     // Initialize all the XRC handlers.
00116     wxXmlResource::Get()->InitAllHandlers();
00117     wxXmlResource::Get()->AddHandler(new LensCalImageCtrlXmlHandler());
00118     // load XRC files
00119     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("lenscal_frame.xrc"));
00120     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("lensdb_dialogs.xrc"));
00121     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("dlg_warning.xrc"));
00122 
00123     // create main frame
00124     m_frame = new LensCalFrame(NULL);
00125     SetTopWindow(m_frame);
00126 
00127     // setup main frame size, after it has been created.
00128     RestoreFramePosition(m_frame, wxT("LensCalFrame"));
00129 
00130     // show the frame.
00131     m_frame->Show(TRUE);
00132 
00133     // suppress tiff warnings
00134     TIFFSetWarningHandler(0);
00135 
00136     return true;
00137 }
00138 
00139 #if wxUSE_ON_FATAL_EXCEPTION
00140 void LensCalApp::OnFatalException()
00141 {
00142     GenerateReport(wxDebugReport::Context_Exception);
00143 };
00144 #endif
00145 
00146 // utility functions
00147 void RestoreFramePosition(wxTopLevelWindow * frame, const wxString & basename)
00148 {
00149     DEBUG_TRACE(basename.mb_str(wxConvLocal));
00150     wxConfigBase * config = wxConfigBase::Get();
00151 
00152     // get display size
00153     int dx,dy;
00154     wxDisplaySize(&dx,&dy);
00155 
00156 #if ( __WXGTK__ )
00157 // restoring the splitter positions properly when maximising doesn't work.
00158 // Disabling maximise on wxWidgets >= 2.6.0 and gtk
00159         //size
00160         int w = config->Read(wxT("/") + basename + wxT("/width"),-1l);
00161         int h = config->Read(wxT("/") + basename + wxT("/height"),-1l);
00162         if (w > 0 && w <= dx) {
00163             frame->SetClientSize(w,h);
00164         } else {
00165             frame->Fit();
00166         }
00167         //position
00168         int x = config->Read(wxT("/") + basename + wxT("/positionX"),-1l);
00169         int y = config->Read(wxT("/") + basename + wxT("/positionY"),-1l);
00170         if ( y >= 0 && x >= 0 && x < dx && y < dy) {
00171             frame->Move(x, y);
00172         } else {
00173             frame->Move(0, 44);
00174         }
00175 #else
00176     bool maximized = config->Read(wxT("/") + basename + wxT("/maximized"), 0l) != 0;
00177     if (maximized) {
00178         frame->Maximize();
00179         } else {
00180         //size
00181         int w = config->Read(wxT("/") + basename + wxT("/width"),-1l);
00182         int h = config->Read(wxT("/") + basename + wxT("/height"),-1l);
00183         if (w > 0 && w <= dx) {
00184             frame->SetClientSize(w,h);
00185         } else {
00186             frame->Fit();
00187         }
00188         //position
00189         int x = config->Read(wxT("/") + basename + wxT("/positionX"),-1l);
00190         int y = config->Read(wxT("/") + basename + wxT("/positionY"),-1l);
00191         if ( y >= 0 && x >= 0 && x < dx && y < dy) {
00192             frame->Move(x, y);
00193         } else {
00194             frame->Move(0, 44);
00195         }
00196     }
00197 #endif
00198 }
00199 
00200 
00201 void StoreFramePosition(wxTopLevelWindow * frame, const wxString & basename)
00202 {
00203     DEBUG_TRACE(basename);
00204 
00205     wxConfigBase * config = wxConfigBase::Get();
00206 
00207 #if ( __WXGTK__ )
00208 // restoring the splitter positions properly when maximising doesn't work.
00209 // Disabling maximise on wxWidgets >= 2.6.0 and gtk
00210     
00211         wxSize sz = frame->GetClientSize();
00212         config->Write(wxT("/") + basename + wxT("/width"), sz.GetWidth());
00213         config->Write(wxT("/") + basename + wxT("/height"), sz.GetHeight());
00214         wxPoint ps = frame->GetPosition();
00215         config->Write(wxT("/") + basename + wxT("/positionX"), ps.x);
00216         config->Write(wxT("/") + basename + wxT("/positionY"), ps.y);
00217         config->Write(wxT("/") + basename + wxT("/maximized"), 0);
00218 #else
00219     if ( (! frame->IsMaximized()) && (! frame->IsIconized()) ) {
00220         wxSize sz = frame->GetClientSize();
00221         config->Write(wxT("/") + basename + wxT("/width"), sz.GetWidth());
00222         config->Write(wxT("/") + basename + wxT("/height"), sz.GetHeight());
00223         wxPoint ps = frame->GetPosition();
00224         config->Write(wxT("/") + basename + wxT("/positionX"), ps.x);
00225         config->Write(wxT("/") + basename + wxT("/positionY"), ps.y);
00226         config->Write(wxT("/") + basename + wxT("/maximized"), 0);
00227     } else if (frame->IsMaximized()){
00228         config->Write(wxT("/") + basename + wxT("/maximized"), 1l);
00229     }
00230 #endif
00231 }

Generated on 27 Jul 2015 for Hugintrunk by  doxygen 1.4.7