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

Generated on 19 Nov 2017 for Hugintrunk by  doxygen 1.4.7