MainFrame.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00002 
00027 #include "hugin_config.h"
00028 
00029 #include <wx/dir.h>
00030 #include <wx/stdpaths.h>
00031 #include <wx/wfstream.h>
00032 #include "panoinc_WX.h"
00033 #include "panoinc.h"
00034 
00035 #include "base_wx/platform.h"
00036 #include "base_wx/wxPlatform.h"
00037 
00038 #include "vigra/imageinfo.hxx"
00039 #include "vigra_ext/Correlation.h"
00040 
00041 #include "hugin/config_defaults.h"
00042 #include "hugin/PreferencesDialog.h"
00043 #include "hugin/MainFrame.h"
00044 #include "base_wx/wxPanoCommand.h"
00045 #include "base_wx/CommandHistory.h"
00046 #include "hugin/PanoPanel.h"
00047 #include "hugin/ImagesPanel.h"
00048 #include "hugin/MaskEditorPanel.h"
00049 #include "hugin/OptimizePanel.h"
00050 #include "hugin/OptimizePhotometricPanel.h"
00051 #include "hugin/PreviewFrame.h"
00052 #include "hugin/GLPreviewFrame.h"
00053 #include "hugin/huginApp.h"
00054 #include "hugin/CPEditorPanel.h"
00055 #include "hugin/CPListFrame.h"
00056 #include "hugin/LocalizedFileTipProvider.h"
00057 #include "algorithms/control_points/CleanCP.h"
00058 #include "hugin/PanoOperation.h"
00059 #include "hugin/PapywizardImport.h"
00060 
00061 #include "base_wx/MyProgressDialog.h"
00062 #include "base_wx/RunStitchPanel.h"
00063 #include "base_wx/wxImageCache.h"
00064 #include "base_wx/PTWXDlg.h"
00065 #include "base_wx/MyExternalCmdExecDialog.h"
00066 #include "base_wx/AssistantExecutor.h"
00067 #include "algorithms/optimizer/ImageGraph.h"
00068 
00069 #include "base_wx/huginConfig.h"
00070 #include "hugin/AboutDialog.h"
00071 
00072 #if HUGIN_HSI
00073 #include "PluginItems.h"
00074 #endif
00075 
00076 #ifdef __MINGW32__
00077 // fixes for mingw compilation...
00078 #undef FindWindow
00079 #endif
00080 
00085 class HuginSplashScreen : public wxFrame
00086 {
00087 public:
00088     HuginSplashScreen() {};
00089     HuginSplashScreen(wxWindow* parent, wxBitmap bitmap) : 
00090         wxFrame(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxFRAME_TOOL_WINDOW | wxFRAME_NO_TASKBAR | wxSTAY_ON_TOP)
00091     {
00092         SetExtraStyle(GetExtraStyle() | wxWS_EX_TRANSIENT);
00093         wxSizer* topSizer=new wxBoxSizer(wxVERTICAL);
00094         wxStaticBitmap* staticBitmap=new wxStaticBitmap(this,wxID_ANY,bitmap);
00095         topSizer->Add(staticBitmap,1,wxEXPAND);
00096         SetSizerAndFit(topSizer);
00097         SetClientSize(bitmap.GetWidth(), bitmap.GetHeight());
00098         CenterOnScreen();
00099         Show(true);
00100         SetFocus();
00101 #if defined(__WXMSW__) || defined(__WXMAC__)
00102         Update();
00103 #elif defined(__WXGTK20__)
00104         //do nothing
00105 #else
00106         wxYieldIfNeeded();
00107 #endif
00108     };
00109     DECLARE_DYNAMIC_CLASS(HuginSplashScreen)
00110     DECLARE_EVENT_TABLE()
00111 };
00112 
00113 IMPLEMENT_DYNAMIC_CLASS(HuginSplashScreen, wxFrame)
00114 BEGIN_EVENT_TABLE(HuginSplashScreen, wxFrame)
00115 END_EVENT_TABLE()
00116 
00118 bool PanoDropTarget::OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames)
00119 {
00120     DEBUG_TRACE("OnDropFiles");
00121     MainFrame * mf = MainFrame::Get();
00122     if (!mf) return false;
00123 
00124     if (!m_imageOnly && filenames.GetCount() == 1) {
00125         wxFileName file(filenames[0]);
00126         if (file.GetExt().CmpNoCase(wxT("pto")) == 0 ||
00127             file.GetExt().CmpNoCase(wxT("ptp")) == 0 ||
00128             file.GetExt().CmpNoCase(wxT("pts")) == 0 )
00129         {
00130             // load project
00131             if (mf->CloseProject(true, MainFrame::LOAD_NEW_PROJECT))
00132             {
00133                 mf->LoadProjectFile(file.GetFullPath());
00134                 // remove old images from cache
00135                 ImageCache::getInstance().flush();
00136             }
00137             return true;
00138         }
00139     }
00140 
00141     // try to add as images
00142     std::vector<std::string> filesv;
00143     wxArrayString invalidFiles;
00144     for (unsigned int i=0; i< filenames.GetCount(); i++) {
00145         wxFileName file(filenames[i]);
00146 
00147         if (file.GetExt().CmpNoCase(wxT("jpg")) == 0 ||
00148             file.GetExt().CmpNoCase(wxT("jpeg")) == 0 ||
00149             file.GetExt().CmpNoCase(wxT("tif")) == 0 ||
00150             file.GetExt().CmpNoCase(wxT("tiff")) == 0 ||
00151             file.GetExt().CmpNoCase(wxT("png")) == 0 ||
00152             file.GetExt().CmpNoCase(wxT("bmp")) == 0 ||
00153             file.GetExt().CmpNoCase(wxT("gif")) == 0 ||
00154             file.GetExt().CmpNoCase(wxT("pnm")) == 0 ||
00155             file.GetExt().CmpNoCase(wxT("sun")) == 0 ||
00156             file.GetExt().CmpNoCase(wxT("hdr")) == 0 ||
00157             file.GetExt().CmpNoCase(wxT("viff")) == 0 )
00158         {
00159             if(containsInvalidCharacters(filenames[i]))
00160             {
00161                 invalidFiles.Add(file.GetFullPath());
00162             }
00163             else
00164             {
00165                 filesv.push_back((const char *)filenames[i].mb_str(HUGIN_CONV_FILENAME));
00166             };
00167         }
00168     }
00169     // we got some images to add.
00170     if (filesv.size() > 0)
00171     {
00172         // use a Command to ensure proper undo and updating of GUI parts
00173         wxBusyCursor();
00174         if(pano.getNrOfCtrlPoints()>0)
00175         {
00176             PanoCommand::GlobalCmdHist::getInstance().addCommand(new PanoCommand::wxAddImagesCmd(pano, filesv));
00177         }
00178         else
00179         {
00180             std::vector<PanoCommand::PanoCommand*> cmds;
00181             cmds.push_back(new PanoCommand::wxAddImagesCmd(pano, filesv));
00182             cmds.push_back(new PanoCommand::DistributeImagesCmd(pano));
00183             cmds.push_back(new PanoCommand::CenterPanoCmd(pano));
00184             PanoCommand::GlobalCmdHist::getInstance().addCommand(new PanoCommand::CombinedPanoCommand(pano, cmds));
00185         };
00186 
00187     }
00188     if(invalidFiles.size()>0)
00189     {
00190         ShowFilenameWarning(mf, invalidFiles);
00191     }
00192 
00193     return true;
00194 }
00195 
00196 
00197 #if defined _WIN32 && defined Hugin_shared
00198 DEFINE_LOCAL_EVENT_TYPE(EVT_LOADING_FAILED)
00199 #else
00200 DEFINE_EVENT_TYPE(EVT_LOADING_FAILED)
00201 #endif
00202 
00203 // event table. this frame will recieve mostly global commands.
00204 BEGIN_EVENT_TABLE(MainFrame, wxFrame)
00205     EVT_MENU(XRCID("action_new_project"),  MainFrame::OnNewProject)
00206     EVT_MENU(XRCID("action_load_project"),  MainFrame::OnLoadProject)
00207     EVT_MENU(XRCID("action_save_project"),  MainFrame::OnSaveProject)
00208     EVT_MENU(XRCID("action_save_as_project"),  MainFrame::OnSaveProjectAs)
00209     EVT_MENU(XRCID("action_save_as_ptstitcher"),  MainFrame::OnSavePTStitcherAs)
00210     EVT_MENU(XRCID("action_open_batch_processor"),  MainFrame::OnOpenPTBatcher)
00211     EVT_MENU(XRCID("action_import_project"), MainFrame::OnMergeProject)
00212     EVT_MENU(XRCID("action_import_papywizard"), MainFrame::OnReadPapywizard)
00213     EVT_MENU(XRCID("action_apply_template"),  MainFrame::OnApplyTemplate)
00214     EVT_MENU(XRCID("action_exit_hugin"),  MainFrame::OnUserQuit)
00215     EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, MainFrame::OnMRUFiles)
00216     EVT_MENU(XRCID("action_show_about"),  MainFrame::OnAbout)
00217     EVT_MENU(XRCID("action_show_help"),  MainFrame::OnHelp)
00218     EVT_MENU(XRCID("action_show_tip"),  MainFrame::OnTipOfDay)
00219     EVT_MENU(XRCID("action_show_shortcuts"),  MainFrame::OnKeyboardHelp)
00220     EVT_MENU(XRCID("action_show_faq"),  MainFrame::OnFAQ)
00221     EVT_MENU(XRCID("action_show_donate"),  MainFrame::OnShowDonate)
00222     EVT_MENU(XRCID("action_show_prefs"), MainFrame::OnShowPrefs)
00223     EVT_MENU(XRCID("action_assistant"), MainFrame::OnRunAssistant)
00224     EVT_MENU(XRCID("action_batch_assistant"), MainFrame::OnSendToAssistantQueue)
00225     EVT_MENU(XRCID("action_gui_simple"), MainFrame::OnSetGuiSimple)
00226     EVT_MENU(XRCID("action_gui_advanced"), MainFrame::OnSetGuiAdvanced)
00227     EVT_MENU(XRCID("action_gui_expert"), MainFrame::OnSetGuiExpert)
00228 #ifdef HUGIN_HSI
00229     EVT_MENU(XRCID("action_python_script"), MainFrame::OnPythonScript)
00230 #endif
00231     EVT_MENU(XRCID("ID_EDITUNDO"), MainFrame::OnUndo)
00232     EVT_MENU(XRCID("ID_EDITREDO"), MainFrame::OnRedo)
00233     EVT_MENU(XRCID("ID_SHOW_FULL_SCREEN"), MainFrame::OnFullScreen)
00234     EVT_MENU(XRCID("ID_SHOW_PREVIEW_FRAME"), MainFrame::OnTogglePreviewFrame)
00235     EVT_MENU(XRCID("ID_SHOW_GL_PREVIEW_FRAME"), MainFrame::OnToggleGLPreviewFrame)
00236     EVT_BUTTON(XRCID("ID_SHOW_PREVIEW_FRAME"),MainFrame::OnTogglePreviewFrame)
00237     EVT_BUTTON(XRCID("ID_SHOW_GL_PREVIEW_FRAME"), MainFrame::OnToggleGLPreviewFrame)
00238 
00239     EVT_MENU(XRCID("action_optimize"),  MainFrame::OnOptimize)
00240     EVT_MENU(XRCID("action_optimize_only_active"), MainFrame::OnOnlyActiveImages)
00241     EVT_BUTTON(XRCID("action_optimize"),  MainFrame::OnOptimize)
00242     EVT_MENU(XRCID("action_finetune_all_cp"), MainFrame::OnFineTuneAll)
00243 //    EVT_BUTTON(XRCID("action_finetune_all_cp"), MainFrame::OnFineTuneAll)
00244     EVT_MENU(XRCID("action_remove_cp_in_masks"), MainFrame::OnRemoveCPinMasks)
00245 
00246     EVT_MENU(XRCID("ID_CP_TABLE"), MainFrame::OnShowCPFrame)
00247     EVT_BUTTON(XRCID("ID_CP_TABLE"),MainFrame::OnShowCPFrame)
00248 
00249     EVT_MENU(XRCID("ID_SHOW_PANEL_IMAGES"), MainFrame::OnShowPanel)
00250     EVT_MENU(XRCID("ID_SHOW_PANEL_MASK"), MainFrame::OnShowPanel)
00251     EVT_MENU(XRCID("ID_SHOW_PANEL_CP_EDITOR"), MainFrame::OnShowPanel)
00252     EVT_MENU(XRCID("ID_SHOW_PANEL_OPTIMIZER"), MainFrame::OnShowPanel)
00253     EVT_MENU(XRCID("ID_SHOW_PANEL_OPTIMIZER_PHOTOMETRIC"), MainFrame::OnShowPanel)
00254     EVT_MENU(XRCID("ID_SHOW_PANEL_PANORAMA"), MainFrame::OnShowPanel)
00255     EVT_MENU(XRCID("action_stitch"), MainFrame::OnDoStitch)
00256     EVT_MENU(XRCID("action_stitch_userdefined"), MainFrame::OnUserDefinedStitch)
00257     EVT_MENU(XRCID("action_add_images"),  MainFrame::OnAddImages)
00258     EVT_BUTTON(XRCID("action_add_images"),  MainFrame::OnAddImages)
00259     EVT_MENU(XRCID("action_add_time_images"),  MainFrame::OnAddTimeImages)
00260     EVT_BUTTON(XRCID("action_add_time_images"),  MainFrame::OnAddTimeImages)
00261     EVT_CLOSE(  MainFrame::OnExit)
00262     EVT_SIZE(MainFrame::OnSize)
00263     EVT_COMMAND(wxID_ANY, EVT_LOADING_FAILED, MainFrame::OnLoadingFailed)
00264 END_EVENT_TABLE()
00265 
00266 // change this variable definition
00267 //wxTextCtrl *itemProjTextMemo;
00268 // image preview
00269 //wxBitmap *p_img = (wxBitmap *) NULL;
00270 //WX_DEFINE_ARRAY()
00271 
00272 enum
00273 {
00274     wxIDPYTHONSCRIPTS = wxID_HIGHEST + 2000,
00275     wxIDUSEROUTPUTSEQUENCE = wxID_HIGHEST + 2500
00276 };
00277 
00278 MainFrame::MainFrame(wxWindow* parent, HuginBase::Panorama & pano)
00279     : cp_frame(0), pano(pano)
00280 {
00281     preview_frame = 0;
00282     svmModel=NULL;
00283 
00284     bool disableOpenGL=false;
00285     if(wxGetKeyState(WXK_COMMAND))
00286     {
00287         wxDialog dlg;
00288         wxXmlResource::Get()->LoadDialog(&dlg, NULL, wxT("disable_opengl_dlg"));
00289         long noOpenGL=wxConfigBase::Get()->Read(wxT("DisableOpenGL"), 0l);
00290         if(noOpenGL==1)
00291         {
00292             XRCCTRL(dlg, "disable_dont_ask_checkbox", wxCheckBox)->SetValue(true);
00293         };
00294         if(dlg.ShowModal()==wxID_OK)
00295         {
00296             if(XRCCTRL(dlg, "disable_dont_ask_checkbox", wxCheckBox)->IsChecked())
00297             {
00298                 wxConfigBase::Get()->Write(wxT("DisableOpenGL"), 1l);
00299             }
00300             else
00301             {
00302                 wxConfigBase::Get()->Write(wxT("DisableOpenGL"), 0l);
00303             };
00304             disableOpenGL=true;
00305         }
00306         else
00307         {
00308             wxConfigBase::Get()->Write(wxT("DisableOpenGL"), 0l);
00309         };
00310     }
00311     else
00312     {
00313         long noOpenGL=wxConfigBase::Get()->Read(wxT("DisableOpenGL"), 0l);
00314         disableOpenGL=(noOpenGL==1);
00315     };
00316 
00317     wxBitmap bitmap;
00318     HuginSplashScreen* splash = 0;
00319     wxYield();
00320 
00321     if (bitmap.LoadFile(huginApp::Get()->GetXRCPath() + wxT("data/splash.png"), wxBITMAP_TYPE_PNG))
00322     {
00323         // embed package version into string.
00324         {
00325             wxMemoryDC dc;
00326             dc.SelectObject(bitmap);
00327 #ifdef __WXMAC__
00328             wxFont font(9, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
00329 #else
00330             wxFont font(8, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
00331 #endif
00332             dc.SetFont(font);
00333             dc.SetTextForeground(*wxBLACK);
00334             dc.SetTextBackground(*wxWHITE);
00335             int tw, th;
00336             wxString version;
00337             version.Printf(_("Version %s"), wxString(hugin_utils::GetHuginVersion().c_str(), wxConvLocal).c_str());
00338             dc.GetTextExtent(version, &tw, &th);
00339             // place text on bitmap.
00340             dc.DrawText(version, bitmap.GetWidth() - tw - 3, bitmap.GetHeight() - th - 3);
00341             dc.SelectObject(wxNullBitmap);
00342         }
00343 
00344         splash = new HuginSplashScreen(NULL, bitmap);
00345     } else {
00346         wxLogFatalError(_("Fatal installation error\nThe file data/splash.png was not found at:") + huginApp::Get()->GetXRCPath());
00347         abort();
00348     }
00349     //splash->Refresh();
00350     wxYield();
00351 
00352     // save our pointer
00353     m_this = this;
00354 
00355     DEBUG_TRACE("");
00356     // load our children. some children might need special
00357     // initialization. this will be done later.
00358     wxXmlResource::Get()->LoadFrame(this, parent, wxT("main_frame"));
00359     DEBUG_TRACE("");
00360 
00361     // load our menu bar
00362 #ifdef __WXMAC__
00363     wxApp::s_macAboutMenuItemId = XRCID("action_show_about");
00364     wxApp::s_macPreferencesMenuItemId = XRCID("action_show_prefs");
00365     wxApp::s_macExitMenuItemId = XRCID("action_exit_hugin");
00366     wxApp::s_macHelpMenuTitleName = _("&Help");
00367 #endif
00368     wxMenuBar* mainMenu=wxXmlResource::Get()->LoadMenuBar(this, wxT("main_menubar"));
00369     m_menu_file_simple=wxXmlResource::Get()->LoadMenu(wxT("file_menu_simple"));
00370     m_menu_file_advanced=wxXmlResource::Get()->LoadMenu(wxT("file_menu_advanced"));
00371     mainMenu->Insert(0, m_menu_file_simple, _("&File"));
00372     SetMenuBar(mainMenu);
00373     SetOptimizeOnlyActiveImages(m_optOnlyActiveImages);
00374 
00375 #ifdef HUGIN_HSI
00376     wxMenuBar* menubar=GetMenuBar();
00377     // the plugin menu will be generated dynamically
00378     wxMenu *pluginMenu=new wxMenu();
00379     // search for all .py files in plugins directory
00380     wxDir dir(GetDataPath()+wxT("plugins"));
00381     if (dir.IsOpened())
00382     {
00383         wxString filename;
00384         bool cont = dir.GetFirst(&filename, wxT("*.py"), wxDIR_FILES | wxDIR_HIDDEN);
00385         PluginItems items;
00386         while (cont)
00387         {
00388             wxFileName file(dir.GetName(), filename);
00389             file.MakeAbsolute();
00390             PluginItem item(file);
00391             if (item.IsAPIValid())
00392             {
00393                 items.push_back(item);
00394             };
00395             cont = dir.GetNext(&filename);
00396         };
00397         items.sort(comparePluginItem);
00398 
00399         int pluginID = wxIDPYTHONSCRIPTS;
00400         for (PluginItems::const_iterator it = items.begin(); it != items.end(); ++it)
00401         {
00402             PluginItem item = *it;
00403             int categoryID = pluginMenu->FindItem(item.GetCategory());
00404             wxMenu* categoryMenu;
00405             if (categoryID == wxNOT_FOUND)
00406             {
00407                 categoryMenu = new wxMenu();
00408                 pluginMenu->AppendSubMenu(categoryMenu, item.GetCategory());
00409             }
00410             else
00411             {
00412                 categoryMenu = pluginMenu->FindItem(categoryID)->GetSubMenu();
00413             };
00414             categoryMenu->Append(pluginID, item.GetName(), item.GetDescription());
00415             m_plugins[pluginID] = item.GetFilename();
00416             Connect(pluginID, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::OnPlugin));
00417             pluginID++;
00418         };
00419         // show the new menu
00420         if (pluginMenu->GetMenuItemCount() > 0)
00421         {
00422             menubar->Insert(menubar->GetMenuCount() - 2, pluginMenu, _("&Actions"));
00423         };
00424     };
00425 #else
00426     GetMenuBar()->Enable(XRCID("action_python_script"), false);
00427 #endif
00428 
00429     // add saved user defined output sequences
00430     {
00431         wxArrayString files;
00432         // search all .executor files, do not follow links
00433         wxDir::GetAllFiles(GetDataPath(), &files, wxT("*.executor"), wxDIR_FILES | wxDIR_HIDDEN | wxDIR_NO_FOLLOW);
00434         const size_t nrAllUserSequences = files.size();
00435         wxDir::GetAllFiles(hugin_utils::GetUserAppDataDir(), &files, wxT("*executor"), wxDIR_FILES | wxDIR_HIDDEN | wxDIR_NO_FOLLOW);
00436         if (!files.IsEmpty())
00437         {
00438             // we found some files
00439             long outputId = wxIDUSEROUTPUTSEQUENCE;
00440             int outputMenuId=mainMenu->FindMenu(_("&Output"));
00441             if (outputMenuId != wxNOT_FOUND)
00442             {
00443                 wxMenu* outputSequencesMenu = new wxMenu;
00444                 size_t i = 0;
00445                 for (auto file : files)
00446                 {
00447                     if (i > 0 && i == nrAllUserSequences && outputSequencesMenu->GetMenuItemCount() > 0)
00448                     {
00449                         outputSequencesMenu->AppendSeparator();
00450                     };
00451                     wxFileInputStream inputStream(file);
00452                     if (inputStream.IsOk())
00453                     {
00454                         // read descriptions from file
00455                         wxFileConfig executorFile(inputStream);
00456                         wxString desc = executorFile.Read(wxT("/General/Description"), wxEmptyString);
00457                         desc = desc.Trim(true).Trim(false);
00458                         wxString help = executorFile.Read(wxT("/General/Help"), wxEmptyString);
00459                         help = help.Trim(true).Trim(false);
00460                         if (help.IsEmpty())
00461                         {
00462                             help = wxString::Format(_("User defined sequence: %s"), file);
00463                         };
00464                         // add menu
00465                         if (!desc.IsEmpty())
00466                         {
00467                             outputSequencesMenu->Append(outputId, desc, help);
00468                             Bind(wxEVT_MENU, &MainFrame::OnUserDefinedStitchSaved, this, outputId);
00469                             m_userOutput[outputId] = file;
00470                             ++outputId;
00471                         };
00472                     };
00473                     i++;
00474                 };
00475                 if ((outputSequencesMenu->GetMenuItemCount() == 1 && !(outputSequencesMenu->FindItemByPosition(0)->IsSeparator())) ||
00476                     outputSequencesMenu->GetMenuItemCount() > 1)
00477                 {
00478                     mainMenu->GetMenu(outputMenuId)->AppendSubMenu(outputSequencesMenu, _("User defined output sequences"));
00479                 }
00480                 else
00481                 {
00482                     delete outputSequencesMenu;
00483                 };
00484             };
00485         };
00486     };
00487     // create tool bar
00488     SetToolBar(wxXmlResource::Get()->LoadToolBar(this, wxT("main_toolbar")));
00489 
00490     // Disable tools by default
00491     enableTools(false);
00492 
00493     // put an "unknown" object in an xrc file and
00494     // take as wxObject (second argument) the return value of wxXmlResource::Get
00495     // finish the images_panel
00496     DEBUG_TRACE("");
00497 
00498     // image_panel
00499     images_panel = XRCCTRL(*this, "images_panel_unknown", ImagesPanel);
00500     assert(images_panel);
00501     images_panel->Init(&pano);
00502     DEBUG_TRACE("");
00503 
00504     m_notebook = XRCCTRL((*this), "controls_notebook", wxNotebook);
00505 //    m_notebook = ((wxNotebook*) ((*this).FindWindow(XRCID("controls_notebook"))));
00506 //    m_notebook = ((wxNotebook*) (FindWindow(XRCID("controls_notebook"))));
00507     DEBUG_ASSERT(m_notebook);
00508 
00509     // the mask panel
00510     mask_panel = XRCCTRL(*this, "mask_panel_unknown", MaskEditorPanel);
00511     assert(mask_panel);
00512     mask_panel->Init(&pano);
00513 
00514     // the pano_panel
00515     DEBUG_TRACE("");
00516     pano_panel = XRCCTRL(*this, "panorama_panel_unknown", PanoPanel);
00517     assert(pano_panel);
00518     pano_panel->Init(&pano);
00519     pano_panel->panoramaChanged (pano); // initialize from pano
00520 
00521     cpe = XRCCTRL(*this, "cp_editor_panel_unknown", CPEditorPanel);
00522     assert(cpe);
00523     cpe->Init(&pano);
00524 
00525     opt_panel = XRCCTRL(*this, "optimizer_panel_unknown", OptimizePanel);
00526     assert(opt_panel);
00527     opt_panel->Init(&pano);
00528     m_show_opt_panel=true;
00529 
00530     opt_photo_panel = XRCCTRL(*this, "optimizer_photometric_panel_unknown", OptimizePhotometricPanel);
00531     assert(opt_photo_panel);
00532     opt_photo_panel->Init(&pano);
00533     m_show_opt_photo_panel=true;
00534 
00535     // generate list of most recently uses files and add it to menu
00536     // needs to be initialized before the fast preview, there we call AddFilesToMenu()
00537     wxConfigBase * config=wxConfigBase::Get();
00538     m_mruFiles.Load(*config);
00539     m_mruFiles.UseMenu(m_menu_file_advanced->FindItem(XRCID("menu_mru"))->GetSubMenu());
00540 
00541     preview_frame = new PreviewFrame(this, pano);
00542     if(disableOpenGL)
00543     {
00544         gl_preview_frame=NULL;
00545         DisableOpenGLTools();
00546         m_mruFiles.AddFilesToMenu();
00547     }
00548     else
00549     {
00550         gl_preview_frame = new GLPreviewFrame(this, pano);
00551     };
00552 
00553     // set the minimize icon
00554 #ifdef __WXMSW__
00555     wxIcon myIcon(GetXRCPath() + wxT("data/hugin.ico"),wxBITMAP_TYPE_ICO);
00556 #else
00557     wxIcon myIcon(GetXRCPath() + wxT("data/hugin.png"),wxBITMAP_TYPE_PNG);
00558 #endif
00559     SetIcon(myIcon);
00560 
00561     // create a new drop handler. wxwindows deletes the automaticall
00562     SetDropTarget(new PanoDropTarget(pano));
00563     DEBUG_TRACE("");
00564 
00565     PanoOperation::GeneratePanoOperationVector();
00566 
00567     // create a status bar
00568     const int fields (2);
00569     CreateStatusBar(fields);
00570     int widths[fields] = {-1, 85};
00571     SetStatusWidths( fields, &widths[0]);
00572     SetStatusText(_("Started"), 0);
00573     wxYield();
00574     DEBUG_TRACE("");
00575 
00576     // observe the panorama
00577     pano.addObserver(this);
00578 
00579     // Set sizing characteristics
00580     //set minumum size
00581 #if defined __WXMAC__ || defined __WXMSW__
00582     // a minimum nice looking size; smaller than this would clutter the layout.
00583     SetSizeHints(900, 675);
00584 #else
00585     // For ASUS eeePc
00586     SetSizeHints(780, 455); //set minumum size
00587 #endif
00588 
00589     // set progress display for image cache.
00590     ImageCache::getInstance().setProgressDisplay(this);
00591 #if defined __WXMSW__
00592     unsigned long long mem = HUGIN_IMGCACHE_UPPERBOUND;
00593     unsigned long mem_low = wxConfigBase::Get()->Read(wxT("/ImageCache/UpperBound"), HUGIN_IMGCACHE_UPPERBOUND);
00594     unsigned long mem_high = wxConfigBase::Get()->Read(wxT("/ImageCache/UpperBoundHigh"), (long) 0);
00595     if (mem_high > 0) {
00596       mem = ((unsigned long long) mem_high << 32) + mem_low;
00597     }
00598     else {
00599       mem = mem_low;
00600     }
00601     ImageCache::getInstance().SetUpperLimit(mem);
00602 #else
00603     ImageCache::getInstance().SetUpperLimit(wxConfigBase::Get()->Read(wxT("/ImageCache/UpperBound"), HUGIN_IMGCACHE_UPPERBOUND));
00604 #endif
00605 
00606     if(splash) {
00607         splash->Close();
00608         delete splash;
00609     }
00610     wxYield();
00611 
00612     // disable automatic Layout() calls, to it by hand
00613     SetAutoLayout(false);
00614 
00615 
00616 #ifdef __WXMSW__
00617     // wxFrame does have a strange background color on Windows, copy color from a child widget
00618     this->SetBackgroundColour(images_panel->GetBackgroundColour());
00619 #endif
00620 
00621 // By using /SUBSYSTEM:CONSOLE /ENTRY:"WinMainCRTStartup" in the linker
00622 // options for the debug build, a console window will be used for stdout
00623 // and stderr. No need to redirect to a file. Better security since we can't
00624 // guarantee that c: exists and writing a file to the root directory is
00625 // never a good idea. release build still uses /SUBSYSTEM:WINDOWS
00626 
00627 #if 0
00628 #ifdef DEBUG
00629 #ifdef __WXMSW__
00630 
00631     freopen("c:\\hugin_stdout.txt", "w", stdout);    // redirect stdout to file
00632     freopen("c:\\hugin_stderr.txt", "w", stderr);    // redirect stderr to file
00633 #endif
00634 #endif
00635 #endif
00636     //reload gui level
00637     m_guiLevel=GUI_ADVANCED;
00638     long guiLevel=config->Read(wxT("/GuiLevel"),(long)0);
00639     guiLevel = std::max<long>(0, std::min<long>(2, guiLevel));
00640     if(guiLevel==GUI_SIMPLE && disableOpenGL)
00641     {
00642         guiLevel=GUI_ADVANCED;
00643     };
00644     SetGuiLevel((GuiLevel)guiLevel);
00645 
00646     DEBUG_TRACE("");
00647 #ifdef __WXGTK__
00648     // set explicit focus to assistant panel for better processing key presses
00649     images_panel->SetFocus();
00650 #endif
00651 }
00652 
00653 MainFrame::~MainFrame()
00654 {
00655     DEBUG_TRACE("dtor");
00656     if(m_guiLevel==GUI_SIMPLE)
00657     {
00658         delete m_menu_file_advanced;
00659     }
00660     else
00661     {
00662         delete m_menu_file_simple;
00663     };
00664     ImageCache::getInstance().setProgressDisplay(NULL);
00665         delete & ImageCache::getInstance();
00666     delete & PanoCommand::GlobalCmdHist::getInstance();
00667 //    delete cpe;
00668 //    delete images_panel;
00669     DEBUG_DEBUG("removing observer");
00670     pano.removeObserver(this);
00671 
00672     // get the global config object
00673     wxConfigBase* config = wxConfigBase::Get();
00674 
00675     StoreFramePosition(this, wxT("MainFrame"));
00676 
00677     //store most recently used files
00678     m_mruFiles.Save(*config);
00679     //store gui level
00680     config->Write(wxT("/GuiLevel"),(long)m_guiLevel);
00681     config->Flush();
00682     if(svmModel!=NULL)
00683     {
00684         celeste::destroySVMmodel(svmModel);
00685     };
00686     PanoOperation::CleanPanoOperationVector();
00687 
00688     DEBUG_TRACE("dtor end");
00689 }
00690 
00691 void MainFrame::panoramaChanged(HuginBase::Panorama &pano)
00692 {
00693     wxToolBar* theToolBar = GetToolBar();
00694     wxMenuBar* theMenuBar = GetMenuBar();
00695     bool can_undo = PanoCommand::GlobalCmdHist::getInstance().canUndo();
00696     theMenuBar->Enable    (XRCID("ID_EDITUNDO"), can_undo);
00697     theToolBar->EnableTool(XRCID("ID_EDITUNDO"), can_undo);
00698     bool can_redo = PanoCommand::GlobalCmdHist::getInstance().canRedo();
00699     theMenuBar->Enable    (XRCID("ID_EDITREDO"), can_redo);
00700     theToolBar->EnableTool(XRCID("ID_EDITREDO"), can_redo);
00701 
00702     //show or hide optimizer and exposure optimizer tab depending on optimizer master switches
00703     if(pano.getOptimizerSwitch()==0 && !m_show_opt_panel)
00704     {
00705         m_notebook->InsertPage(3, opt_panel, _("Optimizer"));
00706         m_show_opt_panel=true;
00707     };
00708     if(pano.getOptimizerSwitch()!=0 && m_show_opt_panel)
00709     {
00710         m_notebook->RemovePage(3);
00711         m_show_opt_panel=false;
00712     };
00713     if(pano.getPhotometricOptimizerSwitch()==0 && !m_show_opt_photo_panel)
00714     {
00715         if(m_show_opt_panel)
00716         {
00717             m_notebook->InsertPage(4, opt_photo_panel, _("Exposure"));
00718         }
00719         else
00720         {
00721             m_notebook->InsertPage(3, opt_photo_panel, _("Exposure"));
00722         }
00723         m_show_opt_photo_panel=true;
00724     };
00725     if(pano.getPhotometricOptimizerSwitch()!=0 && m_show_opt_photo_panel)
00726     {
00727         if(m_show_opt_panel)
00728         {
00729             m_notebook->RemovePage(4);
00730         }
00731         else
00732         {
00733             m_notebook->RemovePage(3);
00734         };
00735         m_show_opt_photo_panel=false;
00736     };
00737     theMenuBar->Enable(XRCID("ID_SHOW_PANEL_OPTIMIZER"), m_show_opt_panel);
00738     theMenuBar->Enable(XRCID("ID_SHOW_PANEL_OPTIMIZER_PHOTOMETRIC"), m_show_opt_photo_panel);
00739 }
00740 
00741 //void MainFrame::panoramaChanged(HuginBase::Panorama &panorama)
00742 void MainFrame::panoramaImagesChanged(HuginBase::Panorama &panorama, const HuginBase::UIntSet & changed)
00743 {
00744     DEBUG_TRACE("");
00745     assert(&pano == &panorama);
00746     if (pano.getNrOfImages() == 0) {
00747           enableTools(false);
00748         } else {
00749           enableTools(true);
00750         }
00751     GetMenuBar()->Enable(XRCID("action_assistant"), pano.getNrOfImages()>=2);
00752     GetMenuBar()->Enable(XRCID("action_batch_assistant"), pano.getNrOfImages()>=2);
00753 }
00754 
00755 void MainFrame::OnUserQuit(wxCommandEvent & e)
00756 {
00757     Close();
00758 }
00759 
00760 bool MainFrame::CloseProject(bool cancelable, CloseReason reason)
00761 {
00762     if (pano.isDirty()) {
00763         wxString messageString;
00764         switch (reason)
00765         {
00766             case LOAD_NEW_PROJECT:
00767                 messageString = _("Save changes to the panorama before opening an other project?");
00768                 break;
00769             case NEW_PROJECT:
00770                 messageString = _("Save changes to the panorama before starting a new project?");
00771                 break;
00772             case CLOSE_PROGRAM:
00773             default:
00774                 messageString = _("Save changes to the panorama before closing?");
00775                 break;
00776         };
00777                 wxMessageDialog message(wxGetActiveWindow(), messageString,
00778 #ifdef _WIN32
00779                                 _("Hugin"),
00780 #else
00781                                 wxT(""),
00782 #endif
00783                                 wxICON_EXCLAMATION | wxYES_NO | (cancelable? (wxCANCEL):0));
00784         switch(reason)
00785         {
00786             case LOAD_NEW_PROJECT:
00787                 message.SetExtendedMessage(_("If you load an other project without saving, your changes since your last save will be discarded."));
00788                 break;
00789             case NEW_PROJECT:
00790                 message.SetExtendedMessage(_("If you start a new project without saving, your changes since your last save will be discarded."));
00791                 break;
00792             case CLOSE_PROGRAM:
00793             default:
00794                 message.SetExtendedMessage(_("If you close without saving, your changes since your last save will be discarded."));
00795                 break;
00796         };
00797     #if defined __WXMAC__ || defined __WXMSW__
00798         // Apple human interface guidelines and Windows user experience interaction guidelines
00799         message.SetYesNoLabels(wxID_SAVE, _("Don't Save"));
00800     #else
00801         // Gnome human interface guidelines:
00802         message.SetYesNoLabels(wxID_SAVE, _("Close without saving"));
00803     #endif
00804         int answer = message.ShowModal();
00805         switch (answer){
00806             case wxID_YES:
00807             {
00808                 wxCommandEvent dummy;
00809                 OnSaveProject(dummy);
00810                 return !pano.isDirty();
00811             }
00812             case wxID_CANCEL:
00813                 return false;
00814             default: //no save
00815                 return true;
00816         }
00817     }
00818     else return true;
00819 }
00820 
00821 void MainFrame::OnExit(wxCloseEvent & e)
00822 {
00823     DEBUG_TRACE("");
00824     if(m_guiLevel!=GUI_SIMPLE)
00825     {
00826         if(!CloseProject(e.CanVeto(), CLOSE_PROGRAM))
00827         {
00828            if (e.CanVeto())
00829            {
00830                 e.Veto();
00831                 return;
00832            }
00833            wxLogError(_("forced close"));
00834         }
00835     }
00836     else
00837     {
00838         if(e.CanVeto())
00839         {
00840             Hide();
00841             e.Veto();
00842             return;
00843         };
00844     };
00845 
00846     if(preview_frame)
00847     {
00848        preview_frame->Close(true);
00849     }
00850 
00851     ImageCache::getInstance().flush();
00852     Destroy();
00853     DEBUG_TRACE("");
00854 }
00855 
00856 void MainFrame::OnSaveProject(wxCommandEvent & e)
00857 {
00858     DEBUG_TRACE("");
00859     try {
00860     wxFileName scriptName = m_filename;
00861     if (m_filename == wxT("")) {
00862         OnSaveProjectAs(e);
00863         scriptName = m_filename;
00864     } else {
00865         // the project file is just a PTOptimizer script...
00866         std::string path = hugin_utils::getPathPrefix(std::string(scriptName.GetFullPath().mb_str(HUGIN_CONV_FILENAME)));
00867         DEBUG_DEBUG("stripping " << path << " from image filenames");
00868         std::ofstream script(scriptName.GetFullPath().mb_str(HUGIN_CONV_FILENAME));
00869         script.exceptions ( std::ofstream::eofbit | std::ofstream::failbit | std::ofstream::badbit );
00870         HuginBase::UIntSet all;
00871         if (pano.getNrOfImages() > 0) {
00872            fill_set(all, 0, pano.getNrOfImages()-1);
00873         }
00874         pano.printPanoramaScript(script, pano.getOptimizeVector(), pano.getOptions(), all, false, path);
00875         script.close();
00876 
00877         SetStatusText(wxString::Format(_("saved project %s"), m_filename.c_str()),0);
00878         if(m_guiLevel==GUI_SIMPLE)
00879         {
00880             if(gl_preview_frame)
00881             {
00882                 gl_preview_frame->SetTitle(scriptName.GetName() + wxT(".") + scriptName.GetExt() + wxT(" - ") + _("Hugin - Panorama Stitcher"));
00883             };
00884             SetTitle(scriptName.GetName() + wxT(".") + scriptName.GetExt() + wxT(" - ") + _("Panorama editor"));
00885         }
00886         else
00887         {
00888             SetTitle(scriptName.GetName() + wxT(".") + scriptName.GetExt() + wxT(" - ") + _("Hugin - Panorama Stitcher"));
00889         };
00890 
00891         pano.clearDirty();
00892     }
00893     } catch (std::exception & e) {
00894         wxString err(e.what(), wxConvLocal);
00895             wxMessageBox(wxString::Format(_("Could not save project file \"%s\".\nMaybe the file or the folder is read-only.\n\n(Error code: %s)"),m_filename.c_str(),err.c_str()),_("Error"),wxOK|wxICON_ERROR);
00896     }
00897 }
00898 
00899 void MainFrame::OnSaveProjectAs(wxCommandEvent & e)
00900 {
00901     DEBUG_TRACE("");
00902     wxFileName scriptName;
00903     if (m_filename.IsEmpty())
00904     {
00905         scriptName.Assign(getDefaultProjectName(pano) + wxT(".pto"));
00906     }
00907     else
00908     {
00909         scriptName=m_filename;
00910     };
00911     scriptName.Normalize();
00912     wxFileDialog dlg(wxGetActiveWindow(),
00913                      _("Save project file"),
00914                      scriptName.GetPath(), scriptName.GetFullName(),
00915                      _("Project files (*.pto)|*.pto|All files (*)|*"),
00916                      wxFD_SAVE | wxFD_OVERWRITE_PROMPT, wxDefaultPosition);
00917     if (dlg.ShowModal() == wxID_OK) {
00918         wxConfig::Get()->Write(wxT("/actualPath"), dlg.GetDirectory());  // remember for later
00919         wxString fn = dlg.GetPath();
00920         if (fn.Right(4).CmpNoCase(wxT(".pto"))!=0)
00921         {
00922             fn.Append(wxT(".pto"));
00923             if (wxFile::Exists(fn)) {
00924                 int d = wxMessageBox(wxString::Format(_("File %s exists. Overwrite?"), fn.c_str()),
00925                     _("Save project"), wxYES_NO | wxICON_QUESTION);
00926                 if (d != wxYES) {
00927                     return;
00928                 }
00929             }
00930         }
00931         m_filename = fn;
00932         m_mruFiles.AddFileToHistory(m_filename);
00933         OnSaveProject(e);
00934     }
00935 }
00936 
00937 void MainFrame::OnSavePTStitcherAs(wxCommandEvent & e)
00938 {
00939     DEBUG_TRACE("");
00940     wxString scriptName = m_filename;
00941     if (m_filename == wxT("")) {
00942         scriptName = getDefaultProjectName(pano);
00943     }
00944     wxFileName scriptNameFN(scriptName);
00945     wxString fn = scriptNameFN.GetName() + wxT(".txt");
00946     wxFileDialog dlg(wxGetActiveWindow(),
00947                      _("Save PTmender script file"),
00948                      wxConfigBase::Get()->Read(wxT("/actualPath"),wxT("")), fn,
00949                      _("PTmender files (*.txt)|*.txt"),
00950                      wxFD_SAVE | wxFD_OVERWRITE_PROMPT, wxDefaultPosition);
00951     if (dlg.ShowModal() == wxID_OK) {
00952         wxString fname = dlg.GetPath();
00953         // the project file is just a PTStitcher script...
00954         wxFileName scriptName = fname;
00955         HuginBase::UIntSet all;
00956         if (pano.getNrOfImages() > 0) {
00957             fill_set(all, 0, pano.getNrOfImages()-1);
00958         }
00959         std::ofstream script(scriptName.GetFullPath().mb_str(HUGIN_CONV_FILENAME));
00960         pano.printStitcherScript(script, pano.getOptions(), all);
00961         script.close();
00962     }
00963 
00964 }
00965 
00966 void MainFrame::LoadProjectFile(const wxString & filename)
00967 {
00968     DEBUG_TRACE("");
00969 
00970     // remove old images from cache
00971     // hmm probably not a good idea, if the project is reloaded..
00972     // ImageCache::getInstance().flush();
00973 
00974     SetStatusText( _("Open project:   ") + filename);
00975 
00976     wxFileName fname(filename);
00977     wxString path = fname.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
00978     if (fname.IsOk() && fname.FileExists())
00979     {
00980         m_filename = filename;
00981         wxBusyCursor wait;
00982         deregisterPTWXDlgFcn();
00983         PanoCommand::GlobalCmdHist::getInstance().addCommand(
00984             new PanoCommand::wxLoadPTProjectCmd(pano, (const char *)filename.mb_str(HUGIN_CONV_FILENAME), (const char *)path.mb_str(HUGIN_CONV_FILENAME), true)
00985            );
00986         PanoCommand::GlobalCmdHist::getInstance().clear();
00987         registerPTWXDlgFcn();
00988         DEBUG_DEBUG("project contains " << pano.getNrOfImages() << " after load");
00989         GuiLevel reqGuiLevel=GetMinimumGuiLevel(pano);
00990         if(reqGuiLevel>m_guiLevel)
00991         {
00992             SetGuiLevel(reqGuiLevel);
00993         };
00994         SetStatusText(_("Project opened"));
00995         m_mruFiles.AddFileToHistory(fname.GetFullPath());
00996         if(m_guiLevel==GUI_SIMPLE)
00997         {
00998             if(gl_preview_frame)
00999             {
01000                 gl_preview_frame->SetTitle(fname.GetName() + wxT(".") + fname.GetExt() + wxT(" - ") + _("Hugin - Panorama Stitcher"));
01001             };
01002             SetTitle(fname.GetName() + wxT(".") + fname.GetExt() + wxT(" - ") + _("Panorama editor"));
01003         }
01004         else
01005         {
01006             SetTitle(fname.GetName() + wxT(".") + fname.GetExt() + wxT(" - ") + _("Hugin - Panorama Stitcher"));
01007         };
01008         if (! (fname.GetExt() == wxT("pto"))) {
01009             // do not remember filename if its not a hugin project
01010             // to avoid overwriting the original project with an
01011             // incompatible one
01012             m_filename = wxT("");
01013         }
01014         // get the global config object
01015         wxConfigBase* config = wxConfigBase::Get();
01016         config->Write(wxT("/actualPath"), path);  // remember for later
01017     } else {
01018         SetStatusText( _("Error opening project:   ") + filename);
01019         DEBUG_ERROR("Could not open file " << filename);
01020     }
01021 
01022     // force update of preview window
01023     if ( !(preview_frame->IsIconized() ||(! preview_frame->IsShown()) ) ) {
01024         wxCommandEvent dummy;
01025         preview_frame->OnUpdate(dummy);
01026     }
01027 }
01028 
01029 #ifdef __WXMAC__
01030 void MainFrame::MacOnOpenFile(const wxString & filename)
01031 {
01032     if(!CloseProject(true, LOAD_NEW_PROJECT)) return; //if closing old project is canceled do nothing.
01033 
01034     ImageCache::getInstance().flush();
01035     LoadProjectFile(filename);
01036 }
01037 #endif
01038 
01039 void MainFrame::OnLoadProject(wxCommandEvent & e)
01040 {
01041     DEBUG_TRACE("");
01042 
01043     if(CloseProject(true, LOAD_NEW_PROJECT)) //if closing old project is canceled do nothing.
01044     {
01045         // get the global config object
01046         wxConfigBase* config = wxConfigBase::Get();
01047 
01048         wxString defaultdir = config->Read(wxT("/actualPath"),wxT(""));
01049         wxFileDialog dlg(wxGetActiveWindow(),
01050                          _("Open project file"),
01051                          defaultdir, wxT(""),
01052                          _("Project files (*.pto)|*.pto|All files (*)|*"),
01053                          wxFD_OPEN, wxDefaultPosition);
01054         dlg.SetDirectory(defaultdir);
01055         if (dlg.ShowModal() == wxID_OK)
01056         {
01057             wxString filename = dlg.GetPath();
01058             if(vigra::isImage(filename.mb_str(HUGIN_CONV_FILENAME)))
01059             {
01060                 if(wxMessageBox(wxString::Format(_("File %s is an image file and not a project file.\nThis file can't be open with File, Open.\nDo you want to add this image file to the current project?"),filename.c_str()),
01061 #ifdef __WXMSW__
01062                     _("Hugin"),
01063 #else
01064                     wxT(""),
01065 #endif
01066                     wxYES_NO | wxICON_QUESTION)==wxYES)
01067                 {
01068                     wxArrayString filenameArray;
01069                     filenameArray.Add(filename);
01070                     AddImages(filenameArray);
01071                 };
01072                 return;
01073             }
01074             else
01075             {
01076                 // remove old images from cache
01077                 ImageCache::getInstance().flush();
01078 
01079                 LoadProjectFile(filename);
01080                 return;
01081             };
01082         }
01083     }
01084     // do not close old project
01085     // nothing to open
01086     SetStatusText( _("Open project: cancel"));
01087 }
01088 
01089 void MainFrame::OnNewProject(wxCommandEvent & e)
01090 {
01091     if(!CloseProject(true, NEW_PROJECT)) return; //if closing current project is canceled
01092 
01093     m_filename = wxT("");
01094     PanoCommand::GlobalCmdHist::getInstance().addCommand(new PanoCommand::wxNewProjectCmd(pano));
01095     PanoCommand::GlobalCmdHist::getInstance().clear();
01096     // remove old images from cache
01097     ImageCache::getInstance().flush();
01098     if(m_guiLevel==GUI_SIMPLE)
01099     {
01100         if(gl_preview_frame)
01101         {
01102             gl_preview_frame->SetTitle(_("Hugin - Panorama Stitcher"));
01103         };
01104         SetTitle(_("Panorama editor"));
01105     }
01106     else
01107     {
01108         SetTitle(_("Hugin - Panorama Stitcher"));
01109     };
01110 
01111     wxCommandEvent dummy;
01112     preview_frame->OnUpdate(dummy);
01113 }
01114 
01115 void MainFrame::OnAddImages( wxCommandEvent& event )
01116 {
01117     DEBUG_TRACE("");
01118     PanoOperation::AddImageOperation addImage;
01119     HuginBase::UIntSet images;
01120     PanoCommand::PanoCommand* cmd = addImage.GetCommand(wxGetActiveWindow(), pano, images, m_guiLevel);
01121     if(cmd!=NULL)
01122     {
01123         PanoCommand::GlobalCmdHist::getInstance().addCommand(cmd);
01124     }
01125     else
01126     {
01127         // nothing to open
01128         SetStatusText( _("Add Image: cancel"));
01129     }
01130 
01131     DEBUG_TRACE("");
01132 }
01133 
01134 void MainFrame::AddImages(wxArrayString& filenameArray)
01135 {
01136     wxArrayString invalidFiles;
01137     for(unsigned int i=0;i<filenameArray.GetCount(); i++)
01138     {
01139         if(containsInvalidCharacters(filenameArray[i]))
01140         {
01141             invalidFiles.Add(filenameArray[i]);
01142         };
01143     };
01144     if(invalidFiles.size()>0)
01145     {
01146         ShowFilenameWarning(this, invalidFiles);
01147     }
01148     else
01149     {
01150         std::vector<std::string> filesv;
01151         for (unsigned int i=0; i< filenameArray.GetCount(); i++) {
01152             filesv.push_back((const char *)filenameArray[i].mb_str(HUGIN_CONV_FILENAME));
01153         }
01154 
01155         // we got some images to add.
01156         if (filesv.size() > 0) {
01157             // use a Command to ensure proper undo and updating of GUI
01158             // parts
01159             wxBusyCursor();
01160             PanoCommand::GlobalCmdHist::getInstance().addCommand(
01161                 new PanoCommand::wxAddImagesCmd(pano, filesv)
01162                 );
01163         };
01164     };
01165 };
01166 
01167 void MainFrame::OnAddTimeImages( wxCommandEvent& event )
01168 {
01169     PanoOperation::AddImagesSeriesOperation imageSeriesOp;
01170     HuginBase::UIntSet images;
01171     PanoCommand::PanoCommand* cmd = imageSeriesOp.GetCommand(wxGetActiveWindow(), pano, images, m_guiLevel);
01172     if(cmd!=NULL)
01173     {
01174         PanoCommand::GlobalCmdHist::getInstance().addCommand(cmd);
01175     };
01176 };
01177 
01178 void MainFrame::OnShowDonate(wxCommandEvent & e)
01179 {
01180     wxLaunchDefaultBrowser(wxT("http://sourceforge.net/project/project_donations.php?group_id=77506"));
01181 }
01182 
01183 
01184 void MainFrame::OnShowPanel(wxCommandEvent & e)
01185 {
01186     if(e.GetId()==XRCID("ID_SHOW_PANEL_MASK"))
01187         m_notebook->SetSelection(1);
01188     else
01189         if(e.GetId()==XRCID("ID_SHOW_PANEL_CP_EDITOR"))
01190             m_notebook->SetSelection(2);
01191         else
01192             if(e.GetId()==XRCID("ID_SHOW_PANEL_OPTIMIZER"))
01193                 m_notebook->SetSelection(3);
01194             else
01195                 if(e.GetId()==XRCID("ID_SHOW_PANEL_OPTIMIZER_PHOTOMETRIC"))
01196                 {
01197                     if(m_show_opt_panel)
01198                     {
01199                         m_notebook->SetSelection(4);
01200                     }
01201                     else
01202                     {
01203                         m_notebook->SetSelection(3);
01204                     };
01205                 }
01206                 else
01207                     if(e.GetId()==XRCID("ID_SHOW_PANEL_PANORAMA"))
01208                     {
01209                         if(m_show_opt_panel && m_show_opt_photo_panel)
01210                         {
01211                             m_notebook->SetSelection(5);
01212                         }
01213                         else
01214                         {
01215                             if(m_show_opt_panel || m_show_opt_photo_panel)
01216                             {
01217                                 m_notebook->SetSelection(4);
01218                             }
01219                             else
01220                             {
01221                                 m_notebook->SetSelection(3);
01222                             };
01223                         };
01224                     }
01225                     else
01226                         m_notebook->SetSelection(0);
01227 }
01228 
01229 void MainFrame::OnLoadingFailed(wxCommandEvent & e)
01230 {
01231     // check if file exists
01232     if (wxFileExists(e.GetString()))
01233     {
01234         // file exists, but could not loaded
01235         wxMessageBox(wxString::Format(_("Could not load image \"%s\".\nThis file is not a valid image.\nThis file will be removed from the project."), e.GetString()),
01236 #ifdef _WIN32
01237             _("Hugin"),
01238 #else
01239             wxT(""),
01240 #endif
01241             wxOK | wxICON_ERROR);
01242     }
01243     else
01244     {
01245         // file does not exists
01246         wxMessageBox(wxString::Format(_("Could not load image \"%s\".\nThis file was renamed, deleted or is on a non-accessible drive.\nThis file will be removed from the project."), e.GetString()),
01247 #ifdef _WIN32
01248             _("Hugin"),
01249 #else
01250             wxT(""),
01251 #endif
01252             wxOK | wxICON_ERROR);
01253     };
01254     // now remove the file from the pano
01255     const std::string filename(e.GetString().mb_str(HUGIN_CONV_FILENAME));
01256     HuginBase::UIntSet imagesToRemove;
01257     for (size_t i = 0; i < pano.getNrOfImages(); ++i)
01258     {
01259         if (pano.getImage(i).getFilename() == filename)
01260         {
01261             imagesToRemove.insert(i);
01262         };
01263     };
01264     if (!imagesToRemove.empty())
01265     {
01266         PanoCommand::GlobalCmdHist::getInstance().addCommand(new PanoCommand::RemoveImagesCmd(pano, imagesToRemove));
01267     };
01268 }
01269 
01270 
01271 void MainFrame::OnAbout(wxCommandEvent & e)
01272 {
01273     AboutDialog dlg(wxGetActiveWindow());
01274     dlg.ShowModal();
01275 }
01276 
01277 /*
01278 void MainFrame::OnAbout(wxCommandEvent & e)
01279 {
01280     DEBUG_TRACE("");
01281     wxDialog dlg;
01282         wxString strFile;
01283         wxString langCode;
01284 
01285     wxXmlResource::Get()->LoadDialog(&dlg, this, wxT("about_dlg"));
01286 
01287 #if __WXMAC__ && defined MAC_SELF_CONTAINED_BUNDLE
01288     //rely on the system's locale choice
01289     strFile = MacGetPathToBundledResourceFile(CFSTR("about.htm"));
01290     if(strFile!=wxT("")) XRCCTRL(dlg,"about_html",wxHtmlWindow)->LoadPage(strFile);
01291 #else
01292     //if the language is not default, load custom About file (if exists)
01293     langCode = huginApp::Get()->GetLocale().GetName().Left(2).Lower();
01294     DEBUG_INFO("Lang Code: " << langCode.mb_str(wxConvLocal));
01295     if(langCode != wxString(wxT("en")))
01296     {
01297         strFile = GetXRCPath() + wxT("data/about_") + langCode + wxT(".htm");
01298         if(wxFile::Exists(strFile))
01299         {
01300             DEBUG_TRACE("Using About: " << strFile.mb_str(wxConvLocal));
01301             XRCCTRL(dlg,"about_html",wxHtmlWindow)->LoadPage(strFile);
01302         }
01303     }
01304 #endif
01305     dlg.ShowModal();
01306 }
01307 */
01308 
01309 void MainFrame::OnHelp(wxCommandEvent & e)
01310 {
01311     DisplayHelp();
01312 }
01313 
01314 void MainFrame::OnKeyboardHelp(wxCommandEvent & e)
01315 {
01316     DisplayHelp(wxT("Hugin_Keyboard_shortcuts.html"));
01317 }
01318 
01319 void MainFrame::OnFAQ(wxCommandEvent & e)
01320 {
01321     DisplayHelp(wxT("Hugin_FAQ.html"));
01322 }
01323 
01324 
01325 void MainFrame::DisplayHelp(wxString section)
01326 {
01327     if (section.IsEmpty())
01328     {
01329         GetHelpController().DisplayContents();
01330     }
01331     else
01332     {
01333 #if defined __wxMSW__ && !(wxCHECK_VERSION(3,1,1))
01334         // wxWidgets 3.x has a bug, that prevents DisplaySection to work on Win8/10 64 bit
01335         // see: http://trac.wxwidgets.org/ticket/14888
01336         // so using DisplayContents() and our own implementation of HuginCHMHelpController
01337         GetHelpController().DisplayHelpPage(section);
01338 #else
01339         GetHelpController().DisplaySection(section);
01340 #endif
01341     };
01342 }
01343 
01344 void MainFrame::OnTipOfDay(wxCommandEvent& WXUNUSED(e))
01345 {
01346     wxString strFile;
01347     bool bShowAtStartup;
01348 // DGSW FIXME - Unreferenced
01349 //      bool bTipsExist = false;
01350     int nValue;
01351 
01352     wxConfigBase * config = wxConfigBase::Get();
01353     nValue = config->Read(wxT("/MainFrame/ShowStartTip"),1l);
01354 
01355     //TODO: tips not localisable
01356     DEBUG_INFO("Tip index: " << nValue);
01357     strFile = GetXRCPath() + wxT("data/tips.txt");  //load default file
01358 
01359     DEBUG_INFO("Reading tips from " << strFile.mb_str(wxConvLocal));
01360     wxTipProvider *tipProvider = new LocalizedFileTipProvider(strFile, nValue);
01361     bShowAtStartup = wxShowTip(wxGetActiveWindow(), tipProvider, (nValue ? true : false));
01362 
01363     //store startup preferences
01364     nValue = (bShowAtStartup ? tipProvider->GetCurrentTip() : 0);
01365     DEBUG_INFO("Writing tip index: " << nValue);
01366     config->Write(wxT("/MainFrame/ShowStartTip"), nValue);
01367     delete tipProvider;
01368 }
01369 
01370 
01371 void MainFrame::OnShowPrefs(wxCommandEvent & e)
01372 {
01373     DEBUG_TRACE("");
01374     PreferencesDialog pref_dlg(wxGetActiveWindow());
01375     pref_dlg.ShowModal();
01376     //update image cache size
01377     wxConfigBase* cfg=wxConfigBase::Get();
01378 #if defined __WXMSW__
01379     unsigned long long mem = HUGIN_IMGCACHE_UPPERBOUND;
01380     unsigned long mem_low = cfg->Read(wxT("/ImageCache/UpperBound"), HUGIN_IMGCACHE_UPPERBOUND);
01381     unsigned long mem_high = cfg->Read(wxT("/ImageCache/UpperBoundHigh"), (long) 0);
01382     if (mem_high > 0)
01383     {
01384       mem = ((unsigned long long) mem_high << 32) + mem_low;
01385     }
01386     else
01387     {
01388       mem = mem_low;
01389     }
01390     ImageCache::getInstance().SetUpperLimit(mem);
01391 #else
01392     ImageCache::getInstance().SetUpperLimit(cfg->Read(wxT("/ImageCache/UpperBound"), HUGIN_IMGCACHE_UPPERBOUND));
01393 #endif
01394     images_panel->ReloadCPDetectorSettings();
01395     if(gl_preview_frame)
01396     {
01397         gl_preview_frame->SetShowProjectionHints(cfg->Read(wxT("/GLPreviewFrame/ShowProjectionHints"),HUGIN_SHOW_PROJECTION_HINTS)!=0);
01398     };
01399 }
01400 
01401 void MainFrame::UpdatePanels( wxCommandEvent& WXUNUSED(event) )
01402 {   // Maybe this can be invoced by the Panorama::Changed() or
01403     // something like this. So no everytime update would be needed.
01404     DEBUG_TRACE("");
01405 }
01406 
01407 void MainFrame::OnTogglePreviewFrame(wxCommandEvent & e)
01408 {
01409     DEBUG_TRACE("");
01410     if (preview_frame->IsIconized()) {
01411         preview_frame->Iconize(false);
01412     }
01413     preview_frame->Show();
01414     preview_frame->Raise();
01415 
01416         // we need to force an update since autoupdate fires
01417         // before the preview frame is shown
01418     wxCommandEvent dummy;
01419         preview_frame->OnUpdate(dummy);
01420 }
01421 
01422 void MainFrame::OnToggleGLPreviewFrame(wxCommandEvent & e)
01423 {
01424     if(gl_preview_frame==NULL)
01425     {
01426         return;
01427     };
01428 #if defined __WXMSW__ || defined __WXMAC__
01429     gl_preview_frame->InitPreviews();
01430 #endif
01431     if (gl_preview_frame->IsIconized()) {
01432         gl_preview_frame->Iconize(false);
01433     }
01434     gl_preview_frame->Show();
01435 #if defined __WXMSW__
01436     // on wxMSW Show() does not send OnShowEvent needed to update the
01437     // visibility state of the fast preview windows
01438     // so explicit calling this event handler
01439     wxShowEvent se;
01440     se.SetShow(true);
01441     gl_preview_frame->OnShowEvent(se);
01442 #elif defined __WXGTK__
01443     gl_preview_frame->LoadOpenGLLayout();
01444 #endif
01445     gl_preview_frame->Raise();
01446 }
01447 
01448 void MainFrame::OnShowCPFrame(wxCommandEvent & e)
01449 {
01450     DEBUG_TRACE("");
01451     if (cp_frame) {
01452         if (cp_frame->IsIconized()) {
01453             cp_frame->Iconize(false);
01454         }
01455         cp_frame->Show();
01456         cp_frame->Raise();
01457     } else {
01458         cp_frame = new CPListFrame(this, pano);
01459         cp_frame->Show();
01460     }
01461 }
01462 
01463 void MainFrame::OnCPListFrameClosed()
01464 {
01465     cp_frame = 0;
01466 }
01467 
01468 void MainFrame::OnOptimize(wxCommandEvent & e)
01469 {
01470     DEBUG_TRACE("");
01471     wxCommandEvent dummy;
01472     opt_panel->OnOptimizeButton(dummy);
01473 }
01474 
01475 void MainFrame::OnOnlyActiveImages(wxCommandEvent &e)
01476 {
01477     m_optOnlyActiveImages = GetMenuBar()->IsChecked(XRCID("action_optimize_only_active"));
01478     opt_panel->SetOnlyActiveImages(m_optOnlyActiveImages);
01479     // notify all observer so they can update their display
01480     pano.changeFinished();
01481 };
01482 
01483 void MainFrame::SetOptimizeOnlyActiveImages(const bool onlyActive)
01484 {
01485     m_optOnlyActiveImages = onlyActive;
01486     wxMenuBar* menubar = GetMenuBar();
01487     if (menubar)
01488     {
01489         menubar->Check(XRCID("action_optimize_only_active"), onlyActive);
01490         // notify all observer so they can update their display
01491         pano.changeFinished();
01492     };
01493 };
01494 
01495 const bool MainFrame::GetOptimizeOnlyActiveImages() const
01496 {
01497     return m_optOnlyActiveImages;
01498 };
01499 
01500 void MainFrame::OnPhotometricOptimize(wxCommandEvent & e)
01501 {
01502     wxCommandEvent dummy;
01503     opt_photo_panel->OnOptimizeButton(dummy);
01504 };
01505 
01506 void MainFrame::OnDoStitch(wxCommandEvent & e)
01507 {
01508     DEBUG_TRACE("");
01509     wxCommandEvent cmdEvt(wxEVT_COMMAND_BUTTON_CLICKED,XRCID("pano_button_stitch"));
01510     pano_panel->GetEventHandler()->AddPendingEvent(cmdEvt);
01511 }
01512 
01513 void MainFrame::OnUserDefinedStitch(wxCommandEvent & e)
01514 {
01515     pano_panel->DoUserDefinedStitch();
01516 }
01517 
01518 void MainFrame::OnUserDefinedStitchSaved(wxCommandEvent & e)
01519 {
01520     auto filename = m_userOutput.find(e.GetId());
01521     if (filename != m_userOutput.end())
01522     {
01523         pano_panel->DoUserDefinedStitch(filename->second);
01524     }
01525     else
01526     {
01527         wxBell();
01528     };
01529 }
01530 
01531 void MainFrame::OnMergeProject(wxCommandEvent & e)
01532 {
01533     // get the global config object
01534     wxConfigBase* config = wxConfigBase::Get();
01535 
01536     wxString defaultdir = config->Read(wxT("/actualPath"),wxT(""));
01537     wxFileDialog dlg(wxGetActiveWindow(),
01538                      _("Open project file"),
01539                      defaultdir, wxT(""),
01540                      _("Project files (*.pto)|*.pto|All files (*)|*"),
01541                      wxFD_OPEN, wxDefaultPosition);
01542     dlg.SetDirectory(defaultdir);
01543     if (dlg.ShowModal() == wxID_OK)
01544     {
01545         wxString filename = dlg.GetPath();
01546         wxFileName fname(filename);
01547         wxString path = fname.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
01548         if (fname.IsOk() && fname.FileExists())
01549         {
01550             wxBusyCursor wait;
01551             HuginBase::PanoramaMemento newPano;
01552             std::ifstream in((const char *)fname.GetFullPath().mb_str(HUGIN_CONV_FILENAME));
01553             int ptoversion=0;
01554             if (newPano.loadPTScript(in, ptoversion, (const char *)path.mb_str(HUGIN_CONV_FILENAME)))
01555             {
01556                 HuginBase::Panorama new_pano;
01557                 new_pano.setMemento(newPano);
01558                 PanoCommand::GlobalCmdHist::getInstance().addCommand(
01559                     new PanoCommand::MergePanoCmd(pano, new_pano)
01560                 );
01561                 m_mruFiles.AddFileToHistory(fname.GetFullPath());
01562                 // force update of preview window
01563                 if ( !(preview_frame->IsIconized() ||(! preview_frame->IsShown()) ) )
01564                 {
01565                     wxCommandEvent dummy;
01566                     preview_frame->OnUpdate(dummy);
01567                 };
01568             }
01569             else
01570             {
01571                 wxMessageBox(wxString::Format(_("Could not read project file %s."),fname.GetFullPath().c_str()),_("Error"),wxOK|wxICON_ERROR);
01572             };
01573         };
01574     }
01575 }
01576 
01577 void MainFrame::OnReadPapywizard(wxCommandEvent & e)
01578 {
01579     wxString currentDir = wxConfigBase::Get()->Read(wxT("/actualPath"), wxT(""));
01580     wxFileDialog dlg(wxGetActiveWindow(), _("Open Papywizard xml file"),
01581         currentDir, wxT(""), _("Papywizard xml files (*.xml)|*.xml|All files (*)|*"),
01582         wxFD_OPEN, wxDefaultPosition);
01583     dlg.SetDirectory(currentDir);
01584     if (dlg.ShowModal() == wxID_OK)
01585     {
01586         wxConfigBase::Get()->Write(wxT("/actualPath"), dlg.GetDirectory());
01587         Papywizard::ImportPapywizardFile(dlg.GetPath(), pano);
01588     };
01589 };
01590 
01591 void MainFrame::OnApplyTemplate(wxCommandEvent & e)
01592 {
01593     // get the global config object
01594     wxConfigBase* config = wxConfigBase::Get();
01595 
01596     wxFileDialog dlg(wxGetActiveWindow(),
01597                      _("Choose template project"),
01598                      config->Read(wxT("/templatePath"),wxT("")), wxT(""),
01599                      _("Project files (*.pto)|*.pto|All files (*)|*"),
01600                      wxFD_OPEN, wxDefaultPosition);
01601     dlg.SetDirectory(wxConfigBase::Get()->Read(wxT("/templatePath"),wxT("")));
01602     if (dlg.ShowModal() == wxID_OK) {
01603         wxString filename = dlg.GetPath();
01604         wxConfig::Get()->Write(wxT("/templatePath"), dlg.GetDirectory());  // remember for later
01605 
01606         std::ifstream file((const char *)filename.mb_str(HUGIN_CONV_FILENAME));
01607 
01608         PanoCommand::GlobalCmdHist::getInstance().addCommand(
01609             new PanoCommand::wxApplyTemplateCmd(pano, file));
01610 
01611     }
01612 }
01613 
01614 void MainFrame::OnOpenPTBatcher(wxCommandEvent & e)
01615 {
01616 #if defined __WXMAC__ && defined MAC_SELF_CONTAINED_BUNDLE
01617         // Original patch for OSX by Charlie Reiman dd. 18 June 2011
01618         // Slightly modified by HvdW. Errors in here are mine, not Charlie's. 
01619         FSRef appRef;
01620         FSRef actuallyLaunched;
01621         OSStatus err;
01622         FSRef documentArray[1]; // Don't really need an array if we only have 1 item
01623         LSLaunchFSRefSpec launchSpec;
01624         Boolean  isDir;
01625         
01626         err = LSFindApplicationForInfo(kLSUnknownCreator,
01627                                                                    CFSTR("net.sourceforge.hugin.PTBatcherGUI"),
01628                                                                    NULL,
01629                                                                    &appRef,
01630                                                                    NULL);
01631         if (err != noErr) {
01632                 // error, can't find PTBatcherGUI
01633                 wxMessageBox(wxString::Format(_("External program %s not found in the bundle, reverting to system path"), wxT("open")), _("Error"));
01634                 // Possibly a silly attempt otherwise the previous would have worked as well, but just try it.
01635                 wxExecute(_T("open -b net.sourceforge.hugin.PTBatcherGUI"));
01636         }
01637         else {
01638                 wxExecute(_T("open -b net.sourceforge.hugin.PTBatcherGUI"));
01639         }       
01640 #else
01641     const wxFileName exePath(wxStandardPaths::Get().GetExecutablePath());
01642         wxExecute(exePath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR) + _T("PTBatcherGUI"));
01643 #endif
01644 }
01645 
01646 void MainFrame::OnFineTuneAll(wxCommandEvent & e)
01647 {
01648     DEBUG_TRACE("");
01649     // fine-tune all points
01650 
01651     HuginBase::CPVector cps = pano.getCtrlPoints();
01652 
01653     // create a map of all control points.
01654     std::set<unsigned int> unoptimized;
01655     for (unsigned int i=0; i < cps.size(); i++) {
01656         // create all control points.
01657         unoptimized.insert(i);
01658     }
01659 
01660     unsigned int nGood=0;
01661     unsigned int nBad=0;
01662 
01663     wxConfigBase *cfg = wxConfigBase::Get();
01664     double corrThresh=HUGIN_FT_CORR_THRESHOLD;
01665     cfg->Read(wxT("/Finetune/CorrThreshold"), &corrThresh, HUGIN_FT_CORR_THRESHOLD);
01666     double curvThresh = HUGIN_FT_CURV_THRESHOLD;
01667     cfg->Read(wxT("/Finetune/CurvThreshold"),&curvThresh, HUGIN_FT_CURV_THRESHOLD);
01668     // load parameters
01669     const long templWidth = cfg->Read(wxT("/Finetune/TemplateSize"), HUGIN_FT_TEMPLATE_SIZE);
01670     const long sWidth = templWidth + cfg->Read(wxT("/Finetune/LocalSearchWidth"), HUGIN_FT_LOCAL_SEARCH_WIDTH);
01671 
01672     {
01673         ProgressReporterDialog progress(unoptimized.size(), _("Fine-tuning all points"), _("Fine-tuning"), wxGetActiveWindow());
01674 
01675     ImageCache & imgCache = ImageCache::getInstance();
01676 
01677     // do not process the control points in random order,
01678     // but walk from image to image, to reduce image reloading
01679     // in low mem situations.
01680     for (unsigned int imgNr = 0 ; imgNr < pano.getNrOfImages(); imgNr++) {
01681         std::set<unsigned int>::iterator it=unoptimized.begin();
01682 
01683         imgCache.softFlush();
01684 
01685         while (it != unoptimized.end()) {
01686             if (cps[*it].image1Nr == imgNr || cps[*it].image2Nr == imgNr) {
01687                 if (!progress.updateDisplayValue())
01688                 {
01689                     return;
01690                 };
01691                 if (cps[*it].mode == HuginBase::ControlPoint::X_Y) {
01692                     // finetune only normal points
01693                     DEBUG_DEBUG("fine tuning point: " << *it);
01694                     wxImage wxSearchImg;
01695                     ImageCache::ImageCacheRGB8Ptr searchImg = imgCache.getImage(
01696                         pano.getImage(cps[*it].image2Nr).getFilename())->get8BitImage();
01697 
01698                     ImageCache::ImageCacheRGB8Ptr templImg = imgCache.getImage(
01699                         pano.getImage(cps[*it].image1Nr).getFilename())->get8BitImage();
01700 
01701                     vigra_ext::CorrelationResult res;
01702                     vigra::Diff2D roundP1(hugin_utils::roundi(cps[*it].x1), hugin_utils::roundi(cps[*it].y1));
01703                     vigra::Diff2D roundP2(hugin_utils::roundi(cps[*it].x2), hugin_utils::roundi(cps[*it].y2));
01704 
01705                     res = PointFineTuneProjectionAware(pano.getImage(cps[*it].image1Nr), *templImg, roundP1, templWidth,
01706                         pano.getImage(cps[*it].image2Nr), *searchImg, roundP2, sWidth);
01707 
01708                     // invert curvature. we always assume its a maxima, the curvature there is negative
01709                     // however, we allow the user to specify a positive threshold, so we need to
01710                     // invert it
01711                     res.curv.x = - res.curv.x;
01712                     res.curv.y = - res.curv.y;
01713 
01714                     if (res.maxi < corrThresh || res.curv.x < curvThresh || res.curv.y < curvThresh ||
01715                         res.maxpos.x < 0 || res.maxpos.y < 0 || res.corrPos.x < 0 || res.corrPos.y < 0)
01716                     {
01717                         // Bad correlation result.
01718                         nBad++;
01719                         if (res.maxi >= corrThresh) {
01720                             cps[*it].error = 0;
01721                         }
01722                         cps[*it].error = res.maxi;
01723                         DEBUG_DEBUG("low correlation: " << res.maxi << " curv: " << res.curv);
01724                     } else {
01725                         nGood++;
01726                         // only update if a good correlation was found
01727                         cps[*it].x1 = res.corrPos.x;
01728                         cps[*it].y1 = res.corrPos.y;
01729                         cps[*it].x2 = res.maxpos.x;
01730                         cps[*it].y2 = res.maxpos.y;
01731                         cps[*it].error = res.maxi;
01732                     }
01733                 }
01734                 unsigned int rm = *it;
01735                 ++it;
01736                 unoptimized.erase(rm);
01737             } else {
01738                 ++it;
01739             }
01740         }
01741     }
01742     }
01743     wxString result;
01744     result.Printf(_("%d points fine-tuned, %d points not updated due to low correlation\n\nHint: The errors of the fine-tuned points have been set to the correlation coefficient\nProblematic points can be spotted (just after fine-tune, before optimizing)\nby an error <= %.3f.\nThe error of points without a well defined peak (typically in regions with uniform color)\nwill be set to 0\n\nUse the Control Point list (F3) to see all points of the current project\n"),
01745                   nGood, nBad, corrThresh);
01746     wxMessageBox(result, _("Fine-tune result"), wxOK);
01747     // set newly optimized points
01748     PanoCommand::GlobalCmdHist::getInstance().addCommand(
01749         new PanoCommand::UpdateCPsCmd(pano, cps, false)
01750         );
01751 }
01752 
01753 void MainFrame::OnRemoveCPinMasks(wxCommandEvent & e)
01754 {
01755     if(pano.getCtrlPoints().size()<2)
01756         return;
01757     HuginBase::UIntSet cps=getCPinMasks(pano);
01758     if(cps.size()>0)
01759     {
01760         PanoCommand::GlobalCmdHist::getInstance().addCommand(
01761                     new PanoCommand::RemoveCtrlPointsCmd(pano,cps)
01762                     );
01763         wxMessageBox(wxString::Format(_("Removed %lu control points"), static_cast<unsigned long>(cps.size())),
01764                    _("Removing control points in masks"),wxOK|wxICON_INFORMATION);
01765     };
01766 }
01767 
01768 #ifdef HUGIN_HSI
01769 void MainFrame::OnPythonScript(wxCommandEvent & e)
01770 {
01771     wxString fname;
01772     wxFileDialog dlg(wxGetActiveWindow(),
01773             _("Select python script"),
01774             wxConfigBase::Get()->Read(wxT("/lensPath"),wxT("")), wxT(""),
01775             _("Python script (*.py)|*.py|All files (*.*)|*.*"),
01776             wxFD_OPEN, wxDefaultPosition);
01777     dlg.SetDirectory(wxConfigBase::Get()->Read(wxT("/pythonScriptPath"),wxT("")));
01778 
01779     if (dlg.ShowModal() == wxID_OK)
01780     {
01781         wxString filename = dlg.GetPath();
01782         wxConfig::Get()->Write(wxT("/pythonScriptPath"), dlg.GetDirectory());
01783         std::string scriptfile((const char *)filename.mb_str(HUGIN_CONV_FILENAME));
01784         PanoCommand::GlobalCmdHist::getInstance().addCommand(
01785             new PanoCommand::PythonScriptPanoCmd(pano,scriptfile)
01786             );
01787     }
01788 }
01789 
01790 void MainFrame::OnPlugin(wxCommandEvent & e)
01791 {
01792     wxFileName file=m_plugins[e.GetId()];
01793     if(file.FileExists())
01794     {
01795         std::string scriptfile((const char *)file.GetFullPath().mb_str(HUGIN_CONV_FILENAME));
01796         PanoCommand::GlobalCmdHist::getInstance().addCommand(
01797                                  new PanoCommand::PythonScriptPanoCmd(pano,scriptfile)
01798                                  );
01799     }
01800     else
01801     {
01802         wxMessageBox(wxString::Format(wxT("Python-Script %s not found.\nStopping processing."),file.GetFullPath().c_str()),_("Warning"),wxOK|wxICON_INFORMATION);
01803     };
01804 }
01805 
01806 #endif
01807 
01808 void MainFrame::OnUndo(wxCommandEvent & e)
01809 {
01810     DEBUG_TRACE("OnUndo");
01811     if (PanoCommand::GlobalCmdHist::getInstance().canUndo())
01812     {
01813         PanoCommand::GlobalCmdHist::getInstance().undo();
01814     }
01815     else
01816     {
01817         wxBell();
01818     };
01819 }
01820 
01821 void MainFrame::OnRedo(wxCommandEvent & e)
01822 {
01823     DEBUG_TRACE("OnRedo");
01824     if (PanoCommand::GlobalCmdHist::getInstance().canRedo())
01825     {
01826         PanoCommand::GlobalCmdHist::getInstance().redo();
01827     };
01828 }
01829 
01830 void MainFrame::ShowCtrlPoint(unsigned int cpNr)
01831 {
01832     DEBUG_DEBUG("Showing control point " << cpNr);
01833     m_notebook->SetSelection(2);
01834     cpe->ShowControlPoint(cpNr);
01835 }
01836 
01837 void MainFrame::ShowCtrlPointEditor(unsigned int img1, unsigned int img2)
01838 {
01839     if(!IsShown())
01840     {
01841         Show();
01842         Raise();
01843     };
01844     m_notebook->SetSelection(2);
01845     cpe->setLeftImage(img1);
01846     cpe->setRightImage(img2);
01847 }
01848 
01849 void MainFrame::ShowMaskEditor(size_t imgNr)
01850 {
01851     if(!IsShown())
01852     {
01853         Show();
01854         Raise();
01855     };
01856     m_notebook->SetSelection(1);
01857     mask_panel->setImage(imgNr, true);
01858 };
01859 
01860 void MainFrame::ShowStitcherTab()
01861 {
01863     if(m_show_opt_panel && m_show_opt_photo_panel)
01864     {
01865         m_notebook->SetSelection(5);
01866     }
01867     else
01868     {
01869         if(m_show_opt_panel || m_show_opt_photo_panel)
01870         {
01871             m_notebook->SetSelection(4);
01872         }
01873         else
01874         {
01875             m_notebook->SetSelection(3);
01876         };
01877     };
01878 }
01879 
01881 void MainFrame::updateProgressDisplay()
01882 {
01883     wxString msg;
01884     if (!m_message.empty())
01885     {
01886         msg = wxGetTranslation(wxString(m_message.c_str(), wxConvLocal));
01887         if (!m_filename.empty())
01888         {
01889             msg.Append(wxT(" "));
01890             msg.Append(wxString(ProgressDisplay::m_filename.c_str(), HUGIN_CONV_FILENAME));
01891         };
01892     };
01893     GetStatusBar()->SetStatusText(msg, 0);
01894 
01895 #ifdef __WXMSW__
01896     UpdateWindow(NULL);
01897 #endif
01898 }
01899 
01900 void MainFrame::enableTools(bool option)
01901 {
01902     wxToolBar* theToolBar = GetToolBar();
01903     theToolBar->EnableTool(XRCID("action_optimize"), option);
01904     theToolBar->EnableTool(XRCID("ID_SHOW_PREVIEW_FRAME"), option);
01905     //theToolBar->EnableTool(XRCID("ID_SHOW_GL_PREVIEW_FRAME"), option);
01906     wxMenuBar* theMenuBar = GetMenuBar();
01907     theMenuBar->Enable(XRCID("action_optimize"), option);
01908     theMenuBar->Enable(XRCID("action_finetune_all_cp"), option);
01909     theMenuBar->Enable(XRCID("action_remove_cp_in_masks"), option);
01910     theMenuBar->Enable(XRCID("ID_SHOW_PREVIEW_FRAME"), option);
01911     theMenuBar->Enable(XRCID("action_stitch"), option);
01912     theMenuBar->Enable(XRCID("action_stitch_userdefined"), option);
01913     const int userOutputMenuId = theMenuBar->FindMenuItem(_("&Output"), _("User defined output sequences"));
01914     if (userOutputMenuId != wxNOT_FOUND)
01915     {
01916         theMenuBar->Enable(userOutputMenuId, option);
01917     };
01918     m_menu_file_advanced->Enable(XRCID("action_import_papywizard"), option);
01919     //theMenuBar->Enable(XRCID("ID_SHOW_GL_PREVIEW_FRAME"), option);
01920 }
01921 
01922 
01923 void MainFrame::OnSize(wxSizeEvent &e)
01924 {
01925 #ifdef DEBUG
01926     wxSize sz = this->GetSize();
01927     wxSize csz = this->GetClientSize();
01928     wxSize vsz = this->GetVirtualSize();
01929     DEBUG_TRACE(" size:" << sz.x << "," << sz.y <<
01930                 " client: "<< csz.x << "," << csz.y <<
01931                 " virtual: "<< vsz.x << "," << vsz.y);
01932 #endif
01933 
01934     Layout();
01935     e.Skip();
01936 }
01937 
01938 CPDetectorSetting& MainFrame::GetDefaultSetting()
01939 {
01940     return images_panel->GetDefaultSetting();
01941 };
01942 
01943 void MainFrame::RunCPGenerator(CPDetectorSetting &setting, const HuginBase::UIntSet& img)
01944 {
01945     images_panel->RunCPGenerator(setting, img);
01946 };
01947 
01948 void MainFrame::RunCPGenerator(const HuginBase::UIntSet& img)
01949 {
01950     images_panel->RunCPGenerator(img);
01951 };
01952 
01953 const wxString MainFrame::GetSelectedCPGenerator()
01954 {
01955     return images_panel->GetSelectedCPGenerator();
01956 };
01957 
01958 const wxString & MainFrame::GetXRCPath()
01959 {
01960      return huginApp::Get()->GetXRCPath();
01961 };
01962 
01963 const wxString & MainFrame::GetDataPath()
01964 {
01965     return wxGetApp().GetDataPath();
01966 };
01967 
01969 MainFrame * MainFrame::Get()
01970 {
01971     if (m_this) {
01972         return m_this;
01973     } else {
01974         DEBUG_FATAL("MainFrame not yet created");
01975         DEBUG_ASSERT(m_this);
01976         return 0;
01977     }
01978 }
01979 
01980 wxString MainFrame::getProjectName()
01981 {
01982     return m_filename;
01983 }
01984 
01985 void MainFrame::OnMRUFiles(wxCommandEvent &e)
01986 {
01987     size_t index = e.GetId() - wxID_FILE1;
01988     wxString f(m_mruFiles.GetHistoryFile(index));
01989     if (!f.empty())
01990     {
01991         wxFileName fn(f);
01992         if (fn.FileExists())
01993         {
01994             // if closing old project was canceled do nothing
01995             if (CloseProject(true, LOAD_NEW_PROJECT))
01996             {
01997                 // remove old images from cache
01998                 ImageCache::getInstance().flush();
01999                 // finally load project
02000                 LoadProjectFile(f);
02001             };
02002         }
02003         else
02004         {
02005             m_mruFiles.RemoveFileFromHistory(index);
02006             wxMessageBox(wxString::Format(_("File \"%s\" not found.\nMaybe file was renamed, moved or deleted."),f.c_str()),
02007                 _("Error!"),wxOK | wxICON_INFORMATION );
02008         };
02009     };
02010 }
02011 
02012 void MainFrame::OnFullScreen(wxCommandEvent & e)
02013 {
02014     ShowFullScreen(!IsFullScreen(), wxFULLSCREEN_NOBORDER | wxFULLSCREEN_NOCAPTION);
02015 #ifdef __WXGTK__
02016     //workaround a wxGTK bug that also the toolbar is hidden, but not requested to hide
02017     GetToolBar()->Show(true);
02018 #endif
02019 };
02020 
02021 struct celeste::svm_model* MainFrame::GetSVMModel()
02022 {
02023     if(svmModel==NULL)
02024     {
02025         // determine file name of SVM model file
02026         // get XRC path from application
02027         wxString wxstrModelFileName = huginApp::Get()->GetDataPath() + wxT(HUGIN_CELESTE_MODEL);
02028         // convert wxString to string
02029         std::string strModelFileName(wxstrModelFileName.mb_str(HUGIN_CONV_FILENAME));
02030 
02031         // SVM model file
02032         if (! wxFile::Exists(wxstrModelFileName) ) {
02033             wxMessageBox(wxString::Format(_("Celeste model expected in %s not found, Hugin needs to be properly installed."),wxstrModelFileName.c_str()), _("Fatal Error"));
02034             return NULL;
02035         }
02036         if(!celeste::loadSVMmodel(svmModel,strModelFileName))
02037         {
02038             wxMessageBox(wxString::Format(_("Could not load Celeste model file %s"),wxstrModelFileName.c_str()),_("Error"));
02039             svmModel=NULL;
02040         };
02041     }
02042     return svmModel;
02043 };
02044 
02045 GLPreviewFrame * MainFrame::getGLPreview()
02046 {
02047     return gl_preview_frame;
02048 }
02049 
02050 void MainFrame::SetGuiLevel(GuiLevel newLevel)
02051 {
02052     if(gl_preview_frame==NULL && newLevel==GUI_SIMPLE)
02053     {
02054         SetGuiLevel(GUI_ADVANCED);
02055         return;
02056     };
02057     if(m_guiLevel==GUI_EXPERT && newLevel!=GUI_EXPERT && pano.getOptimizerSwitch()==0)
02058     {
02059         bool needsUpdateOptimizerVar=false;
02060         HuginBase::OptimizeVector optVec = pano.getOptimizeVector();
02061         for(size_t i=0; i<optVec.size(); i++)
02062         {
02063             bool hasTrX=optVec[i].erase("TrX")>0;
02064             bool hasTrY=optVec[i].erase("TrY")>0;
02065             bool hasTrZ=optVec[i].erase("TrZ")>0;
02066             bool hasTpy=optVec[i].erase("Tpy")>0;
02067             bool hasTpp=optVec[i].erase("Tpp")>0;
02068             bool hasg=optVec[i].erase("g")>0;
02069             bool hast=optVec[i].erase("t")>0;
02070             needsUpdateOptimizerVar=needsUpdateOptimizerVar || hasTrX || hasTrY || hasTrZ || hasTpy || hasTpp || hasg || hast;
02071         };
02072         if(needsUpdateOptimizerVar)
02073         {
02074             PanoCommand::GlobalCmdHist::getInstance().addCommand(
02075                 new PanoCommand::UpdateOptimizeVectorCmd(pano, optVec)
02076             );
02077         };
02078     };
02079     if(newLevel==GUI_SIMPLE && pano.getPhotometricOptimizerSwitch()==0)
02080     {
02081         bool needsUpdateOptimizerVar=false;
02082         HuginBase::OptimizeVector optVec = pano.getOptimizeVector();
02083         for(size_t i=0; i<optVec.size(); i++)
02084         {
02085             bool hasVx=optVec[i].erase("Vx")>0;
02086             bool hasVy=optVec[i].erase("Vy")>0;
02087             needsUpdateOptimizerVar=needsUpdateOptimizerVar || hasVx || hasVy;
02088         };
02089         if(needsUpdateOptimizerVar)
02090         {
02091             PanoCommand::GlobalCmdHist::getInstance().addCommand(
02092                 new PanoCommand::UpdateOptimizeVectorCmd(pano, optVec)
02093             );
02094         };
02095     };
02096     m_guiLevel=newLevel;
02097     images_panel->SetGuiLevel(m_guiLevel);
02098     opt_panel->SetGuiLevel(m_guiLevel);
02099     opt_photo_panel->SetGuiLevel(m_guiLevel);
02100     pano_panel->SetGuiLevel(m_guiLevel);
02101     if(gl_preview_frame)
02102     {
02103         gl_preview_frame->SetGuiLevel(m_guiLevel);
02104     };
02105     switch(m_guiLevel)
02106     {
02107         case GUI_SIMPLE:
02108             GetMenuBar()->FindItem(XRCID("action_gui_simple"))->Check();
02109             break;
02110         case GUI_ADVANCED:
02111             GetMenuBar()->FindItem(XRCID("action_gui_advanced"))->Check();
02112             break;
02113         case GUI_EXPERT:
02114             GetMenuBar()->FindItem(XRCID("action_gui_expert"))->Check();
02115             break;
02116     };
02117     if(m_guiLevel==GUI_SIMPLE)
02118     {
02119         if(!gl_preview_frame->IsShown())
02120         {
02121             wxCommandEvent dummy;
02122             OnToggleGLPreviewFrame(dummy);
02123         };
02124         wxGetApp().SetTopWindow(gl_preview_frame);
02125         GetMenuBar()->Remove(0);
02126         GetMenuBar()->Insert(0, m_menu_file_simple, _("&File"));
02127         if(m_filename.IsEmpty())
02128         {
02129             gl_preview_frame->SetTitle(_("Hugin - Panorama Stitcher"));
02130             SetTitle(_("Panorama editor"));
02131         }
02132         else
02133         {
02134             wxFileName scriptName = m_filename;
02135             gl_preview_frame->SetTitle(scriptName.GetName() + wxT(".") + scriptName.GetExt() + wxT(" - ") + _("Hugin - Panorama Stitcher"));
02136             SetTitle(scriptName.GetName() + wxT(".") + scriptName.GetExt() + wxT(" - ") + _("Panorama editor"));
02137         };
02138         Hide();
02139     }
02140     else
02141     {
02142         wxGetApp().SetTopWindow(this);
02143         GetMenuBar()->Remove(0);
02144         GetMenuBar()->Insert(0, m_menu_file_advanced, _("&File"));
02145         if(m_filename.IsEmpty())
02146         {
02147             SetTitle(_("Hugin - Panorama Stitcher"));
02148         }
02149         else
02150         {
02151             wxFileName scriptName = m_filename;
02152             SetTitle(scriptName.GetName() + wxT(".") + scriptName.GetExt() + wxT(" - ") + _("Hugin - Panorama Stitcher"));
02153         };
02154         if(!IsShown())
02155         {
02156             Show();
02157         };
02158     };
02159 };
02160 
02161 void MainFrame::OnSetGuiSimple(wxCommandEvent & e)
02162 {
02163     GuiLevel reqGuiLevel=GetMinimumGuiLevel(pano);
02164     if(reqGuiLevel<=GUI_SIMPLE)
02165     {
02166         SetGuiLevel(GUI_SIMPLE);
02167     }
02168     else
02169     {
02170         if(reqGuiLevel==GUI_ADVANCED)
02171         {
02172             wxMessageBox(_("Can't switch to simple interface. The project is using stacks and/or vignetting center shift.\nThese features are not supported in simple interface."),
02173 #ifdef __WXMSW__
02174                          wxT("Hugin"),
02175 #else
02176                          wxT(""),
02177 #endif
02178                          wxOK | wxICON_INFORMATION);
02179         }
02180         else
02181         {
02182             wxMessageBox(_("Can't switch to simple interface. The project is using translation or shear parameters.\nThese parameters are not supported in simple interface."),
02183 #ifdef __WXMSW__
02184                          wxT("Hugin"),
02185 #else
02186                          wxT(""),
02187 #endif
02188                          wxOK | wxICON_INFORMATION);
02189         }
02190         SetGuiLevel(m_guiLevel);
02191     };
02192 };
02193 
02194 void MainFrame::OnSetGuiAdvanced(wxCommandEvent & e)
02195 {
02196     GuiLevel reqGuiLevel=GetMinimumGuiLevel(pano);
02197     if(reqGuiLevel<=GUI_ADVANCED)
02198     {
02199         SetGuiLevel(GUI_ADVANCED);
02200     }
02201     else
02202     {
02203         wxMessageBox(_("Can't switch to advanced interface. The project is using translation or shear parameters.\nThese parameters are not supported in advanced interface."),
02204 #ifdef __WXMSW__
02205                      wxT("Hugin"),
02206 #else
02207                      wxT(""),
02208 #endif
02209                      wxOK | wxICON_INFORMATION);
02210         SetGuiLevel(GUI_EXPERT);
02211     };
02212 };
02213 
02214 void MainFrame::OnSetGuiExpert(wxCommandEvent & e)
02215 {
02216     SetGuiLevel(GUI_EXPERT);
02217 };
02218 
02219 void MainFrame::DisableOpenGLTools()
02220 {
02221     GetMenuBar()->Enable(XRCID("ID_SHOW_GL_PREVIEW_FRAME"), false);
02222     GetMenuBar()->Enable(XRCID("action_gui_simple"), false);
02223     GetToolBar()->EnableTool(XRCID("ID_SHOW_GL_PREVIEW_FRAME"), false); 
02224 };
02225 
02226 void MainFrame::RunAssistant(wxWindow* mainWin)
02227 {
02228     //save project into temp directory
02229     wxString tempDir= wxConfig::Get()->Read(wxT("tempDir"),wxT(""));
02230     if(!tempDir.IsEmpty())
02231     {
02232         if(tempDir.Last()!=wxFileName::GetPathSeparator())
02233         {
02234             tempDir.Append(wxFileName::GetPathSeparator());
02235         }
02236     };
02237     wxFileName scriptFileName(wxFileName::CreateTempFileName(tempDir+wxT("ha")));
02238     std::ofstream script(scriptFileName.GetFullPath().mb_str(HUGIN_CONV_FILENAME));
02239     script.exceptions ( std::ofstream::eofbit | std::ofstream::failbit | std::ofstream::badbit );
02240     HuginBase::UIntSet all;
02241     fill_set(all, 0, pano.getNrOfImages()-1);
02242     pano.printPanoramaScript(script, pano.getOptimizeVector(), pano.getOptions(), all, false);
02243     script.close();
02244 
02245     // get assistant queue
02246     const wxFileName exePath(wxStandardPaths::Get().GetExecutablePath());
02247     HuginQueue::CommandQueue* commands = HuginQueue::GetAssistantCommandQueue(pano, exePath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR), scriptFileName.GetFullPath());
02248     //execute queue
02249     int ret = MyExecuteCommandQueue(commands, mainWin, _("Running assistant"));
02250 
02251     //read back panofile
02252     PanoCommand::GlobalCmdHist::getInstance().addCommand(new PanoCommand::wxLoadPTProjectCmd(pano,
02253         (const char *)scriptFileName.GetFullPath().mb_str(HUGIN_CONV_FILENAME), 
02254         (const char *)scriptFileName.GetPath(wxPATH_NATIVE | wxPATH_GET_SEPARATOR).mb_str(HUGIN_CONV_FILENAME), 
02255         ret==0, false));
02256 
02257     //delete temporary files
02258     wxRemoveFile(scriptFileName.GetFullPath());
02259     //if return value is non-zero, an error occurred in the assistant
02260     if(ret!=0)
02261     {
02262         if (pano.getNrOfImages())
02263         {
02264             wxMessageBox(_("The assistant could not find vertical lines. Please add vertical lines in the panorama editor and optimize project manually."),
02265                 _("Warning"), wxOK | wxICON_INFORMATION, mainWin);
02266         }
02267         else
02268         {
02269             //check for unconnected images
02270             HuginGraph::ImageGraph graph(pano);
02271             const HuginGraph::ImageGraph::Components comps = graph.GetComponents();
02272             if (comps.size() > 1)
02273             {
02274                 // switch to images panel.
02275                 unsigned i1 = *(comps[0].rbegin());
02276                 unsigned i2 = *(comps[1].begin());
02277                 ShowCtrlPointEditor(i1, i2);
02278                 // display message box with 
02279                 wxMessageBox(wxString::Format(_("Warning %d unconnected image groups found:"), static_cast<int>(comps.size())) + Components2Str(comps) + wxT("\n")
02280                     + _("Please create control points between unconnected images using the Control Points tab in the panorama editor.\n\nAfter adding the points, press the \"Align\" button again"), _("Error"), wxOK, mainWin);
02281                 return;
02282             };
02283             wxMessageBox(_("The assistant did not complete successfully. Please check the resulting project file."),
02284                 _("Warning"), wxOK | wxICON_INFORMATION, mainWin);
02285         };
02286     };
02287 };
02288 
02289 void MainFrame::OnRunAssistant(wxCommandEvent & e)
02290 {
02291     RunAssistant(this);
02292 };
02293 
02294 void MainFrame::OnSendToAssistantQueue(wxCommandEvent &e)
02295 {
02296     wxCommandEvent dummy;
02297     OnSaveProject(dummy);
02298     wxString projectFile = getProjectName();
02299     if(wxFileName::FileExists(projectFile))
02300     {
02301 #if defined __WXMAC__ && defined MAC_SELF_CONTAINED_BUNDLE
02302         // Original patch for OSX by Charlie Reiman dd. 18 June 2011
02303         // Slightly modified by HvdW. Errors in here are mine, not Charlie's. 
02304         FSRef appRef;
02305         FSRef actuallyLaunched;
02306         OSStatus err;
02307         FSRef documentArray[1]; // Don't really need an array if we only have 1 item
02308         LSLaunchFSRefSpec launchSpec;
02309         Boolean  isDir;
02310 
02311         err = LSFindApplicationForInfo(kLSUnknownCreator,
02312                                        CFSTR("net.sourceforge.hugin.PTBatcherGUI"),
02313                                        NULL,
02314                                        &appRef,
02315                                        NULL);
02316         if (err != noErr)
02317         {
02318             // error, can't find PTBatcherGUI
02319             wxMessageBox(wxString::Format(_("External program %s not found in the bundle, reverting to system path"), wxT("open")), _("Error"));
02320             // Possibly a silly attempt otherwise the previous would have worked as well, but just try it.
02321             wxExecute(_T("open -b net.sourceforge.hugin.PTBatcherGUI ")+hugin_utils::wxQuoteFilename(projectFile));
02322             return;
02323         }
02324 
02325         wxCharBuffer projectFilebuffer=projectFile.ToUTF8();
02326         // Point to document
02327         err = FSPathMakeRef((unsigned char*) projectFilebuffer.data(), &documentArray[0], &isDir);
02328         if (err != noErr || isDir)
02329         {
02330             // Something went wrong.
02331             wxMessageBox(wxString::Format(_("Project file not found"), wxT("open")), _("Error"));
02332             return;
02333         }
02334         launchSpec.appRef = &appRef;
02335         launchSpec.numDocs = sizeof(documentArray)/sizeof(documentArray[0]);
02336         launchSpec.itemRefs = documentArray;
02337         launchSpec.passThruParams = NULL;
02338         launchSpec.launchFlags = kLSLaunchDontAddToRecents + kLSLaunchDontSwitch;
02339         launchSpec.asyncRefCon = NULL;
02340 
02341         err = LSOpenFromRefSpec(&launchSpec, &actuallyLaunched);
02342         if (err != noErr && err != kLSLaunchInProgressErr)
02343         {  
02344             // Should be ok if it's in progress... I think. 
02345             // Launch failed.
02346             wxMessageBox(wxString::Format(_("Can't launch PTBatcherGui"), wxT("open")), _("Error"));
02347             return;
02348         }
02349 
02350         // Should verify that actuallyLaunched and appRef are the same.
02351         if (FSCompareFSRefs(&appRef, &actuallyLaunched) != noErr)
02352         {
02353             // error, lauched the wrong thing.
02354             wxMessageBox(wxString::Format(_("Launched incorrect programme"), wxT("open")), _("Error"));
02355             return;
02356         }
02357 #else
02358         const wxFileName exePath(wxStandardPaths::Get().GetExecutablePath());
02359         wxExecute(exePath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR) + wxT("PTBatcherGUI -a ")+hugin_utils::wxQuoteFilename(projectFile));
02360 #endif
02361     }
02362 };
02363 
02364 wxString MainFrame::GetCurrentOptimizerString()
02365 {
02366     return images_panel->GetCurrentOptimizerString();
02367 };
02368 
02369 MainFrame * MainFrame::m_this = 0;

Generated on 26 May 2017 for Hugintrunk by  doxygen 1.4.7