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>
|
2018-01-29 15:39:40 +00:00
|
|
|
#include <pcb_base_frame.h>
|
2012-09-11 07:33:17 +00:00
|
|
|
|
|
|
|
#include <pcbnew.h>
|
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_module.h>
|
|
|
|
#include <class_pad.h>
|
2018-02-02 20:57:12 +00:00
|
|
|
#include <board_design_settings.h>
|
2012-09-11 07:33:17 +00:00
|
|
|
|
|
|
|
/* 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
|
|
|
|
2017-02-10 19:44:02 +00:00
|
|
|
D_PAD& masterPad = GetDesignSettings().m_Pad_Master;
|
|
|
|
|
|
|
|
masterPad.ImportSettingsFromMaster( *aPad );
|
2012-09-11 07:33:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Imports the board design settings to aPad
|
|
|
|
* - The position, names, and keys are not modifed.
|
2016-06-07 08:02:19 +00:00
|
|
|
* The parameters are expected to be correct (i.e. settings are valid)
|
2012-09-11 07:33:17 +00:00
|
|
|
*/
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
2017-02-10 19:44:02 +00:00
|
|
|
const D_PAD& mp = GetDesignSettings().m_Pad_Master;
|
2012-09-11 07:33:17 +00:00
|
|
|
|
2017-02-10 19:44:02 +00:00
|
|
|
aPad->ImportSettingsFromMaster( mp );
|
2012-09-11 07:33:17 +00:00
|
|
|
|
2017-09-20 08:28:52 +00:00
|
|
|
aPad->SetPrimitives( mp.GetPrimitives() );
|
2017-01-13 17:51:22 +00:00
|
|
|
aPad->SetAnchorPadShape( mp.GetAnchorPadShape() );
|
2017-09-20 08:28:52 +00:00
|
|
|
aPad->MergePrimitivesAsPolygon();
|
2017-01-13 17:51:22 +00:00
|
|
|
|
2012-09-11 07:33:17 +00:00
|
|
|
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.
|
2017-04-25 09:06:24 +00:00
|
|
|
aModule->PadsList().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()
|
2017-08-11 09:22:13 +00:00
|
|
|
.m_Pad_Master.GetName() );
|
2012-09-11 07:33:17 +00:00
|
|
|
}
|
2015-08-23 19:40:33 +00:00
|
|
|
|
2017-08-11 09:22:13 +00:00
|
|
|
pad->SetName( padName );
|
|
|
|
GetDesignSettings().m_Pad_Master.SetName( 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 );
|
|
|
|
}
|