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

Generated on 30 Sep 2016 for Hugintrunk by  doxygen 1.4.7