huginApp.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00002 
00027 #include "hugin_config.h"
00028 
00029 #include "panoinc_WX.h"
00030 
00031 #ifdef __WXMAC__
00032 #include <wx/sysopt.h>
00033 #include <wx/dir.h>
00034 #endif
00035 
00036 #include "panoinc.h"
00037 
00038 #include "hugin/config_defaults.h"
00039 #include "hugin/huginApp.h"
00040 #include "hugin/ImagesPanel.h"
00041 #include "hugin/MaskEditorPanel.h"
00042 #include "hugin/CPEditorPanel.h"
00043 #include "hugin/OptimizePhotometricPanel.h"
00044 #include "hugin/PanoPanel.h"
00045 #include "hugin/ImagesList.h"
00046 #include "hugin/CPListFrame.h"
00047 #include "hugin/PreviewPanel.h"
00048 #include "hugin/GLPreviewFrame.h"
00049 #include "base_wx/PTWXDlg.h"
00050 #include "base_wx/CommandHistory.h"
00051 #include "base_wx/wxcms.h"
00052 #include "base_wx/wxPanoCommand.h"
00053 #include "hugin/HtmlWindow.h"
00054 #include "hugin/treelistctrl.h"
00055 #include "hugin/ImagesTree.h"
00056 
00057 #include "base_wx/platform.h"
00058 #include "base_wx/huginConfig.h"
00059 #include <wx/cshelp.h>
00060 #ifdef __WXMSW__
00061 #include <wx/dir.h>
00062 #include <wx/stdpaths.h>
00063 #if wxCHECK_VERSION(3,1,0)
00064 #include <wx/taskbarbutton.h>
00065 #endif
00066 #endif
00067 #if defined __WXGTK__ && wxCHECK_VERSION(3,1,1)
00068 #include "base_wx/wxPlatform.h"
00069 #endif
00070 
00071 #include <tiffio.h>
00072 
00073 #include "AboutDialog.h"
00074 
00075 //for natural sorting
00076 #include "hugin_utils/alphanum.h"
00077 #include "lensdb/LensDB.h"
00078 
00079 bool checkVersion(wxString v1, wxString v2)
00080 {
00081     return doj::alphanum_comp(std::string(v1.mb_str(wxConvLocal)),std::string(v2.mb_str(wxConvLocal))) < 0;
00082 };
00083 
00084 wxString Components2Str(const HuginGraph::ImageGraph::Components & comp)
00085 {
00086     wxString ret;
00087     for (unsigned i=0; i < comp.size(); i++) {
00088         ret.Append(wxT("["));
00089         HuginGraph::ImageGraph::Components::value_type::const_iterator it = comp[i].begin();
00090         while (it != comp[i].end())
00091         {
00092             unsigned int imgNr = *it;
00093             ret << imgNr;
00094             it++;
00095             if (it != comp[i].end() && *it == imgNr + 1)
00096             {
00097                 ret.Append(wxT("-"));
00098                 while (it != comp[i].end() && *it == imgNr + 1)
00099                 {
00100                     ++it;
00101                     ++imgNr;
00102                 };
00103                 ret << imgNr;
00104                 if (it != comp[i].end())
00105                 {
00106                     ret.Append(wxT(", "));
00107                 };
00108             }
00109             else
00110             {
00111                 if (it != comp[i].end())
00112                 {
00113                     ret.Append(wxT(", "));
00114                 };
00115             };
00116         };
00117 
00118         ret.Append(wxT("]"));
00119         if (i + 1 != comp.size())
00120         {
00121             ret.Append(wxT(", "));
00122         };
00123     }
00124     return ret;
00125 }
00126 
00127 #if defined _WIN32 && defined Hugin_shared
00128 DEFINE_LOCAL_EVENT_TYPE( EVT_IMAGE_READY )
00129 #else
00130 DEFINE_EVENT_TYPE( EVT_IMAGE_READY )
00131 #endif
00132 
00133 BEGIN_EVENT_TABLE(huginApp, wxApp)
00134     EVT_IMAGE_READY2(-1, huginApp::relayImageLoaded)
00135 END_EVENT_TABLE()
00136 
00137 // make wxwindows use this class as the main application
00138 #if defined USE_GDKBACKEND_X11
00139 // wxWidgets does not support wxGLCanvas on Wayland
00140 // so until it is fixed upstream enforce using x11 backend
00141 // see ticket http://trac.wxwidgets.org/ticket/17702
00142 #warning Using Hugin with hard coded GDK_BACKEND=x11
00143 wxIMPLEMENT_WX_THEME_SUPPORT
00144 wxIMPLEMENT_APP_NO_MAIN(huginApp);
00145 #include <stdlib.h>
00146 int main(int argc, char **argv)
00147 {   
00148     wxDISABLE_DEBUG_SUPPORT();
00149     char backend[]="GDK_BACKEND=x11";
00150     putenv(backend);
00151     return wxEntry(argc, argv);
00152 };
00153 #else
00154 wxIMPLEMENT_APP(huginApp);
00155 #endif
00156 
00157 huginApp::huginApp()
00158 {
00159     DEBUG_TRACE("ctor");
00160     m_this=this;
00161     m_monitorProfile = NULL;
00162 #if wxUSE_ON_FATAL_EXCEPTION
00163     wxHandleFatalExceptions();
00164 #endif
00165 }
00166 
00167 huginApp::~huginApp()
00168 {
00169     DEBUG_TRACE("dtor");
00170     // delete temporary dir
00171 //    if (!wxRmdir(m_workDir)) {
00172 //        DEBUG_ERROR("Could not remove temporary directory");
00173 //    }
00174 
00175         // todo: remove all listeners from the panorama object
00176 
00177 //    delete frame;
00178     HuginBase::LensDB::LensDB::Clean();
00179     // delete monitor profile
00180     if (m_monitorProfile)
00181     {
00182         cmsCloseProfile(m_monitorProfile);
00183     };
00184     DEBUG_TRACE("dtor end");
00185 }
00186 
00187 bool huginApp::OnInit()
00188 {
00189     DEBUG_TRACE("=========================== huginApp::OnInit() begin ===================");
00190     SetAppName(wxT("hugin"));
00191 #if defined __WXGTK__ && wxCHECK_VERSION(3,1,1)
00192     CheckConfigFilename();
00193 #endif
00194 
00195     // Connect to ImageCache: we need to tell it when it is safe to handle UI events.
00196     ImageCache::getInstance().asyncLoadCompleteSignal = &huginApp::imageLoadedAsync;
00197 
00198 #ifdef __WXMAC__
00199     // do not use the native list control on OSX (it is very slow with the control point list window)
00200     wxSystemOptions::SetOption(wxT("mac.listctrl.always_use_generic"), 1);
00201 #endif
00202 
00203     // register our custom pano tools dialog handlers
00204     registerPTWXDlgFcn();
00205 
00206     // required by wxHtmlHelpController
00207     wxFileSystem::AddHandler(new wxZipFSHandler);
00208 
00209     // initialize help provider
00210     wxHelpControllerHelpProvider* provider = new wxHelpControllerHelpProvider;
00211     wxHelpProvider::Set(provider);
00212 
00213 #if defined __WXMSW__
00214     wxFileName exePath(wxStandardPaths::Get().GetExecutablePath());
00215     m_utilsBinDir = exePath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
00216     exePath.RemoveLastDir();
00217     const wxString huginRoot=exePath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
00218     m_xrcPrefix = huginRoot + wxT("share\\hugin\\xrc\\");
00219     m_DataDir = huginRoot + wxT("share\\hugin\\data\\");
00220 
00221     // locale setup
00222     locale.AddCatalogLookupPathPrefix(huginRoot + wxT("share\\locale"));
00223 
00224 #elif defined __WXMAC__ && defined MAC_SELF_CONTAINED_BUNDLE
00225     // initialize paths
00226     {
00227         wxString thePath = MacGetPathToBundledResourceFile(CFSTR("xrc"));
00228         if (thePath == wxT("")) {
00229             wxMessageBox(_("xrc directory not found in bundle"), _("Fatal Error"));
00230             return false;
00231         }
00232         m_xrcPrefix = thePath + wxT("/");
00233         m_DataDir = thePath + wxT("/");
00234     }
00235 
00236 #ifdef HUGIN_HSI
00237     // Set PYTHONHOME for the hsi module
00238     {
00239         wxString pythonHome = MacGetPathToBundledFrameworksDirectory() + wxT("/Python27.framework/Versions/Current");
00240         if(! wxDir::Exists(pythonHome)){
00241             wxMessageBox(wxString::Format(_("Directory '%s' does not exists"), pythonHome.c_str()));
00242         } else {
00243             wxUnsetEnv(wxT("PYTHONPATH"));
00244             if(! wxSetEnv(wxT("PYTHONHOME"), pythonHome)){
00245                 wxMessageBox(_("Could not set environment variable PYTHONHOME"));
00246             } else {
00247                 DEBUG_TRACE("PYTHONHOME set to " << pythonHome);
00248             }
00249         }
00250     }
00251 #endif
00252     
00253         
00254 #else
00255     // add the locale directory specified during configure
00256     m_xrcPrefix = wxT(INSTALL_XRC_DIR);
00257     m_DataDir = wxT(INSTALL_DATA_DIR);
00258     locale.AddCatalogLookupPathPrefix(wxT(INSTALL_LOCALE_DIR));
00259 #endif
00260 
00261     if ( ! wxFile::Exists(m_xrcPrefix + wxT("/main_frame.xrc")) ) {
00262         wxMessageBox(_("xrc directory not found, hugin needs to be properly installed\nTried Path:" + m_xrcPrefix ), _("Fatal Error"));
00263         return false;
00264     }
00265 
00266     // here goes and comes configuration
00267     wxConfigBase * config = wxConfigBase::Get();
00268     // do not record default values in the preferences file
00269     config->SetRecordDefaults(false);
00270 
00271     config->Flush();
00272 
00273     // need to explicitly initialize locale for C++ library/runtime
00274     setlocale(LC_ALL, "");
00275     // initialize i18n
00276     int localeID = config->Read(wxT("language"), (long) HUGIN_LANGUAGE);
00277     DEBUG_TRACE("localeID: " << localeID);
00278     {
00279         bool bLInit;
00280             bLInit = locale.Init(localeID);
00281             if (bLInit) {
00282                 DEBUG_TRACE("locale init OK");
00283                 DEBUG_TRACE("System Locale: " << locale.GetSysName().mb_str(wxConvLocal))
00284                 DEBUG_TRACE("Canonical Locale: " << locale.GetCanonicalName().mb_str(wxConvLocal))
00285         } else {
00286           DEBUG_TRACE("locale init failed");
00287         }
00288         }
00289         
00290     // set the name of locale recource to look for
00291     locale.AddCatalog(wxT("hugin"));
00292 
00293     // initialize image handlers
00294     wxInitAllImageHandlers();
00295 
00296     // Initialize all the XRC handlers.
00297     wxXmlResource::Get()->InitAllHandlers();
00298 
00299     // load all XRC files.
00300     #ifdef _INCLUDE_UI_RESOURCES
00301         InitXmlResource();
00302     #else
00303 
00304     // add custom XRC handlers
00305     wxXmlResource::Get()->AddHandler(new ImagesPanelXmlHandler());
00306     wxXmlResource::Get()->AddHandler(new CPEditorPanelXmlHandler());
00307     wxXmlResource::Get()->AddHandler(new CPImageCtrlXmlHandler());
00308     wxXmlResource::Get()->AddHandler(new CPImagesComboBoxXmlHandler());
00309     wxXmlResource::Get()->AddHandler(new MaskEditorPanelXmlHandler());
00310     wxXmlResource::Get()->AddHandler(new ImagesListMaskXmlHandler());
00311     wxXmlResource::Get()->AddHandler(new MaskImageCtrlXmlHandler());
00312     wxXmlResource::Get()->AddHandler(new OptimizePanelXmlHandler());
00313     wxXmlResource::Get()->AddHandler(new OptimizePhotometricPanelXmlHandler());
00314     wxXmlResource::Get()->AddHandler(new PanoPanelXmlHandler());
00315     wxXmlResource::Get()->AddHandler(new PreviewPanelXmlHandler());
00316     wxXmlResource::Get()->AddHandler(new HtmlWindowXmlHandler());
00317     wxXmlResource::Get()->AddHandler(new wxcode::wxTreeListCtrlXmlHandler());
00318     wxXmlResource::Get()->AddHandler(new ImagesTreeCtrlXmlHandler());
00319     wxXmlResource::Get()->AddHandler(new CPListCtrlXmlHandler());
00320 
00321     // load XRC files
00322     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("cp_list_frame.xrc"));
00323     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("preview_frame.xrc"));
00324     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("edit_script_dialog.xrc"));
00325     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("main_menu.xrc"));
00326     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("main_tool.xrc"));
00327     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("about.xrc"));
00328     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("pref_dialog.xrc"));
00329     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("cpdetector_dialog.xrc"));
00330     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("reset_dialog.xrc"));
00331     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("optimize_photo_panel.xrc"));
00332     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("cp_editor_panel.xrc"));
00333     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("images_panel.xrc"));
00334     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("main_frame.xrc"));
00335     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("optimize_panel.xrc"));
00336     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("pano_panel.xrc"));
00337     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("mask_editor_panel.xrc"));
00338     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("lensdb_dialogs.xrc"));
00339     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("image_variable_dlg.xrc"));
00340     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("dlg_warning.xrc"));
00341 #endif
00342 
00343 #ifdef __WXMAC__
00344     // If hugin is starting with file opening AppleEvent, MacOpenFile will be called on first wxYield().
00345     // Those need to be initialised before first call of Yield which happens in Mainframe constructor.
00346     m_macInitDone=false;
00347     m_macOpenFileOnStart=false;
00348 #endif
00349     // read monitor profile
00350     HuginBase::Color::GetMonitorProfile(m_monitorProfileName, m_monitorProfile);
00351     // create main frame
00352     frame = new MainFrame(NULL, pano);
00353     SetTopWindow(frame);
00354 
00355     // setup main frame size, after it has been created.
00356     RestoreFramePosition(frame, wxT("MainFrame"));
00357 #ifdef __WXMSW__
00358     frame->SendSizeEvent();
00359 #if wxCHECK_VERSION(3,1,0)
00360     wxTaskBarJumpList jumpList;
00361     wxFileName exeFile(wxStandardPaths::Get().GetExecutablePath());
00362     exeFile.SetName("PTBatcherGUI");
00363     wxTaskBarJumpListItem *item1 = new wxTaskBarJumpListItem(
00364         NULL, wxTASKBAR_JUMP_LIST_TASK, _("Open Batch Processor"), exeFile.GetFullPath(), wxEmptyString,
00365         _("Opens PTBatcher, the batch processor for Hugin's project files"),
00366         exeFile.GetFullPath(), 0);
00367     jumpList.GetTasks().Append(item1);
00368     exeFile.SetName("calibrate_lens_gui");
00369     wxTaskBarJumpListItem *item2 = new wxTaskBarJumpListItem(
00370         NULL, wxTASKBAR_JUMP_LIST_TASK, _("Open Lens calibrate tool"), exeFile.GetFullPath(), wxEmptyString,
00371         _("Opens Calibrate_lens_gui, a simple GUI for lens calibration"),
00372         exeFile.GetFullPath(), 0);
00373     jumpList.GetTasks().Append(item2);
00374 #endif
00375 #endif
00376     // init help system
00377     provider->SetHelpController(&frame->GetHelpController());
00378 #ifdef __WXMSW__
00379     frame->GetHelpController().Initialize(m_xrcPrefix + wxT("data/hugin_help_en_EN.chm"));
00380 #else
00381 #if wxUSE_WXHTML_HELP
00382     // using wxHtmlHelpController
00383 #if defined __WXMAC__ && defined MAC_SELF_CONTAINED_BUNDLE
00384     // On Mac, xrc/data/help_LOCALE should be in the bundle as LOCALE.lproj/help
00385     // which we can rely on the operating sytem to pick the right locale's.
00386     wxString strFile = MacGetPathToBundledResourceFile(CFSTR("help"));
00387     if (!strFile.IsEmpty())
00388     {
00389         frame->GetHelpController().AddBook(wxFileName(strFile + wxT("/hugin_help_en_EN.hhp")));
00390     }
00391     else
00392     {
00393         wxLogError(wxString::Format(wxT("Could not find help directory in the bundle"), strFile.c_str()));
00394         return false;
00395     }
00396 #else
00397     frame->GetHelpController().AddBook(wxFileName(m_xrcPrefix + wxT("data/help_en_EN/hugin_help_en_EN.hhp")));
00398 #endif
00399 #else
00400     // using wxExtHelpController
00401     frame->GetHelpController().Initialize(Initialize(m_xrcPrefix + wxT("data/help_en_EN")));
00402 #endif
00403 #endif
00404 
00405     // we are closing Hugin, if the top level window is deleted
00406     SetExitOnFrameDelete(true);
00407     // show the frame.
00408     if(frame->GetGuiLevel()==GUI_SIMPLE)
00409     {
00410         SetTopWindow(frame->getGLPreview());
00411     }
00412     else
00413     {
00414         frame->Show(TRUE);
00415     };
00416 
00417     wxString cwd = wxFileName::GetCwd();
00418 
00419     m_workDir = config->Read(wxT("tempDir"),wxT(""));
00420     // FIXME, make secure against some symlink attacks
00421     // get a temp dir
00422     if (m_workDir == wxT("")) {
00423 #if (defined __WXMSW__)
00424         DEBUG_DEBUG("figuring out windows temp dir");
00425         /* added by Yili Zhao */
00426         wxChar buffer[MAX_PATH];
00427         GetTempPath(MAX_PATH, buffer);
00428         m_workDir = buffer;
00429 #elif (defined __WXMAC__) && (defined MAC_SELF_CONTAINED_BUNDLE)
00430         DEBUG_DEBUG("temp dir on Mac");
00431         m_workDir = MacGetPathToUserDomainTempDir();
00432         if(m_workDir == wxT(""))
00433             m_workDir = wxT("/tmp");
00434 #else //UNIX
00435         DEBUG_DEBUG("temp dir on unix");
00436         // try to read environment variable
00437         if (!wxGetEnv(wxT("TMPDIR"), &m_workDir)) {
00438             // still no tempdir, use /tmp
00439             m_workDir = wxT("/tmp");
00440         }
00441 #endif
00442         
00443     }
00444 
00445     if (!wxFileName::DirExists(m_workDir)) {
00446         DEBUG_DEBUG("creating temp dir: " << m_workDir.mb_str(wxConvLocal));
00447         if (!wxMkdir(m_workDir)) {
00448             DEBUG_ERROR("Tempdir could not be created: " << m_workDir.mb_str(wxConvLocal));
00449         }
00450     }
00451     if (!wxSetWorkingDirectory(m_workDir)) {
00452         DEBUG_ERROR("could not change to temp. dir: " << m_workDir.mb_str(wxConvLocal));
00453     }
00454     DEBUG_DEBUG("using temp dir: " << m_workDir.mb_str(wxConvLocal));
00455 
00456     // set some suitable defaults
00457     PanoCommand::GlobalCmdHist::getInstance().addCommand(new PanoCommand::wxNewProjectCmd(pano));
00458     PanoCommand::GlobalCmdHist::getInstance().clear();
00459 
00460     // suppress tiff warnings
00461     TIFFSetWarningHandler(0);
00462 
00463     if (argc > 1)
00464     {
00465 #ifdef __WXMSW__
00466         //on Windows we need to update the fast preview first
00467         //otherwise there is an infinite loop when starting with a project file
00468         //and closed panorama editor aka mainframe
00469         if(frame->GetGuiLevel()==GUI_SIMPLE)
00470         {
00471             frame->getGLPreview()->Update();
00472         };
00473 #endif
00474         wxFileName file(argv[1]);
00475         // if the first file is a project file, open it
00476         if (file.GetExt().CmpNoCase(wxT("pto")) == 0 ||
00477             file.GetExt().CmpNoCase(wxT("pts")) == 0 ||
00478             file.GetExt().CmpNoCase(wxT("ptp")) == 0 )
00479         {
00480             if(file.IsRelative())
00481                 file.MakeAbsolute(cwd);
00482             // Loading the project file with set actualPath to its
00483             // parent directory.  (actualPath is used as starting
00484             // directory by many subsequent file selection dialogs.)
00485             frame->LoadProjectFile(file.GetFullPath());
00486         } else {
00487             std::vector<std::string> filesv;
00488             bool actualPathSet = false;
00489             for (int i=1; i< argc; i++) 
00490             {
00491 #if defined __WXMSW__
00492                 //expand wildcards
00493                 wxFileName fileList(argv[i]);
00494                 if(fileList.IsRelative())
00495                     fileList.MakeAbsolute(cwd);
00496                 wxDir dir;
00497                 wxString foundFile;
00498                 wxFileName file;
00499                 if(fileList.DirExists())
00500                     if(dir.Open(fileList.GetPath()))
00501                         if(dir.GetFirst(&foundFile,fileList.GetFullName(),wxDIR_FILES | wxDIR_HIDDEN))
00502                             do
00503                             {
00504                                 file=foundFile;
00505                                 file.MakeAbsolute(dir.GetName());
00506 #else
00507                 wxFileName file(argv[i]);
00508 #endif
00509                 if (file.GetExt().CmpNoCase(wxT("jpg")) == 0 ||
00510                     file.GetExt().CmpNoCase(wxT("jpeg")) == 0 ||
00511                     file.GetExt().CmpNoCase(wxT("tif")) == 0 ||
00512                     file.GetExt().CmpNoCase(wxT("tiff")) == 0 ||
00513                     file.GetExt().CmpNoCase(wxT("png")) == 0 ||
00514                     file.GetExt().CmpNoCase(wxT("bmp")) == 0 ||
00515                     file.GetExt().CmpNoCase(wxT("gif")) == 0 ||
00516                     file.GetExt().CmpNoCase(wxT("pnm")) == 0 ||
00517                     file.GetExt().CmpNoCase(wxT("sun")) == 0 ||
00518                     file.GetExt().CmpNoCase(wxT("hdr")) == 0 ||
00519                     file.GetExt().CmpNoCase(wxT("viff")) == 0 )
00520                 {
00521                     if(file.IsRelative())
00522                         file.MakeAbsolute(cwd);
00523                     if(!containsInvalidCharacters(file.GetFullPath()))
00524                     {
00525                         filesv.push_back((const char *)(file.GetFullPath().mb_str(HUGIN_CONV_FILENAME)));
00526                     };
00527 
00528                     // Use the first filename to set actualPath.
00529                     if (! actualPathSet)
00530                     {
00531                         config->Write(wxT("/actualPath"), file.GetPath());
00532                         actualPathSet = true;
00533                     }
00534                 }
00535 #if defined __WXMSW__
00536                 } while (dir.GetNext(&foundFile));
00537 #endif
00538             }
00539             if(!filesv.empty())
00540             {
00541                 std::vector<PanoCommand::PanoCommand*> cmds;
00542                 cmds.push_back(new PanoCommand::wxAddImagesCmd(pano,filesv));
00543                 cmds.push_back(new PanoCommand::DistributeImagesCmd(pano));
00544                 cmds.push_back(new PanoCommand::CenterPanoCmd(pano));
00545                 PanoCommand::GlobalCmdHist::getInstance().addCommand(new PanoCommand::CombinedPanoCommand(pano, cmds));
00546             }
00547         }
00548     }
00549 #ifdef __WXMAC__
00550     m_macInitDone = true;
00551     if(m_macOpenFileOnStart) {frame->LoadProjectFile(m_macFileNameToOpenOnStart);}
00552     m_macOpenFileOnStart = false;
00553 #endif
00554 
00555         //check for no tip switch, needed by PTBatcher
00556         wxString secondParam = argc > 2 ? wxString(argv[2]) : wxString();
00557         if(secondParam.Cmp(_T("-notips"))!=0)
00558         {
00559                 //load tip startup preferences (tips will be started after splash terminates)
00560                 int nValue = config->Read(wxT("/MainFrame/ShowStartTip"), 1l);
00561 
00562                 //show tips if needed now
00563                 if(nValue > 0)
00564                 {
00565                         wxCommandEvent dummy;
00566                         frame->OnTipOfDay(dummy);
00567                 }
00568         }
00569 
00570     DEBUG_TRACE("=========================== huginApp::OnInit() end ===================");
00571     return true;
00572 }
00573 
00574 int huginApp::OnExit()
00575 {
00576     DEBUG_TRACE("");
00577     delete wxHelpProvider::Set(NULL);
00578     return 0;
00579 }
00580 
00581 huginApp * huginApp::Get()
00582 {
00583     if (m_this) {
00584         return m_this;
00585     } else {
00586         DEBUG_FATAL("huginApp not yet created");
00587         DEBUG_ASSERT(m_this);
00588         return 0;
00589     }
00590 }
00591 
00592 MainFrame* huginApp::getMainFrame()
00593 {
00594     if (m_this) {
00595         return m_this->frame;
00596     } else {
00597         return 0;
00598     }
00599 }
00600 
00601 void huginApp::relayImageLoaded(ImageReadyEvent & event)
00602 {
00603     if (event.entry.get())
00604     {
00605         ImageCache::getInstance().postEvent(event.request, event.entry);
00606     }
00607     else
00608     {
00609         // loading failed, first remove request from image cache list
00610         ImageCache::getInstance().removeRequest(event.request);
00611         // now notify main frame to remove the failed image from project
00612         wxCommandEvent e(EVT_LOADING_FAILED);
00613         e.SetString(wxString(event.request->getFilename().c_str(), HUGIN_CONV_FILENAME));
00614         frame->GetEventHandler()->AddPendingEvent(e);
00615     };
00616 }
00617 
00618 void huginApp::imageLoadedAsync(ImageCache::RequestPtr request, ImageCache::EntryPtr entry)
00619 {
00620     ImageReadyEvent event(request, entry);
00621     // AddPendingEvent adds the event to the event queue and returns without
00622     // processing it. This is necessary since we are probably not in the
00623     // UI thread, but the event handler must be run in the UI thread since it
00624     // could update image views.
00625     Get()->AddPendingEvent(event);
00626 }
00627 
00628 #ifdef __WXMAC__
00629 void huginApp::MacOpenFile(const wxString &fileName)
00630 {
00631     if(!m_macInitDone)
00632     {
00633         m_macOpenFileOnStart=true;
00634         m_macFileNameToOpenOnStart = fileName;
00635         return;
00636     }
00637 
00638     if(frame) frame->MacOnOpenFile(fileName);
00639 }
00640 #endif
00641 
00642 #if wxUSE_ON_FATAL_EXCEPTION
00643 void huginApp::OnFatalException()
00644 {
00645     GenerateReport(wxDebugReport::Context_Exception);
00646 };
00647 #endif
00648 
00649 huginApp * huginApp::m_this = 0;
00650 
00651 
00652 // utility functions
00653 
00654 void RestoreFramePosition(wxTopLevelWindow * frame, const wxString & basename)
00655 {
00656     DEBUG_TRACE(basename.mb_str(wxConvLocal));
00657 
00658     wxConfigBase * config = wxConfigBase::Get();
00659 
00660     // get display size
00661     int dx,dy;
00662     wxDisplaySize(&dx,&dy);
00663 
00664 #if ( __WXGTK__ )
00665 // restoring the splitter positions properly when maximising doesn't work.
00666 // Disabling maximise on wxWidgets >= 2.6.0 and gtk
00667         //size
00668         int w = config->Read(wxT("/") + basename + wxT("/width"),-1l);
00669         int h = config->Read(wxT("/") + basename + wxT("/height"),-1l);
00670         if (w > 0 && w <= dx) {
00671             frame->SetClientSize(w,h);
00672         } else {
00673             frame->Fit();
00674         }
00675         //position
00676         int x = config->Read(wxT("/") + basename + wxT("/positionX"),-1l);
00677         int y = config->Read(wxT("/") + basename + wxT("/positionY"),-1l);
00678         if ( y >= 0 && x >= 0 && x < dx && y < dy) {
00679             frame->Move(x, y);
00680         } else {
00681             frame->Move(0, 44);
00682         }
00683 #else
00684     bool maximized = config->Read(wxT("/") + basename + wxT("/maximized"), 0l) != 0;
00685     if (maximized) {
00686         frame->Maximize();
00687         } else {
00688         //size
00689         int w = config->Read(wxT("/") + basename + wxT("/width"),-1l);
00690         int h = config->Read(wxT("/") + basename + wxT("/height"),-1l);
00691         if (w > 0 && w <= dx) {
00692             frame->SetClientSize(w,h);
00693         } else {
00694             frame->Fit();
00695         }
00696         //position
00697         int x = config->Read(wxT("/") + basename + wxT("/positionX"),-1l);
00698         int y = config->Read(wxT("/") + basename + wxT("/positionY"),-1l);
00699         if ( y >= 0 && x >= 0 && x < dx && y < dy) {
00700             frame->Move(x, y);
00701         } else {
00702             frame->Move(0, 44);
00703         }
00704     }
00705 #endif
00706 }
00707 
00708 
00709 void StoreFramePosition(wxTopLevelWindow * frame, const wxString & basename)
00710 {
00711     DEBUG_TRACE(basename);
00712 
00713     wxConfigBase * config = wxConfigBase::Get();
00714 
00715 #if ( __WXGTK__ )
00716 // restoring the splitter positions properly when maximising doesn't work.
00717 // Disabling maximise on wxWidgets >= 2.6.0 and gtk
00718     
00719         wxSize sz = frame->GetClientSize();
00720         config->Write(wxT("/") + basename + wxT("/width"), sz.GetWidth());
00721         config->Write(wxT("/") + basename + wxT("/height"), sz.GetHeight());
00722         wxPoint ps = frame->GetPosition();
00723         config->Write(wxT("/") + basename + wxT("/positionX"), ps.x);
00724         config->Write(wxT("/") + basename + wxT("/positionY"), ps.y);
00725         config->Write(wxT("/") + basename + wxT("/maximized"), 0);
00726 #else
00727     if ( (! frame->IsMaximized()) && (! frame->IsIconized()) ) {
00728         wxSize sz = frame->GetClientSize();
00729         config->Write(wxT("/") + basename + wxT("/width"), sz.GetWidth());
00730         config->Write(wxT("/") + basename + wxT("/height"), sz.GetHeight());
00731         wxPoint ps = frame->GetPosition();
00732         config->Write(wxT("/") + basename + wxT("/positionX"), ps.x);
00733         config->Write(wxT("/") + basename + wxT("/positionY"), ps.y);
00734         config->Write(wxT("/") + basename + wxT("/maximized"), 0);
00735     } else if (frame->IsMaximized()){
00736         config->Write(wxT("/") + basename + wxT("/maximized"), 1l);
00737     }
00738 #endif
00739 }

Generated on 22 May 2018 for Hugintrunk by  doxygen 1.4.7