1 // -*- c-basic-offset: 4 -*- 2 /** @file MaskEditorPanel.h 3 * 4 * @author Thomas Modes 5 * 6 * $Id$ 7 * 8 */ 9 10 /* This is free software; you can redistribute it and/or 11 * modify it under the terms of the GNU General Public 12 * License as published by the Free Software Foundation; either 13 * version 2 of the License, or (at your option) any later version. 14 * 15 * This software is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 * Lesser General Public License for more details. 19 * 20 * You should have received a copy of the GNU General Public 21 * License along with this software. If not, see 22 * <http://www.gnu.org/licenses/>. 23 * 24 */ 25 26 #ifndef _MaskEditorPanel_H 27 #define _MaskEditorPanel_H 28 29 30 //----------------------------------------------------------------------------- 31 // Headers 32 //----------------------------------------------------------------------------- 33 34 #include <panodata/Panorama.h> 35 #include <wx/clrpicker.h> 36 #include "MaskImageCtrl.h" 37 #include "ImagesList.h" 38 39 /** mask editor panel. 40 * 41 * This panel is used to create/change/edit masks 42 * 43 */ 44 class MaskEditorPanel : public wxPanel, public HuginBase::PanoramaObserver 45 { 46 public: 47 /** ctor. 48 */ 49 MaskEditorPanel(); 50 51 bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxTAB_TRAVERSAL, const wxString& name = wxT("panel")); 52 53 void Init(HuginBase::Panorama * pano); 54 55 /** dtor. 56 */ 57 virtual ~MaskEditorPanel(); 58 SetPano(HuginBase::Panorama * panorama)59 void SetPano(HuginBase::Panorama * panorama) 60 { m_pano = panorama; }; 61 /** sets the image, which is currently edited 62 @param imgNr the image which should be shown, use UINT_MAX for no image selected 63 @param updateListSelection if true, the selection of the images list is updated, 64 otherwise the selection of the list remains unchanged (e.g. when calling 65 from the list selection changed event handler) 66 */ 67 void setImage(unsigned int imgNr, bool updateListSelection=false); 68 /** sets active mask number, set to UINT_MAX, if no mask is currently editing */ 69 void setMask(unsigned int maskNr); 70 /** called when mask where changed in MaskImageCtrl */ 71 void UpdateMask(); 72 /** called when new mask added in MaskImageCtrl */ 73 void AddMask(); 74 /** selects the mask with index newMaskNr in the listbox */ 75 void SelectMask(unsigned int newMaskNr); 76 77 /** updated the crop in the Panorama object with the current values from GUI 78 * @param updateFromImgCtrl if true, the crop is updated from the image control, otherwise from the values inside 79 * MaskEditorPanel (so from wxTextCtrls) 80 */ 81 void UpdateCrop(bool updateFromImgCtrl=false); 82 /** updates the displayed crop in the text boxes (for dragging) */ 83 void UpdateCropFromImage(); 84 /** switches the controls to crop mode */ 85 void SwitchToCropMode(); 86 87 /** called when the panorama changes and we should 88 * update our display 89 */ 90 void panoramaChanged(HuginBase::Panorama &pano); 91 void panoramaImagesChanged(HuginBase::Panorama &pano, const HuginBase::UIntSet & imgNr); 92 93 /** called when user selected another image */ 94 void OnImageSelect(wxListEvent &e); 95 /** called when user selected another mask */ 96 void OnMaskSelect(wxListEvent &e); 97 /** handler when mask type was changed */ 98 void OnMaskTypeChange(wxCommandEvent &e); 99 /** called when user wants to create new polygon */ 100 void OnMaskAdd(wxCommandEvent &e); 101 /** called when user wants to save active mask */ 102 void OnMaskSave(wxCommandEvent &e); 103 /** called when user wants to load a mask into the selected image */ 104 void OnMaskLoad(wxCommandEvent &e); 105 /** called when user wants to copy a mask to clipboard */ 106 void OnMaskCopy(wxCommandEvent &e); 107 /** called when user wants to paste a mask from clipboard */ 108 void OnMaskPaste(wxCommandEvent &e); 109 /** called when user wants to delete active mask */ 110 void OnMaskDelete(wxCommandEvent &e); 111 /** sets the actual zoom factor */ 112 void OnZoom(wxCommandEvent & e); 113 /** event handler for changing colours */ 114 void OnColourChanged(wxColourPickerEvent &e); 115 /** event handler for changing option if active masks should be drawn */ 116 void OnShowActiveMasks(wxCommandEvent &e); 117 // reset crop area. 118 void OnResetButton(wxCommandEvent & e); 119 void OnSetLeft(wxCommandEvent & e); 120 void OnSetRight(wxCommandEvent & e); 121 void OnSetTop(wxCommandEvent & e); 122 void OnSetBottom(wxCommandEvent & e); 123 void OnAutoCenter(wxCommandEvent & e); 124 void OnModeChanged(wxNotebookEvent & e); 125 126 private: 127 128 /** updates the display after another image has been selected. 129 * updates mask list and editor panel 130 */ 131 void UpdateMaskList(bool restoreSelection=false); 132 /** return index of currently selected masks, return UINT_MAX if no mask is selected */ 133 unsigned int GetSelectedMask(); 134 /** called, when column with of mask list box was changed */ 135 void OnColumnWidthChange( wxListEvent & e ); 136 /** determines, if the image should be rotated for display */ 137 MaskImageCtrl::ImageRotation GetRot(const unsigned int imgNr); 138 /** copies the crop information from the Panorama object to GUI */ 139 void DisplayCrop(int imgNr); 140 141 /** update GUI display */ 142 void UpdateCropDisplay(); 143 // ensure that the crop roi is centered 144 void CenterCrop(); 145 146 size_t GetImgNr(); 147 148 // GUI controls 149 MaskImageCtrl *m_editImg; 150 ImagesListMask *m_imagesListMask; 151 wxListCtrl *m_maskList; 152 wxChoice *m_maskType; 153 wxNotebook *m_maskCropCtrl; 154 155 // my data 156 HuginBase::Panorama * m_pano; 157 HuginBase::ConstStandardImageVariableGroups* m_imageGroups=nullptr; 158 // current masks vector 159 HuginBase::MaskPolygonVector m_currentMasks; 160 HuginBase::MaskPolygon::MaskType m_defaultMaskType; 161 // mask or crop mode 162 bool m_maskMode; 163 // the current images 164 HuginBase::UIntSet m_selectedImages; 165 // the current mask 166 unsigned int m_MaskNr; 167 // the filename of the current image 168 std::string m_File; 169 170 // controls for crop editing 171 wxTextCtrl * m_left_textctrl; 172 wxTextCtrl * m_right_textctrl; 173 wxTextCtrl * m_top_textctrl; 174 wxTextCtrl * m_bottom_textctrl; 175 wxCheckBox * m_autocenter_cb; 176 wxCheckBox * m_cropLens; 177 HuginBase::SrcPanoImage::CropMode m_cropMode; 178 vigra::Rect2D m_cropRect; 179 bool m_autoCenterCrop = true; 180 vigra::Point2D m_cropCenter; 181 182 DECLARE_EVENT_TABLE(); 183 DECLARE_DYNAMIC_CLASS(MaskEditorPanel) 184 }; 185 186 /** xrc handler for handling mask editor panel */ 187 class MaskEditorPanelXmlHandler : public wxXmlResourceHandler 188 { 189 DECLARE_DYNAMIC_CLASS(MaskEditorPanelXmlHandler) 190 191 public: 192 MaskEditorPanelXmlHandler(); 193 virtual wxObject *DoCreateResource(); 194 virtual bool CanHandle(wxXmlNode *node); 195 }; 196 197 198 #endif // _MaskEditorPanel_H 199