2019-01-11 22:03:45 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2019 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <pcbnew_utils/board_construction_utils.h>
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
#include <pcb_shape.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <footprint.h>
|
2019-01-11 22:03:45 +00:00
|
|
|
#include <geometry/seg.h>
|
|
|
|
#include <math/vector2d.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace KI_TEST
|
|
|
|
{
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void DrawSegment( FOOTPRINT& aFootprint, const SEG& aSeg, int aWidth, PCB_LAYER_ID aLayer )
|
2019-01-11 22:03:45 +00:00
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
std::unique_ptr<PCB_SHAPE> seg = std::make_unique<PCB_SHAPE>( &aFootprint, SHAPE_T::SEGMENT );
|
2019-01-11 22:03:45 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
seg->SetStart( aSeg.A );
|
|
|
|
seg->SetEnd( aSeg.B );
|
2019-01-11 22:03:45 +00:00
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
seg->SetStroke( STROKE_PARAMS( aWidth, PLOT_DASH_TYPE::SOLID ) );
|
2019-01-11 22:03:45 +00:00
|
|
|
seg->SetLayer( aLayer );
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
seg->Rotate( { 0, 0 }, aFootprint.GetOrientation() );
|
|
|
|
seg->Move( aFootprint.GetPosition() );
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
aFootprint.Add( seg.release() );
|
2019-01-11 22:03:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void DrawPolyline( FOOTPRINT& aFootprint, const std::vector<VECTOR2I>& aPts, int aWidth,
|
|
|
|
PCB_LAYER_ID aLayer )
|
2019-01-11 22:03:45 +00:00
|
|
|
{
|
|
|
|
for( unsigned i = 0; i < aPts.size() - 1; ++i )
|
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
DrawSegment( aFootprint, { aPts[i], aPts[i + 1] }, aWidth, aLayer );
|
2019-01-11 22:03:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void DrawArc( FOOTPRINT& aFootprint, const VECTOR2I& aCentre, const VECTOR2I& aStart,
|
2022-01-16 16:15:07 +00:00
|
|
|
const EDA_ANGLE& aAngle, int aWidth, PCB_LAYER_ID aLayer )
|
2019-01-11 22:03:45 +00:00
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
std::unique_ptr<PCB_SHAPE> arc = std::make_unique<PCB_SHAPE>( &aFootprint, SHAPE_T::ARC );
|
2019-01-11 22:03:45 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
arc->SetCenter( aCentre );
|
|
|
|
arc->SetStart( aStart );
|
|
|
|
arc->SetArcAngleAndEnd( aAngle );
|
2019-01-11 22:03:45 +00:00
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
arc->SetStroke( STROKE_PARAMS( aWidth, PLOT_DASH_TYPE::SOLID ) );
|
|
|
|
arc->SetLayer( aLayer );
|
2019-01-11 22:03:45 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
arc->Rotate( { 0, 0 }, aFootprint.GetOrientation() );
|
|
|
|
arc->Move( aFootprint.GetPosition() );
|
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
aFootprint.Add( arc.release() );
|
2019-01-11 22:03:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void DrawRect( FOOTPRINT& aFootprint, const VECTOR2I& aPos, const VECTOR2I& aSize, int aRadius,
|
|
|
|
int aWidth, PCB_LAYER_ID aLayer )
|
2019-01-11 22:03:45 +00:00
|
|
|
{
|
|
|
|
const auto x_r = aPos.x + aSize.x / 2;
|
|
|
|
const auto x_l = aPos.x - aSize.x / 2;
|
|
|
|
const auto y_t = aPos.y + aSize.y / 2;
|
|
|
|
const auto y_b = aPos.y - aSize.y / 2;
|
|
|
|
|
|
|
|
const auto xin_r = x_r - aRadius;
|
|
|
|
const auto xin_l = x_l + aRadius;
|
|
|
|
const auto yin_t = y_t - aRadius;
|
|
|
|
const auto yin_b = y_b + aRadius;
|
|
|
|
|
|
|
|
// If non-zero (could be zero if it's a stadium shape)
|
|
|
|
if( xin_l != xin_r )
|
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
DrawSegment( aFootprint, { { xin_l, y_t }, { xin_r, y_t } }, aWidth, aLayer );
|
|
|
|
DrawSegment( aFootprint, { { xin_l, y_b }, { xin_r, y_b } }, aWidth, aLayer );
|
2019-01-11 22:03:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( yin_b != yin_t )
|
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
DrawSegment( aFootprint, { { x_l, yin_b }, { x_l, yin_t } }, aWidth, aLayer );
|
|
|
|
DrawSegment( aFootprint, { { x_r, yin_b }, { x_r, yin_t } }, aWidth, aLayer );
|
2019-01-11 22:03:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( aRadius > 0 )
|
|
|
|
{
|
2022-01-16 16:15:07 +00:00
|
|
|
DrawArc( aFootprint, { xin_r, yin_t }, { x_r, yin_t }, ANGLE_90, aWidth, aLayer );
|
|
|
|
DrawArc( aFootprint, { xin_l, yin_t }, { xin_l, y_t }, ANGLE_90, aWidth, aLayer );
|
|
|
|
DrawArc( aFootprint, { xin_l, yin_b }, { x_l, yin_b }, ANGLE_90, aWidth, aLayer );
|
|
|
|
DrawArc( aFootprint, { xin_r, yin_b }, { xin_r, y_b }, ANGLE_90, aWidth, aLayer );
|
2019-01-11 22:03:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace KI_TEST
|