2017-01-13 17:51:22 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2018-08-28 15:48:13 +00:00
|
|
|
* Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2023-09-11 21:03:38 +00:00
|
|
|
* Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2017-01-13 17:51:22 +00: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 19:03:10 +00:00
|
|
|
#include <board_design_settings.h>
|
2020-11-14 18:11:28 +00:00
|
|
|
#include <board_item.h>
|
2020-10-04 23:34:59 +00:00
|
|
|
#include <pcb_shape.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <pad.h>
|
2017-01-13 17:51:22 +00:00
|
|
|
#include <convert_basic_shapes_to_polygon.h>
|
2019-05-22 14:47:38 +00:00
|
|
|
#include <geometry/shape_rect.h>
|
2017-01-13 17:51:22 +00: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 21:16:06 +00:00
|
|
|
|
2020-11-14 01:16:02 +00:00
|
|
|
void PAD::AddPrimitivePoly( const SHAPE_POLY_SET& aPoly, int aThickness, bool aFilled )
|
2017-10-19 21:16:06 +00:00
|
|
|
{
|
2018-08-28 15:48:13 +00: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 21:35:01 +00: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 21:35:01 +00:00
|
|
|
item->SetParent( this );
|
2024-06-07 23:18:34 +00:00
|
|
|
m_padStack.AddPrimitive( item );
|
2022-02-02 21:35:01 +00:00
|
|
|
}
|
|
|
|
|
2021-08-01 00:14:02 +00:00
|
|
|
SetDirty();
|
2017-10-19 21:16:06 +00:00
|
|
|
}
|
|
|
|
|
2020-06-19 20:46:43 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void PAD::AddPrimitivePoly( const std::vector<VECTOR2I>& aPoly, int aThickness, bool aFilled )
|
2017-01-13 17:51:22 +00:00
|
|
|
{
|
2021-07-17 18:52:13 +00: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 11:12:39 +00: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-06-07 23:18:34 +00:00
|
|
|
m_padStack.AddPrimitive( item );
|
2021-01-08 00:26:32 +00:00
|
|
|
SetDirty();
|
2017-01-13 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
void PAD::ReplacePrimitives( const std::vector<std::shared_ptr<PCB_SHAPE>>& aPrimitivesList )
|
2017-01-13 17:51:22 +00:00
|
|
|
{
|
|
|
|
// clear old list
|
2020-07-24 16:02:56 +00:00
|
|
|
DeletePrimitivesList();
|
2017-01-13 17:51:22 +00:00
|
|
|
|
2020-07-24 16:02:56 +00:00
|
|
|
// Import to the given shape list
|
2017-09-20 08:28:52 +00:00
|
|
|
if( aPrimitivesList.size() )
|
2020-07-24 16:02:56 +00:00
|
|
|
AppendPrimitives( aPrimitivesList );
|
2017-01-13 17:51:22 +00:00
|
|
|
|
2021-01-08 00:26:32 +00:00
|
|
|
SetDirty();
|
2017-01-13 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
2020-06-19 20:46:43 +00:00
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
void PAD::AppendPrimitives( const std::vector<std::shared_ptr<PCB_SHAPE>>& aPrimitivesList )
|
2018-03-06 13:58:25 +00:00
|
|
|
{
|
2020-07-24 16:02:56 +00:00
|
|
|
// Add duplicates of aPrimitivesList to the pad primitives list:
|
2020-10-04 23:34:59 +00:00
|
|
|
for( const std::shared_ptr<PCB_SHAPE>& prim : aPrimitivesList )
|
|
|
|
AddPrimitive( new PCB_SHAPE( *prim ) );
|
2018-03-06 13:58:25 +00:00
|
|
|
|
2021-01-08 00:26:32 +00:00
|
|
|
SetDirty();
|
2018-03-06 13:58:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
void PAD::AddPrimitive( PCB_SHAPE* aPrimitive )
|
2020-06-27 11:57:40 +00:00
|
|
|
{
|
2021-02-24 22:53:16 +00:00
|
|
|
aPrimitive->SetParent( this );
|
2024-06-07 23:18:34 +00:00
|
|
|
m_padStack.AddPrimitive( aPrimitive );
|
2020-06-27 11:57:40 +00:00
|
|
|
|
2021-01-08 00:26:32 +00:00
|
|
|
SetDirty();
|
2020-06-27 11:57:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-13 17:51:22 +00:00
|
|
|
// clear the basic shapes list and associated data
|
2020-11-12 22:30:02 +00:00
|
|
|
void PAD::DeletePrimitivesList()
|
2017-01-13 17:51:22 +00:00
|
|
|
{
|
2024-06-07 23:18:34 +00:00
|
|
|
m_padStack.ClearPrimitives();
|
2021-01-08 00:26:32 +00:00
|
|
|
SetDirty();
|
2017-01-13 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-23 11:29:38 +00:00
|
|
|
void PAD::addPadPrimitivesToPolygon( SHAPE_POLY_SET* aMergedPolygon, int aError,
|
|
|
|
ERROR_LOC aErrorLoc ) const
|
2017-10-19 21:16:06 +00:00
|
|
|
{
|
2020-06-22 19:35:09 +00:00
|
|
|
SHAPE_POLY_SET polyset;
|
2017-01-13 17:51:22 +00:00
|
|
|
|
2024-06-07 23:18:34 +00:00
|
|
|
for( const std::shared_ptr<PCB_SHAPE>& primitive : m_padStack.Primitives() )
|
2021-08-23 11:29:38 +00:00
|
|
|
{
|
2023-09-13 10:27:04 +00:00
|
|
|
if( !primitive->IsProxyItem() )
|
2022-10-21 12:48:45 +00:00
|
|
|
primitive->TransformShapeToPolygon( polyset, UNDEFINED_LAYER, 0, aError, aErrorLoc );
|
2021-08-23 11:29:38 +00:00
|
|
|
}
|
2017-01-13 17:51:22 +00:00
|
|
|
|
2020-06-22 19:35:09 +00:00
|
|
|
polyset.Simplify( SHAPE_POLY_SET::PM_FAST );
|
2017-10-19 21:16:06 +00:00
|
|
|
|
2018-05-18 06:38:03 +00:00
|
|
|
// Merge all polygons with the initial pad anchor shape
|
2020-06-22 19:35:09 +00:00
|
|
|
if( polyset.OutlineCount() )
|
2017-01-13 17:51:22 +00:00
|
|
|
{
|
2020-06-22 19:35:09 +00:00
|
|
|
aMergedPolygon->BooleanAdd( polyset, SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
|
2018-05-18 06:38:03 +00:00
|
|
|
aMergedPolygon->Fracture( SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
|
2017-01-13 17:51:22 +00:00
|
|
|
}
|
2017-10-19 21:16:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 11:29:38 +00:00
|
|
|
void PAD::MergePrimitivesAsPolygon( SHAPE_POLY_SET* aMergedPolygon, ERROR_LOC aErrorLoc ) const
|
2017-10-19 21:16:06 +00:00
|
|
|
{
|
2021-08-16 09:53:27 +00:00
|
|
|
const BOARD* board = GetBoard();
|
|
|
|
int maxError = board ? board->GetDesignSettings().m_MaxError : ARC_HIGH_DEF;
|
2019-05-22 14:47:38 +00:00
|
|
|
|
2017-10-19 21:16:06 +00:00
|
|
|
aMergedPolygon->RemoveAllContours();
|
|
|
|
|
|
|
|
// Add the anchor pad shape in aMergedPolygon, others in aux_polyset:
|
|
|
|
// The anchor pad is always at 0,0
|
|
|
|
switch( GetAnchorPadShape() )
|
|
|
|
{
|
2023-06-02 09:10:48 +00:00
|
|
|
case PAD_SHAPE::RECTANGLE:
|
2019-05-14 12:39:34 +00:00
|
|
|
{
|
|
|
|
SHAPE_RECT rect( -GetSize().x / 2, -GetSize().y / 2, GetSize().x, GetSize().y );
|
2017-10-19 21:16:06 +00:00
|
|
|
aMergedPolygon->AddOutline( rect.Outline() );
|
2020-06-22 19:35:09 +00:00
|
|
|
}
|
|
|
|
break;
|
2019-05-14 12:39:34 +00:00
|
|
|
|
2020-06-22 19:35:09 +00:00
|
|
|
default:
|
2021-05-01 12:22:35 +00:00
|
|
|
case PAD_SHAPE::CIRCLE:
|
2023-02-19 03:40:07 +00:00
|
|
|
TransformCircleToPolygon( *aMergedPolygon, VECTOR2I( 0, 0 ), GetSize().x / 2, maxError,
|
2021-12-15 23:38:51 +00:00
|
|
|
aErrorLoc );
|
2017-10-19 21:16:06 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-01-13 17:51:22 +00:00
|
|
|
|
2021-08-23 11:29:38 +00:00
|
|
|
addPadPrimitivesToPolygon( aMergedPolygon, maxError, aErrorLoc );
|
2017-01-13 17:51:22 +00:00
|
|
|
}
|