From 5134781a3881a96fb7b150ae1b56fe06f0dd6164 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 9 Jul 2014 11:22:43 +0200 Subject: [PATCH] GAL view in pad properties dialog - initial version. --- common/view/view.cpp | 5 +- include/view/view.h | 5 +- pcbnew/dialogs/dialog_pad_properties.cpp | 50 +++++++++-- pcbnew/dialogs/dialog_pad_properties_base.cpp | 3 + pcbnew/dialogs/dialog_pad_properties_base.fbp | 85 +++++++++++++++++++ pcbnew/dialogs/dialog_pad_properties_base.h | 2 + 6 files changed, 141 insertions(+), 9 deletions(-) diff --git a/common/view/view.cpp b/common/view/view.cpp index d4b20e9b42..4fb2f7c75e 100644 --- a/common/view/view.cpp +++ b/common/view/view.cpp @@ -272,9 +272,12 @@ BOX2D VIEW::GetViewport() const } -void VIEW::SetViewport( const BOX2D& aViewport, bool aKeepAspect ) +void VIEW::SetViewport( const BOX2D& aViewport ) { VECTOR2D ssize = ToWorld( m_gal->GetScreenPixelSize(), false ); + + wxASSERT( ssize.x > 0 && ssize.y > 0 ); + VECTOR2D centre = aViewport.Centre(); VECTOR2D vsize = aViewport.GetSize(); double zoom = 1.0 / std::max( fabs( vsize.x / ssize.x ), fabs( vsize.y / ssize.y ) ); diff --git a/include/view/view.h b/include/view/view.h index 1857664af9..529f3c63ce 100644 --- a/include/view/view.h +++ b/include/view/view.h @@ -159,9 +159,8 @@ public: * Function SetViewport() * Sets the visible area of the VIEW. * @param aViewport: desired visible area, in world space coordinates. - * @param aKeepProportions: when true, the X/Y size proportions are kept. */ - void SetViewport( const BOX2D& aViewport, bool aKeepProportions = true ); + void SetViewport( const BOX2D& aViewport ); /** * Function GetViewport() @@ -201,7 +200,7 @@ public: * Function GetScale() * @return Current scalefactor of this VIEW */ - double GetScale() const + double GetScale() const { return m_scale; } diff --git a/pcbnew/dialogs/dialog_pad_properties.cpp b/pcbnew/dialogs/dialog_pad_properties.cpp index b962b670c0..de92b283a4 100644 --- a/pcbnew/dialogs/dialog_pad_properties.cpp +++ b/pcbnew/dialogs/dialog_pad_properties.cpp @@ -117,6 +117,8 @@ private: bool padValuesOK(); ///< test if all values are acceptable for the pad + void redraw(); + /** * Function setPadLayersList * updates the CheckBox states in pad layers list, @@ -174,6 +176,21 @@ DIALOG_PAD_PROPERTIES::DIALOG_PAD_PROPERTIES( PCB_BASE_FRAME* aParent, D_PAD* aP else // We are editing a "master" pad, i.e. a pad used to create new pads m_dummyPad->Copy( m_padMaster ); + if( m_parent->IsGalCanvasActive() ) + { + m_panelShowPadGal->UseColorScheme( m_board->GetColorsSettings() ); + m_panelShowPadGal->SwitchBackend( m_parent->GetGalCanvas()->GetBackend() ); + m_panelShowPad->Hide(); + m_panelShowPadGal->Show(); + m_panelShowPadGal->GetView()->Add( m_dummyPad ); + m_panelShowPadGal->StartDrawing(); + } + else + { + m_panelShowPad->Show(); + m_panelShowPadGal->Hide(); + } + initValues(); m_sdbSizer1OK->SetDefault(); @@ -537,7 +554,7 @@ void DIALOG_PAD_PROPERTIES::OnPadShapeSelection( wxCommandEvent& event ) } transferDataToPad( m_dummyPad ); - m_panelShowPad->Refresh(); + redraw(); } @@ -566,7 +583,7 @@ void DIALOG_PAD_PROPERTIES::OnDrillShapeSelected( wxCommandEvent& event ) } transferDataToPad( m_dummyPad ); - m_panelShowPad->Refresh(); + redraw(); } @@ -599,7 +616,7 @@ void DIALOG_PAD_PROPERTIES::PadOrientEvent( wxCommandEvent& event ) m_PadOrientCtrl->SetValue( msg ); transferDataToPad( m_dummyPad ); - m_panelShowPad->Refresh(); + redraw(); } @@ -667,7 +684,7 @@ void DIALOG_PAD_PROPERTIES::setPadLayersList( LSET layer_mask ) void DIALOG_PAD_PROPERTIES::OnSetLayers( wxCommandEvent& event ) { transferDataToPad( m_dummyPad ); - m_panelShowPad->Refresh(); + redraw(); } @@ -758,6 +775,29 @@ bool DIALOG_PAD_PROPERTIES::padValuesOK() } +void DIALOG_PAD_PROPERTIES::redraw() +{ + if( m_parent->IsGalCanvasActive() ) + { + m_dummyPad->ViewUpdate(); + + BOX2I bbox = m_dummyPad->ViewBBox(); + + // Autozoom + m_panelShowPadGal->GetView()->SetViewport( BOX2D( bbox.GetOrigin(), bbox.GetSize() ) ); + + // Add a margin + m_panelShowPadGal->GetView()->SetScale( m_panelShowPadGal->GetView()->GetScale() * 0.7 ); + + m_panelShowPadGal->Refresh(); + } + else + { + m_panelShowPad->Refresh(); + } +} + + void DIALOG_PAD_PROPERTIES::PadPropertiesAccept( wxCommandEvent& event ) { if( !padValuesOK() ) @@ -1132,7 +1172,7 @@ void DIALOG_PAD_PROPERTIES::OnValuesChanged( wxCommandEvent& event ) if( m_canUpdate ) { transferDataToPad( m_dummyPad ); - m_panelShowPad->Refresh(); + redraw(); } } diff --git a/pcbnew/dialogs/dialog_pad_properties_base.cpp b/pcbnew/dialogs/dialog_pad_properties_base.cpp index 6da97464e5..c7a62c1d54 100644 --- a/pcbnew/dialogs/dialog_pad_properties_base.cpp +++ b/pcbnew/dialogs/dialog_pad_properties_base.cpp @@ -536,6 +536,9 @@ DIALOG_PAD_PROPERTIES_BASE::DIALOG_PAD_PROPERTIES_BASE( wxWindow* parent, wxWind bSizerDisplayPad->Add( m_panelShowPad, 4, wxRIGHT|wxTOP|wxEXPAND, 5 ); + m_panelShowPadGal = new PCB_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), wxDefaultSize, EDA_DRAW_PANEL_GAL::GAL_TYPE_CAIRO ); + bSizerDisplayPad->Add( m_panelShowPadGal, 4, wxEXPAND|wxRIGHT|wxTOP, 5 ); + bSizerUpper->Add( bSizerDisplayPad, 1, wxEXPAND|wxTOP|wxBOTTOM, 5 ); diff --git a/pcbnew/dialogs/dialog_pad_properties_base.fbp b/pcbnew/dialogs/dialog_pad_properties_base.fbp index cb8df4557b..8696b831e5 100644 --- a/pcbnew/dialogs/dialog_pad_properties_base.fbp +++ b/pcbnew/dialogs/dialog_pad_properties_base.fbp @@ -8310,6 +8310,91 @@ + + 5 + wxEXPAND|wxRIGHT|wxTOP + 4 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + PCB_DRAW_PANEL_GAL + 1 + m_panelShowPadGal = new PCB_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), wxDefaultSize, EDA_DRAW_PANEL_GAL::GAL_TYPE_CAIRO ); + + 1 + PCB_DRAW_PANEL_GAL* m_panelShowPadGal; + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + #include <pcb_draw_panel_gal.h> + + 0 + + + 0 + + 1 + m_panelShowPadGal + 1 + + + protected + 1 + + Resizable + + 1 + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pcbnew/dialogs/dialog_pad_properties_base.h b/pcbnew/dialogs/dialog_pad_properties_base.h index 8a6ffd636d..1170f7bf20 100644 --- a/pcbnew/dialogs/dialog_pad_properties_base.h +++ b/pcbnew/dialogs/dialog_pad_properties_base.h @@ -30,6 +30,7 @@ class DIALOG_SHIM; #include #include #include +#include #include #include @@ -143,6 +144,7 @@ class DIALOG_PAD_PROPERTIES_BASE : public DIALOG_SHIM wxStaticText* m_ThermalGapUnits; wxStaticText* m_staticTextWarning; wxPanel* m_panelShowPad; + PCB_DRAW_PANEL_GAL* m_panelShowPadGal; wxStaticText* m_staticTextWarningPadFlipped; wxStdDialogButtonSizer* m_sdbSizer1; wxButton* m_sdbSizer1OK;