2017-01-13 18:51:22 +01:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2018-08-28 17:48:13 +02:00
|
|
|
* Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2023-09-11 22:03:38 +01:00
|
|
|
* Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2017-01-13 18:51:22 +01:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2021-06-06 15:03:10 -04:00
|
|
|
#include <board_design_settings.h>
|
2020-11-14 18:11:28 +00:00
|
|
|
#include <board_item.h>
|
2020-10-05 00:34:59 +01:00
|
|
|
#include <pcb_shape.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <pad.h>
|
2017-01-13 18:51:22 +01:00
|
|
|
#include <convert_basic_shapes_to_polygon.h>
|
2019-05-22 07:47:38 -07:00
|
|
|
#include <geometry/shape_rect.h>
|
2017-01-13 18:51:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Has meaning only for free shape pads.
|
|
|
|
* add a free shape to the shape list.
|
|
|
|
* the shape is a polygon (can be with thick outline), segment, circle or arc
|
|
|
|
*/
|
2017-10-19 23:16:06 +02:00
|
|
|
|
2024-09-15 13:26:01 -04:00
|
|
|
void PAD::AddPrimitivePoly( PCB_LAYER_ID aLayer, const SHAPE_POLY_SET& aPoly, int aThickness,
|
|
|
|
bool aFilled )
|
2017-10-19 23:16:06 +02:00
|
|
|
{
|
2018-08-28 17:48:13 +02:00
|
|
|
// If aPoly has holes, convert it to a polygon with no holes.
|
|
|
|
SHAPE_POLY_SET poly_no_hole;
|
|
|
|
poly_no_hole.Append( aPoly );
|
2022-02-02 13:35:01 -08:00
|
|
|
|
|
|
|
if( poly_no_hole.HasHoles() )
|
|
|
|
poly_no_hole.Fracture( SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
|
|
|
|
|
|
|
|
// There should never be multiple shapes, but if there are, we split them into
|
|
|
|
// primitives so that we can edit them both.
|
|
|
|
for( int ii = 0; ii < poly_no_hole.OutlineCount(); ++ii )
|
|
|
|
{
|
|
|
|
SHAPE_POLY_SET poly_outline( poly_no_hole.COutline( ii ) );
|
|
|
|
PCB_SHAPE* item = new PCB_SHAPE();
|
|
|
|
item->SetShape( SHAPE_T::POLY );
|
|
|
|
item->SetFilled( aFilled );
|
|
|
|
item->SetPolyShape( poly_outline );
|
2023-11-25 13:05:45 +00:00
|
|
|
item->SetStroke( STROKE_PARAMS( aThickness, LINE_STYLE::SOLID ) );
|
2022-02-02 13:35:01 -08:00
|
|
|
item->SetParent( this );
|
2024-09-15 13:26:01 -04:00
|
|
|
m_padStack.AddPrimitive( item, aLayer );
|
2022-02-02 13:35:01 -08:00
|
|
|
}
|
|
|
|
|
2021-08-01 01:14:02 +01:00
|
|
|
SetDirty();
|
2017-10-19 23:16:06 +02:00
|
|
|
}
|
|
|
|
|
2020-06-19 21:46:43 +01:00
|
|
|
|
2024-09-15 13:26:01 -04:00
|
|
|
void PAD::AddPrimitivePoly( PCB_LAYER_ID aLayer, const std::vector<VECTOR2I>& aPoly, int aThickness,
|
|
|
|
bool aFilled )
|
2017-01-13 18:51:22 +01:00
|
|
|
{
|
2021-07-17 19:52:13 +01:00
|
|
|
PCB_SHAPE* item = new PCB_SHAPE( nullptr, SHAPE_T::POLY );
|
2020-11-14 01:16:02 +00:00
|
|
|
item->SetFilled( aFilled );
|
2020-06-24 12:12:39 +01:00
|
|
|
item->SetPolyPoints( aPoly );
|
2023-11-25 13:05:45 +00:00
|
|
|
item->SetStroke( STROKE_PARAMS( aThickness, LINE_STYLE::SOLID ) );
|
2021-02-24 22:53:16 +00:00
|
|
|
item->SetParent( this );
|
2024-09-15 13:26:01 -04:00
|
|
|
m_padStack.AddPrimitive( item, aLayer );
|
2021-01-08 00:26:32 +00:00
|
|
|
SetDirty();
|
2017-01-13 18:51:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-09-15 13:26:01 -04:00
|
|
|
void PAD::ReplacePrimitives( PCB_LAYER_ID aLayer,
|
|
|
|
const std::vector<std::shared_ptr<PCB_SHAPE>>& aPrimitivesList )
|
2017-01-13 18:51:22 +01:00
|
|
|
{
|
|
|
|
// clear old list
|
2024-09-15 13:26:01 -04:00
|
|
|
DeletePrimitivesList( aLayer );
|
2017-01-13 18:51:22 +01:00
|
|
|
|
2020-07-24 18:02:56 +02:00
|
|
|
// Import to the given shape list
|
2017-09-20 10:28:52 +02:00
|
|
|
if( aPrimitivesList.size() )
|
2024-09-15 13:26:01 -04:00
|
|
|
AppendPrimitives( aLayer, aPrimitivesList );
|
2017-01-13 18:51:22 +01:00
|
|
|
|
2021-01-08 00:26:32 +00:00
|
|
|
SetDirty();
|
2017-01-13 18:51:22 +01:00
|
|
|
}
|
|
|
|
|
2020-06-19 21:46:43 +01:00
|
|
|
|
2024-09-15 13:26:01 -04:00
|
|
|
void PAD::AppendPrimitives( PCB_LAYER_ID aLayer,
|
|
|
|
const std::vector<std::shared_ptr<PCB_SHAPE>>& aPrimitivesList )
|
2018-03-06 14:58:25 +01:00
|
|
|
{
|
2020-07-24 18:02:56 +02:00
|
|
|
// Add duplicates of aPrimitivesList to the pad primitives list:
|
2020-10-05 00:34:59 +01:00
|
|
|
for( const std::shared_ptr<PCB_SHAPE>& prim : aPrimitivesList )
|
2024-09-15 13:26:01 -04:00
|
|
|
AddPrimitive( aLayer, new PCB_SHAPE( *prim ) );
|
2018-03-06 14:58:25 +01:00
|
|
|
|
2021-01-08 00:26:32 +00:00
|
|
|
SetDirty();
|
2018-03-06 14:58:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-09-15 13:26:01 -04:00
|
|
|
void PAD::AddPrimitive( PCB_LAYER_ID aLayer, PCB_SHAPE* aPrimitive )
|
2020-06-27 12:57:40 +01:00
|
|
|
{
|
2021-02-24 22:53:16 +00:00
|
|
|
aPrimitive->SetParent( this );
|
2024-09-15 13:26:01 -04:00
|
|
|
m_padStack.AddPrimitive( aPrimitive, aLayer );
|
2020-06-27 12:57:40 +01:00
|
|
|
|
2021-01-08 00:26:32 +00:00
|
|
|
SetDirty();
|
2020-06-27 12:57:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-13 18:51:22 +01:00
|
|
|
// clear the basic shapes list and associated data
|
2024-09-15 13:26:01 -04:00
|
|
|
void PAD::DeletePrimitivesList( PCB_LAYER_ID aLayer )
|
2017-01-13 18:51:22 +01:00
|
|
|
{
|
2024-09-15 13:26:01 -04:00
|
|
|
if( aLayer == UNDEFINED_LAYER )
|
|
|
|
{
|
|
|
|
m_padStack.ForEachUniqueLayer(
|
|
|
|
[&]( PCB_LAYER_ID l )
|
|
|
|
{
|
|
|
|
m_padStack.ClearPrimitives( l );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_padStack.ClearPrimitives( aLayer);
|
|
|
|
}
|
2021-01-08 00:26:32 +00:00
|
|
|
SetDirty();
|
2017-01-13 18:51:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-09-15 13:26:01 -04:00
|
|
|
void PAD::addPadPrimitivesToPolygon( PCB_LAYER_ID aLayer, SHAPE_POLY_SET* aMergedPolygon,
|
|
|
|
int aError, ERROR_LOC aErrorLoc ) const
|
2017-10-19 23:16:06 +02:00
|
|
|
{
|
2020-06-22 20:35:09 +01:00
|
|
|
SHAPE_POLY_SET polyset;
|
2017-01-13 18:51:22 +01:00
|
|
|
|
2024-09-15 13:26:01 -04:00
|
|
|
for( const std::shared_ptr<PCB_SHAPE>& primitive : m_padStack.Primitives( aLayer ) )
|
2021-08-23 12:29:38 +01:00
|
|
|
{
|
2023-09-13 11:27:04 +01:00
|
|
|
if( !primitive->IsProxyItem() )
|
2022-10-21 13:48:45 +01:00
|
|
|
primitive->TransformShapeToPolygon( polyset, UNDEFINED_LAYER, 0, aError, aErrorLoc );
|
2021-08-23 12:29:38 +01:00
|
|
|
}
|
2017-01-13 18:51:22 +01:00
|
|
|
|
2020-06-22 20:35:09 +01:00
|
|
|
polyset.Simplify( SHAPE_POLY_SET::PM_FAST );
|
2017-10-19 23:16:06 +02:00
|
|
|
|
2018-05-18 08:38:03 +02:00
|
|
|
// Merge all polygons with the initial pad anchor shape
|
2020-06-22 20:35:09 +01:00
|
|
|
if( polyset.OutlineCount() )
|
2017-01-13 18:51:22 +01:00
|
|
|
{
|
2020-06-22 20:35:09 +01:00
|
|
|
aMergedPolygon->BooleanAdd( polyset, SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
|
2018-05-18 08:38:03 +02:00
|
|
|
aMergedPolygon->Fracture( SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
|
2017-01-13 18:51:22 +01:00
|
|
|
}
|
2017-10-19 23:16:06 +02:00
|
|
|
}
|
|
|
|
|
2024-09-15 13:26:01 -04:00
|
|
|
void PAD::MergePrimitivesAsPolygon( PCB_LAYER_ID aLayer, SHAPE_POLY_SET* aMergedPolygon,
|
|
|
|
ERROR_LOC aErrorLoc ) const
|
2017-10-19 23:16:06 +02:00
|
|
|
{
|
2021-08-16 10:53:27 +01:00
|
|
|
const BOARD* board = GetBoard();
|
|
|
|
int maxError = board ? board->GetDesignSettings().m_MaxError : ARC_HIGH_DEF;
|
2019-05-22 07:47:38 -07:00
|
|
|
|
2017-10-19 23:16:06 +02:00
|
|
|
aMergedPolygon->RemoveAllContours();
|
|
|
|
|
|
|
|
// Add the anchor pad shape in aMergedPolygon, others in aux_polyset:
|
|
|
|
// The anchor pad is always at 0,0
|
2024-09-15 13:26:01 -04:00
|
|
|
VECTOR2I padSize = GetSize( aLayer );
|
|
|
|
|
|
|
|
switch( GetAnchorPadShape( aLayer ) )
|
2017-10-19 23:16:06 +02:00
|
|
|
{
|
2023-06-02 11:10:48 +02:00
|
|
|
case PAD_SHAPE::RECTANGLE:
|
2019-05-14 05:39:34 -07:00
|
|
|
{
|
2024-09-15 13:26:01 -04:00
|
|
|
SHAPE_RECT rect( -padSize.x / 2, -padSize.y / 2, padSize.x, padSize.y );
|
2017-10-19 23:16:06 +02:00
|
|
|
aMergedPolygon->AddOutline( rect.Outline() );
|
2020-06-22 20:35:09 +01:00
|
|
|
}
|
|
|
|
break;
|
2019-05-14 05:39:34 -07:00
|
|
|
|
2020-06-22 20:35:09 +01:00
|
|
|
default:
|
2021-05-01 08:22:35 -04:00
|
|
|
case PAD_SHAPE::CIRCLE:
|
2024-09-15 13:26:01 -04:00
|
|
|
TransformCircleToPolygon( *aMergedPolygon, VECTOR2I( 0, 0 ), padSize.x / 2, maxError,
|
2021-12-15 23:38:51 +00:00
|
|
|
aErrorLoc );
|
2017-10-19 23:16:06 +02:00
|
|
|
break;
|
|
|
|
}
|
2017-01-13 18:51:22 +01:00
|
|
|
|
2024-09-15 13:26:01 -04:00
|
|
|
addPadPrimitivesToPolygon( aLayer, aMergedPolygon, maxError, aErrorLoc );
|
2017-01-13 18:51:22 +01:00
|
|
|
}
|