2012-09-11 07:33:17 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
|
|
|
|
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
|
|
|
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2012-09-12 17:28:55 +00:00
|
|
|
* @file pad_edition_functions.cpp
|
2012-09-11 07:33:17 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <fctsys.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <trigo.h>
|
2013-05-02 18:06:58 +00:00
|
|
|
#include <macros.h>
|
2012-09-11 07:33:17 +00:00
|
|
|
#include <wxBasePcbFrame.h>
|
|
|
|
|
|
|
|
#include <pcbnew.h>
|
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_module.h>
|
|
|
|
#include <class_pad.h>
|
|
|
|
#include <class_board_design_settings.h>
|
|
|
|
|
|
|
|
/* Exports the current pad settings to board design settings.
|
|
|
|
*/
|
|
|
|
void PCB_BASE_FRAME::Export_Pad_Settings( D_PAD* aPad )
|
|
|
|
{
|
|
|
|
if( aPad == NULL )
|
|
|
|
return;
|
|
|
|
|
2013-01-12 17:32:24 +00:00
|
|
|
SetMsgPanel( aPad );
|
2012-09-11 07:33:17 +00:00
|
|
|
|
|
|
|
D_PAD& mp = GetDesignSettings().m_Pad_Master;
|
2016-04-06 18:15:49 +00:00
|
|
|
// Copy all settings. Some of them are not used, but they break anything
|
|
|
|
mp.Copy( aPad );
|
|
|
|
// The pad orientation, for historical reasons is the
|
|
|
|
// pad rotation + parent rotation.
|
|
|
|
// store only the pad rotation.
|
2012-09-11 07:33:17 +00:00
|
|
|
mp.SetOrientation( aPad->GetOrientation() - aPad->GetParent()->GetOrientation() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Imports the board design settings to aPad
|
|
|
|
* - The position, names, and keys are not modifed.
|
|
|
|
*/
|
|
|
|
void PCB_BASE_FRAME::Import_Pad_Settings( D_PAD* aPad, bool aDraw )
|
|
|
|
{
|
|
|
|
if( aDraw )
|
|
|
|
{
|
|
|
|
aPad->SetFlags( DO_NOT_DRAW );
|
|
|
|
m_canvas->RefreshDrawingRect( aPad->GetBoundingBox() );
|
|
|
|
aPad->ClearFlags( DO_NOT_DRAW );
|
|
|
|
}
|
|
|
|
|
|
|
|
D_PAD& mp = GetDesignSettings().m_Pad_Master;
|
|
|
|
|
|
|
|
aPad->SetShape( mp.GetShape() );
|
2014-06-24 16:17:18 +00:00
|
|
|
aPad->SetLayerSet( mp.GetLayerSet() );
|
2012-09-11 07:33:17 +00:00
|
|
|
aPad->SetAttribute( mp.GetAttribute() );
|
|
|
|
aPad->SetOrientation( mp.GetOrientation() + aPad->GetParent()->GetOrientation() );
|
|
|
|
aPad->SetSize( mp.GetSize() );
|
|
|
|
aPad->SetDelta( wxSize( 0, 0 ) );
|
|
|
|
aPad->SetOffset( mp.GetOffset() );
|
|
|
|
aPad->SetDrillSize( mp.GetDrillSize() );
|
|
|
|
aPad->SetDrillShape( mp.GetDrillShape() );
|
2016-05-11 08:54:44 +00:00
|
|
|
aPad->SetRoundRectRadiusRatio( mp.GetRoundRectRadiusRatio() );
|
2012-09-11 07:33:17 +00:00
|
|
|
|
|
|
|
switch( mp.GetShape() )
|
|
|
|
{
|
2015-08-23 19:40:33 +00:00
|
|
|
case PAD_SHAPE_TRAPEZOID:
|
2012-09-11 07:33:17 +00:00
|
|
|
aPad->SetDelta( mp.GetDelta() );
|
|
|
|
break;
|
|
|
|
|
2015-08-23 19:40:33 +00:00
|
|
|
case PAD_SHAPE_CIRCLE:
|
2012-09-11 07:33:17 +00:00
|
|
|
// ensure size.y == size.x
|
|
|
|
aPad->SetSize( wxSize( aPad->GetSize().x, aPad->GetSize().x ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch( mp.GetAttribute() )
|
|
|
|
{
|
2015-08-23 19:40:33 +00:00
|
|
|
case PAD_ATTRIB_SMD:
|
|
|
|
case PAD_ATTRIB_CONN:
|
2012-09-11 07:33:17 +00:00
|
|
|
aPad->SetDrillSize( wxSize( 0, 0 ) );
|
|
|
|
aPad->SetOffset( wxPoint( 0, 0 ) );
|
|
|
|
break;
|
2016-04-06 18:15:49 +00:00
|
|
|
|
2012-09-11 07:33:17 +00:00
|
|
|
default:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aDraw )
|
|
|
|
m_canvas->RefreshDrawingRect( aPad->GetBoundingBox() );
|
|
|
|
|
|
|
|
aPad->GetParent()->SetLastEditTime();
|
2014-02-26 14:06:24 +00:00
|
|
|
|
|
|
|
OnModify();
|
2012-09-11 07:33:17 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 17:19:15 +00:00
|
|
|
/** Compute the 'next' pad number for autoincrement
|
|
|
|
* aPadName is the last pad name used */
|
|
|
|
static wxString GetNextPadName( wxString aPadName )
|
|
|
|
{
|
|
|
|
// Automatically increment the current pad number.
|
|
|
|
int num = 0;
|
|
|
|
int ponder = 1;
|
|
|
|
|
|
|
|
// Trim and extract the trailing numeric part
|
2014-02-26 14:06:24 +00:00
|
|
|
while( aPadName.Len()
|
|
|
|
&& aPadName.Last() >= '0'
|
2014-02-10 17:19:15 +00:00
|
|
|
&& aPadName.Last() <= '9' )
|
|
|
|
{
|
|
|
|
num += ( aPadName.Last() - '0' ) * ponder;
|
|
|
|
aPadName.RemoveLast();
|
|
|
|
ponder *= 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
num++; // Use next number for the new pad
|
|
|
|
aPadName << num;
|
|
|
|
|
|
|
|
return aPadName;
|
|
|
|
}
|
2012-09-11 07:33:17 +00:00
|
|
|
|
|
|
|
/* Add a new pad to aModule.
|
|
|
|
*/
|
|
|
|
void PCB_BASE_FRAME::AddPad( MODULE* aModule, bool draw )
|
|
|
|
{
|
|
|
|
m_Pcb->m_Status_Pcb = 0;
|
|
|
|
aModule->SetLastEditTime();
|
|
|
|
|
|
|
|
D_PAD* pad = new D_PAD( aModule );
|
|
|
|
|
|
|
|
// Add the new pad to end of the module pad list.
|
2013-03-18 19:36:07 +00:00
|
|
|
aModule->Pads().PushBack( pad );
|
2012-09-11 07:33:17 +00:00
|
|
|
|
2015-02-11 10:10:53 +00:00
|
|
|
// Update the pad properties,
|
|
|
|
// and keep NETINFO_LIST::ORPHANED as net info
|
|
|
|
// which is the default when nets cannot be handled.
|
2012-09-11 07:33:17 +00:00
|
|
|
Import_Pad_Settings( pad, false );
|
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
pad->SetPosition( GetCrossHairPosition() );
|
2012-09-11 07:33:17 +00:00
|
|
|
|
|
|
|
// Set the relative pad position
|
|
|
|
// ( pad position for module orient, 0, and relative to the module position)
|
|
|
|
|
|
|
|
wxPoint pos0 = pad->GetPosition() - aModule->GetPosition();
|
|
|
|
RotatePoint( &pos0, -aModule->GetOrientation() );
|
|
|
|
pad->SetPos0( pos0 );
|
|
|
|
|
2014-02-10 17:19:15 +00:00
|
|
|
/* NPTH pads take empty pad number (since they can't be connected),
|
|
|
|
* other pads get incremented from the last one edited */
|
|
|
|
wxString padName;
|
2015-08-23 19:40:33 +00:00
|
|
|
|
|
|
|
if( pad->GetAttribute() != PAD_ATTRIB_HOLE_NOT_PLATED )
|
|
|
|
{
|
2014-02-10 17:19:15 +00:00
|
|
|
padName = GetNextPadName( GetDesignSettings()
|
|
|
|
.m_Pad_Master.GetPadName() );
|
2012-09-11 07:33:17 +00:00
|
|
|
}
|
2015-08-23 19:40:33 +00:00
|
|
|
|
2014-02-10 17:19:15 +00:00
|
|
|
pad->SetPadName( padName );
|
|
|
|
GetDesignSettings().m_Pad_Master.SetPadName( padName );
|
2012-09-11 07:33:17 +00:00
|
|
|
|
|
|
|
aModule->CalculateBoundingBox();
|
2013-01-12 17:32:24 +00:00
|
|
|
SetMsgPanel( pad );
|
2012-09-11 07:33:17 +00:00
|
|
|
|
|
|
|
if( draw )
|
|
|
|
m_canvas->RefreshDrawingRect( aModule->GetBoundingBox() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PCB_BASE_FRAME::DeletePad( D_PAD* aPad, bool aQuery )
|
|
|
|
{
|
|
|
|
if( aPad == NULL )
|
|
|
|
return;
|
|
|
|
|
2015-11-04 08:48:34 +00:00
|
|
|
MODULE* module = aPad->GetParent();
|
2012-09-11 07:33:17 +00:00
|
|
|
module->SetLastEditTime();
|
|
|
|
|
2015-03-23 11:45:31 +00:00
|
|
|
// aQuery = true to prompt for confirmation, false to delete silently
|
2012-09-11 07:33:17 +00:00
|
|
|
if( aQuery )
|
|
|
|
{
|
|
|
|
wxString msg;
|
2015-03-23 11:45:31 +00:00
|
|
|
msg.Printf( _( "Delete Pad (footprint %s %s) ?" ),
|
2013-03-13 18:53:58 +00:00
|
|
|
GetChars( module->GetReference() ),
|
|
|
|
GetChars( module->GetValue() ) );
|
2012-09-11 07:33:17 +00:00
|
|
|
|
|
|
|
if( !IsOK( this, msg ) )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-20 14:59:25 +00:00
|
|
|
// Stores the initial bounding box to refresh the old area
|
|
|
|
EDA_RECT bbox = module->GetBoundingBox();
|
|
|
|
|
2012-09-11 07:33:17 +00:00
|
|
|
m_Pcb->m_Status_Pcb = 0;
|
2015-09-23 23:02:40 +00:00
|
|
|
|
|
|
|
GetBoard()->PadDelete( aPad );
|
|
|
|
|
2015-03-23 11:45:31 +00:00
|
|
|
// Update the bounding box
|
2012-09-11 07:33:17 +00:00
|
|
|
module->CalculateBoundingBox();
|
|
|
|
|
2015-04-20 14:59:25 +00:00
|
|
|
// Refresh the modified screen area, using the initial bounding box
|
|
|
|
// which is perhaps larger than the new bounding box
|
|
|
|
m_canvas->RefreshDrawingRect( bbox );
|
|
|
|
|
2012-09-11 07:33:17 +00:00
|
|
|
OnModify();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Rotate selected pad 90 degrees.
|
|
|
|
void PCB_BASE_FRAME::RotatePad( D_PAD* aPad, wxDC* DC )
|
|
|
|
{
|
|
|
|
if( aPad == NULL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
MODULE* module = aPad->GetParent();
|
|
|
|
|
|
|
|
module->SetLastEditTime();
|
|
|
|
|
|
|
|
OnModify();
|
|
|
|
|
|
|
|
if( DC )
|
|
|
|
module->Draw( m_canvas, DC, GR_XOR );
|
|
|
|
|
|
|
|
wxSize sz = aPad->GetSize();
|
2015-06-26 13:41:56 +00:00
|
|
|
std::swap( sz.x, sz.y );
|
2012-09-11 07:33:17 +00:00
|
|
|
aPad->SetSize( sz );
|
|
|
|
|
|
|
|
sz = aPad->GetDrillSize();
|
2015-06-26 13:41:56 +00:00
|
|
|
std::swap( sz.x, sz.y );
|
2012-09-11 07:33:17 +00:00
|
|
|
aPad->SetDrillSize( sz );
|
|
|
|
|
|
|
|
wxPoint pt = aPad->GetOffset();
|
2015-06-26 13:41:56 +00:00
|
|
|
std::swap( pt.x, pt.y );
|
2012-09-11 07:33:17 +00:00
|
|
|
aPad->SetOffset( pt );
|
|
|
|
|
|
|
|
aPad->SetOffset( wxPoint( aPad->GetOffset().x, -aPad->GetOffset().y ) );
|
|
|
|
|
|
|
|
sz = aPad->GetDelta();
|
2015-06-26 13:41:56 +00:00
|
|
|
std::swap( sz.x, sz.y );
|
2012-09-11 07:33:17 +00:00
|
|
|
sz.x = -sz.x;
|
|
|
|
aPad->SetDelta( sz );
|
|
|
|
|
|
|
|
module->CalculateBoundingBox();
|
2013-01-12 17:32:24 +00:00
|
|
|
SetMsgPanel( aPad );
|
2012-09-11 07:33:17 +00:00
|
|
|
|
|
|
|
if( DC )
|
|
|
|
module->Draw( m_canvas, DC, GR_OR );
|
|
|
|
}
|