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     // initialize i18n
00268 #if defined _MSC_VER && defined Hugin_shared
00269     setlocale(LC_NUMERIC, "");
00270 #endif
00271     int localeID = config->Read(wxT("language"), (long) HUGIN_LANGUAGE);
00272     DEBUG_TRACE("localeID: " << localeID);
00273     {
00274         bool bLInit;
00275             bLInit = locale.Init(localeID);
00276             if (bLInit) {
00277                 DEBUG_TRACE("locale init OK");
00278                 DEBUG_TRACE("System Locale: " << locale.GetSysName().mb_str(wxConvLocal))
00279                 DEBUG_TRACE("Canonical Locale: " << locale.GetCanonicalName().mb_str(wxConvLocal))
00280         } else {
00281           DEBUG_TRACE("locale init failed");
00282         }
00283         }
00284         
00285     // set the name of locale recource to look for
00286     locale.AddCatalog(wxT("hugin"));
00287 
00288     // initialize image handlers
00289     wxInitAllImageHandlers();
00290 
00291     // Initialize all the XRC handlers.
00292     wxXmlResource::Get()->InitAllHandlers();
00293 
00294     // load all XRC files.
00295     #ifdef _INCLUDE_UI_RESOURCES
00296         InitXmlResource();
00297     #else
00298 
00299     // add custom XRC handlers
00300     wxXmlResource::Get()->AddHandler(new ImagesPanelXmlHandler());
00301     wxXmlResource::Get()->AddHandler(new CPEditorPanelXmlHandler());
00302     wxXmlResource::Get()->AddHandler(new CPImageCtrlXmlHandler());
00303     wxXmlResource::Get()->AddHandler(new CPImagesComboBoxXmlHandler());
00304     wxXmlResource::Get()->AddHandler(new MaskEditorPanelXmlHandler());
00305     wxXmlResource::Get()->AddHandler(new ImagesListMaskXmlHandler());
00306     wxXmlResource::Get()->AddHandler(new MaskImageCtrlXmlHandler());
00307     wxXmlResource::Get()->AddHandler(new OptimizePanelXmlHandler());
00308     wxXmlResource::Get()->AddHandler(new OptimizePhotometricPanelXmlHandler());
00309     wxXmlResource::Get()->AddHandler(new PanoPanelXmlHandler());
00310     wxXmlResource::Get()->AddHandler(new PreviewPanelXmlHandler());
00311     wxXmlResource::Get()->AddHandler(new HtmlWindowXmlHandler());
00312     wxXmlResource::Get()->AddHandler(new wxcode::wxTreeListCtrlXmlHandler());
00313     wxXmlResource::Get()->AddHandler(new ImagesTreeCtrlXmlHandler());
00314     wxXmlResource::Get()->AddHandler(new CPListCtrlXmlHandler());
00315 
00316     // load XRC files
00317     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("cp_list_frame.xrc"));
00318     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("preview_frame.xrc"));
00319     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("edit_script_dialog.xrc"));
00320     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("main_menu.xrc"));
00321     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("main_tool.xrc"));
00322     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("about.xrc"));
00323     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("pref_dialog.xrc"));
00324     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("cpdetector_dialog.xrc"));
00325     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("reset_dialog.xrc"));
00326     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("optimize_photo_panel.xrc"));
00327     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("cp_editor_panel.xrc"));
00328     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("images_panel.xrc"));
00329     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("main_frame.xrc"));
00330     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("optimize_panel.xrc"));
00331     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("pano_panel.xrc"));
00332     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("mask_editor_panel.xrc"));
00333     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("lensdb_dialogs.xrc"));
00334     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("image_variable_dlg.xrc"));
00335     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("dlg_warning.xrc"));
00336 #endif
00337 
00338 #ifdef __WXMAC__
00339     // If hugin is starting with file opening AppleEvent, MacOpenFile will be called on first wxYield().
00340     // Those need to be initialised before first call of Yield which happens in Mainframe constructor.
00341     m_macInitDone=false;
00342     m_macOpenFileOnStart=false;
00343 #endif
00344     // read monitor profile
00345     HuginBase::Color::GetMonitorProfile(m_monitorProfileName, m_monitorProfile);
00346     // create main frame
00347     frame = new MainFrame(NULL, pano);
00348     SetTopWindow(frame);
00349 
00350     // setup main frame size, after it has been created.
00351     RestoreFramePosition(frame, wxT("MainFrame"));
00352 #ifdef __WXMSW__
00353     frame->SendSizeEvent();
00354 #if wxCHECK_VERSION(3,1,0)
00355     wxTaskBarJumpList jumpList;
00356     wxFileName exeFile(wxStandardPaths::Get().GetExecutablePath());
00357     exeFile.SetName("PTBatcherGUI");
00358     wxTaskBarJumpListItem *item1 = new wxTaskBarJumpListItem(
00359         NULL, wxTASKBAR_JUMP_LIST_TASK, _("Open Batch Processor"), exeFile.GetFullPath(), wxEmptyString,
00360         _("Opens PTBatcher, the batch processor for Hugin's project files"),
00361         exeFile.GetFullPath(), 0);
00362     jumpList.GetTasks().Append(item1);
00363     exeFile.SetName("calibrate_lens_gui");
00364     wxTaskBarJumpListItem *item2 = new wxTaskBarJumpListItem(
00365         NULL, wxTASKBAR_JUMP_LIST_TASK, _("Open Lens calibrate tool"), exeFile.GetFullPath(), wxEmptyString,
00366         _("Opens Calibrate_lens_gui, a simple GUI for lens calibration"),
00367         exeFile.GetFullPath(), 0);
00368     jumpList.GetTasks().Append(item2);
00369 #endif
00370 #endif
00371     // init help system
00372     provider->SetHelpController(&frame->GetHelpController());
00373 #ifdef __WXMSW__
00374     frame->GetHelpController().Initialize(m_xrcPrefix + wxT("data/hugin_help_en_EN.chm"));
00375 #else
00376 #if wxUSE_WXHTML_HELP
00377     // using wxHtmlHelpController
00378 #if defined __WXMAC__ && defined MAC_SELF_CONTAINED_BUNDLE
00379     // On Mac, xrc/data/help_LOCALE should be in the bundle as LOCALE.lproj/help
00380     // which we can rely on the operating sytem to pick the right locale's.
00381     wxString strFile = MacGetPathToBundledResourceFile(CFSTR("help"));
00382     if (!strFile.IsEmpty())
00383     {
00384         frame->GetHelpController().AddBook(wxFileName(strFile + wxT("/hugin_help_en_EN.hhp")));
00385     }
00386     else
00387     {
00388         wxLogError(wxString::Format(wxT("Could not find help directory in the bundle"), strFile.c_str()));
00389         return false;
00390     }
00391 #else
00392     frame->GetHelpController().AddBook(wxFileName(m_xrcPrefix + wxT("data/help_en_EN/hugin_help_en_EN.hhp")));
00393 #endif
00394 #else
00395     // using wxExtHelpController
00396     frame->GetHelpController().Initialize(Initialize(m_xrcPrefix + wxT("data/help_en_EN")));
00397 #endif
00398 #endif
00399 
00400     // we are closing Hugin, if the top level window is deleted
00401     SetExitOnFrameDelete(true);
00402     // show the frame.
00403     if(frame->GetGuiLevel()==GUI_SIMPLE)
00404     {
00405         SetTopWindow(frame->getGLPreview());
00406     }
00407     else
00408     {
00409         frame->Show(TRUE);
00410     };
00411 
00412     wxString cwd = wxFileName::GetCwd();
00413 
00414     m_workDir = config->Read(wxT("tempDir"),wxT(""));
00415     // FIXME, make secure against some symlink attacks
00416     // get a temp dir
00417     if (m_workDir == wxT("")) {
00418 #if (defined __WXMSW__)
00419         DEBUG_DEBUG("figuring out windows temp dir");
00420         /* added by Yili Zhao */
00421         wxChar buffer[MAX_PATH];
00422         GetTempPath(MAX_PATH, buffer);
00423         m_workDir = buffer;
00424 #elif (defined __WXMAC__) && (defined MAC_SELF_CONTAINED_BUNDLE)
00425         DEBUG_DEBUG("temp dir on Mac");
00426         m_workDir = MacGetPathToUserDomainTempDir();
00427         if(m_workDir == wxT(""))
00428             m_workDir = wxT("/tmp");
00429 #else //UNIX
00430         DEBUG_DEBUG("temp dir on unix");
00431         // try to read environment variable
00432         if (!wxGetEnv(wxT("TMPDIR"), &m_workDir)) {
00433             // still no tempdir, use /tmp
00434             m_workDir = wxT("/tmp");
00435         }
00436 #endif
00437         
00438     }
00439 
00440     if (!wxFileName::DirExists(m_workDir)) {
00441         DEBUG_DEBUG("creating temp dir: " << m_workDir.mb_str(wxConvLocal));
00442         if (!wxMkdir(m_workDir)) {
00443             DEBUG_ERROR("Tempdir could not be created: " << m_workDir.mb_str(wxConvLocal));
00444         }
00445     }
00446     if (!wxSetWorkingDirectory(m_workDir)) {
00447         DEBUG_ERROR("could not change to temp. dir: " << m_workDir.mb_str(wxConvLocal));
00448     }
00449     DEBUG_DEBUG("using temp dir: " << m_workDir.mb_str(wxConvLocal));
00450 
00451     // set some suitable defaults
00452     PanoCommand::GlobalCmdHist::getInstance().addCommand(new PanoCommand::wxNewProjectCmd(pano));
00453     PanoCommand::GlobalCmdHist::getInstance().clear();
00454 
00455     // suppress tiff warnings
00456     TIFFSetWarningHandler(0);
00457 
00458     if (argc > 1)
00459     {
00460 #ifdef __WXMSW__
00461         //on Windows we need to update the fast preview first
00462         //otherwise there is an infinite loop when starting with a project file
00463         //and closed panorama editor aka mainframe
00464         if(frame->GetGuiLevel()==GUI_SIMPLE)
00465         {
00466             frame->getGLPreview()->Update();
00467         };
00468 #endif
00469         wxFileName file(argv[1]);
00470         // if the first file is a project file, open it
00471         if (file.GetExt().CmpNoCase(wxT("pto")) == 0 ||
00472             file.GetExt().CmpNoCase(wxT("pts")) == 0 ||
00473             file.GetExt().CmpNoCase(wxT("ptp")) == 0 )
00474         {
00475             if(file.IsRelative())
00476                 file.MakeAbsolute(cwd);
00477             // Loading the project file with set actualPath to its
00478             // parent directory.  (actualPath is used as starting
00479             // directory by many subsequent file selection dialogs.)
00480             frame->LoadProjectFile(file.GetFullPath());
00481         } else {
00482             std::vector<std::string> filesv;
00483             bool actualPathSet = false;
00484             for (int i=1; i< argc; i++) 
00485             {
00486 #if defined __WXMSW__
00487                 //expand wildcards
00488                 wxFileName fileList(argv[i]);
00489                 if(fileList.IsRelative())
00490                     fileList.MakeAbsolute(cwd);
00491                 wxDir dir;
00492                 wxString foundFile;
00493                 wxFileName file;
00494                 if(fileList.DirExists())
00495                     if(dir.Open(fileList.GetPath()))
00496                         if(dir.GetFirst(&foundFile,fileList.GetFullName(),wxDIR_FILES | wxDIR_HIDDEN))
00497                             do
00498                             {
00499                                 file=foundFile;
00500                                 file.MakeAbsolute(dir.GetName());
00501 #else
00502                 wxFileName file(argv[i]);
00503 #endif
00504                 if (file.GetExt().CmpNoCase(wxT("jpg")) == 0 ||
00505                     file.GetExt().CmpNoCase(wxT("jpeg")) == 0 ||
00506                     file.GetExt().CmpNoCase(wxT("tif")) == 0 ||
00507                     file.GetExt().CmpNoCase(wxT("tiff")) == 0 ||
00508                     file.GetExt().CmpNoCase(wxT("png")) == 0 ||
00509                     file.GetExt().CmpNoCase(wxT("bmp")) == 0 ||
00510                     file.GetExt().CmpNoCase(wxT("gif")) == 0 ||
00511                     file.GetExt().CmpNoCase(wxT("pnm")) == 0 ||
00512                     file.GetExt().CmpNoCase(wxT("sun")) == 0 ||
00513                     file.GetExt().CmpNoCase(wxT("hdr")) == 0 ||
00514                     file.GetExt().CmpNoCase(wxT("viff")) == 0 )
00515                 {
00516                     if(file.IsRelative())
00517                         file.MakeAbsolute(cwd);
00518                     if(!containsInvalidCharacters(file.GetFullPath()))
00519                     {
00520                         filesv.push_back((const char *)(file.GetFullPath().mb_str(HUGIN_CONV_FILENAME)));
00521                     };
00522 
00523                     // Use the first filename to set actualPath.
00524                     if (! actualPathSet)
00525                     {
00526                         config->Write(wxT("/actualPath"), file.GetPath());
00527                         actualPathSet = true;
00528                     }
00529                 }
00530 #if defined __WXMSW__
00531                 } while (dir.GetNext(&foundFile));
00532 #endif
00533             }
00534             if(filesv.size()>0)
00535             {
00536                 std::vector<PanoCommand::PanoCommand*> cmds;
00537                 cmds.push_back(new PanoCommand::wxAddImagesCmd(pano,filesv));
00538                 cmds.push_back(new PanoCommand::DistributeImagesCmd(pano));
00539                 cmds.push_back(new PanoCommand::CenterPanoCmd(pano));
00540                 PanoCommand::GlobalCmdHist::getInstance().addCommand(new PanoCommand::CombinedPanoCommand(pano, cmds));
00541             }
00542         }
00543     }
00544 #ifdef __WXMAC__
00545     m_macInitDone = true;
00546     if(m_macOpenFileOnStart) {frame->LoadProjectFile(m_macFileNameToOpenOnStart);}
00547     m_macOpenFileOnStart = false;
00548 #endif
00549 
00550         //check for no tip switch, needed by PTBatcher
00551         wxString secondParam = argc > 2 ? wxString(argv[2]) : wxString();
00552         if(secondParam.Cmp(_T("-notips"))!=0)
00553         {
00554                 //load tip startup preferences (tips will be started after splash terminates)
00555                 int nValue = config->Read(wxT("/MainFrame/ShowStartTip"), 1l);
00556 
00557                 //show tips if needed now
00558                 if(nValue > 0)
00559                 {
00560                         wxCommandEvent dummy;
00561                         frame->OnTipOfDay(dummy);
00562                 }
00563         }
00564 
00565     DEBUG_TRACE("=========================== huginApp::OnInit() end ===================");
00566     return true;
00567 }
00568 
00569 int huginApp::OnExit()
00570 {
00571     DEBUG_TRACE("");
00572     delete wxHelpProvider::Set(NULL);
00573     return wxApp::OnExit();
00574 }
00575 
00576 huginApp * huginApp::Get()
00577 {
00578     if (m_this) {
00579         return m_this;
00580     } else {
00581         DEBUG_FATAL("huginApp not yet created");
00582         DEBUG_ASSERT(m_this);
00583         return 0;
00584     }
00585 }
00586 
00587 MainFrame* huginApp::getMainFrame()
00588 {
00589     if (m_this) {
00590         return m_this->frame;
00591     } else {
00592         return 0;
00593     }
00594 }
00595 
00596 void huginApp::relayImageLoaded(ImageReadyEvent & event)
00597 {
00598     if (event.entry.get())
00599     {
00600         ImageCache::getInstance().postEvent(event.request, event.entry);
00601     }
00602     else
00603     {
00604         // loading failed, first remove request from image cache list
00605         ImageCache::getInstance().removeRequest(event.request);
00606         // now notify main frame to remove the failed image from project
00607         wxCommandEvent e(EVT_LOADING_FAILED);
00608         e.SetString(wxString(event.request->getFilename().c_str(), HUGIN_CONV_FILENAME));
00609         frame->GetEventHandler()->AddPendingEvent(e);
00610     };
00611 }
00612 
00613 void huginApp::imageLoadedAsync(ImageCache::RequestPtr request, ImageCache::EntryPtr entry)
00614 {
00615     ImageReadyEvent event(request, entry);
00616     // AddPendingEvent adds the event to the event queue and returns without
00617     // processing it. This is necessary since we are probably not in the
00618     // UI thread, but the event handler must be run in the UI thread since it
00619     // could update image views.
00620     Get()->AddPendingEvent(event);
00621 }
00622 
00623 #ifdef __WXMAC__
00624 void huginApp::MacOpenFile(const wxString &fileName)
00625 {
00626     if(!m_macInitDone)
00627     {
00628         m_macOpenFileOnStart=true;
00629         m_macFileNameToOpenOnStart = fileName;
00630         return;
00631     }
00632 
00633     if(frame) frame->MacOnOpenFile(fileName);
00634 }
00635 #endif
00636 
00637 #if wxUSE_ON_FATAL_EXCEPTION
00638 void huginApp::OnFatalException()
00639 {
00640     GenerateReport(wxDebugReport::Context_Exception);
00641 };
00642 #endif
00643 
00644 huginApp * huginApp::m_this = 0;
00645 
00646 
00647 // utility functions
00648 
00649 void RestoreFramePosition(wxTopLevelWindow * frame, const wxString & basename)
00650 {
00651     DEBUG_TRACE(basename.mb_str(wxConvLocal));
00652 
00653     wxConfigBase * config = wxConfigBase::Get();
00654 
00655     // get display size
00656     int dx,dy;
00657     wxDisplaySize(&dx,&dy);
00658 
00659 #if ( __WXGTK__ )
00660 // restoring the splitter positions properly when maximising doesn't work.
00661 // Disabling maximise on wxWidgets >= 2.6.0 and gtk
00662         //size
00663         int w = config->Read(wxT("/") + basename + wxT("/width"),-1l);
00664         int h = config->Read(wxT("/") + basename + wxT("/height"),-1l);
00665         if (w > 0 && w <= dx) {
00666             frame->SetClientSize(w,h);
00667         } else {
00668             frame->Fit();
00669         }
00670         //position
00671         int x = config->Read(wxT("/") + basename + wxT("/positionX"),-1l);
00672         int y = config->Read(wxT("/") + basename + wxT("/positionY"),-1l);
00673         if ( y >= 0 && x >= 0 && x < dx && y < dy) {
00674             frame->Move(x, y);
00675         } else {
00676             frame->Move(0, 44);
00677         }
00678 #else
00679     bool maximized = config->Read(wxT("/") + basename + wxT("/maximized"), 0l) != 0;
00680     if (maximized) {
00681         frame->Maximize();
00682         } else {
00683         //size
00684         int w = config->Read(wxT("/") + basename + wxT("/width"),-1l);
00685         int h = config->Read(wxT("/") + basename + wxT("/height"),-1l);
00686         if (w > 0 && w <= dx) {
00687             frame->SetClientSize(w,h);
00688         } else {
00689             frame->Fit();
00690         }
00691         //position
00692         int x = config->Read(wxT("/") + basename + wxT("/positionX"),-1l);
00693         int y = config->Read(wxT("/") + basename + wxT("/positionY"),-1l);
00694         if ( y >= 0 && x >= 0 && x < dx && y < dy) {
00695             frame->Move(x, y);
00696         } else {
00697             frame->Move(0, 44);
00698         }
00699     }
00700 #endif
00701 }
00702 
00703 
00704 void StoreFramePosition(wxTopLevelWindow * frame, const wxString & basename)
00705 {
00706     DEBUG_TRACE(basename);
00707 
00708     wxConfigBase * config = wxConfigBase::Get();
00709 
00710 #if ( __WXGTK__ )
00711 // restoring the splitter positions properly when maximising doesn't work.
00712 // Disabling maximise on wxWidgets >= 2.6.0 and gtk
00713     
00714         wxSize sz = frame->GetClientSize();
00715         config->Write(wxT("/") + basename + wxT("/width"), sz.GetWidth());
00716         config->Write(wxT("/") + basename + wxT("/height"), sz.GetHeight());
00717         wxPoint ps = frame->GetPosition();
00718         config->Write(wxT("/") + basename + wxT("/positionX"), ps.x);
00719         config->Write(wxT("/") + basename + wxT("/positionY"), ps.y);
00720         config->Write(wxT("/") + basename + wxT("/maximized"), 0);
00721 #else
00722     if ( (! frame->IsMaximized()) && (! frame->IsIconized()) ) {
00723         wxSize sz = frame->GetClientSize();
00724         config->Write(wxT("/") + basename + wxT("/width"), sz.GetWidth());
00725         config->Write(wxT("/") + basename + wxT("/height"), sz.GetHeight());
00726         wxPoint ps = frame->GetPosition();
00727         config->Write(wxT("/") + basename + wxT("/positionX"), ps.x);
00728         config->Write(wxT("/") + basename + wxT("/positionY"), ps.y);
00729         config->Write(wxT("/") + basename + wxT("/maximized"), 0);
00730     } else if (frame->IsMaximized()){
00731         config->Write(wxT("/") + basename + wxT("/maximized"), 1l);
00732     }
00733 #endif
00734 }

Generated on 27 May 2017 for Hugintrunk by  doxygen 1.4.7