kicad/pcbnew/dialogs/dialog_pad_properties.cpp

1014 lines
30 KiB
C++
Raw Normal View History

2008-12-23 13:14:01 +00:00
/*******************************************************************/
/* dialog_pad_properties.cpp: Pad editing functions and dialog box */
/* see also dialog_pad_properties.xxx (built with wxFormBuilder) */
/*******************************************************************/
2008-11-22 11:10:40 +00:00
#include <fctsys.h>
#include <common.h>
#include <gr_basic.h>
#include <class_drawpanel.h>
#include <confirm.h>
#include <pcbnew.h>
#include <trigo.h>
#include <macros.h>
#include <wxBasePcbFrame.h>
#include <pcbcommon.h>
#include <wx/dcbuffer.h>
2012-02-19 04:02:19 +00:00
#include <protos.h>
2008-11-22 11:10:40 +00:00
#include <class_board.h>
#include <class_module.h>
#include <dialog_pad_properties_base.h>
2012-02-19 04:02:19 +00:00
// list of pad shapes.
static PAD_SHAPE_T CodeShape[] = {
2008-11-22 11:10:40 +00:00
PAD_CIRCLE, PAD_OVAL, PAD_RECT, PAD_TRAPEZOID
};
#define NBTYPES 4
2012-02-19 04:02:19 +00:00
static PAD_ATTR_T CodeType[NBTYPES] = {
2008-11-22 11:10:40 +00:00
PAD_STANDARD, PAD_SMD, PAD_CONN, PAD_HOLE_NOT_PLATED
};
// Default mask layers setup for pads according to the pad type
2008-11-22 11:10:40 +00:00
static long Std_Pad_Layers[NBTYPES] =
{
// PAD_STANDARD:
2009-09-23 06:02:37 +00:00
PAD_STANDARD_DEFAULT_LAYERS,
2008-11-22 11:10:40 +00:00
// PAD_CONN:
2009-09-23 06:02:37 +00:00
PAD_CONN_DEFAULT_LAYERS,
2008-11-22 11:10:40 +00:00
// PAD_SMD:
2009-09-23 06:02:37 +00:00
PAD_SMD_DEFAULT_LAYERS,
2008-11-22 11:10:40 +00:00
//PAD_HOLE_NOT_PLATED:
2009-09-23 06:02:37 +00:00
PAD_HOLE_NOT_PLATED_DEFAULT_LAYERS
2008-11-22 11:10:40 +00:00
};
/**
* class DIALOG_PAD_PROPERTIES, derived from DIALOG_PAD_PROPERTIES_BASE,
* created by wxFormBuilder
*/
class DIALOG_PAD_PROPERTIES : public DIALOG_PAD_PROPERTIES_BASE
2008-11-22 11:10:40 +00:00
{
public:
2012-02-19 04:02:19 +00:00
DIALOG_PAD_PROPERTIES( PCB_BASE_FRAME* aParent, D_PAD* aPad );
~DIALOG_PAD_PROPERTIES()
{
delete m_dummyPad;
}
private:
2012-02-19 04:02:19 +00:00
PCB_BASE_FRAME* m_Parent;
D_PAD* m_CurrentPad; // pad currently being edited
D_PAD* m_dummyPad; // a working copy used to show changes
BOARD* m_Board;
D_PAD& m_Pad_Master;
bool m_isFlipped; // true if the parent footprint (therefore pads) is flipped (mirrored)
// in this case, some Y coordinates values must be negated
bool m_canUpdate;
void initValues();
2008-11-22 11:10:40 +00:00
void OnPadShapeSelection( wxCommandEvent& event );
void OnDrillShapeSelected( wxCommandEvent& event );
void PadOrientEvent( wxCommandEvent& event );
void PadTypeSelected( wxCommandEvent& event );
void PadPropertiesAccept( wxCommandEvent& event );
void SetPadLayersList( long layer_mask );
void OnSetLayers( wxCommandEvent& event );
void OnCancelButtonClick( wxCommandEvent& event );
void OnPaintShowPanel( wxPaintEvent& event );
bool TransfertDataToPad( D_PAD* aPad, bool aPromptOnError = false );
void OnValuesChanged( wxCommandEvent& event );
2008-11-22 11:10:40 +00:00
};
2012-02-19 04:02:19 +00:00
DIALOG_PAD_PROPERTIES::DIALOG_PAD_PROPERTIES( PCB_BASE_FRAME* aParent, D_PAD* aPad ) :
DIALOG_PAD_PROPERTIES_BASE( aParent ),
m_Pad_Master( aParent->GetBoard()->GetDesignSettings().m_Pad_Master )
{
m_canUpdate = false;
m_Parent = aParent;
m_CurrentPad = aPad;
m_Board = m_Parent->GetBoard();
m_dummyPad = new D_PAD( (MODULE*) NULL );
if( aPad )
m_dummyPad->Copy( aPad );
else
m_dummyPad->Copy( &m_Pad_Master );
initValues();
m_sdbSizer1OK->SetDefault();
GetSizer()->SetSizeHints( this );
Center();
m_canUpdate = true;
}
void DIALOG_PAD_PROPERTIES::OnPaintShowPanel( wxPaintEvent& event )
{
wxPaintDC dc( m_panelShowPad );
PAD_DRAWINFO drawInfo;
int color = 0;
2012-02-19 04:02:19 +00:00
if( m_dummyPad->GetLayerMask() & LAYER_FRONT )
{
color = m_Board->GetVisibleElementColor( PAD_FR_VISIBLE );
}
2012-02-19 04:02:19 +00:00
if( m_dummyPad->GetLayerMask() & LAYER_BACK )
{
color |= m_Board->GetVisibleElementColor( PAD_BK_VISIBLE );
}
if( color == 0 )
color = LIGHTGRAY;
drawInfo.m_Color = color;
drawInfo.m_HoleColor = DARKGRAY;
2012-02-19 04:02:19 +00:00
drawInfo.m_Offset = m_dummyPad->GetPosition();
drawInfo.m_Display_padnum = true;
drawInfo.m_Display_netname = true;
2012-02-19 04:02:19 +00:00
if( m_dummyPad->GetAttribute() == PAD_HOLE_NOT_PLATED )
drawInfo.m_ShowNotPlatedHole = true;
// Shows the local pad clearance
2012-02-19 04:02:19 +00:00
drawInfo.m_PadClearance = m_dummyPad->GetLocalClearance();
wxSize dc_size = dc.GetSize();
dc.SetDeviceOrigin( dc_size.x / 2, dc_size.y / 2 );
// Calculate a suitable scale to fit the available draw area
2012-02-19 04:02:19 +00:00
int dim = m_dummyPad->GetSize().x + ABS( m_dummyPad->GetDelta().y);
if( m_dummyPad->GetLocalClearance() > 0 )
dim += m_dummyPad->GetLocalClearance() * 2;
double scale = (double) dc_size.x / dim;
dim = m_dummyPad->GetSize().y + ABS( m_dummyPad->GetDelta().x);
if( m_dummyPad->GetLocalClearance() > 0 )
dim += m_dummyPad->GetLocalClearance() * 2;
double altscale = (double) dc_size.y / dim;
scale = MIN( scale, altscale );
// Give a margin
scale *= 0.7;
dc.SetUserScale( scale, scale );
2011-04-18 20:22:17 +00:00
GRResetPenAndBrush( &dc );
m_dummyPad->DrawShape( NULL, &dc, drawInfo );
event.Skip();
}
void PCB_BASE_FRAME::InstallPadOptionsFrame( D_PAD* Pad )
2008-11-22 11:10:40 +00:00
{
2009-12-19 19:24:49 +00:00
DIALOG_PAD_PROPERTIES dlg( this, Pad );
dlg.ShowModal();
2008-11-22 11:10:40 +00:00
}
void DIALOG_PAD_PROPERTIES::initValues()
2008-11-22 11:10:40 +00:00
{
2012-02-19 04:02:19 +00:00
SetFocus(); // Required under wxGTK if we want to dismiss the dialog with the ESC key
int internalUnits = m_Parent->GetInternalUnits();
wxString msg;
double angle;
m_isFlipped = false;
2012-02-19 04:02:19 +00:00
if( m_CurrentPad )
{
2012-02-19 04:02:19 +00:00
MODULE* module = m_CurrentPad->GetParent();
if( module->GetLayer() == LAYER_N_BACK )
{
m_isFlipped = true;
m_staticModuleSideValue->SetLabel( _( "Back side (footprint is mirrored)" ) );
}
2012-02-19 04:02:19 +00:00
msg.Printf( wxT( "%.1f" ), (double) module->GetOrientation() / 10 );
m_staticModuleRotValue->SetLabel( msg );
}
2008-11-22 11:10:40 +00:00
if( m_isFlipped )
{
2012-02-19 04:02:19 +00:00
wxPoint pt = m_dummyPad->GetOffset();
NEGATE( pt.y );
m_dummyPad->SetOffset( pt );
wxSize sz = m_dummyPad->GetDelta();
NEGATE( sz.y );
m_dummyPad->SetDelta( sz );
// flip pad's layers
m_dummyPad->SetLayerMask( ChangeSideMaskLayer( m_dummyPad->GetLayerMask() ) );
}
2012-02-19 04:02:19 +00:00
m_staticTextWarningPadFlipped->Show(m_isFlipped);
2008-11-22 11:10:40 +00:00
2011-12-12 08:37:05 +00:00
m_PadNumCtrl->SetValue( m_dummyPad->GetPadName() );
m_PadNetNameCtrl->SetValue( m_dummyPad->GetNetname() );
2008-11-22 11:10:40 +00:00
// Display current unit name in dialog:
m_PadPosX_Unit->SetLabel( GetUnitsLabel( g_UserUnit ) );
m_PadPosY_Unit->SetLabel( GetUnitsLabel( g_UserUnit ) );
m_PadDrill_X_Unit->SetLabel( GetUnitsLabel( g_UserUnit ) );
m_PadDrill_Y_Unit->SetLabel( GetUnitsLabel( g_UserUnit ) );
m_PadShapeSizeX_Unit->SetLabel( GetUnitsLabel( g_UserUnit ) );
m_PadShapeSizeY_Unit->SetLabel( GetUnitsLabel( g_UserUnit ) );
m_PadShapeOffsetX_Unit->SetLabel( GetUnitsLabel( g_UserUnit ) );
m_PadShapeOffsetY_Unit->SetLabel( GetUnitsLabel( g_UserUnit ) );
m_PadShapeDelta_Unit->SetLabel( GetUnitsLabel( g_UserUnit ) );
m_PadLengthDie_Unit->SetLabel( GetUnitsLabel( g_UserUnit ) );
m_NetClearanceUnits->SetLabel( GetUnitsLabel( g_UserUnit ) );
// Display current pad masks clearances units
m_NetClearanceUnits->SetLabel( GetUnitsLabel( g_UserUnit ) );
m_SolderMaskMarginUnits->SetLabel( GetUnitsLabel( g_UserUnit ) );
m_SolderPasteMarginUnits->SetLabel( GetUnitsLabel( g_UserUnit ) );
// Display current pad parameters units:
2012-02-19 04:02:19 +00:00
PutValueInLocalUnits( *m_PadPosition_X_Ctrl, m_dummyPad->GetPosition().x, internalUnits );
PutValueInLocalUnits( *m_PadPosition_Y_Ctrl, m_dummyPad->GetPosition().y, internalUnits );
2012-02-19 04:02:19 +00:00
PutValueInLocalUnits( *m_PadDrill_X_Ctrl, m_dummyPad->GetDrillSize().x, internalUnits );
PutValueInLocalUnits( *m_PadDrill_Y_Ctrl, m_dummyPad->GetDrillSize().y, internalUnits );
2012-02-19 04:02:19 +00:00
PutValueInLocalUnits( *m_ShapeSize_X_Ctrl, m_dummyPad->GetSize().x, internalUnits );
PutValueInLocalUnits( *m_ShapeSize_Y_Ctrl, m_dummyPad->GetSize().y, internalUnits );
2012-02-19 04:02:19 +00:00
PutValueInLocalUnits( *m_ShapeOffset_X_Ctrl, m_dummyPad->GetOffset().x, internalUnits );
PutValueInLocalUnits( *m_ShapeOffset_Y_Ctrl, m_dummyPad->GetOffset().y, internalUnits );
2012-02-19 04:02:19 +00:00
if( m_dummyPad->GetDelta().x )
{
2012-02-19 04:02:19 +00:00
PutValueInLocalUnits( *m_ShapeDelta_Ctrl, m_dummyPad->GetDelta().x, internalUnits );
m_radioBtnDeltaXdir->SetValue(true);
}
else
{
2012-02-19 04:02:19 +00:00
PutValueInLocalUnits( *m_ShapeDelta_Ctrl, m_dummyPad->GetDelta().y, internalUnits );
m_radioBtnDeltaYdir->SetValue(true);
}
2012-02-19 04:02:19 +00:00
PutValueInLocalUnits( *m_LengthDieCtrl, m_dummyPad->GetDieLength(), internalUnits );
2012-02-19 04:02:19 +00:00
PutValueInLocalUnits( *m_NetClearanceValueCtrl, m_dummyPad->GetLocalClearance(), internalUnits );
PutValueInLocalUnits( *m_SolderMaskMarginCtrl,
2012-02-19 04:02:19 +00:00
m_dummyPad->GetLocalSolderMaskMargin(),
internalUnits );
// These 2 parameters are usually < 0, so prepare entering a negative value, if current is 0
PutValueInLocalUnits( *m_SolderPasteMarginCtrl,
2012-02-19 04:02:19 +00:00
m_dummyPad->GetLocalSolderPasteMargin(),
internalUnits );
2012-02-19 04:02:19 +00:00
if( m_dummyPad->GetLocalSolderPasteMargin() == 0 )
m_SolderPasteMarginCtrl->SetValue( wxT( "-" ) + m_SolderPasteMarginCtrl->GetValue() );
2012-02-19 04:02:19 +00:00
msg.Printf( wxT( "%.1f" ), m_dummyPad->GetLocalSolderPasteMarginRatio() * 100.0 );
if( m_dummyPad->GetLocalSolderPasteMarginRatio() == 0.0 && msg[0] == '0' )
// Sometimes Printf adds a sign if the value is small
m_SolderPasteMarginRatioCtrl->SetValue( wxT( "-" ) + msg );
else
m_SolderPasteMarginRatioCtrl->SetValue( msg );
2008-11-22 11:10:40 +00:00
switch( m_dummyPad->GetZoneConnection() )
{
default:
case UNDEFINED_CONNECTION:
m_ZoneConnectionChoice->SetSelection( 0 );
break;
case PAD_IN_ZONE:
m_ZoneConnectionChoice->SetSelection( 1 );
break;
case THERMAL_PAD:
m_ZoneConnectionChoice->SetSelection( 2 );
break;
case PAD_NOT_IN_ZONE:
m_ZoneConnectionChoice->SetSelection( 3 );
break;
}
2008-11-22 11:10:40 +00:00
if( m_CurrentPad )
{
2012-02-19 04:02:19 +00:00
MODULE* module = m_CurrentPad->GetParent();
angle = m_CurrentPad->GetOrientation() - module->GetOrientation();
if( m_isFlipped )
2012-02-19 04:02:19 +00:00
NEGATE( angle );
m_dummyPad->SetOrientation( angle );
2008-11-22 11:10:40 +00:00
}
2012-02-19 04:02:19 +00:00
angle = m_dummyPad->GetOrientation();
2012-02-19 04:02:19 +00:00
NORMALIZE_ANGLE_180( angle ); // ? normalizing is in D_PAD::SetOrientation()
2012-02-19 04:02:19 +00:00
// Set layers used by this pad: :
SetPadLayersList( m_dummyPad->GetLayerMask() );
2008-11-22 11:10:40 +00:00
// Pad Orient
2012-02-19 04:02:19 +00:00
switch( int( angle ) )
2008-11-22 11:10:40 +00:00
{
case 0:
m_PadOrient->SetSelection( 0 );
break;
case 900:
m_PadOrient->SetSelection( 1 );
break;
case - 900:
m_PadOrient->SetSelection( 2 );
break;
case 1800:
case -1800:
2008-11-22 11:10:40 +00:00
m_PadOrient->SetSelection( 3 );
break;
default:
m_PadOrient->SetSelection( 4 );
break;
}
2012-02-19 04:02:19 +00:00
switch( m_dummyPad->GetShape() )
2008-11-22 11:10:40 +00:00
{
default:
case PAD_CIRCLE:
m_PadShape->SetSelection( 0 );
break;
case PAD_OVAL:
m_PadShape->SetSelection( 1 );
break;
case PAD_RECT:
m_PadShape->SetSelection( 2 );
break;
case PAD_TRAPEZOID:
m_PadShape->SetSelection( 3 );
break;
}
2012-02-19 04:02:19 +00:00
msg.Printf( wxT( "%g" ), angle );
m_PadOrientCtrl->SetValue( msg );
2008-11-22 11:10:40 +00:00
// Type of pad selection
2008-11-22 11:10:40 +00:00
m_PadType->SetSelection( 0 );
2012-02-19 04:02:19 +00:00
2008-11-22 11:10:40 +00:00
for( int ii = 0; ii < NBTYPES; ii++ )
{
2012-02-19 04:02:19 +00:00
if( CodeType[ii] == m_dummyPad->GetAttribute() )
2008-11-22 11:10:40 +00:00
{
m_PadType->SetSelection( ii );
break;
2008-11-22 11:10:40 +00:00
}
}
// Enable/disable Pad name,and pad length die
// (disable for NPTH pads (mechanical pads)
2012-02-19 04:02:19 +00:00
bool enable = m_dummyPad->GetAttribute() != PAD_HOLE_NOT_PLATED;
m_PadNumCtrl->Enable( enable );
m_PadNetNameCtrl->Enable( enable );
m_LengthDieCtrl->Enable( enable );
2012-02-19 04:02:19 +00:00
if( m_dummyPad->GetDrillShape() != PAD_OVAL )
2008-11-22 11:10:40 +00:00
m_DrillShapeCtrl->SetSelection( 0 );
else
m_DrillShapeCtrl->SetSelection( 1 );
// Setup layers names from board
m_rbCopperLayersSel->SetString( 0, m_Board->GetLayerName( LAYER_N_FRONT ) );
m_rbCopperLayersSel->SetString( 1, m_Board->GetLayerName( LAYER_N_BACK ) );
m_PadLayerAdhCmp->SetLabel( m_Board->GetLayerName( ADHESIVE_N_FRONT ) );
m_PadLayerAdhCu->SetLabel( m_Board->GetLayerName( ADHESIVE_N_BACK ) );
m_PadLayerPateCmp->SetLabel( m_Board->GetLayerName( SOLDERPASTE_N_FRONT ) );
m_PadLayerPateCu->SetLabel( m_Board->GetLayerName( SOLDERPASTE_N_BACK ) );
m_PadLayerSilkCmp->SetLabel( m_Board->GetLayerName( SILKSCREEN_N_FRONT ) );
m_PadLayerSilkCu->SetLabel( m_Board->GetLayerName( SILKSCREEN_N_BACK ) );
m_PadLayerMaskCmp->SetLabel( m_Board->GetLayerName( SOLDERMASK_N_FRONT ) );
m_PadLayerMaskCu->SetLabel( m_Board->GetLayerName( SOLDERMASK_N_BACK ) );
m_PadLayerECO1->SetLabel( m_Board->GetLayerName( ECO1_N ) );
m_PadLayerECO2->SetLabel( m_Board->GetLayerName( ECO2_N ) );
m_PadLayerDraft->SetLabel( m_Board->GetLayerName( DRAW_N ) );
2012-02-19 04:02:19 +00:00
// Update some dialog widgets state (Enable/disable options):
wxCommandEvent cmd_event;
OnPadShapeSelection( cmd_event );
OnDrillShapeSelected( cmd_event );
2008-11-22 11:10:40 +00:00
}
void DIALOG_PAD_PROPERTIES::OnPadShapeSelection( wxCommandEvent& event )
2008-11-22 11:10:40 +00:00
{
switch( m_PadShape->GetSelection() )
{
case 0: //CIRCLE:
m_ShapeDelta_Ctrl->Enable( false );
m_radioBtnDeltaXdir->Enable( false );
m_radioBtnDeltaYdir->Enable( false );
m_ShapeSize_Y_Ctrl->Enable( false );
2008-11-22 11:10:40 +00:00
break;
case 1: //OVALE:
m_ShapeDelta_Ctrl->Enable( false );
m_radioBtnDeltaXdir->Enable( false );
m_radioBtnDeltaYdir->Enable( false );
m_ShapeSize_Y_Ctrl->Enable( true );
2008-11-22 11:10:40 +00:00
break;
case 2: // PAD_RECT:
m_ShapeDelta_Ctrl->Enable( false );
m_radioBtnDeltaXdir->Enable( false );
m_radioBtnDeltaYdir->Enable( false );
m_ShapeSize_Y_Ctrl->Enable( true );
2008-11-22 11:10:40 +00:00
break;
case 3: //TRAPEZE:
m_ShapeDelta_Ctrl->Enable( true );
m_radioBtnDeltaXdir->Enable( true );
m_radioBtnDeltaYdir->Enable( true );
m_ShapeSize_Y_Ctrl->Enable( true );
2008-11-22 11:10:40 +00:00
break;
}
TransfertDataToPad( m_dummyPad );
m_panelShowPad->Refresh();
2008-11-22 11:10:40 +00:00
}
void DIALOG_PAD_PROPERTIES::OnDrillShapeSelected( wxCommandEvent& event )
2008-11-22 11:10:40 +00:00
{
2012-02-19 04:02:19 +00:00
if( m_PadType->GetSelection() == 1 || m_PadType->GetSelection() == 2 )
{
// pad type = SMD or CONN: no hole allowed
m_PadDrill_X_Ctrl->Enable( false );
m_PadDrill_Y_Ctrl->Enable( false );
2008-11-22 11:10:40 +00:00
}
else
2008-11-22 11:10:40 +00:00
{
switch( m_DrillShapeCtrl->GetSelection() )
{
case 0: //CIRCLE:
m_PadDrill_X_Ctrl->Enable( true );
m_PadDrill_Y_Ctrl->Enable( false );
break;
case 1: //OVALE:
m_PadDrill_X_Ctrl->Enable( true );
m_PadDrill_Y_Ctrl->Enable( true );
break;
}
2008-11-22 11:10:40 +00:00
}
TransfertDataToPad( m_dummyPad );
m_panelShowPad->Refresh();
2008-11-22 11:10:40 +00:00
}
void DIALOG_PAD_PROPERTIES::PadOrientEvent( wxCommandEvent& event )
2008-11-22 11:10:40 +00:00
{
switch( m_PadOrient->GetSelection() )
{
case 0:
2012-02-19 04:02:19 +00:00
m_dummyPad->SetOrientation( 0 );
2008-11-22 11:10:40 +00:00
break;
case 1:
2012-02-19 04:02:19 +00:00
m_dummyPad->SetOrientation( 900 );
2008-11-22 11:10:40 +00:00
break;
case 2:
2012-02-19 04:02:19 +00:00
m_dummyPad->SetOrientation( -900 );
2008-11-22 11:10:40 +00:00
break;
case 3:
2012-02-19 04:02:19 +00:00
m_dummyPad->SetOrientation( 1800 );
2008-11-22 11:10:40 +00:00
break;
default:
break;
}
wxString msg;
2012-01-04 06:18:38 +00:00
msg.Printf( wxT( "%g" ), m_dummyPad->GetOrientation() );
m_PadOrientCtrl->SetValue( msg );
TransfertDataToPad( m_dummyPad );
m_panelShowPad->Refresh();
2008-11-22 11:10:40 +00:00
}
void DIALOG_PAD_PROPERTIES::PadTypeSelected( wxCommandEvent& event )
2008-11-22 11:10:40 +00:00
/* Adjust the better mask layer according to the selected pad type
*/
{
long layer_mask;
int ii;
ii = m_PadType->GetSelection();
if( (ii < 0) || ( ii >= NBTYPES) )
ii = 0;
layer_mask = Std_Pad_Layers[ii];
SetPadLayersList( layer_mask );
// Enable/disable drill dialog items:
event.SetId( m_DrillShapeCtrl->GetSelection() );
2008-11-22 11:10:40 +00:00
OnDrillShapeSelected( event );
// Enable/disable Pad name,and pad length die
// (disable for NPTH pads (mechanical pads)
bool enable = ii != 3;
m_PadNumCtrl->Enable( enable );
m_PadNetNameCtrl->Enable( enable );
m_LengthDieCtrl->Enable( enable );
2008-11-22 11:10:40 +00:00
}
void DIALOG_PAD_PROPERTIES::SetPadLayersList( long layer_mask )
2008-11-22 11:10:40 +00:00
/** SetPadLayersList
* Update the CheckBoxes state in pad layers list,
* @param layer_mask = pad layer mask (ORed layers bit mask)
*/
{
if( ( layer_mask & ALL_CU_LAYERS ) == LAYER_FRONT )
m_rbCopperLayersSel->SetSelection(0);
else if( ( layer_mask & ALL_CU_LAYERS ) == LAYER_BACK)
m_rbCopperLayersSel->SetSelection(1);
else if( ( layer_mask & ALL_CU_LAYERS ) != 0 )
m_rbCopperLayersSel->SetSelection(2);
else
m_rbCopperLayersSel->SetSelection(3);
2008-11-22 11:10:40 +00:00
m_PadLayerAdhCmp->SetValue( ( layer_mask & ADHESIVE_LAYER_FRONT ) );
m_PadLayerAdhCu->SetValue( ( layer_mask & ADHESIVE_LAYER_BACK ) );
2008-11-22 11:10:40 +00:00
m_PadLayerPateCmp->SetValue( ( layer_mask & SOLDERPASTE_LAYER_FRONT ) );
m_PadLayerPateCu->SetValue( ( layer_mask & SOLDERPASTE_LAYER_BACK ) );
2008-11-22 11:10:40 +00:00
m_PadLayerSilkCmp->SetValue( ( layer_mask & SILKSCREEN_LAYER_FRONT ) );
m_PadLayerSilkCu->SetValue( ( layer_mask & SILKSCREEN_LAYER_BACK ) );
2008-11-22 11:10:40 +00:00
m_PadLayerMaskCmp->SetValue( ( layer_mask & SOLDERMASK_LAYER_FRONT ) );
m_PadLayerMaskCu->SetValue( ( layer_mask & SOLDERMASK_LAYER_BACK ) );
2008-11-22 11:10:40 +00:00
m_PadLayerECO1->SetValue( ( layer_mask & ECO1_LAYER ) );
m_PadLayerECO2->SetValue( ( layer_mask & ECO2_LAYER ) );
m_PadLayerDraft->SetValue( ( layer_mask & DRAW_LAYER ) );
}
// Called when select/deselect a layer.
void DIALOG_PAD_PROPERTIES::OnSetLayers( wxCommandEvent& event )
{
TransfertDataToPad( m_dummyPad );
m_panelShowPad->Refresh();
}
void DIALOG_PAD_PROPERTIES::PadPropertiesAccept( wxCommandEvent& event )
2008-11-22 11:10:40 +00:00
/* Updates the different parameters for the component being edited.
2008-11-22 11:10:40 +00:00
*/
{
bool rastnestIsChanged = false;
int isign = m_isFlipped ? -1 : 1;
bool success = TransfertDataToPad( m_dummyPad, true );
if( !success ) // An error on parameters has occured
return;
2012-02-19 04:02:19 +00:00
TransfertDataToPad( &m_Pad_Master, false );
if( m_CurrentPad ) // Set current Pad parameters
{
2012-02-19 04:02:19 +00:00
wxSize size;
MODULE* module = m_CurrentPad->GetParent();
m_Parent->SaveCopyInUndoList( module, UR_CHANGED );
module->m_LastEdit_Time = time( NULL );
// redraw the area where the pad was, without pad (delete pad on screen)
m_CurrentPad->SetFlags( DO_NOT_DRAW );
m_Parent->GetCanvas()->RefreshDrawingRect( m_CurrentPad->GetBoundingBox() );
m_CurrentPad->ClearFlags( DO_NOT_DRAW );
// Update values
2012-02-19 04:02:19 +00:00
m_CurrentPad->SetShape( m_Pad_Master.GetShape() );
m_CurrentPad->SetAttribute( m_Pad_Master.GetAttribute() );
2012-02-19 04:02:19 +00:00
if( m_CurrentPad->GetPosition() != m_Pad_Master.GetPosition() )
{
2012-02-19 04:02:19 +00:00
m_CurrentPad->SetPosition( m_Pad_Master.GetPosition() );
rastnestIsChanged = true;
}
2012-02-19 04:02:19 +00:00
// compute the pos 0 value, i.e. pad position for module with orientation = 0
// i.e. relative to module origin (module position)
wxPoint pt = m_CurrentPad->GetPosition() - module->GetPosition();
RotatePoint( &pt, -module->GetOrientation() );
m_CurrentPad->SetPos0( pt );
m_CurrentPad->SetOrientation( m_Pad_Master.GetOrientation() * isign + module->GetOrientation() );
m_CurrentPad->SetSize( m_Pad_Master.GetSize() );
2012-02-19 04:02:19 +00:00
size = m_Pad_Master.GetDelta();
size.y *= isign;
m_CurrentPad->SetDelta( size );
2012-02-19 04:02:19 +00:00
m_CurrentPad->SetDrillSize( m_Pad_Master.GetDrillSize() );
m_CurrentPad->SetDrillShape( m_Pad_Master.GetDrillShape() );
2012-02-19 04:02:19 +00:00
wxPoint offset = m_Pad_Master.GetOffset();
offset.y *= isign;
m_CurrentPad->SetOffset( offset );
m_CurrentPad->SetDieLength( m_Pad_Master.GetDieLength() );
if( m_CurrentPad->GetLayerMask() != m_Pad_Master.GetLayerMask() )
{
rastnestIsChanged = true;
2012-02-19 04:02:19 +00:00
m_CurrentPad->SetLayerMask( m_Pad_Master.GetLayerMask() );
}
2012-02-19 04:02:19 +00:00
if( m_isFlipped )
2012-02-19 04:02:19 +00:00
m_CurrentPad->SetLayerMask( ChangeSideMaskLayer( m_CurrentPad->GetLayerMask() ) );
2012-02-19 04:02:19 +00:00
m_CurrentPad->SetPadName( m_Pad_Master.GetPadName() );
2012-02-19 04:02:19 +00:00
if( m_CurrentPad->GetNetname() != m_Pad_Master.GetNetname() )
{
2012-02-19 04:02:19 +00:00
if( m_Pad_Master.GetNetname().IsEmpty() )
{
rastnestIsChanged = true;
m_CurrentPad->SetNet( 0 );
m_CurrentPad->SetNetname( wxEmptyString );
}
else
{
2012-02-19 04:02:19 +00:00
const NETINFO_ITEM* net = m_Parent->GetBoard()->FindNet( m_Pad_Master.GetNetname() );
if( net )
{
rastnestIsChanged = true;
2012-02-19 04:02:19 +00:00
m_CurrentPad->SetNetname( m_Pad_Master.GetNetname() );
m_CurrentPad->SetNet( net->GetNet() );
}
else
DisplayError( NULL, _( "Unknown netname, netname not changed" ) );
}
}
2012-02-19 04:02:19 +00:00
m_CurrentPad->SetLocalClearance( m_Pad_Master.GetLocalClearance() );
m_CurrentPad->SetLocalSolderMaskMargin( m_Pad_Master.GetLocalSolderMaskMargin() );
m_CurrentPad->SetLocalSolderPasteMargin( m_Pad_Master.GetLocalSolderPasteMargin() );
m_CurrentPad->SetLocalSolderPasteMarginRatio( m_Pad_Master.GetLocalSolderPasteMarginRatio() );
m_CurrentPad->SetZoneConnection( m_Pad_Master.GetZoneConnection() );
2012-02-19 04:02:19 +00:00
module->CalculateBoundingBox();
m_CurrentPad->DisplayInfo( m_Parent );
// redraw the area where the pad was
m_Parent->GetCanvas()->RefreshDrawingRect( m_CurrentPad->GetBoundingBox() );
m_Parent->OnModify();
}
EndModal( wxID_OK );
if( rastnestIsChanged ) // The net ratsnest must be recalculated
m_Parent->GetBoard()->m_Status_Pcb = 0;
}
// Copy values from dialog to aPad parameters.
// If aPromptOnError is true, and an incorrect value is detected,
// user will be prompted for an error
bool DIALOG_PAD_PROPERTIES::TransfertDataToPad( D_PAD* aPad, bool aPromptOnError )
{
2012-02-19 04:02:19 +00:00
long padLayerMask;
int internalUnits = m_Parent->GetInternalUnits();
wxString msg;
int x, y;
2008-11-22 11:10:40 +00:00
2012-02-19 04:02:19 +00:00
aPad->SetAttribute( CodeType[m_PadType->GetSelection()] );
aPad->SetShape( CodeShape[m_PadShape->GetSelection()] );
// Read pad clearances values:
2012-02-19 04:02:19 +00:00
aPad->SetLocalClearance( ReturnValueFromTextCtrl( *m_NetClearanceValueCtrl,
internalUnits ) );
aPad->SetLocalSolderMaskMargin( ReturnValueFromTextCtrl( *m_SolderMaskMarginCtrl,
internalUnits ) );
aPad->SetLocalSolderPasteMargin( ReturnValueFromTextCtrl( *m_SolderPasteMarginCtrl,
internalUnits ) );
double dtmp = 0.0;
msg = m_SolderPasteMarginRatioCtrl->GetValue();
msg.ToDouble( &dtmp );
2012-02-19 04:02:19 +00:00
// A margin ratio of -50% means no paste on a pad, the ratio must be >= 50 %
if( dtmp < -50 )
dtmp = -50;
if( dtmp > +100 )
dtmp = +100;
2012-02-19 04:02:19 +00:00
aPad->SetLocalSolderPasteMarginRatio( dtmp / 100 );
switch( m_ZoneConnectionChoice->GetSelection() )
{
default:
case 0:
aPad->SetZoneConnection( UNDEFINED_CONNECTION );
break;
case 1:
aPad->SetZoneConnection( PAD_IN_ZONE );
break;
case 2:
aPad->SetZoneConnection( THERMAL_PAD );
break;
case 3:
aPad->SetZoneConnection( PAD_NOT_IN_ZONE );
break;
}
// Read pad position:
2012-02-19 04:02:19 +00:00
x = ReturnValueFromTextCtrl( *m_PadPosition_X_Ctrl, internalUnits );
y = ReturnValueFromTextCtrl( *m_PadPosition_Y_Ctrl, internalUnits );
aPad->SetPosition( wxPoint( x, y ) );
aPad->SetPos0( wxPoint( x, y ) );
// Read pad drill:
2012-02-19 04:02:19 +00:00
x = ReturnValueFromTextCtrl( *m_PadDrill_X_Ctrl, internalUnits );
y = ReturnValueFromTextCtrl( *m_PadDrill_Y_Ctrl, internalUnits );
2008-11-22 11:10:40 +00:00
if( m_DrillShapeCtrl->GetSelection() == 0 )
{
2012-02-19 04:02:19 +00:00
aPad->SetDrillShape( PAD_CIRCLE );
y = x;
2008-11-22 11:10:40 +00:00
}
else
2012-02-19 04:02:19 +00:00
aPad->SetDrillShape( PAD_OVAL );
aPad->SetDrillSize( wxSize( x, y ) );
// Read pad shape size:
2012-02-19 04:02:19 +00:00
x = ReturnValueFromTextCtrl( *m_ShapeSize_X_Ctrl, internalUnits );
y = ReturnValueFromTextCtrl( *m_ShapeSize_Y_Ctrl, internalUnits );
if( aPad->GetShape() == PAD_CIRCLE )
y = x;
aPad->SetSize( wxSize( x, y ) );
// Read pad length die
aPad->SetDieLength( ReturnValueFromTextCtrl( *m_LengthDieCtrl, internalUnits ) );
// Read pad shape delta size:
// m_DeltaSize.x or m_DeltaSize.y must be NULL. for a trapezoid.
wxSize delta;
2012-02-19 04:02:19 +00:00
if( m_radioBtnDeltaXdir->GetValue() )
delta.x = ReturnValueFromTextCtrl( *m_ShapeDelta_Ctrl, internalUnits );
else
delta.y = ReturnValueFromTextCtrl( *m_ShapeDelta_Ctrl, internalUnits );
2012-02-19 04:02:19 +00:00
// Test bad values (be sure delta values are not too large)
// remember DeltaSize.x is the Y size variation
bool error = false;
2012-02-19 04:02:19 +00:00
if( delta.x < 0 && delta.x <= -aPad->GetSize().y )
{
2012-02-19 04:02:19 +00:00
delta.x = -aPad->GetSize().y + 2;
error = true;
}
2012-02-19 04:02:19 +00:00
if( delta.x > 0 && delta.x >= aPad->GetSize().y )
{
2012-02-19 04:02:19 +00:00
delta.x = aPad->GetSize().y - 2;
error = true;
}
2012-02-19 04:02:19 +00:00
if( delta.y < 0 && delta.y <= -aPad->GetSize().x )
{
2012-02-19 04:02:19 +00:00
delta.y = -aPad->GetSize().x + 2;
error = true;
}
2012-02-19 04:02:19 +00:00
if( delta.y > 0 && delta.y >= aPad->GetSize().x )
{
2012-02-19 04:02:19 +00:00
delta.y = aPad->GetSize().x - 2;
error = true;
}
2012-02-19 04:02:19 +00:00
aPad->SetDelta( delta );
// Read pad shape offset:
2012-02-19 04:02:19 +00:00
x = ReturnValueFromTextCtrl( *m_ShapeOffset_X_Ctrl, internalUnits );
y = ReturnValueFromTextCtrl( *m_ShapeOffset_Y_Ctrl, internalUnits );
aPad->SetOffset( wxPoint( x, y ) );
2012-01-04 06:18:38 +00:00
double orient_value = 0;
msg = m_PadOrientCtrl->GetValue();
2012-01-04 06:18:38 +00:00
msg.ToDouble( &orient_value );
aPad->SetOrientation( orient_value );
2008-11-22 11:10:40 +00:00
msg = m_PadNumCtrl->GetValue().Left( 4 );
aPad->SetPadName( msg );
aPad->SetNetname( m_PadNetNameCtrl->GetValue() );
2008-11-22 11:10:40 +00:00
2010-02-12 17:15:47 +00:00
// Clear some values, according to the pad type and shape
2012-02-19 04:02:19 +00:00
switch( aPad->GetShape() )
2010-02-12 17:15:47 +00:00
{
case PAD_CIRCLE:
2012-02-19 04:02:19 +00:00
aPad->SetOffset( wxPoint( 0, 0 ) );
aPad->SetDelta( wxSize( 0, 0 ) );
x = aPad->GetSize().x;
aPad->SetSize( wxSize( x, x ) );
2010-02-12 17:15:47 +00:00
break;
case PAD_RECT:
2012-02-19 04:02:19 +00:00
aPad->SetDelta( wxSize( 0, 0 ) );
2010-02-12 17:15:47 +00:00
break;
case PAD_OVAL:
2012-02-19 04:02:19 +00:00
aPad->SetDelta( wxSize( 0, 0 ) );
2010-02-12 17:15:47 +00:00
break;
case PAD_TRAPEZOID:
break;
2012-02-19 04:02:19 +00:00
default:
;
2010-02-12 17:15:47 +00:00
}
2012-02-19 04:02:19 +00:00
switch( aPad->GetAttribute() )
2010-02-12 17:15:47 +00:00
{
case PAD_STANDARD:
break;
case PAD_CONN:
case PAD_SMD:
2012-02-19 04:02:19 +00:00
aPad->SetOffset( wxPoint( 0, 0 ) );
aPad->SetDrillSize( wxSize( 0, 0 ) );
2010-02-12 17:15:47 +00:00
break;
case PAD_HOLE_NOT_PLATED:
// Mechanical purpose only:
// no offset, no net name, no pad name allowed
2012-02-19 04:02:19 +00:00
aPad->SetOffset( wxPoint( 0, 0 ) );
aPad->SetPadName( wxEmptyString );
aPad->SetNetname( wxEmptyString );
2010-02-12 17:15:47 +00:00
break;
default:
DisplayError( NULL, wxT( "Error: unknown pad type" ) );
2010-02-12 17:15:47 +00:00
break;
}
2012-02-19 04:02:19 +00:00
padLayerMask = 0;
switch( m_rbCopperLayersSel->GetSelection() )
{
2012-02-19 04:02:19 +00:00
case 0:
padLayerMask |= LAYER_FRONT;
break;
2012-02-19 04:02:19 +00:00
case 1:
padLayerMask |= LAYER_BACK;
break;
2012-02-19 04:02:19 +00:00
case 2:
padLayerMask |= ALL_CU_LAYERS;
break;
2012-02-19 04:02:19 +00:00
case 3: // No copper layers
break;
}
2008-11-22 11:10:40 +00:00
if( m_PadLayerAdhCmp->GetValue() )
2012-02-19 04:02:19 +00:00
padLayerMask |= ADHESIVE_LAYER_FRONT;
2008-11-22 11:10:40 +00:00
if( m_PadLayerAdhCu->GetValue() )
2012-02-19 04:02:19 +00:00
padLayerMask |= ADHESIVE_LAYER_BACK;
2008-11-22 11:10:40 +00:00
if( m_PadLayerPateCmp->GetValue() )
2012-02-19 04:02:19 +00:00
padLayerMask |= SOLDERPASTE_LAYER_FRONT;
2008-11-22 11:10:40 +00:00
if( m_PadLayerPateCu->GetValue() )
2012-02-19 04:02:19 +00:00
padLayerMask |= SOLDERPASTE_LAYER_BACK;
2008-11-22 11:10:40 +00:00
if( m_PadLayerSilkCmp->GetValue() )
2012-02-19 04:02:19 +00:00
padLayerMask |= SILKSCREEN_LAYER_FRONT;
2008-11-22 11:10:40 +00:00
if( m_PadLayerSilkCu->GetValue() )
2012-02-19 04:02:19 +00:00
padLayerMask |= SILKSCREEN_LAYER_BACK;
2008-11-22 11:10:40 +00:00
if( m_PadLayerMaskCmp->GetValue() )
2012-02-19 04:02:19 +00:00
padLayerMask |= SOLDERMASK_LAYER_FRONT;
2008-11-22 11:10:40 +00:00
if( m_PadLayerMaskCu->GetValue() )
2012-02-19 04:02:19 +00:00
padLayerMask |= SOLDERMASK_LAYER_BACK;
2008-11-22 11:10:40 +00:00
if( m_PadLayerECO1->GetValue() )
2012-02-19 04:02:19 +00:00
padLayerMask |= ECO1_LAYER;
2008-11-22 11:10:40 +00:00
if( m_PadLayerECO2->GetValue() )
2012-02-19 04:02:19 +00:00
padLayerMask |= ECO2_LAYER;
2008-11-22 11:10:40 +00:00
if( m_PadLayerDraft->GetValue() )
2012-02-19 04:02:19 +00:00
padLayerMask |= DRAW_LAYER;
2008-11-22 11:10:40 +00:00
2012-02-19 04:02:19 +00:00
aPad->SetLayerMask( padLayerMask );
2010-03-07 13:33:20 +00:00
2012-02-19 04:02:19 +00:00
// Test for incorrect values
if( aPromptOnError )
2010-03-07 13:33:20 +00:00
{
2012-02-19 04:02:19 +00:00
if( (aPad->GetSize().x < aPad->GetDrillSize().x) || (aPad->GetSize().y < aPad->GetDrillSize().y) )
2010-03-07 13:33:20 +00:00
{
DisplayError( NULL, _( "Incorrect value for pad drill: pad drill bigger than pad size" ) );
return false;
2010-03-07 13:33:20 +00:00
}
2008-11-22 11:10:40 +00:00
2012-02-19 04:02:19 +00:00
int padlayers_mask = padLayerMask & (LAYER_BACK | LAYER_FRONT);
if( padlayers_mask == 0 )
2008-11-22 11:10:40 +00:00
{
2012-02-19 04:02:19 +00:00
if( aPad->GetDrillSize().x || aPad->GetDrillSize().y )
{
msg = _( "Error: pad is not on a copper layer and has a hole" );
2012-02-19 04:02:19 +00:00
if( aPad->GetAttribute() == PAD_HOLE_NOT_PLATED )
{
msg += wxT("\n");
msg += _( "For NPTH pad, set pad drill value to pad size value,\n\
if you do not want this pad plotted in gerber files");
}
DisplayError( NULL, msg );
return false;
}
2008-11-22 11:10:40 +00:00
}
2012-02-19 04:02:19 +00:00
if( aPad->GetSize().x / 2 <= ABS( aPad->GetOffset().x ) ||
aPad->GetSize().y / 2 <= ABS( aPad->GetOffset().y ) )
{
DisplayError( NULL, _( "Incorrect value for pad offset" ) );
return false;
}
2008-11-22 11:10:40 +00:00
if( error )
2008-11-22 11:10:40 +00:00
{
DisplayError( NULL, _( "Too large value for pad delta size" ) );
return false;
2008-11-22 11:10:40 +00:00
}
}
2008-11-22 11:10:40 +00:00
return true;
}
2008-11-22 11:10:40 +00:00
// Called when a dimension has change.
// Update the pad dimensions shown in the panel.
void DIALOG_PAD_PROPERTIES::OnValuesChanged( wxCommandEvent& event )
{
if( m_canUpdate )
{
TransfertDataToPad( m_dummyPad );
m_panelShowPad->Refresh();
2008-11-22 11:10:40 +00:00
}
}
/*********************************************************************/
void DIALOG_PAD_PROPERTIES::OnCancelButtonClick( wxCommandEvent& event )
/*********************************************************************/
{
EndModal( wxID_CANCEL );
}