From: <bru...@us...> - 2009-02-24 23:16:57
|
Revision: 3667 http://hugin.svn.sourceforge.net/hugin/?rev=3667&view=rev Author: brunopostle Date: 2009-02-24 23:16:52 +0000 (Tue, 24 Feb 2009) Log Message: ----------- Add hints to Control Point tab pull down lists (Thomas Modes) Modified Paths: -------------- hugin/trunk/src/hugin1/hugin/CMakeLists.txt hugin/trunk/src/hugin1/hugin/CPEditorPanel.cpp hugin/trunk/src/hugin1/hugin/CPEditorPanel.h hugin/trunk/src/hugin1/hugin/PanoPanel.cpp hugin/trunk/src/hugin1/hugin/huginApp.cpp hugin/trunk/src/hugin1/hugin/xrc/cp_editor_panel.xrc Added Paths: ----------- hugin/trunk/src/hugin1/hugin/CPImagesComboBox.cpp hugin/trunk/src/hugin1/hugin/CPImagesComboBox.h Modified: hugin/trunk/src/hugin1/hugin/CMakeLists.txt =================================================================== --- hugin/trunk/src/hugin1/hugin/CMakeLists.txt 2009-02-24 21:31:42 UTC (rev 3666) +++ hugin/trunk/src/hugin1/hugin/CMakeLists.txt 2009-02-24 23:16:52 UTC (rev 3667) @@ -23,7 +23,7 @@ # sources set(hugin_SOURCES huginApp.cpp ImagesList.cpp AutoCtrlPointCreator.cpp -MainFrame.cpp CPImageCtrl.cpp CPEditorPanel.cpp LensPanel.cpp +MainFrame.cpp CPImageCtrl.cpp CPImagesComboBox.cpp CPEditorPanel.cpp LensPanel.cpp ImagesPanel.cpp CommandHistory.cpp PanoPanel.cpp NonaOptionsDialog.cpp PreviewFrame.cpp PreviewPanel.cpp GLPreviewFrame.cpp GLViewer.cpp GLRenderer.cpp CropPanel.cpp OptimizePhotometricPanel.cpp OptimizePanel.cpp CPListFrame.cpp Modified: hugin/trunk/src/hugin1/hugin/CPEditorPanel.cpp =================================================================== --- hugin/trunk/src/hugin1/hugin/CPEditorPanel.cpp 2009-02-24 21:31:42 UTC (rev 3666) +++ hugin/trunk/src/hugin1/hugin/CPEditorPanel.cpp 2009-02-24 23:16:52 UTC (rev 3667) @@ -94,8 +94,8 @@ BEGIN_EVENT_TABLE(CPEditorPanel, wxPanel) EVT_CPEVENT(CPEditorPanel::OnCPEvent) #ifdef HUGIN_CP_IMG_CHOICE - EVT_CHOICE(XRCID("cp_editor_left_choice"), CPEditorPanel::OnLeftChoiceChange ) - EVT_CHOICE(XRCID("cp_editor_right_choice"), CPEditorPanel::OnRightChoiceChange ) + EVT_COMBOBOX(XRCID("cp_editor_left_choice"), CPEditorPanel::OnLeftChoiceChange ) + EVT_COMBOBOX(XRCID("cp_editor_right_choice"), CPEditorPanel::OnRightChoiceChange ) #endif #ifdef HUGIN_CP_IMG_TAB EVT_NOTEBOOK_PAGE_CHANGED ( XRCID("cp_editor_left_tab"),CPEditorPanel::OnLeftImgChange ) @@ -168,7 +168,7 @@ m_leftTabs->SetSizeHints(1,tabH,1000,tabH,-1,-1); #endif #ifdef HUGIN_CP_IMG_CHOICE - m_leftChoice = XRCCTRL(*this, "cp_editor_left_choice", wxChoice); + m_leftChoice = XRCCTRL(*this, "cp_editor_left_choice", CPImagesComboBox); #endif #if 0 @@ -187,7 +187,7 @@ m_rightTabs->SetSizeHints(1,tabH,1000,tabH,-1,-1); #endif #ifdef HUGIN_CP_IMG_CHOICE - m_rightChoice = XRCCTRL(*this, "cp_editor_right_choice", wxChoice); + m_rightChoice = XRCCTRL(*this, "cp_editor_right_choice", CPImagesComboBox); #endif #if 0 @@ -360,6 +360,8 @@ if (m_leftChoice->GetSelection() != (int) imgNr) { m_leftChoice->SetSelection(imgNr); } + m_rightChoice->SetRefImage(m_pano,m_leftImageNr); + m_rightChoice->Refresh(); #endif #ifdef HUGIN_CP_IMG_TAB if (m_leftTabs->GetSelection() != (int) imgNr) { @@ -400,17 +402,19 @@ m_rightRot = GetRot(yaw, pitch, roll); m_rightImg->setImage(m_pano->getImage(imgNr).getFilename(), m_rightRot); // select tab + m_rightImageNr = imgNr; #ifdef HUGIN_CP_IMG_CHOICE if (m_rightChoice->GetSelection() != (int) imgNr) { m_rightChoice->SetSelection(imgNr); } + m_leftChoice->SetRefImage(m_pano,m_rightImageNr); + m_leftChoice->Refresh(); #endif #ifdef HUGIN_CP_IMG_TAB if (m_rightTabs->GetSelection() != (int) imgNr) { m_rightTabs->SetSelection(imgNr); } #endif - m_rightImageNr = imgNr; m_rightFile = m_pano->getImage(imgNr).getFilename(); // update the rest of the display (new control points etc) changeState(NO_POINT); @@ -628,6 +632,10 @@ SelectGlobalPoint(lPoint); changeState(NO_POINT); MainFrame::Get()->SetStatusText(_("new control point added")); +#ifdef HUGIN_CP_IMG_CHOICE + m_leftChoice->CalcCPDistance(m_pano); + m_rightChoice->CalcCPDistance(m_pano); +#endif } @@ -1293,8 +1301,8 @@ #ifdef HUGIN_CP_IMG_CHOICE for (unsigned int i=0; i < ((nrTabs < nrImages)? nrTabs: nrImages); i++) { wxFileName fileName(wxString (pano.getImage(i).getFilename().c_str(), HUGIN_CONV_FILENAME)); - m_leftChoice->SetString(i, wxString::Format(wxT("%2d"), i) + wxT(". - ") + fileName.GetFullName()); - m_rightChoice->SetString(i, wxString::Format(wxT("%2d"), i) + wxT(". - ") + fileName.GetFullName()); + m_leftChoice->SetString(i, wxString::Format(wxT("%d"), i) + wxT(". - ") + fileName.GetFullName()); + m_rightChoice->SetString(i, wxString::Format(wxT("%d"), i) + wxT(". - ") + fileName.GetFullName()); } /* ls = m_leftChoice->GetSelection(); @@ -1315,8 +1323,8 @@ for (unsigned int i=nrTabs; i < nrImages; i++) { #ifdef HUGIN_CP_IMG_CHOICE wxFileName fileName(wxString (pano.getImage(i).getFilename().c_str(), HUGIN_CONV_FILENAME)); - m_leftChoice->Append(wxString::Format(wxT("%2d"), i) + wxT(". - ") + fileName.GetFullName()); - m_rightChoice->Append(wxString::Format(wxT("%2d"), i) + wxT(". - ") + fileName.GetFullName()); + m_leftChoice->Append(wxString::Format(wxT("%d"), i) + wxT(". - ") + fileName.GetFullName()); + m_rightChoice->Append(wxString::Format(wxT("%d"), i) + wxT(". - ") + fileName.GetFullName()); #endif #ifdef HUGIN_CP_IMG_TAB wxWindow* t1= new wxWindow(m_leftTabs,-1,wxPoint(0,0),wxSize(0,0)); @@ -1467,6 +1475,10 @@ wxLogError(wxString::Format(wxT("panoramaImagesChanged. After update\nleft: %d, right: %d, count: %d %d"), ls, rs, nrTabsNew)); #endif */ +#ifdef HUGIN_CP_IMG_CHOICE + m_leftChoice->CalcCPDistance(m_pano); + m_rightChoice->CalcCPDistance(m_pano); +#endif } void CPEditorPanel::UpdateDisplay(bool newPair) @@ -1956,6 +1968,10 @@ GlobalCmdHist::getInstance().addCommand( new PT::RemoveCtrlPointCmd(*m_pano,pNr ) ); +#ifdef HUGIN_CP_IMG_CHOICE + m_leftChoice->CalcCPDistance(m_pano); + m_rightChoice->CalcCPDistance(m_pano); +#endif } } Modified: hugin/trunk/src/hugin1/hugin/CPEditorPanel.h =================================================================== --- hugin/trunk/src/hugin1/hugin/CPEditorPanel.h 2009-02-24 21:31:42 UTC (rev 3666) +++ hugin/trunk/src/hugin1/hugin/CPEditorPanel.h 2009-02-24 23:16:52 UTC (rev 3667) @@ -42,6 +42,7 @@ #include <PT/Panorama.h> +#include "CPImagesComboBox.h" // Always use wxChoice, the tabs behave badly with many images on GTK as well. #define HUGIN_CP_IMG_CHOICE @@ -265,8 +266,8 @@ // GUI controls #ifdef HUGIN_CP_IMG_CHOICE - wxChoice *m_leftChoice; - wxChoice *m_rightChoice; + CPImagesComboBox *m_leftChoice; + CPImagesComboBox *m_rightChoice; #endif #ifdef HUGIN_CP_IMG_TAB wxNotebook *m_leftTabs, *m_rightTabs; Added: hugin/trunk/src/hugin1/hugin/CPImagesComboBox.cpp =================================================================== --- hugin/trunk/src/hugin1/hugin/CPImagesComboBox.cpp (rev 0) +++ hugin/trunk/src/hugin1/hugin/CPImagesComboBox.cpp 2009-02-24 23:16:52 UTC (rev 3667) @@ -0,0 +1,197 @@ +#include "hugin/CPImagesComboBox.h" + +BEGIN_EVENT_TABLE(CPImagesComboBox,wxOwnerDrawnComboBox) + EVT_MOUSEWHEEL(CPImagesComboBox::OnMouseWheel) + EVT_KEY_DOWN(CPImagesComboBox::OnKeyDown) +END_EVENT_TABLE() + +void CPImagesComboBox::OnMouseWheel(wxMouseEvent & e) +{ + //mimic wxChoice behaviour + //when popup is shown, there could be a scrollbar which processes the mouse wheel event + if(!IsPopupShown()) + { + if(e.GetWheelRotation()<0) + SelectNext(); + else + SelectPrev(); + } + else + { + e.Skip(); + }; +}; + +void CPImagesComboBox::OnKeyDown(wxKeyEvent & e) +{ + if(!IsPopupShown()) + { + //mimic wxChoice behaviour + switch (e.GetKeyCode()){ + case WXK_DOWN: + case WXK_RIGHT: + case WXK_NUMPAD_DOWN: + case WXK_NUMPAD_RIGHT: + SelectNext(); + break; + case WXK_UP: + case WXK_LEFT: + case WXK_NUMPAD_UP: + case WXK_NUMPAD_LEFT: + SelectPrev(); + break; + case WXK_PAGEDOWN: + case WXK_NUMPAD_PAGEDOWN: + SelectNext(5); + break; + case WXK_PAGEUP: + case WXK_NUMPAD_PAGEUP: + SelectPrev(5); + break; + case WXK_HOME: + case WXK_NUMPAD_HOME: + SelectPrev(GetCount()); + break; + case WXK_END: + case WXK_NUMPAD_END: + SelectNext(GetCount()); + break; + case WXK_SPACE: + ShowPopup(); + break; + default: + e.Skip(); + }; + } + else + { + e.Skip(); + } +}; + +void CPImagesComboBox::SelectNext(int step) +{ + int index=min<int>(GetSelection()+step,GetCount()-1); + if(index!=GetSelection()) + { + Select(index); + Update(); + NotifyParent(); + }; +}; + +void CPImagesComboBox::SelectPrev(int step) +{ + int index=max<int>(GetSelection()-step,0); + if(index!=GetSelection()) + { + Select(index); + Update(); + NotifyParent(); + }; +}; + +void CPImagesComboBox::NotifyParent() +{ + //notify parent about changed selection + //select doesn't send the corresponding event + wxCommandEvent ne(wxEVT_COMMAND_COMBOBOX_SELECTED); + ne.SetEventObject(this); + ne.SetId(this->GetId()); + ne.SetInt(GetSelection()); + ProcessEvent(ne); +}; + +void CPImagesComboBox::Init() +{ + CPConnection.resize(0); + refImage=0; +}; + +void CPImagesComboBox::OnDrawItem(wxDC& dc, + const wxRect& rect, + int item, + int WXUNUSED(flags)) const +{ + if ( item == wxNOT_FOUND ) + return; + dc.DrawText(GetString(item),rect.x + 3,rect.y + ((rect.height - dc.GetCharHeight())/2)); + //draw rectangle when images are connected by control points + if(CPConnection[item]>-1.0) + { + wxCoord x; + x=rect.width / 5 *(1-min<double>(CPConnection[item],10)/10); + //ensure that always a bar is drawn + x=max<wxCoord>(5,x); + wxPen MyPen(wxColour(0,192,0),1,wxSOLID); + wxBrush MyBrush(wxColour(0,192,0),wxSOLID); + const wxPen * oldPen = & dc.GetPen(); + const wxBrush * oldBrush= & dc.GetBrush(); + if(CPConnection[item]>5) + { + MyPen.SetColour(wxColour(255,0,0)); + MyBrush.SetColour(wxColour(255,0,0)); + }; + //inner rectangle, proportional to max cp error (max. 10) + dc.SetPen(MyPen); + dc.SetBrush(MyBrush); + dc.DrawRectangle(rect.x+0.75*rect.width,rect.y+rect.height/3-1,x,2*rect.height/3); + //outer rectangle, same colour as text + MyPen.SetColour(dc.GetTextForeground()); + dc.SetPen(MyPen); + dc.SetBrush(*wxTRANSPARENT_BRUSH); + dc.DrawRectangle(rect.x+0.75*rect.width,rect.y+rect.height/3-1,rect.width/5,2*rect.height/3); + dc.SetPen(*oldPen); + dc.SetBrush(*oldBrush); + }; +}; + +void CPImagesComboBox::CalcCPDistance(Panorama * pano) +{ + CPConnection.clear(); + CPConnection.resize(this->GetCount(),-1.0); + unsigned int noPts = pano->getNrOfCtrlPoints(); + // loop over all points to get the maximum error + for (unsigned int ptIdx = 0 ; ptIdx < noPts ; ptIdx++) + { + const ControlPoint & cp = pano->getCtrlPoint(ptIdx); + if(cp.image1Nr==refImage) + { + CPConnection[cp.image2Nr]=max<double>(cp.error,CPConnection[cp.image2Nr]); + } + else if(cp.image2Nr==refImage) + { + CPConnection[cp.image1Nr]=max<double>(cp.error,CPConnection[cp.image1Nr]); + }; + } +}; + +IMPLEMENT_DYNAMIC_CLASS(CPImagesComboBox, wxOwnerDrawnComboBox) + +IMPLEMENT_DYNAMIC_CLASS(CPImagesComboBoxXmlHandler, wxOwnerDrawnComboBoxXmlHandler) + +CPImagesComboBoxXmlHandler::CPImagesComboBoxXmlHandler() + : wxOwnerDrawnComboBoxXmlHandler() +{ + AddWindowStyles(); +} + +wxObject *CPImagesComboBoxXmlHandler::DoCreateResource() +{ + XRC_MAKE_INSTANCE(cp, CPImagesComboBox) + + cp->Create(m_parentAsWindow, + GetID(), wxEmptyString, + GetPosition(), GetSize(), + GetStyle(wxT("style")), wxDefaultValidator, + GetName()); + + SetupWindow(cp); + + return cp; +} + +bool CPImagesComboBoxXmlHandler::CanHandle(wxXmlNode *node) +{ + return IsOfClass(node, wxT("CPImagesComboBox")); +} Added: hugin/trunk/src/hugin1/hugin/CPImagesComboBox.h =================================================================== --- hugin/trunk/src/hugin1/hugin/CPImagesComboBox.h (rev 0) +++ hugin/trunk/src/hugin1/hugin/CPImagesComboBox.h 2009-02-24 23:16:52 UTC (rev 3667) @@ -0,0 +1,78 @@ +// -*- c-basic-offset: 4 -*- +/** @file CPImagesComboBox.h + * + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this software; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ifndef _CPIMAGESCOMBOBOX_H +#define _CPIMAGESCOMBOBOX_H + +// standard wx include +//#include <config.h> +#include "panoinc.h" +#include "panoinc_WX.h" +#include "wx/odcombo.h" +#include "wx/xrc/xh_odcombo.h" + + +using namespace std; +using namespace PT; + +class CPImagesComboBox : public wxOwnerDrawnComboBox +{ +public: + virtual void OnDrawItem(wxDC& dc, + const wxRect& rect, + int item, + int WXUNUSED(flags)) const; + void CalcCPDistance(Panorama * pano); + void SetRefImage(Panorama * pano, unsigned int newRefImg) + { + refImage=newRefImg; + CalcCPDistance(pano); + }; + const unsigned int GetRefImage() + { + return refImage; + }; +protected: + void OnMouseWheel(wxMouseEvent & e); + void OnKeyDown(wxKeyEvent & e); +private: + unsigned int refImage; + std::vector<double> CPConnection; + void Init(); + void SelectNext(int step = 1); + void SelectPrev(int step = 1); + void NotifyParent(); + + DECLARE_EVENT_TABLE() + DECLARE_DYNAMIC_CLASS(CPImagesComboBox) +}; + +/** xrc handler */ +class CPImagesComboBoxXmlHandler : public wxOwnerDrawnComboBoxXmlHandler +{ + DECLARE_DYNAMIC_CLASS(CPImagesComboBoxXmlHandler) + +public: + CPImagesComboBoxXmlHandler(); + virtual wxObject *DoCreateResource(); + virtual bool CanHandle(wxXmlNode *node); +}; + +#endif Modified: hugin/trunk/src/hugin1/hugin/PanoPanel.cpp =================================================================== --- hugin/trunk/src/hugin1/hugin/PanoPanel.cpp 2009-02-24 21:31:42 UTC (rev 3666) +++ hugin/trunk/src/hugin1/hugin/PanoPanel.cpp 2009-02-24 23:16:52 UTC (rev 3667) @@ -54,6 +54,7 @@ //#include "hugin/LensPanel.h" //#include "hugin/ImagesPanel.h" #include "hugin/CPImageCtrl.h" +#include "hugin/CPImagesComboBox.h" #include "hugin/PanoPanel.h" #include "hugin/MainFrame.h" #include "hugin/huginApp.h" Modified: hugin/trunk/src/hugin1/hugin/huginApp.cpp =================================================================== --- hugin/trunk/src/hugin1/hugin/huginApp.cpp 2009-02-24 21:31:42 UTC (rev 3666) +++ hugin/trunk/src/hugin1/hugin/huginApp.cpp 2009-02-24 23:16:52 UTC (rev 3667) @@ -216,6 +216,7 @@ wxXmlResource::Get()->AddHandler(new CenterCanvasXmlHandler()); wxXmlResource::Get()->AddHandler(new CPEditorPanelXmlHandler()); wxXmlResource::Get()->AddHandler(new CPImageCtrlXmlHandler()); + wxXmlResource::Get()->AddHandler(new CPImagesComboBoxXmlHandler()); wxXmlResource::Get()->AddHandler(new OptimizePanelXmlHandler()); wxXmlResource::Get()->AddHandler(new OptimizePhotometricPanelXmlHandler()); wxXmlResource::Get()->AddHandler(new PanoPanelXmlHandler()); Modified: hugin/trunk/src/hugin1/hugin/xrc/cp_editor_panel.xrc =================================================================== --- hugin/trunk/src/hugin1/hugin/xrc/cp_editor_panel.xrc 2009-02-24 21:31:42 UTC (rev 3666) +++ hugin/trunk/src/hugin1/hugin/xrc/cp_editor_panel.xrc 2009-02-24 23:16:52 UTC (rev 3667) @@ -26,8 +26,9 @@ <border>3</border> </object> <object class="sizeritem"> - <object class="wxChoice" name="cp_editor_left_choice"> + <object class="CPImagesComboBox" name="cp_editor_left_choice"> <content/> + <style>wxCB_READONLY</style> </object> <option>1</option> <flag>wxALL|wxADJUST_MINSIZE</flag> @@ -58,8 +59,9 @@ <object class="wxBoxSizer"> <orient>wxHORIZONTAL</orient> <object class="sizeritem"> - <object class="wxChoice" name="cp_editor_right_choice"> + <object class="CPImagesComboBox" name="cp_editor_right_choice"> <content/> + <style>wxCB_READONLY</style> </object> <option>1</option> <flag>wxALL|wxADJUST_MINSIZE</flag> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |