huginApp.cpp

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

Generated on 10 Dec 2016 for Hugintrunk by  doxygen 1.4.7