diff --git a/common/dialogs/panel_image_editor.cpp b/common/dialogs/panel_image_editor.cpp index 5b605c2fae..24e3e04c4c 100644 --- a/common/dialogs/panel_image_editor.cpp +++ b/common/dialogs/panel_image_editor.cpp @@ -118,6 +118,26 @@ bool PANEL_IMAGE_EDITOR::TransferDataFromWindow() } +double PANEL_IMAGE_EDITOR::GetScale() const +{ + return m_scale.GetDoubleValue(); +} + + +void PANEL_IMAGE_EDITOR::SetScale( double aScale ) +{ + m_scale.ChangeDoubleValue( aScale ); + m_workingImage->SetScale( aScale ); + m_panelDraw->Refresh(); +} + + +VECTOR2I PANEL_IMAGE_EDITOR::GetImageSize() const +{ + return m_workingImage->GetSize(); +} + + void PANEL_IMAGE_EDITOR::OnRedrawPanel( wxPaintEvent& event ) { wxPaintDC dc( m_panelDraw ); diff --git a/common/widgets/unit_binder.cpp b/common/widgets/unit_binder.cpp index 6acf724c43..adfe782d74 100644 --- a/common/widgets/unit_binder.cpp +++ b/common/widgets/unit_binder.cpp @@ -516,7 +516,7 @@ void UNIT_BINDER::ChangeValue( const wxString& aValue ) } -long long int UNIT_BINDER::GetValue() +long long int UNIT_BINDER::GetValue() const { wxTextEntry* textEntry = dynamic_cast( m_valueCtrl ); wxStaticText* staticText = dynamic_cast( m_valueCtrl ); @@ -565,7 +565,7 @@ double UNIT_BINDER::setPrecision( double aValue, bool aValueUsesUserUnits ) cons } -double UNIT_BINDER::GetDoubleValue() +double UNIT_BINDER::GetDoubleValue() const { wxTextEntry* textEntry = dynamic_cast( m_valueCtrl ); wxStaticText* staticText = dynamic_cast( m_valueCtrl ); diff --git a/include/dialogs/panel_image_editor.h b/include/dialogs/panel_image_editor.h index 0fb2cbdb49..fd6c0ba792 100644 --- a/include/dialogs/panel_image_editor.h +++ b/include/dialogs/panel_image_editor.h @@ -26,6 +26,7 @@ #include #include +#include #include @@ -43,6 +44,11 @@ public: bool TransferDataToWindow() override; bool TransferDataFromWindow() override; + double GetScale() const; + void SetScale( double aScale ); + VECTOR2I GetImageSize() const; + wxTextCtrl* GetScaleCtrl() const { return m_textCtrlScale; } + /** * Copy edited image to \a aItem. */ diff --git a/include/widgets/unit_binder.h b/include/widgets/unit_binder.h index 745949f9de..dcad1addac 100644 --- a/include/widgets/unit_binder.h +++ b/include/widgets/unit_binder.h @@ -129,9 +129,9 @@ public: /** * Return the current value in Internal Units. */ - virtual long long int GetValue(); + virtual long long int GetValue() const; - int GetIntValue() { return (int) GetValue(); } + int GetIntValue() const { return (int) GetValue(); } /** * Return the current value in Internal Units. @@ -139,7 +139,7 @@ public: * The returned value will be truncated according to the precision set by * SetPrecision() (if not <= 0). */ - virtual double GetDoubleValue(); + virtual double GetDoubleValue() const; virtual EDA_ANGLE GetAngleValue(); @@ -259,7 +259,7 @@ protected: wxString m_errorMessage; - NUMERIC_EVALUATOR m_eval; + mutable NUMERIC_EVALUATOR m_eval; bool m_allowEval; bool m_needsEval; diff --git a/pcbnew/dialogs/dialog_reference_image_properties.cpp b/pcbnew/dialogs/dialog_reference_image_properties.cpp index 1773e2d542..2b7d704376 100644 --- a/pcbnew/dialogs/dialog_reference_image_properties.cpp +++ b/pcbnew/dialogs/dialog_reference_image_properties.cpp @@ -38,7 +38,9 @@ DIALOG_REFERENCE_IMAGE_PROPERTIES::DIALOG_REFERENCE_IMAGE_PROPERTIES( PCB_BASE_F m_frame( aParent ), m_bitmap( aBitmap ), m_posX( aParent, m_XPosLabel, m_ModPositionX, m_XPosUnit ), - m_posY( aParent, m_YPosLabel, m_ModPositionY, m_YPosUnit ) + m_posY( aParent, m_YPosLabel, m_ModPositionY, m_YPosUnit ), + m_width( aParent, m_WidthLabel, m_ModWidth, m_WidthUnit ), + m_height( aParent, m_HeightLabel, m_ModHeight, m_HeightUnit ) { // Create the image editor page m_imageEditor = new PANEL_IMAGE_EDITOR( aParent, this, aBitmap.GetReferenceImage().MutableImage() ); @@ -47,6 +49,12 @@ DIALOG_REFERENCE_IMAGE_PROPERTIES::DIALOG_REFERENCE_IMAGE_PROPERTIES( PCB_BASE_F m_posX.SetCoordType( ORIGIN_TRANSFORMS::ABS_X_COORD ); m_posY.SetCoordType( ORIGIN_TRANSFORMS::ABS_Y_COORD ); + m_width.SetCoordType( ORIGIN_TRANSFORMS::ABS_X_COORD ); + m_height.SetCoordType( ORIGIN_TRANSFORMS::ABS_Y_COORD ); + + m_ModWidth->Bind( wxEVT_TEXT, &DIALOG_REFERENCE_IMAGE_PROPERTIES::onWidthChanged, this ); + m_ModHeight->Bind( wxEVT_TEXT, &DIALOG_REFERENCE_IMAGE_PROPERTIES::onHeightChanged, this ); + m_imageEditor->GetScaleCtrl()->Bind( wxEVT_TEXT, &DIALOG_REFERENCE_IMAGE_PROPERTIES::onScaleChanged, this ); // Only show unactivated board layers if the bitmap is on one of them if( !m_frame->GetBoard()->IsLayerEnabled( m_bitmap.GetLayer() ) ) @@ -88,7 +96,12 @@ bool DIALOG_REFERENCE_IMAGE_PROPERTIES::TransferDataToWindow() m_cbLocked->SetToolTip( _( "Locked items cannot be freely moved and oriented on the canvas and can only be " "selected when the 'Locked items' checkbox is checked in the selection filter." ) ); - return m_imageEditor->TransferDataToWindow(); + m_imageEditor->TransferDataToWindow(); + VECTOR2I size = m_imageEditor->GetImageSize(); + m_width.SetValue( size.x ); + m_height.SetValue( size.y ); + + return true; } @@ -113,3 +126,47 @@ bool DIALOG_REFERENCE_IMAGE_PROPERTIES::TransferDataFromWindow() return false; } + + +void DIALOG_REFERENCE_IMAGE_PROPERTIES::onWidthChanged( wxCommandEvent& aEvent ) +{ + double newWidth = m_width.GetDoubleValue(); + VECTOR2I size = m_imageEditor->GetImageSize(); + + if( size.x > 0 ) + { + double scale = m_imageEditor->GetScale() * newWidth / size.x; + m_imageEditor->SetScale( scale ); + VECTOR2I newSize = m_imageEditor->GetImageSize(); + m_height.ChangeDoubleValue( newSize.y ); + } +} + + +void DIALOG_REFERENCE_IMAGE_PROPERTIES::onHeightChanged( wxCommandEvent& aEvent ) +{ + double newHeight = m_height.GetDoubleValue(); + VECTOR2I size = m_imageEditor->GetImageSize(); + + if( size.y > 0 ) + { + double scale = m_imageEditor->GetScale() * newHeight / size.y; + m_imageEditor->SetScale( scale ); + VECTOR2I newSize = m_imageEditor->GetImageSize(); + m_width.ChangeDoubleValue( newSize.x ); + } +} + + +void DIALOG_REFERENCE_IMAGE_PROPERTIES::onScaleChanged( wxCommandEvent& aEvent ) +{ + double scale = m_imageEditor->GetScale(); + + if( scale <= 0 ) + return; + + m_imageEditor->SetScale( scale ); + VECTOR2I size = m_imageEditor->GetImageSize(); + m_width.ChangeDoubleValue( size.x ); + m_height.ChangeDoubleValue( size.y ); +} diff --git a/pcbnew/dialogs/dialog_reference_image_properties.h b/pcbnew/dialogs/dialog_reference_image_properties.h index 6b084674af..ccd570898f 100644 --- a/pcbnew/dialogs/dialog_reference_image_properties.h +++ b/pcbnew/dialogs/dialog_reference_image_properties.h @@ -41,6 +41,9 @@ public: private: bool TransferDataToWindow() override; bool TransferDataFromWindow() override; + void onWidthChanged( wxCommandEvent& aEvent ); + void onHeightChanged( wxCommandEvent& aEvent ); + void onScaleChanged( wxCommandEvent& aEvent ); private: PCB_BASE_FRAME* m_frame; @@ -50,4 +53,6 @@ private: UNIT_BINDER m_posX; UNIT_BINDER m_posY; + UNIT_BINDER m_width; + UNIT_BINDER m_height; }; diff --git a/pcbnew/dialogs/dialog_reference_image_properties_base.cpp b/pcbnew/dialogs/dialog_reference_image_properties_base.cpp index 3e8881d429..e3eb47e10b 100644 --- a/pcbnew/dialogs/dialog_reference_image_properties_base.cpp +++ b/pcbnew/dialogs/dialog_reference_image_properties_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version 4.2.1-0-g80c4cb6) +// C++ code generated with wxFormBuilder (version 4.2.1-0-g80c4cb6a-dirty) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -49,6 +49,28 @@ DIALOG_REFERENCE_IMAGE_PROPERTIES_BASE::DIALOG_REFERENCE_IMAGE_PROPERTIES_BASE( m_YPosUnit->Wrap( -1 ); gbSizer1->Add( m_YPosUnit, wxGBPosition( 1, 2 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL, 5 ); + m_WidthLabel = new wxStaticText( this, wxID_ANY, _("Width:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_WidthLabel->Wrap( -1 ); + gbSizer1->Add( m_WidthLabel, wxGBPosition( 4, 0 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL, 5 ); + + m_ModWidth = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); + gbSizer1->Add( m_ModWidth, wxGBPosition( 4, 1 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL|wxEXPAND, 5 ); + + m_WidthUnit = new wxStaticText( this, wxID_ANY, _("unit"), wxDefaultPosition, wxDefaultSize, 0 ); + m_WidthUnit->Wrap( -1 ); + gbSizer1->Add( m_WidthUnit, wxGBPosition( 2, 2 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL, 5 ); + + m_HeightLabel = new wxStaticText( this, wxID_ANY, _("Height:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_HeightLabel->Wrap( -1 ); + gbSizer1->Add( m_HeightLabel, wxGBPosition( 3, 0 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL, 5 ); + + m_ModHeight = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); + gbSizer1->Add( m_ModHeight, wxGBPosition( 3, 1 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL|wxEXPAND, 5 ); + + m_HeightUnit = new wxStaticText( this, wxID_ANY, _("unit"), wxDefaultPosition, wxDefaultSize, 0 ); + m_HeightUnit->Wrap( -1 ); + gbSizer1->Add( m_HeightUnit, wxGBPosition( 3, 2 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL, 5 ); + m_LayerLabel = new wxStaticText( this, wxID_ANY, _("Associated layer:"), wxDefaultPosition, wxDefaultSize, 0 ); m_LayerLabel->Wrap( -1 ); gbSizer1->Add( m_LayerLabel, wxGBPosition( 2, 0 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL, 5 ); @@ -57,7 +79,7 @@ DIALOG_REFERENCE_IMAGE_PROPERTIES_BASE::DIALOG_REFERENCE_IMAGE_PROPERTIES_BASE( gbSizer1->Add( m_LayerSelectionCtrl, wxGBPosition( 2, 1 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL|wxEXPAND, 5 ); m_cbLocked = new wxCheckBox( this, wxID_ANY, _("Locked"), wxDefaultPosition, wxDefaultSize, 0 ); - gbSizer1->Add( m_cbLocked, wxGBPosition( 4, 0 ), wxGBSpan( 1, 3 ), wxALIGN_CENTER_VERTICAL, 5 ); + gbSizer1->Add( m_cbLocked, wxGBPosition( 6, 0 ), wxGBSpan( 1, 3 ), wxALIGN_CENTER_VERTICAL, 5 ); gbSizer1->AddGrowableCol( 1 ); diff --git a/pcbnew/dialogs/dialog_reference_image_properties_base.fbp b/pcbnew/dialogs/dialog_reference_image_properties_base.fbp index 92fca51a03..97bac82c28 100644 --- a/pcbnew/dialogs/dialog_reference_image_properties_base.fbp +++ b/pcbnew/dialogs/dialog_reference_image_properties_base.fbp @@ -484,6 +484,402 @@ -1 + + 5 + 1 + 0 + wxALIGN_CENTER_VERTICAL + 4 + 1 + + 1 + 1 + 1 + 1 + 0 + + 0 + 0 + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 0 + 1 + + 1 + + 0 + 0 + wxID_ANY + Width: + 0 + + 0 + + + 0 + + 1 + m_WidthLabel + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + + + -1 + + + + 5 + 1 + 1 + wxALIGN_CENTER_VERTICAL|wxEXPAND + 4 + 1 + + 1 + 1 + 1 + 1 + 0 + + 0 + 0 + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 0 + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + 0 + + 0 + + 1 + m_ModWidth + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + 5 + 1 + 2 + wxALIGN_CENTER_VERTICAL + 2 + 1 + + 1 + 1 + 1 + 1 + 0 + + 0 + 0 + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 0 + 1 + + 1 + + 0 + 0 + wxID_ANY + unit + 0 + + 0 + + + 0 + + 1 + m_WidthUnit + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + + + -1 + + + + 5 + 1 + 0 + wxALIGN_CENTER_VERTICAL + 3 + 1 + + 1 + 1 + 1 + 1 + 0 + + 0 + 0 + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 0 + 1 + + 1 + + 0 + 0 + wxID_ANY + Height: + 0 + + 0 + + + 0 + + 1 + m_HeightLabel + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + + + -1 + + + + 5 + 1 + 1 + wxALIGN_CENTER_VERTICAL|wxEXPAND + 3 + 1 + + 1 + 1 + 1 + 1 + 0 + + 0 + 0 + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 0 + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + 0 + + 0 + + 1 + m_ModHeight + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + 5 + 1 + 2 + wxALIGN_CENTER_VERTICAL + 3 + 1 + + 1 + 1 + 1 + 1 + 0 + + 0 + 0 + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 0 + 1 + + 1 + + 0 + 0 + wxID_ANY + unit + 0 + + 0 + + + 0 + + 1 + m_HeightUnit + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + + + -1 + + 5 1 @@ -623,7 +1019,7 @@ 3 0 wxALIGN_CENTER_VERTICAL - 4 + 6 1 1 diff --git a/pcbnew/dialogs/dialog_reference_image_properties_base.h b/pcbnew/dialogs/dialog_reference_image_properties_base.h index 25f9f4d4d7..c907aac96c 100644 --- a/pcbnew/dialogs/dialog_reference_image_properties_base.h +++ b/pcbnew/dialogs/dialog_reference_image_properties_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version 4.2.1-0-g80c4cb6) +// C++ code generated with wxFormBuilder (version 4.2.1-0-g80c4cb6a-dirty) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -43,6 +43,12 @@ class DIALOG_REFERENCE_IMAGE_PROPERTIES_BASE : public DIALOG_SHIM wxStaticText* m_YPosLabel; wxTextCtrl* m_ModPositionY; wxStaticText* m_YPosUnit; + wxStaticText* m_WidthLabel; + wxTextCtrl* m_ModWidth; + wxStaticText* m_WidthUnit; + wxStaticText* m_HeightLabel; + wxTextCtrl* m_ModHeight; + wxStaticText* m_HeightUnit; wxStaticText* m_LayerLabel; PCB_LAYER_BOX_SELECTOR* m_LayerSelectionCtrl; wxCheckBox* m_cbLocked;