kicad/pcbnew/globaleditpad.cpp

365 lines
11 KiB
C++
Raw Normal View History

/**
* @file globaleditpad.cpp
*/
#include <fctsys.h>
#include <common.h>
#include <class_drawpanel.h>
#include <confirm.h>
#include <wxPcbStruct.h>
#include <pcbcommon.h>
#include <module_editor_frame.h>
#include <class_board.h>
#include <class_module.h>
#include <pcbnew.h>
#include <dialog_global_pads_edition_base.h>
2008-03-04 14:27:48 +00:00
/************************************/
/* class DIALOG_GLOBAL_PADS_EDITION */
2008-03-04 14:27:48 +00:00
/************************************/
class DIALOG_GLOBAL_PADS_EDITION : public DIALOG_GLOBAL_PADS_EDITION_BASE
{
private:
PCB_BASE_FRAME* m_parent;
D_PAD* m_currentPad;
public:
static bool m_Pad_Shape_Filter;
static bool m_Pad_Layer_Filter;
static bool m_Pad_Orient_Filter;
public:
2012-02-19 04:02:19 +00:00
DIALOG_GLOBAL_PADS_EDITION( PCB_BASE_FRAME* aParent, D_PAD* aPad );
private:
void InstallPadEditor( wxCommandEvent& event );
void PadPropertiesAccept( wxCommandEvent& event );
void OnCancelClick( wxCommandEvent& event );
};
2012-02-19 04:02:19 +00:00
DIALOG_GLOBAL_PADS_EDITION::DIALOG_GLOBAL_PADS_EDITION( PCB_BASE_FRAME* aParent, D_PAD* aPad ) :
DIALOG_GLOBAL_PADS_EDITION_BASE( aParent )
{
m_parent = aParent;
m_currentPad = aPad;
2008-03-04 14:27:48 +00:00
// Pad filter selection.
m_Pad_Shape_Filter_CB->SetValue( m_Pad_Shape_Filter );
m_Pad_Layer_Filter_CB->SetValue( m_Pad_Layer_Filter );
m_Pad_Orient_Filter_CB->SetValue( m_Pad_Orient_Filter );
2008-03-04 14:27:48 +00:00
SetFocus();
GetSizer()->Fit( this );
Centre();
}
2008-03-04 14:27:48 +00:00
2012-02-19 04:02:19 +00:00
// Class DIALOG_GLOBAL_PADS_EDITION static variables
bool DIALOG_GLOBAL_PADS_EDITION::m_Pad_Shape_Filter = true;
bool DIALOG_GLOBAL_PADS_EDITION::m_Pad_Layer_Filter = true;
bool DIALOG_GLOBAL_PADS_EDITION::m_Pad_Orient_Filter = true;
2008-03-04 14:27:48 +00:00
void DIALOG_GLOBAL_PADS_EDITION::OnCancelClick( wxCommandEvent& event )
{
EndModal( -1 );
}
/* Calls the Pad editor.
*/
void DIALOG_GLOBAL_PADS_EDITION::InstallPadEditor( wxCommandEvent& event )
{
m_parent->InstallPadOptionsFrame( m_currentPad );
}
/* Update the parameters for the component being edited.
*/
void DIALOG_GLOBAL_PADS_EDITION::PadPropertiesAccept( wxCommandEvent& event )
{
2008-03-04 14:27:48 +00:00
int returncode = 0;
switch( event.GetId() )
{
case ID_CHANGE_ID_MODULES:
returncode = 1;
// Fall through
2008-03-04 14:27:48 +00:00
case ID_CHANGE_CURRENT_MODULE:
m_Pad_Shape_Filter = m_Pad_Shape_Filter_CB->GetValue();
m_Pad_Layer_Filter = m_Pad_Layer_Filter_CB->GetValue();
m_Pad_Orient_Filter = m_Pad_Orient_Filter_CB->GetValue();
2008-03-04 14:27:48 +00:00
EndModal( returncode );
break;
}
m_parent->OnModify();
}
/*
* PCB_EDIT_FRAME::Function DlgGlobalChange_PadSettings
2008-04-18 13:28:56 +00:00
* Function to change pad caracteristics for the given footprint
* or alls footprints which look like the given footprint
* Options are set by the opened dialog.
* aPad is the pattern. The given footprint is the parent of this pad
* aRedraw: if true: redraws the footprint
*/
void PCB_EDIT_FRAME::DlgGlobalChange_PadSettings( D_PAD* aPad, bool aRedraw )
{
2008-03-04 14:27:48 +00:00
int diag;
2008-04-18 13:28:56 +00:00
if( aPad == NULL )
2012-02-19 04:02:19 +00:00
aPad = &GetDesignSettings().m_Pad_Master;
2008-03-04 14:27:48 +00:00
2012-02-19 04:02:19 +00:00
MODULE* module = aPad->GetParent();
2008-03-04 14:27:48 +00:00
2012-02-19 04:02:19 +00:00
if( module == NULL )
2008-03-04 14:27:48 +00:00
{
DisplayError( this, wxT( "Global_Import_Pad_Settings() Error: NULL module" ) );
2008-03-04 14:27:48 +00:00
return;
}
SetMsgPanel( module );
2008-03-04 14:27:48 +00:00
2012-02-19 04:02:19 +00:00
{
DIALOG_GLOBAL_PADS_EDITION dlg( this, aPad );
2008-03-04 14:27:48 +00:00
2012-02-19 04:02:19 +00:00
diag = dlg.ShowModal();
}
2008-03-04 14:27:48 +00:00
if( diag == -1 )
return;
bool edit_Same_Modules = false;
2008-03-04 14:27:48 +00:00
if( diag == 1 )
edit_Same_Modules = true;
2008-03-04 14:27:48 +00:00
GlobalChange_PadSettings( aPad,edit_Same_Modules,
DIALOG_GLOBAL_PADS_EDITION::m_Pad_Shape_Filter,
DIALOG_GLOBAL_PADS_EDITION::m_Pad_Orient_Filter,
DIALOG_GLOBAL_PADS_EDITION::m_Pad_Layer_Filter,
aRedraw, true );
}
2008-03-04 14:27:48 +00:00
/*
* FOOTPRINT_EDIT_FRAME::Function DlgGlobalChange_PadSettings
* Function to change pad caracteristics for the given footprint
* or alls footprints which look like the given footprint
* Options are set by the opened dialog.
* aPad is the pattern. The given footprint is the parent of this pad
*/
void FOOTPRINT_EDIT_FRAME::DlgGlobalChange_PadSettings( D_PAD* aPad )
{
int diag;
if( aPad == NULL )
2012-02-19 04:02:19 +00:00
aPad = &GetDesignSettings().m_Pad_Master;
2012-02-19 04:02:19 +00:00
MODULE* module = aPad->GetParent();
2012-02-19 04:02:19 +00:00
if( module == NULL )
2008-03-04 14:27:48 +00:00
{
DisplayError( this, wxT( "Global_Import_Pad_Settings() Error: NULL module" ) );
return;
}
SetMsgPanel( module );
2012-02-19 04:02:19 +00:00
{
DIALOG_GLOBAL_PADS_EDITION dlg( this, aPad );
2012-02-19 04:02:19 +00:00
dlg.m_buttonIdModules->Enable( false );
diag = dlg.ShowModal();
}
if( diag == -1 )
return;
bool edit_Same_Modules = false;
if( diag == 1 )
edit_Same_Modules = true;
2012-02-19 04:02:19 +00:00
GlobalChange_PadSettings( aPad, edit_Same_Modules,
DIALOG_GLOBAL_PADS_EDITION::m_Pad_Shape_Filter,
DIALOG_GLOBAL_PADS_EDITION::m_Pad_Orient_Filter,
DIALOG_GLOBAL_PADS_EDITION::m_Pad_Layer_Filter,
true, false );
}
/*
* Function GlobalChange_PadSettings
* Function to change pad caracteristics for the given footprint
* or alls footprints which look like the given footprint
* aPad is the pattern. The given footprint is the parent of this pad
* aSameFootprints: if true, make changes on all identical footprints
* aPadShapeFilter: if true, make changes only on pads having the same shape as aPad
* aPadOrientFilter: if true, make changes only on pads having the same orientation as aPad
* aPadLayerFilter: if true, make changes only on pads having the same layers as aPad
* aRedraw: if true: redraws the footprint
* aSaveForUndo: if true: create an entry in the Undo/Redo list
* (usually: true in Schematic editor, false in Module editor)
*/
void PCB_BASE_FRAME::GlobalChange_PadSettings( D_PAD* aPad,
bool aSameFootprints,
bool aPadShapeFilter,
bool aPadOrientFilter,
bool aPadLayerFilter,
bool aRedraw, bool aSaveForUndo )
{
if( aPad == NULL )
2012-02-19 04:02:19 +00:00
aPad = &GetDesignSettings().m_Pad_Master;
2012-02-19 04:02:19 +00:00
MODULE* module = aPad->GetParent();
2012-02-19 04:02:19 +00:00
if( module == NULL )
{
DisplayError( this, wxT( "Global_Import_Pad_Settings() Error: NULL module" ) );
return;
}
2012-02-19 04:02:19 +00:00
// Search and copy the name of library reference.
MODULE* Module_Ref = module;
int pad_orient = aPad->GetOrientation() - Module_Ref->GetOrientation();
// Prepare an undo list:
if( aSaveForUndo )
{
PICKED_ITEMS_LIST itemsList;
2012-02-19 04:02:19 +00:00
for( module = m_Pcb->m_Modules; module; module = module->Next() )
{
2012-02-19 04:02:19 +00:00
if( !aSameFootprints && (module != Module_Ref) )
continue;
2012-02-19 04:02:19 +00:00
if( module->m_LibRef != Module_Ref->m_LibRef )
continue;
bool saveMe = false;
2008-03-04 14:27:48 +00:00
2012-02-19 04:02:19 +00:00
for( D_PAD* pad = module->m_Pads; pad; pad = pad->Next() )
{
2012-02-19 04:02:19 +00:00
// Filters changes prohibited.
if( aPadShapeFilter && ( pad->GetShape() != aPad->GetShape() ) )
continue;
2012-02-19 04:02:19 +00:00
int currpad_orient = pad->GetOrientation() - module->GetOrientation();
if( aPadOrientFilter && ( currpad_orient != pad_orient ) )
continue;
2012-02-19 04:02:19 +00:00
if( aPadLayerFilter && pad->GetLayerMask() != aPad->GetLayerMask() )
continue;
saveMe = true;
}
if( saveMe )
{
2012-02-19 04:02:19 +00:00
ITEM_PICKER itemWrapper( module, UR_CHANGED );
itemsList.PushItem( itemWrapper );
}
}
SaveCopyInUndoList( itemsList, UR_CHANGED );
}
2012-02-19 04:02:19 +00:00
// Update the current module and same others modules if requested.
for( module = m_Pcb->m_Modules; module; module = module->Next() )
{
2012-02-19 04:02:19 +00:00
if( !aSameFootprints && (module != Module_Ref) )
2008-03-04 14:27:48 +00:00
continue;
2012-02-19 04:02:19 +00:00
if( module->m_LibRef != Module_Ref->m_LibRef )
continue;
2008-03-04 14:27:48 +00:00
2012-02-19 04:02:19 +00:00
// Erase module on screen
if( aRedraw )
{
2012-02-19 04:02:19 +00:00
module->SetFlags( DO_NOT_DRAW );
m_canvas->RefreshDrawingRect( module->GetBoundingBox() );
module->ClearFlags( DO_NOT_DRAW );
}
2012-02-19 04:02:19 +00:00
for( D_PAD* pad = module->m_Pads; pad; pad = pad->Next() )
2008-03-04 14:27:48 +00:00
{
// Filters changes prohibited.
2012-02-19 04:02:19 +00:00
if( aPadShapeFilter && ( pad->GetShape() != aPad->GetShape() ) )
continue;
2008-03-04 14:27:48 +00:00
2012-02-19 04:02:19 +00:00
if( aPadOrientFilter && (pad->GetOrientation() - module->GetOrientation()) != pad_orient )
continue;
2008-03-04 14:27:48 +00:00
if( aPadLayerFilter )
2008-03-04 14:27:48 +00:00
{
2012-02-19 04:02:19 +00:00
if( pad->GetLayerMask() != aPad->GetLayerMask() )
2008-03-04 14:27:48 +00:00
continue;
else
m_Pcb->m_Status_Pcb &= ~( LISTE_RATSNEST_ITEM_OK | CONNEXION_OK);
2008-03-04 14:27:48 +00:00
}
// Change characteristics:
2012-02-19 04:02:19 +00:00
pad->SetAttribute( aPad->GetAttribute() );
pad->SetShape( aPad->GetShape() );
2008-03-04 14:27:48 +00:00
2012-02-19 04:02:19 +00:00
pad->SetLayerMask( aPad->GetLayerMask() );
2008-03-04 14:27:48 +00:00
2012-02-19 04:02:19 +00:00
pad->SetSize( aPad->GetSize() );
pad->SetDelta( aPad->GetDelta() );
pad->SetOffset( aPad->GetOffset() );
2008-03-04 14:27:48 +00:00
2012-02-19 04:02:19 +00:00
pad->SetDrillSize( aPad->GetDrillSize() );
pad->SetDrillShape( aPad->GetDrillShape() );
2012-02-19 04:02:19 +00:00
pad->SetOrientation( pad_orient + module->GetOrientation() );
2012-02-19 04:02:19 +00:00
// copy also local mask margins, because these parameters usually depend on
// pad sizes and layers
pad->SetLocalSolderMaskMargin( aPad->GetLocalSolderMaskMargin() );
pad->SetLocalSolderPasteMargin( aPad->GetLocalSolderPasteMargin() );
pad->SetLocalSolderPasteMarginRatio( aPad->GetLocalSolderPasteMarginRatio() );
2008-03-04 14:27:48 +00:00
2012-02-19 04:02:19 +00:00
if( pad->GetShape() != PAD_TRAPEZOID )
2008-03-04 14:27:48 +00:00
{
2012-02-19 04:02:19 +00:00
pad->SetDelta( wxSize( 0, 0 ) );
2008-03-04 14:27:48 +00:00
}
2012-02-19 04:02:19 +00:00
if( pad->GetShape() == PAD_CIRCLE )
{
// Ensure pad size.y = pad size.x
int size = pad->GetSize().x;
pad->SetSize( wxSize( size, size ) );
}
2012-02-19 04:02:19 +00:00
switch( pad->GetAttribute() )
2008-03-04 14:27:48 +00:00
{
case PAD_SMD:
case PAD_CONN:
2012-02-19 04:02:19 +00:00
pad->SetDrillSize( wxSize( 0, 0 ) );
pad->SetOffset( wxPoint( 0, 0 ) );
2008-03-04 14:27:48 +00:00
break;
default:
break;
}
}
2012-02-19 04:02:19 +00:00
module->CalculateBoundingBox();
if( aRedraw )
2012-02-19 04:02:19 +00:00
m_canvas->RefreshDrawingRect( module->GetBoundingBox() );
2008-03-04 14:27:48 +00:00
}
OnModify();
}