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

Generated on 22 Nov 2017 for Hugintrunk by  doxygen 1.4.7