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

Generated on 28 Sep 2016 for Hugintrunk by  doxygen 1.4.7