00001
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
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
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
00058 wxString lensfunDBPath=huginRoot + wxT("/share/lensfun");
00059 HuginBase::LensDB::LensDB::GetSingleton().SetMainDBPath(std::string(lensfunDBPath.mb_str(HUGIN_CONV_FILENAME)));
00060
00061 locale.AddCatalogLookupPathPrefix(huginRoot + wxT("/share/locale"));
00062 #elif defined __WXMAC__ && defined MAC_SELF_CONTAINED_BUNDLE
00063
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
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
00097 wxConfigBase * config = wxConfigBase::Get();
00098
00099 config->SetRecordDefaults(false);
00100 config->Flush();
00101
00102
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
00118 locale.AddCatalog(wxT("hugin"));
00119
00120
00121 wxInitAllImageHandlers();
00122
00123
00124 wxXmlResource::Get()->InitAllHandlers();
00125 wxXmlResource::Get()->AddHandler(new LensCalImageCtrlXmlHandler());
00126
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
00132 m_frame = new LensCalFrame(NULL);
00133 SetTopWindow(m_frame);
00134
00135
00136 RestoreFramePosition(m_frame, wxT("LensCalFrame"));
00137
00138
00139 m_frame->Show(TRUE);
00140
00141
00142 TIFFSetWarningHandler(0);
00143
00144 return true;
00145 }
00146
00147
00148 void RestoreFramePosition(wxTopLevelWindow * frame, const wxString & basename)
00149 {
00150 DEBUG_TRACE(basename.mb_str(wxConvLocal));
00151 wxConfigBase * config = wxConfigBase::Get();
00152
00153
00154 int dx,dy;
00155 wxDisplaySize(&dx,&dy);
00156
00157 #if ( __WXGTK__ ) && wxCHECK_VERSION(2,6,0)
00158
00159
00160
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
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
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
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
00210
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 }