PreviewFrame.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00002 
00027 // use toggle buttons or uncomment check boxes
00028 
00029 //#ifndef __WXMAC__
00030 #define USE_TOGGLE_BUTTON 1
00031 //#endif
00032 //wxMac now has toggle buttons.
00033 
00034 #include <config.h>
00035 
00036 #include "panoinc_WX.h"
00037 
00038 #include "panoinc.h"
00039 
00040 #include "base_wx/platform.h"
00041 #include "hugin/config_defaults.h"
00042 #include "hugin/PreviewFrame.h"
00043 #include "hugin/huginApp.h"
00044 #include "hugin/PreviewPanel.h"
00045 #include "hugin/ImagesPanel.h"
00046 #include "base_wx/CommandHistory.h"
00047 #include "base_wx/PanoCommand.h"
00048 #include "hugin/TextKillFocusHandler.h"
00049 #include "algorithms/nona/FitPanorama.h"
00050 #include "algorithms/basic/CalculateMeanExposure.h"
00051 #include "base_wx/wxPlatform.h"
00052 
00053 #include <vigra_ext/ImageTransforms.h>
00054 
00055 extern "C" {
00056 #include <pano13/queryfeature.h>
00057 }
00058 
00059 using namespace hugin_utils;
00060 
00061 // a random id, hope this doesn't break something..
00062 enum {
00063     ID_PROJECTION_CHOICE = wxID_HIGHEST +1,
00064     ID_BLEND_CHOICE,
00065     ID_UPDATE_BUTTON,
00066     ID_OUTPUTMODE_CHOICE,
00067     ID_EXPOSURE_TEXT,
00068     ID_EXPOSURE_SPIN,
00069     ID_EXPOSURE_DEFAULT,
00070     ID_TOGGLE_BUT = wxID_HIGHEST+100,
00071     PROJ_PARAM_NAMES_ID = wxID_HIGHEST+1000,
00072     PROJ_PARAM_VAL_ID = wxID_HIGHEST+1100,
00073     PROJ_PARAM_SLIDER_ID = wxID_HIGHEST+1200,
00074     PROJ_PARAM_RESET_ID = wxID_HIGHEST+1250,
00075     ID_FULL_SCREEN = wxID_HIGHEST+1700,
00076     ID_UNDO = wxID_HIGHEST+1701,
00077     ID_REDO = wxID_HIGHEST+1702
00078 };
00079 
00080 BEGIN_EVENT_TABLE(PreviewFrame, wxFrame)
00081     EVT_CLOSE(PreviewFrame::OnClose)
00082 //    EVT_CHECKBOX(-1, PreviewFrame::OnAutoPreviewToggle)
00083     EVT_TOOL(XRCID("preview_center_tool"), PreviewFrame::OnCenterHorizontally)
00084     EVT_TOOL(XRCID("preview_fit_pano_tool"), PreviewFrame::OnFitPano)
00085     EVT_TOOL(XRCID("preview_straighten_pano_tool"), PreviewFrame::OnStraighten)
00086     EVT_TOOL(XRCID("preview_auto_update_tool"), PreviewFrame::OnAutoPreviewToggle)
00087     EVT_TOOL(XRCID("preview_update_tool"), PreviewFrame::OnUpdate)
00088     EVT_TOOL(XRCID("preview_show_all_tool"), PreviewFrame::OnShowAll)
00089     EVT_TOOL(XRCID("preview_show_none_tool"), PreviewFrame::OnShowNone)
00090     EVT_TOOL(XRCID("preview_num_transform"), PreviewFrame::OnNumTransform)
00091     EVT_TEXT_ENTER( -1 , PreviewFrame::OnTextCtrlChanged)
00092 
00093     EVT_BUTTON(ID_EXPOSURE_DEFAULT, PreviewFrame::OnDefaultExposure)
00094     EVT_SPIN_DOWN(ID_EXPOSURE_SPIN, PreviewFrame::OnDecreaseExposure)
00095     EVT_SPIN_UP(ID_EXPOSURE_SPIN, PreviewFrame::OnIncreaseExposure)
00096     EVT_CHOICE(ID_BLEND_CHOICE, PreviewFrame::OnBlendChoice)
00097     EVT_CHOICE(ID_PROJECTION_CHOICE, PreviewFrame::OnProjectionChoice)
00098     EVT_CHOICE(ID_OUTPUTMODE_CHOICE, PreviewFrame::OnOutputChoice)
00099 #ifdef USE_TOGGLE_BUTTON
00100     EVT_TOGGLEBUTTON(-1, PreviewFrame::OnChangeDisplayedImgs)
00101 #else
00102     EVT_CHECKBOX(-1, PreviewFrame::OnChangeDisplayedImgs)
00103 #endif
00104 #ifndef __WXMAC__
00105         EVT_SCROLL_CHANGED(PreviewFrame::OnChangeFOV)
00106 #else
00107  #if wxCHECK_VERSION(2,9,0)
00108         EVT_SCROLL_CHANGED(PreviewFrame::OnChangeFOV)
00109  #else
00110         EVT_SCROLL_THUMBRELEASE(PreviewFrame::OnChangeFOV)
00111         EVT_SCROLL_ENDSCROLL(PreviewFrame::OnChangeFOV)
00112         EVT_SCROLL_THUMBTRACK(PreviewFrame::OnChangeFOV)
00113  #endif
00114 #endif
00115         EVT_TOOL(ID_FULL_SCREEN, PreviewFrame::OnFullScreen)
00116     EVT_TOOL(ID_UNDO, PreviewFrame::OnUndo)
00117     EVT_TOOL(ID_REDO, PreviewFrame::OnRedo)
00118     EVT_BUTTON(PROJ_PARAM_RESET_ID, PreviewFrame::OnProjParameterReset)
00119 END_EVENT_TABLE()
00120 
00121 #define PF_STYLE (wxMAXIMIZE_BOX | wxMINIMIZE_BOX | wxRESIZE_BORDER | wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX | wxCLIP_CHILDREN)
00122 
00123 PreviewFrame::PreviewFrame(wxFrame * frame, HuginBase::Panorama &pano)
00124     : wxFrame(frame,-1, _("Panorama preview"), wxDefaultPosition, wxDefaultSize,
00125               PF_STYLE),
00126       m_pano(pano)
00127 {
00128         DEBUG_TRACE("");
00129 
00130     m_oldProjFormat = -1;
00131     m_ToolBar = wxXmlResource::Get()->LoadToolBar(this, wxT("preview_toolbar"));
00132     DEBUG_ASSERT(m_ToolBar);
00133     // create tool bar
00134     SetToolBar(m_ToolBar);
00135 
00136     m_topsizer = new wxBoxSizer( wxVERTICAL );
00137 
00138     m_ToggleButtonSizer = new wxStaticBoxSizer(
00139         new wxStaticBox(this, -1, _("displayed images")),
00140     wxHORIZONTAL );
00141 
00142         m_ButtonPanel = new wxScrolledWindow(this, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
00143         // Set min height big enough to display scrollbars as well
00144     m_ButtonPanel->SetSizeHints(20, 42);
00145         //Horizontal scroll bars only
00146         m_ButtonPanel->SetScrollRate(10, 0);
00147     m_ButtonSizer = new wxBoxSizer(wxHORIZONTAL);
00148     m_ButtonPanel->SetAutoLayout(true);
00149         m_ButtonPanel->SetSizer(m_ButtonSizer);
00150                                                 
00151         m_ToggleButtonSizer->Add(m_ButtonPanel, 1, wxEXPAND, 0);
00152 
00153     m_topsizer->Add(m_ToggleButtonSizer, 0, wxEXPAND | wxALL, 5);
00154 
00155     wxFlexGridSizer * flexSizer = new wxFlexGridSizer(2,0,5,5);
00156     flexSizer->AddGrowableCol(0);
00157     flexSizer->AddGrowableRow(0);
00158 
00159     // create our preview panel
00160     m_PreviewPanel = new PreviewPanel();
00161     m_PreviewPanel->Create(this);
00162     m_PreviewPanel->Init(this, &pano);
00163 
00164     flexSizer->Add(m_PreviewPanel,
00165                   1,        // not vertically stretchable
00166                   wxEXPAND | // horizontally stretchable
00167                   wxALL,    // draw border all around
00168                   5);       // border width
00169 
00170 
00171     m_VFOVSlider = new wxSlider(this, -1, 1,
00172                                 1, 180,
00173                                 wxDefaultPosition, wxDefaultSize,
00174                                 wxSL_VERTICAL | wxSL_AUTOTICKS,
00175                                 wxDefaultValidator,
00176                                 _("VFOV"));
00177     m_VFOVSlider->SetLineSize(2);
00178     m_VFOVSlider->SetPageSize(10);
00179 #if wxCHECK_VERSION(3,0,0)
00180     m_VFOVSlider->SetTickFreq(5);
00181 #else
00182     m_VFOVSlider->SetTickFreq(5,0);
00183 #endif
00184     m_VFOVSlider->SetToolTip(_("drag to change the vertical field of view"));
00185 
00186     flexSizer->Add(m_VFOVSlider, 0, wxEXPAND);
00187 
00188     m_HFOVSlider = new wxSlider(this, -1, 1,
00189                                 1, 360,
00190                                 wxDefaultPosition, wxDefaultSize,
00191                                 wxSL_HORIZONTAL | wxSL_AUTOTICKS,
00192                                 wxDefaultValidator,
00193                                 _("HFOV"));
00194     m_HFOVSlider->SetPageSize(10);
00195     m_HFOVSlider->SetLineSize(2);
00196 #if wxCHECK_VERSION(3,0,0)
00197     m_HFOVSlider->SetTickFreq(5);
00198 #else
00199     m_HFOVSlider->SetTickFreq(5,0);
00200 #endif
00201 
00202     m_HFOVSlider->SetToolTip(_("drag to change the horizontal field of view"));
00203 
00204     flexSizer->Add(m_HFOVSlider, 0, wxEXPAND);
00205 
00206     m_topsizer->Add(flexSizer,
00207                   1,        // vertically stretchable
00208                   wxEXPAND | // horizontally stretchable
00209                   wxALL,    // draw border all around
00210                   5);       // border width
00211 
00212     wxStaticBoxSizer * blendModeSizer = new wxStaticBoxSizer(
00213         new wxStaticBox(this, -1, _("Preview Options")),
00214         wxHORIZONTAL);
00215 
00216     blendModeSizer->Add(new wxStaticText(this, -1, _("projection (f):")),
00217                         0,        // not vertically strechable
00218                         wxALL | wxALIGN_CENTER_VERTICAL, // draw border all around
00219                         5);       // border width
00220     m_ProjectionChoice = new wxChoice(this, ID_PROJECTION_CHOICE,
00221                                       wxDefaultPosition, wxDefaultSize);
00222 
00223     /* populate with all available projection types */
00224     int nP = panoProjectionFormatCount();
00225     for(int n=0; n < nP; n++) {
00226         pano_projection_features proj;
00227         if (panoProjectionFeaturesQuery(n, &proj)) {
00228             wxString str2(proj.name, wxConvLocal);
00229             m_ProjectionChoice->Append(wxGetTranslation(str2));
00230         }
00231     }
00232     m_ProjectionChoice->SetSelection(2);
00233 
00234     blendModeSizer->Add(m_ProjectionChoice,
00235                         0,
00236                         wxALL | wxALIGN_CENTER_VERTICAL,
00237                         5);
00238 
00240     // Blend mode
00241     blendModeSizer->Add(new wxStaticText(this, -1, _("Blend mode:")),
00242                         0,        // not vertically strechable
00243                         wxALL | wxALIGN_CENTER_VERTICAL, // draw border all around
00244                         5);       // border width
00245 
00246     m_choices[0] = _("normal");
00247     m_choices[1] = _("difference");
00248 
00249     int oldMode = wxConfigBase::Get()->Read(wxT("/PreviewFrame/blendMode"), 0l);
00250     if (oldMode > 1) oldMode = 0;
00251     m_BlendModeChoice = new wxChoice(this, ID_BLEND_CHOICE,
00252                                      wxDefaultPosition, wxDefaultSize,
00253                                      2, m_choices);
00254     m_BlendModeChoice->SetSelection((PreviewPanel::BlendMode) oldMode);
00255 
00256     blendModeSizer->Add(m_BlendModeChoice,
00257                         0,
00258                         wxALL | wxALIGN_CENTER_VERTICAL,
00259                         5);
00260 
00262     // LDR, HDR
00263     blendModeSizer->Add(new wxStaticText(this, -1, _("Output:")),
00264                         0,        // not vertically strechable
00265                         wxALL | wxALIGN_CENTER_VERTICAL, // draw border all around
00266                         5);       // border width
00267 
00268     m_choices[0] = _("LDR");
00269     m_choices[1] = _("HDR");
00270     m_outputModeChoice = new wxChoice(this, ID_OUTPUTMODE_CHOICE,
00271                                       wxDefaultPosition, wxDefaultSize,
00272                                       2, m_choices);
00273     m_outputModeChoice->SetSelection(0);
00274     blendModeSizer->Add(m_outputModeChoice,
00275                         0,
00276                         wxALL | wxALIGN_CENTER_VERTICAL,
00277                         5);
00278 
00280     // exposure
00281     blendModeSizer->Add(new wxStaticText(this, -1, _("EV:")),
00282                           0,        // not vertically strechable
00283                           wxALL | wxALIGN_CENTER_VERTICAL, // draw border all around
00284                           5);       // border width
00285     
00286     m_defaultExposureBut = new wxBitmapButton(this, ID_EXPOSURE_DEFAULT,
00287                                               wxArtProvider::GetBitmap(wxART_REDO));
00288     blendModeSizer->Add(m_defaultExposureBut, 0, wxLEFT | wxRIGHT, 5);
00289 
00290 //    m_decExposureBut = new wxBitmapButton(this, ID_EXPOSURE_DECREASE,
00291 //                                          wxArtProvider::GetBitmap(wxART_GO_BACK));
00292 //    blendModeSizer->Add(m_decExposureBut);
00293 
00294     m_exposureTextCtrl = new wxTextCtrl(this, ID_EXPOSURE_TEXT, wxT("0"),
00295                                         wxDefaultPosition,wxSize(50,-1), wxTE_PROCESS_ENTER);
00296     blendModeSizer->Add(m_exposureTextCtrl,
00297                           0,        // not vertically strechable
00298                           wxLEFT | wxTOP | wxBOTTOM  | wxEXPAND | wxALIGN_CENTER_VERTICAL, // draw border all around
00299                           5);       // border width
00300 //    m_incExposureBut = new wxBitmapButton(this, ID_EXPOSURE_INCREASE,
00301 //                                          wxArtProvider::GetBitmap(wxART_GO_FORWARD));
00302     m_exposureSpinBut = new wxSpinButton(this, ID_EXPOSURE_SPIN, wxDefaultPosition,
00303                                          wxDefaultSize, wxSP_VERTICAL);
00304     m_exposureSpinBut->SetRange(-0x8000, 0x7fff);
00305     m_exposureSpinBut->SetValue(0);
00306     blendModeSizer->Add(m_exposureSpinBut, 0, wxALIGN_CENTER_VERTICAL);
00307 
00308     m_topsizer->Add(blendModeSizer, 0, wxEXPAND | wxALL, 5);
00309 
00310     m_projParamSizer = new wxStaticBoxSizer(
00311     new wxStaticBox(this, -1, _("Projection Parameters")),
00312      wxHORIZONTAL);
00313 
00314     wxBitmapButton * resetProjButton=new wxBitmapButton(this, PROJ_PARAM_RESET_ID, 
00315         wxArtProvider::GetBitmap(wxART_REDO));
00316     resetProjButton->SetToolTip(_("Resets the projection's parameters to their default values."));
00317     m_projParamSizer->Add(resetProjButton, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
00318 
00319     m_projParamNamesLabel.resize(PANO_PROJECTION_MAX_PARMS);
00320     m_projParamTextCtrl.resize(PANO_PROJECTION_MAX_PARMS);
00321     m_projParamSlider.resize(PANO_PROJECTION_MAX_PARMS);
00322 
00323     for (int i=0; i < PANO_PROJECTION_MAX_PARMS; i++) {
00324 
00325         m_projParamNamesLabel[i] = new wxStaticText(this, PROJ_PARAM_NAMES_ID+i, _("param:"));
00326         m_projParamSizer->Add(m_projParamNamesLabel[i],
00327                         0,        // not vertically strechable
00328                         wxALL | wxALIGN_CENTER_VERTICAL, // draw border all around
00329                         5);       // border width
00330         m_projParamTextCtrl[i] = new wxTextCtrl(this, PROJ_PARAM_VAL_ID+i, wxT("0"),
00331                                     wxDefaultPosition, wxSize(35,-1), wxTE_PROCESS_ENTER);
00332         m_projParamTextCtrl[i]->PushEventHandler(new TextKillFocusHandler(this));
00333         m_projParamSizer->Add(m_projParamTextCtrl[i],
00334                         0,        // not vertically strechable
00335                         wxALL | wxEXPAND | wxALIGN_CENTER_VERTICAL, // draw border all around
00336                         5);       // border width
00337 
00338         m_projParamSlider[i] = new wxSlider(this, PROJ_PARAM_SLIDER_ID+i, 0, -90, 90);
00339         m_projParamSizer->Add(m_projParamSlider[i],
00340                         1,        // not vertically strechable
00341                         wxALL | wxALIGN_CENTER_VERTICAL | wxEXPAND, // draw border all around
00342                         5);       // border width
00343     }
00344 
00345     m_topsizer->Add(m_projParamSizer, 0, wxEXPAND | wxALL, 5);
00346 
00347     // do not show projection param sizer
00348     m_topsizer->Show(m_projParamSizer, false, true);
00349 
00350     wxConfigBase * config = wxConfigBase::Get();
00351 
00352     // add a status bar
00353     CreateStatusBar(3);
00354     int widths[3] = {-3, 150, 150};
00355     SetStatusWidths(3, widths);
00356     SetStatusText(_("Left click to define new center point, right click to move point to horizon."),0);
00357     SetStatusText(wxT(""),1);
00358     SetStatusText(wxT(""),2);
00359 
00360     // the initial size as calculated by the sizers
00361     this->SetSizer( m_topsizer );
00362     m_topsizer->SetSizeHints( this );
00363 
00364     // set the minimize icon
00365 #ifdef __WXMSW__
00366     wxIcon myIcon(huginApp::Get()->GetXRCPath() + wxT("data/hugin.ico"),wxBITMAP_TYPE_ICO);
00367 #else
00368     wxIcon myIcon(huginApp::Get()->GetXRCPath() + wxT("data/hugin.png"),wxBITMAP_TYPE_PNG);
00369 #endif
00370     SetIcon(myIcon);
00371 
00372     m_pano.addObserver(this);
00373 
00374     RestoreFramePosition(this, wxT("PreviewFrame"));
00375     
00376     m_PreviewPanel->SetBlendMode((PreviewPanel::BlendMode)oldMode );
00377 
00378     long aup = config->Read(wxT("/PreviewFrame/autoUpdate"),0l);
00379     m_PreviewPanel->SetAutoUpdate(aup != 0);
00380 
00381     m_ToolBar->ToggleTool(XRCID("preview_auto_update_tool"), aup !=0);
00382 
00383 #ifdef __WXMSW__
00384     // wxFrame does have a strange background color on Windows..
00385     this->SetBackgroundColour(m_PreviewPanel->GetBackgroundColour());
00386 #endif
00387 
00388     if (config->Read(wxT("/PreviewFrame/isShown"), 0l) != 0) {
00389         Show();
00390     }
00391     SetStatusText(_("Center panorama with left mouse button, set horizon with right button"),0);
00392     wxAcceleratorEntry entries[3];
00393 #ifdef __WXMAC
00394     entries[0].Set(wxACCEL_CMD,(int)'F',ID_FULL_SCREEN);
00395 #else
00396     entries[0].Set(wxACCEL_NORMAL,WXK_F11,ID_FULL_SCREEN);
00397 #endif
00398     entries[1].Set(wxACCEL_CMD,(int)'Z',ID_UNDO);
00399     entries[2].Set(wxACCEL_CMD,(int)'R',ID_REDO);
00400     wxAcceleratorTable accel(3, entries);
00401     SetAcceleratorTable(accel);
00402 #ifdef __WXGTK__
00403     // set explicit focus to button panel, otherwise the hotkey F11 is not right processed
00404     m_ButtonPanel->SetFocus();
00405 #endif
00406 }
00407 
00408 PreviewFrame::~PreviewFrame()
00409 {
00410     DEBUG_TRACE("dtor writing config");
00411     wxConfigBase * config = wxConfigBase::Get();
00412     wxSize sz = GetClientSize();
00413 
00414     StoreFramePosition(this, wxT("PreviewFrame"));
00415 
00416     if ( (!this->IsIconized()) && (! this->IsMaximized()) && this->IsShown()) {
00417         config->Write(wxT("/PreviewFrame/isShown"), 1l);
00418     } else {
00419         config->Write(wxT("/PreviewFrame/isShown"), 0l);
00420     }
00421 
00422     bool checked = m_ToolBar->GetToolState(XRCID("preview_auto_update_tool"));
00423     config->Write(wxT("/PreviewFrame/autoUpdate"), checked ? 1l: 0l);
00424     config->Write(wxT("/PreviewFrame/blendMode"), m_BlendModeChoice->GetSelection());
00425     for (int i=0; i < PANO_PROJECTION_MAX_PARMS; i++)
00426     {
00427         m_projParamTextCtrl[i]->PopEventHandler(true);
00428     };
00429     m_pano.removeObserver(this);
00430     DEBUG_TRACE("dtor end");
00431 }
00432 
00433 void PreviewFrame::OnChangeDisplayedImgs(wxCommandEvent & e)
00434 {
00435     int id = e.GetId() - ID_TOGGLE_BUT;
00436     int nImg = m_pano.getNrOfImages();
00437     UIntSet activeImages = m_pano.getActiveImages();
00438     DEBUG_DEBUG("toggle_button_id: " << id << " nImg:" << nImg << "  m_ToggleButtons.size(): " << m_ToggleButtons.size());
00439     if (id >= 0 && id < nImg) {
00440         if (e.IsChecked()) {
00441             activeImages.insert(id);
00442         } else {
00443             activeImages.erase(id);
00444         }
00445 //        m_PreviewPanel->SetDisplayedImages(m_displayedImgs);
00446         PanoCommand::GlobalCmdHist::getInstance().addCommand(
00447             new PanoCommand::SetActiveImagesCmd(m_pano, activeImages)
00448         );
00449     } else {
00450         DEBUG_ERROR("invalid Togglebutton ID");
00451     }
00452 }
00453 
00454 void PreviewFrame::panoramaChanged(Panorama &pano)
00455 {
00456     const HuginBase::PanoramaOptions & opts = pano.getOptions();
00457 
00458     wxString projection;
00459     m_ProjectionChoice->SetSelection(opts.getProjection());
00460     m_VFOVSlider->Enable( opts.fovCalcSupported(opts.getProjection()) );
00461 
00462     m_outputModeChoice->SetSelection(opts.outputMode);
00463     if (opts.outputMode == HuginBase::PanoramaOptions::OUTPUT_HDR) {
00464         /*
00465         m_exposureTextCtrl->Hide();
00466         m_defaultExposureBut->Hide();
00467         m_decExposureBut->Hide();
00468         m_incExposureBut->Hide();
00469         */
00470     } else {
00471         /*
00472         m_exposureTextCtrl->Show();
00473         m_defaultExposureBut->Show();
00474         m_decExposureBut->Show();
00475         m_incExposureBut->Show();
00476         */
00477     }
00478     m_exposureTextCtrl->SetValue(wxString(doubleToString(opts.outputExposureValue,2).c_str(), wxConvLocal));
00479 
00480     bool activeImgs = pano.getActiveImages().size() > 0;
00481     m_ToolBar->EnableTool(XRCID("preview_center_tool"), activeImgs);
00482     m_ToolBar->EnableTool(XRCID("preview_fit_pano_tool"), activeImgs);
00483     m_ToolBar->EnableTool(XRCID("preview_update_tool"), activeImgs);
00484     m_ToolBar->EnableTool(XRCID("preview_num_transform"), activeImgs);
00485     m_ToolBar->EnableTool(XRCID("preview_straighten_pano_tool"), pano.getNrOfImages() > 0);
00486 
00487     // TODO: enable display of parameters and set their limits, if projection has some.
00488     int nParam = opts.m_projFeatures.numberOfParameters;
00489     bool relayout = false;
00490     // if the projection format has changed
00491     if (opts.getProjection() != m_oldProjFormat) {
00492         DEBUG_DEBUG("Projection format changed");
00493         if (nParam) {
00494             // show parameters and update labels.
00495             m_topsizer->Show(m_projParamSizer, true, true);
00496             int i;
00497             for (i=0; i < nParam; i++) {
00498                 const pano_projection_parameter * pp = & (opts.m_projFeatures.parm[i]);
00499                 wxString str2(pp->name, wxConvLocal);
00500                 str2 = wxGetTranslation(str2);
00501                 m_projParamNamesLabel[i]->SetLabel(str2);
00502                 m_projParamSlider[i]->SetRange(roundi(pp->minValue), roundi(pp->maxValue));
00503             }
00504             for(;i < PANO_PROJECTION_MAX_PARMS; i++) {
00505                 m_projParamNamesLabel[i]->Hide();
00506                 m_projParamSlider[i]->Hide();
00507                 m_projParamTextCtrl[i]->Hide();
00508             }
00509             relayout = true;
00510         } else {
00511             m_topsizer->Show(m_projParamSizer, false, true);
00512             relayout = true;
00513         }
00514     }
00515     if (nParam) {
00516         // display new values
00517         std::vector<double> params = opts.getProjectionParameters();
00518         assert((int) params.size() == nParam);
00519         for (int i=0; i < nParam; i++) {
00520             wxString val = wxString(doubleToString(params[i],1).c_str(), wxConvLocal);
00521             m_projParamTextCtrl[i]->SetValue(wxString(val.wc_str(), wxConvLocal));
00522             m_projParamSlider[i]->SetValue(roundi(params[i]));
00523         }
00524     }
00525     if (relayout) {
00526         m_topsizer->Layout();
00527         Refresh();
00528     }
00529     SetStatusText(_("Center panorama with left mouse button, set horizon with right button"),0);
00530     SetStatusText(wxString::Format(wxT("%.1f x %.1f"), opts.getHFOV(), opts.getVFOV()),2);
00531     m_HFOVSlider->SetValue(roundi(opts.getHFOV()));
00532     m_VFOVSlider->SetValue(roundi(opts.getVFOV()));
00533 
00534     m_oldProjFormat = opts.getProjection();
00535     updatePano();
00536 }
00537 
00538 void PreviewFrame::panoramaImagesChanged(Panorama &pano, const UIntSet &changed)
00539 {
00540     DEBUG_TRACE("");
00541 
00542     bool dirty = false;
00543 
00544     unsigned int nrImages = pano.getNrOfImages();
00545     unsigned int nrButtons = m_ToggleButtons.size();
00546 
00547 //    m_displayedImgs.clear();
00548 
00549     // remove items for nonexisting images
00550     for (int i=nrButtons-1; i>=(int)nrImages; i--)
00551     {
00552         m_ButtonSizer->Detach(m_ToggleButtons[i]);
00553         delete m_ToggleButtons[i];
00554         m_ToggleButtons.pop_back();
00555         dirty = true;
00556     }
00557 
00558     // add buttons
00559     if ( nrImages >= nrButtons ) {
00560         for(UIntSet::const_iterator it = changed.begin(); it != changed.end(); ++it){
00561             if (*it >= nrButtons) {
00562                 // create new item.
00563 //                wxImage * bmp = new wxImage(sz.GetWidth(), sz.GetHeight());
00564 #ifdef USE_TOGGLE_BUTTON
00565                 wxToggleButton * but = new wxToggleButton(m_ButtonPanel,
00566                                                           ID_TOGGLE_BUT + *it,
00567                                                           wxString::Format(wxT("%d"),*it),
00568                                                           wxDefaultPosition, wxDefaultSize,
00569                                                           wxBU_EXACTFIT);
00570 #else
00571                 wxCheckBox * but = new wxCheckBox(m_ButtonPanel,
00572                                                   ID_TOGGLE_BUT + *it,
00573                                                   wxString::Format(wxT("%d"),*it));
00574 #endif
00575                 wxSize sz = but->GetSize();
00576 //                but->SetSize(res.GetWidth(),sz.GetHeight());
00577                 // HACK.. set fixed width. that should work
00578                 // better than all that stupid dialogunit stuff, that
00579                 // breaks on wxWin 2.5
00580                 but->SetSize(20, sz.GetHeight());
00581                 but->SetValue(true);
00582                 m_ButtonSizer->Add(but,
00583                                    0,
00584                                    wxLEFT | wxTOP,
00585                                    5);
00586                 m_ToggleButtons.push_back(but);
00587                 dirty = true;
00588             }
00589         }
00590     }
00591 
00592     // update existing items
00593     UIntSet displayedImages = m_pano.getActiveImages();
00594     for (unsigned i=0; i < nrImages; i++) {
00595         m_ToggleButtons[i]->SetValue(set_contains(displayedImages, i));
00596         wxFileName tFilename(wxString (pano.getImage(i).getFilename().c_str(), HUGIN_CONV_FILENAME));
00597         m_ToggleButtons[i]->SetToolTip(tFilename.GetFullName());
00598     }
00599 
00600     if (dirty) {
00601 #if wxCHECK_VERSION(3,0,0)
00602         m_ButtonSizer->FitInside(m_ButtonPanel);
00603 #else
00604                 m_ButtonSizer->SetVirtualSizeHints(m_ButtonPanel);
00605 #endif
00606                 // Layout();
00607                 DEBUG_INFO("New m_ButtonPanel width: " << (m_ButtonPanel->GetSize()).GetWidth());
00608                 DEBUG_INFO("New m_ButtonPanel Height: " << (m_ButtonPanel->GetSize()).GetHeight());
00609     }
00610     updatePano();
00611 }
00612 
00613 
00614 void PreviewFrame::OnClose(wxCloseEvent& event)
00615 {
00616     DEBUG_TRACE("OnClose")
00617     // do not close, just hide if we're not forced
00618     if (event.CanVeto()) {
00619         event.Veto();
00620         Hide();
00621         DEBUG_DEBUG("hiding");
00622     } else {
00623         DEBUG_DEBUG("closing");
00624         this->Destroy();
00625     }
00626 }
00627 
00628 void PreviewFrame::OnAutoPreviewToggle(wxCommandEvent & e)
00629 {
00630     m_PreviewPanel->SetAutoUpdate(e.IsChecked());
00631     if (e.IsChecked()) {
00632         m_PreviewPanel->ForceUpdate();
00633     }
00634 }
00635 
00636 #if 0
00637 // need to add the wxChoice somewhere
00638 void PreviewFrame::OnProjectionChanged()
00639 {
00640     PanoramaOptions opt = m_pano.getOptions();
00641     int lt = m_ProjectionChoice->GetSelection();
00642     wxString Ip;
00643     switch ( lt ) {
00644     case PanoramaOptions::RECTILINEAR:       Ip = _("Rectilinear"); break;
00645     case PanoramaOptions::CYLINDRICAL:       Ip = _("Cylindrical"); break;
00646     case PanoramaOptions::EQUIRECTANGULAR:   Ip = _("Equirectangular"); break;
00647     }
00648     opt.projectionFormat = (PanoramaOptions::ProjectionFormat) lt;
00649     PanoCommand::GlobalCmdHist::getInstance().addCommand(
00650         new PanoCommand::SetPanoOptionsCmd( pano, opt )
00651         );
00652     DEBUG_DEBUG ("Projection changed: "  << lt << ":" << Ip )
00653 
00654 
00655 }
00656 #endif
00657 
00658 void PreviewFrame::OnCenterHorizontally(wxCommandEvent & e)
00659 {
00660     if (m_pano.getActiveImages().size() == 0) return;
00661 
00662     PanoCommand::GlobalCmdHist::getInstance().addCommand(
00663         new PanoCommand::CenterPanoCmd(m_pano)
00664         );
00665 }
00666 
00667 void PreviewFrame::OnStraighten(wxCommandEvent & e)
00668 {
00669     if (m_pano.getNrOfImages() == 0) return;
00670 
00671     PanoCommand::GlobalCmdHist::getInstance().addCommand(
00672         new PanoCommand::StraightenPanoCmd(m_pano)
00673         );
00674 }
00675 
00676 void PreviewFrame::OnUpdate(wxCommandEvent& event)
00677 {
00678     m_PreviewPanel->ForceUpdate();
00679 }
00680 
00681 void PreviewFrame::updatePano()
00682 {
00683     if (m_ToolBar->GetToolState(XRCID("preview_auto_update_tool"))) {
00684         m_PreviewPanel->ForceUpdate();
00685     }
00686 }
00687 
00688 void PreviewFrame::OnFitPano(wxCommandEvent & e)
00689 {
00690     if (m_pano.getActiveImages().size() == 0) return;
00691 
00692     DEBUG_TRACE("");
00693     HuginBase::PanoramaOptions opt = m_pano.getOptions();
00694     HuginBase::CalculateFitPanorama fitPano(m_pano);
00695     fitPano.run();
00696     opt.setHFOV(fitPano.getResultHorizontalFOV());
00697     opt.setHeight(roundi(fitPano.getResultHeight()));
00698 
00699     PanoCommand::GlobalCmdHist::getInstance().addCommand(
00700         new PanoCommand::SetPanoOptionsCmd( m_pano, opt )
00701         );
00702 
00703     DEBUG_INFO ( "new fov: [" << opt.getHFOV() << " "<< opt.getVFOV() << "] => height: " << opt.getHeight() );
00704     updatePano();
00705 }
00706 
00707 void PreviewFrame::OnShowAll(wxCommandEvent & e)
00708 {
00709     if (m_pano.getNrOfImages() == 0) return;
00710 
00711     DEBUG_ASSERT(m_pano.getNrOfImages() == m_ToggleButtons.size());
00712     UIntSet displayedImgs;
00713     for (unsigned int i=0; i < m_pano.getNrOfImages(); i++) {
00714         displayedImgs.insert(i);
00715     }
00716     PanoCommand::GlobalCmdHist::getInstance().addCommand(
00717         new PanoCommand::SetActiveImagesCmd(m_pano, displayedImgs)
00718         );
00719     updatePano();
00720 }
00721 
00722 void PreviewFrame::OnShowNone(wxCommandEvent & e)
00723 {
00724     if (m_pano.getNrOfImages() == 0) return;
00725 
00726     DEBUG_ASSERT(m_pano.getNrOfImages() == m_ToggleButtons.size());
00727     for (unsigned int i=0; i < m_pano.getNrOfImages(); i++) {
00728         m_ToggleButtons[i]->SetValue(false);
00729     }
00730     UIntSet displayedImgs;
00731     PanoCommand::GlobalCmdHist::getInstance().addCommand(
00732         new PanoCommand::SetActiveImagesCmd(m_pano, displayedImgs)
00733         );
00734     updatePano();
00735 }
00736 
00737 void PreviewFrame::OnNumTransform(wxCommandEvent & e)
00738 {
00739     if (m_pano.getNrOfImages() == 0) return;
00740 
00741     wxDialog dlg;
00742     wxXmlResource::Get()->LoadDialog(&dlg, this, wxT("dlg_numtrans"));
00743     dlg.CentreOnParent();
00744     if (dlg.ShowModal() == wxID_OK ) {
00745         wxString text = XRCCTRL(dlg, "numtrans_yaw", wxTextCtrl)->GetValue();
00746         double y;
00747         if (!str2double(text, y)) {
00748             wxLogError(_("Yaw value must be numeric."));
00749             return;
00750         }
00751         text = XRCCTRL(dlg, "numtrans_pitch", wxTextCtrl)->GetValue();
00752         double p;
00753         if (!str2double(text, p)) {
00754             wxLogError(_("Pitch value must be numeric."));
00755             return;
00756         }
00757         text = XRCCTRL(dlg, "numtrans_roll", wxTextCtrl)->GetValue();
00758         double r;
00759         if (!str2double(text, r)) {
00760             wxLogError(_("Roll value must be numeric."));
00761             return;
00762         }
00763         PanoCommand::GlobalCmdHist::getInstance().addCommand(
00764             new PanoCommand::RotatePanoCmd(m_pano, y, p, r)
00765             );
00766         // update preview panel
00767         updatePano();
00768     } else {
00769         DEBUG_DEBUG("Numerical transform canceled");
00770     }
00771 }
00772 
00773 void PreviewFrame::OnTextCtrlChanged(wxCommandEvent & e)
00774 {
00775     HuginBase::PanoramaOptions opts = m_pano.getOptions();
00776     if (e.GetEventObject() == m_exposureTextCtrl) {
00777         // exposure
00778         wxString text = m_exposureTextCtrl->GetValue();
00779         DEBUG_INFO ("target exposure = " << text.mb_str(wxConvLocal) );
00780         double p = 0;
00781         if (text != wxT("")) {
00782             if (!str2double(text, p)) {
00783                 wxLogError(_("Value must be numeric."));
00784                 return;
00785             }
00786         }
00787         opts.outputExposureValue = p;
00788     } else {
00789         int nParam = opts.m_projFeatures.numberOfParameters;
00790         std::vector<double> para = opts.getProjectionParameters();
00791         for (int i = 0; i < nParam; i++) {
00792             if (e.GetEventObject() == m_projParamTextCtrl[i]) {
00793                 wxString text = m_projParamTextCtrl[i]->GetValue();
00794                 DEBUG_INFO ("param " << i << ":  = " << text.mb_str(wxConvLocal) );
00795                 double p = 0;
00796                 if (text != wxT("")) {
00797                     if (!str2double(text, p)) {
00798                         wxLogError(_("Value must be numeric."));
00799                         return;
00800                     }
00801                 }
00802                 para[i] = p;
00803             }
00804         }
00805         opts.setProjectionParameters(para);
00806     }
00807     PanoCommand::GlobalCmdHist::getInstance().addCommand(
00808             new PanoCommand::SetPanoOptionsCmd( m_pano, opts )
00809                                            );
00810     // update preview panel
00811     updatePano();
00812 
00813 }
00814 
00815 void PreviewFrame::OnProjParameterReset(wxCommandEvent &e)
00816 {
00817     HuginBase::PanoramaOptions opts = m_pano.getOptions();
00818     opts.resetProjectionParameters();
00819     PanoCommand::GlobalCmdHist::getInstance().addCommand(
00820         new PanoCommand::SetPanoOptionsCmd(m_pano, opts)
00821         );
00822 };
00823 
00824 void PreviewFrame::OnChangeFOV(wxScrollEvent & e)
00825 {
00826     DEBUG_TRACE("");
00827 
00828     HuginBase::PanoramaOptions opt = m_pano.getOptions();
00829 
00830     if (e.GetEventObject() == m_HFOVSlider) {
00831         DEBUG_DEBUG("HFOV changed (slider): " << e.GetInt() << " == " << m_HFOVSlider->GetValue());
00832         opt.setHFOV(e.GetInt());
00833     } else if (e.GetEventObject() == m_VFOVSlider) {
00834         DEBUG_DEBUG("VFOV changed (slider): " << e.GetInt());
00835         opt.setVFOV(e.GetInt());
00836     } else {
00837         int nParam = opt.m_projFeatures.numberOfParameters;
00838         std::vector<double> para = opt.getProjectionParameters();
00839         for (int i = 0; i < nParam; i++) {
00840             if (e.GetEventObject() == m_projParamSlider[i]) {
00841                 // update
00842                 para[i] = e.GetInt();
00843             }
00844         }
00845         opt.setProjectionParameters(para);
00846                 opt.setHFOV(m_HFOVSlider->GetValue());
00847                 opt.setVFOV(m_VFOVSlider->GetValue());
00848     }
00849 
00850     PanoCommand::GlobalCmdHist::getInstance().addCommand(
00851         new PanoCommand::SetPanoOptionsCmd( m_pano, opt )
00852         );
00853 }
00854 
00855 void PreviewFrame::OnBlendChoice(wxCommandEvent & e)
00856 {
00857     if (e.GetEventObject() == m_BlendModeChoice) {
00858         int sel = e.GetSelection();
00859         switch (sel) {
00860         case 0:
00861             m_PreviewPanel->SetBlendMode(PreviewPanel::BLEND_COPY);
00862             break;
00863         case 1:
00864             m_PreviewPanel->SetBlendMode(PreviewPanel::BLEND_DIFFERENCE);
00865             break;
00866         default:
00867             DEBUG_WARN("Unknown blend mode selected");
00868         }
00869     } else {
00870         DEBUG_WARN("wxChoice event from unknown object received");
00871     }
00872 }
00873 
00874 
00875 void PreviewFrame::OnDefaultExposure( wxCommandEvent & e )
00876 {
00877     if (m_pano.getNrOfImages() > 0) {
00878         HuginBase::PanoramaOptions opt = m_pano.getOptions();
00879         opt.outputExposureValue = HuginBase::CalculateMeanExposure::calcMeanExposure(m_pano);
00880         PanoCommand::GlobalCmdHist::getInstance().addCommand(
00881                 new PanoCommand::SetPanoOptionsCmd( m_pano, opt )
00882                                                );
00883         updatePano();
00884     }
00885 }
00886 
00887 void PreviewFrame::OnIncreaseExposure( wxSpinEvent & e )
00888 {
00889     HuginBase::PanoramaOptions opt = m_pano.getOptions();
00890     opt.outputExposureValue = opt.outputExposureValue + 1.0/3;
00891     PanoCommand::GlobalCmdHist::getInstance().addCommand(
00892             new PanoCommand::SetPanoOptionsCmd( m_pano, opt )
00893                                             );
00894     updatePano();
00895 }
00896 
00897 void PreviewFrame::OnDecreaseExposure( wxSpinEvent & e )
00898 {
00899     HuginBase::PanoramaOptions opt = m_pano.getOptions();
00900     opt.outputExposureValue = opt.outputExposureValue - 1.0/3;
00901     PanoCommand::GlobalCmdHist::getInstance().addCommand(
00902             new PanoCommand::SetPanoOptionsCmd( m_pano, opt )
00903                                            );
00904     updatePano();
00905 }
00906 
00907 void PreviewFrame::OnProjectionChoice( wxCommandEvent & e )
00908 {
00909     if (e.GetEventObject() == m_ProjectionChoice) {
00910         HuginBase::PanoramaOptions opt = m_pano.getOptions();
00911         int lt = m_ProjectionChoice->GetSelection();
00912         wxString Ip;
00913         opt.setProjection((HuginBase::PanoramaOptions::ProjectionFormat) lt);
00914         PanoCommand::GlobalCmdHist::getInstance().addCommand(
00915                 new PanoCommand::SetPanoOptionsCmd( m_pano, opt )
00916                                             );
00917         DEBUG_DEBUG ("Projection changed: "  << lt);
00918         updatePano();
00919 
00920     } else {
00921         DEBUG_WARN("wxChoice event from unknown object received");
00922     }
00923 }
00924 
00925 void PreviewFrame::OnOutputChoice( wxCommandEvent & e)
00926 {
00927     if (e.GetEventObject() == m_outputModeChoice) {
00928         HuginBase::PanoramaOptions opt = m_pano.getOptions();
00929         int lt = m_outputModeChoice->GetSelection();
00930         wxString Ip;
00931         opt.outputMode = ((HuginBase::PanoramaOptions::OutputMode) lt);
00932         PanoCommand::GlobalCmdHist::getInstance().addCommand(
00933                 new PanoCommand::SetPanoOptionsCmd( m_pano, opt )
00934                                                );
00935         updatePano();
00936 
00937     } else {
00938         DEBUG_WARN("wxChoice event from unknown object received");
00939     }
00940 }
00941 
00943 void PreviewFrame::updateProgressDisplay()
00944 {
00945     wxString msg;
00946     if (!m_message.empty())
00947     {
00948         msg = wxGetTranslation(wxString(m_message.c_str(), wxConvLocal));
00949         if (!m_filename.empty())
00950         {
00951             msg.Append(wxT(" "));
00952             msg.Append(wxString(ProgressDisplay::m_filename.c_str(), HUGIN_CONV_FILENAME));
00953         };
00954     };
00955     GetStatusBar()->SetStatusText(msg, 0);
00956 
00957 #ifdef __WXMSW__
00958     UpdateWindow(NULL);
00959 #endif
00960 }
00961 
00962 void PreviewFrame::OnFullScreen(wxCommandEvent & e)
00963 {
00964     ShowFullScreen(!IsFullScreen(), wxFULLSCREEN_NOBORDER | wxFULLSCREEN_NOCAPTION);
00965 #ifdef __WXGTK__
00966     //workaround a wxGTK bug that also the toolbar is hidden, but not requested to hide
00967     GetToolBar()->Show(true);
00968 #endif
00969     m_PreviewPanel->ForceUpdate();
00970 };
00971 
00972 void PreviewFrame::OnUndo(wxCommandEvent &e)
00973 {
00974     if(PanoCommand::GlobalCmdHist::getInstance().canUndo())
00975     {
00976         wxCommandEvent dummy(wxEVT_COMMAND_MENU_SELECTED, XRCID("ID_EDITUNDO"));
00977         m_parent->GetEventHandler()->AddPendingEvent(dummy);
00978     }
00979     else
00980     {
00981         wxBell();
00982     };
00983 };
00984 
00985 void PreviewFrame::OnRedo(wxCommandEvent &e)
00986 {
00987     if(PanoCommand::GlobalCmdHist::getInstance().canRedo())
00988     {
00989         wxCommandEvent dummy(wxEVT_COMMAND_MENU_SELECTED, XRCID("ID_EDITREDO"));
00990         m_parent->GetEventHandler()->AddPendingEvent(dummy);
00991     }
00992     else
00993     {
00994         wxBell();
00995     };
00996 };
00997 

Generated on 30 Jul 2015 for Hugintrunk by  doxygen 1.4.7