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, write to the Free Software
00023  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024  *
00025  */
00026 
00027 #include "panoinc_WX.h"
00028 #include "panoinc.h"
00029 #include "base_wx/platform.h"
00030 
00031 #include "LensCalApp.h"
00032 #include "LensCalImageCtrl.h"
00033 #include "base_wx/huginConfig.h"
00034 #include "hugin/config_defaults.h"
00035 #include "base_wx/PTWXDlg.h"
00036 #include "lensdb/LensDB.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     SetAppName(wxT("hugin"));
00049     // register our custom pano tools dialog handlers
00050     registerPTWXDlgFcn();
00051 
00052 #if defined __WXMSW__
00053     wxString huginExeDir = getExePath(argv[0]);
00054     wxString huginRoot;
00055     wxFileName::SplitPath( huginExeDir, &huginRoot, NULL, NULL );
00056     m_xrcPrefix = huginRoot + wxT("/share/hugin/xrc/");
00057     // lensfun database init
00058     wxString lensfunDBPath=huginRoot + wxT("/share/lensfun");
00059     HuginBase::LensDB::LensDB::GetSingleton().SetMainDBPath(std::string(lensfunDBPath.mb_str(HUGIN_CONV_FILENAME)));
00060     // locale setup
00061     locale.AddCatalogLookupPathPrefix(huginRoot + wxT("/share/locale"));
00062 #elif defined __WXMAC__ && defined MAC_SELF_CONTAINED_BUNDLE
00063     // initialize paths
00064     wxString thePath = MacGetPathToBundledResourceFile(CFSTR("xrc"));
00065     if (thePath == wxT("")) {
00066         wxMessageBox(_("xrc directory not found in bundle"), _("Fatal Error"));
00067         return false;
00068     }
00069     m_xrcPrefix = thePath + wxT("/");
00070     thePath = MacGetPathToBundledResourceFile(CFSTR("locale"));
00071     if(thePath != wxT(""))
00072         locale.AddCatalogLookupPathPrefix(thePath);
00073     else {
00074         wxMessageBox(_("Translations not found in bundle"), _("Fatal Error"));
00075         return false;
00076     }
00077     thePath = MacGetPathToBundledResourceFile(CFSTR("lensfun"));
00078     if (thePath == wxT("")) {
00079         wxMessageBox(_("lensfun directory not found in bundle"),
00080                         _("Fatal Error"));
00081         return false;
00082     }
00083     HuginBase::LensDB::LensDB::GetSingleton().SetMainDBPath(std::string(thePath.mb_str(HUGIN_CONV_FILENAME)));
00084 #else
00085     // add the locale directory specified during configure
00086     m_xrcPrefix = wxT(INSTALL_XRC_DIR);
00087     locale.AddCatalogLookupPathPrefix(wxT(INSTALL_LOCALE_DIR));
00088 #endif
00089 
00090     if ( ! wxFile::Exists(m_xrcPrefix + wxT("/lenscal_frame.xrc")) )
00091     {
00092         wxMessageBox(_("xrc directory not found, hugin needs to be properly installed\nTried Path:" + m_xrcPrefix ), _("Fatal Error"));
00093         return false;
00094     }
00095 
00096     // here goes and comes configuration
00097     wxConfigBase * config = wxConfigBase::Get();
00098     // do not record default values in the preferences file
00099     config->SetRecordDefaults(false);
00100     config->Flush();
00101 
00102     // initialize i18n
00103     int localeID = config->Read(wxT("language"), (long) HUGIN_LANGUAGE);
00104     DEBUG_TRACE("localeID: " << localeID);
00105     {
00106         bool bLInit;
00107             bLInit = locale.Init(localeID);
00108             if (bLInit) {
00109                 DEBUG_TRACE("locale init OK");
00110                 DEBUG_TRACE("System Locale: " << locale.GetSysName().mb_str(wxConvLocal))
00111                 DEBUG_TRACE("Canonical Locale: " << locale.GetCanonicalName().mb_str(wxConvLocal))
00112         } else {
00113           DEBUG_TRACE("locale init failed");
00114         }
00115         }
00116         
00117     // set the name of locale recource to look for
00118     locale.AddCatalog(wxT("hugin"));
00119 
00120     // initialize image handlers
00121     wxInitAllImageHandlers();
00122 
00123     // Initialize all the XRC handlers.
00124     wxXmlResource::Get()->InitAllHandlers();
00125     wxXmlResource::Get()->AddHandler(new LensCalImageCtrlXmlHandler());
00126     // load XRC files
00127     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("lenscal_frame.xrc"));
00128     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("lensdb_dialogs.xrc"));
00129     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("dlg_warning.xrc"));
00130 
00131     // create main frame
00132     m_frame = new LensCalFrame(NULL);
00133     SetTopWindow(m_frame);
00134 
00135     // setup main frame size, after it has been created.
00136     RestoreFramePosition(m_frame, wxT("LensCalFrame"));
00137 
00138     // show the frame.
00139     m_frame->Show(TRUE);
00140 
00141     // suppress tiff warnings
00142     TIFFSetWarningHandler(0);
00143 
00144     return true;
00145 }
00146 
00147 // utility functions
00148 void RestoreFramePosition(wxTopLevelWindow * frame, const wxString & basename)
00149 {
00150     DEBUG_TRACE(basename.mb_str(wxConvLocal));
00151     wxConfigBase * config = wxConfigBase::Get();
00152 
00153     // get display size
00154     int dx,dy;
00155     wxDisplaySize(&dx,&dy);
00156 
00157 #if ( __WXGTK__ ) &&  wxCHECK_VERSION(2,6,0)
00158 // restoring the splitter positions properly when maximising doesn't work.
00159 // Disabling maximise on wxWidgets >= 2.6.0 and gtk
00160         //size
00161         int w = config->Read(wxT("/") + basename + wxT("/width"),-1l);
00162         int h = config->Read(wxT("/") + basename + wxT("/height"),-1l);
00163         if (w > 0 && w <= dx) {
00164             frame->SetClientSize(w,h);
00165         } else {
00166             frame->Fit();
00167         }
00168         //position
00169         int x = config->Read(wxT("/") + basename + wxT("/positionX"),-1l);
00170         int y = config->Read(wxT("/") + basename + wxT("/positionY"),-1l);
00171         if ( y >= 0 && x >= 0 && x < dx && y < dy) {
00172             frame->Move(x, y);
00173         } else {
00174             frame->Move(0, 44);
00175         }
00176 #else
00177     bool maximized = config->Read(wxT("/") + basename + wxT("/maximized"), 0l) != 0;
00178     if (maximized) {
00179         frame->Maximize();
00180         } else {
00181         //size
00182         int w = config->Read(wxT("/") + basename + wxT("/width"),-1l);
00183         int h = config->Read(wxT("/") + basename + wxT("/height"),-1l);
00184         if (w > 0 && w <= dx) {
00185             frame->SetClientSize(w,h);
00186         } else {
00187             frame->Fit();
00188         }
00189         //position
00190         int x = config->Read(wxT("/") + basename + wxT("/positionX"),-1l);
00191         int y = config->Read(wxT("/") + basename + wxT("/positionY"),-1l);
00192         if ( y >= 0 && x >= 0 && x < dx && y < dy) {
00193             frame->Move(x, y);
00194         } else {
00195             frame->Move(0, 44);
00196         }
00197     }
00198 #endif
00199 }
00200 
00201 
00202 void StoreFramePosition(wxTopLevelWindow * frame, const wxString & basename)
00203 {
00204     DEBUG_TRACE(basename);
00205 
00206     wxConfigBase * config = wxConfigBase::Get();
00207 
00208 #if ( __WXGTK__ ) &&  wxCHECK_VERSION(2,6,0)
00209 // restoring the splitter positions properly when maximising doesn't work.
00210 // Disabling maximise on wxWidgets >= 2.6.0 and gtk
00211     
00212         wxSize sz = frame->GetClientSize();
00213         config->Write(wxT("/") + basename + wxT("/width"), sz.GetWidth());
00214         config->Write(wxT("/") + basename + wxT("/height"), sz.GetHeight());
00215         wxPoint ps = frame->GetPosition();
00216         config->Write(wxT("/") + basename + wxT("/positionX"), ps.x);
00217         config->Write(wxT("/") + basename + wxT("/positionY"), ps.y);
00218         config->Write(wxT("/") + basename + wxT("/maximized"), 0);
00219 #else
00220     if ( (! frame->IsMaximized()) && (! frame->IsIconized()) ) {
00221         wxSize sz = frame->GetClientSize();
00222         config->Write(wxT("/") + basename + wxT("/width"), sz.GetWidth());
00223         config->Write(wxT("/") + basename + wxT("/height"), sz.GetHeight());
00224         wxPoint ps = frame->GetPosition();
00225         config->Write(wxT("/") + basename + wxT("/positionX"), ps.x);
00226         config->Write(wxT("/") + basename + wxT("/positionY"), ps.y);
00227         config->Write(wxT("/") + basename + wxT("/maximized"), 0);
00228     } else if (frame->IsMaximized()){
00229         config->Write(wxT("/") + basename + wxT("/maximized"), 1l);
00230     }
00231 #endif
00232 }

Generated on Sat Sep 20 01:25:31 2014 for Hugintrunk by  doxygen 1.3.9.1