2018-01-28 13:05:17 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
|
2023-08-11 17:40:13 +00:00
|
|
|
* Copyright (C) 2023 CERN
|
2023-03-30 11:49:23 +00:00
|
|
|
* Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2018-01-28 13:05:17 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2023-04-19 11:51:26 +00:00
|
|
|
* @file create_3Dgraphic_brd_items.cpp
|
2018-01-28 13:05:17 +00:00
|
|
|
* @brief This file implements the creation of 2D graphic primitives of pcb items:
|
|
|
|
* pads, tracks, drawsegments, texts....
|
|
|
|
* It is based on the function found in the files:
|
|
|
|
* board_items_to_polygon_shape_transform.cpp
|
|
|
|
*/
|
|
|
|
|
2021-10-21 13:29:19 +00:00
|
|
|
#include "../3d_rendering/raytracing/shapes2D/ring_2d.h"
|
|
|
|
#include "../3d_rendering/raytracing/shapes2D/filled_circle_2d.h"
|
|
|
|
#include "../3d_rendering/raytracing/shapes2D/round_segment_2d.h"
|
|
|
|
#include "../3d_rendering/raytracing/shapes2D/triangle_2d.h"
|
2020-03-26 14:05:20 +00:00
|
|
|
#include <board_adapter.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <footprint.h>
|
|
|
|
#include <pad.h>
|
2020-10-04 23:34:59 +00:00
|
|
|
#include <pcb_text.h>
|
2023-03-30 11:49:23 +00:00
|
|
|
#include <pcb_textbox.h>
|
2021-07-21 15:40:14 +00:00
|
|
|
#include <board_design_settings.h>
|
2022-02-17 17:49:03 +00:00
|
|
|
#include <pcb_painter.h> // for PCB_RENDER_SETTINGS
|
2020-11-11 23:05:59 +00:00
|
|
|
#include <zone.h>
|
2018-01-28 13:05:17 +00:00
|
|
|
#include <convert_basic_shapes_to_polygon.h>
|
|
|
|
#include <trigo.h>
|
2020-06-22 19:35:09 +00:00
|
|
|
#include <geometry/shape_segment.h>
|
2020-04-09 08:37:17 +00:00
|
|
|
#include <geometry/geometry_utils.h>
|
2020-06-22 19:35:09 +00:00
|
|
|
#include <geometry/shape_circle.h>
|
2020-06-30 12:41:59 +00:00
|
|
|
#include <geometry/shape_rect.h>
|
2020-06-22 19:35:09 +00:00
|
|
|
#include <geometry/shape_simple.h>
|
2018-01-28 13:05:17 +00:00
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
2021-06-03 12:11:15 +00:00
|
|
|
#include <wx/log.h>
|
2021-07-21 15:40:14 +00:00
|
|
|
#include <macros.h>
|
2022-01-10 14:03:53 +00:00
|
|
|
#include <callback_gal.h>
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2022-01-30 10:52:52 +00:00
|
|
|
|
2022-02-02 18:18:27 +00:00
|
|
|
#define TO_3DU( x ) ( ( x ) * m_biuTo3Dunits )
|
2022-01-30 10:52:52 +00:00
|
|
|
|
|
|
|
#define TO_SFVEC2F( vec ) SFVEC2F( TO_3DU( vec.x ), TO_3DU( -vec.y ) )
|
|
|
|
|
|
|
|
|
|
|
|
void BOARD_ADAPTER::addText( const EDA_TEXT* aText, CONTAINER_2D_BASE* aContainer,
|
|
|
|
const BOARD_ITEM* aOwner )
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
2022-01-10 14:03:53 +00:00
|
|
|
KIGFX::GAL_DISPLAY_OPTIONS empty_opts;
|
2022-03-12 10:53:20 +00:00
|
|
|
TEXT_ATTRIBUTES attrs = aText->GetAttributes();
|
|
|
|
float penWidth_3DU = TO_3DU( aText->GetEffectiveTextPenWidth() );
|
2022-10-22 20:32:10 +00:00
|
|
|
KIFONT::FONT* font = aText->GetFont();
|
|
|
|
|
|
|
|
if( !font )
|
|
|
|
font = KIFONT::FONT::GetFont( wxEmptyString, aText->IsBold(), aText->IsItalic() );
|
2022-03-12 10:53:20 +00:00
|
|
|
|
|
|
|
if( aOwner && aOwner->IsKnockout() )
|
|
|
|
{
|
2023-05-28 16:20:11 +00:00
|
|
|
SHAPE_POLY_SET finalPoly;
|
|
|
|
const PCB_TEXT* pcbText = static_cast<const PCB_TEXT*>( aOwner );
|
2022-03-12 10:53:20 +00:00
|
|
|
|
2023-05-28 16:20:11 +00:00
|
|
|
pcbText->TransformTextToPolySet( finalPoly, 0, m_board->GetDesignSettings().m_MaxError,
|
|
|
|
ERROR_INSIDE );
|
2022-03-12 10:53:20 +00:00
|
|
|
|
2023-05-09 07:18:20 +00:00
|
|
|
// Do not call finalPoly.Fracture() here: ConvertPolygonToTriangles() call it
|
|
|
|
// if needed, and Fracture() called twice can create bad results and is useless
|
2022-03-12 10:53:20 +00:00
|
|
|
ConvertPolygonToTriangles( finalPoly, *aContainer, m_biuTo3Dunits, *aOwner );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CALLBACK_GAL callback_gal( empty_opts,
|
|
|
|
// Stroke callback
|
|
|
|
[&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 )
|
|
|
|
{
|
|
|
|
const SFVEC2F pt1_3DU = TO_SFVEC2F( aPt1 );
|
|
|
|
const SFVEC2F pt2_3DU = TO_SFVEC2F( aPt2 );
|
|
|
|
|
2023-01-29 22:39:29 +00:00
|
|
|
if( penWidth_3DU == 0.0 )
|
2022-03-12 10:53:20 +00:00
|
|
|
{
|
2023-01-29 22:39:29 +00:00
|
|
|
// Don't attempt to render degenerate shapes
|
|
|
|
}
|
|
|
|
else if( Is_segment_a_circle( pt1_3DU, pt2_3DU ) )
|
|
|
|
{
|
|
|
|
// Cannot add segments that have the same start and end point
|
2022-03-12 10:53:20 +00:00
|
|
|
aContainer->Add( new FILLED_CIRCLE_2D( pt1_3DU, penWidth_3DU / 2,
|
|
|
|
*aOwner ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aContainer->Add( new ROUND_SEGMENT_2D( pt1_3DU, pt2_3DU, penWidth_3DU,
|
|
|
|
*aOwner ) );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// Triangulation callback
|
|
|
|
[&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2, const VECTOR2I& aPt3 )
|
|
|
|
{
|
|
|
|
aContainer->Add( new TRIANGLE_2D( TO_SFVEC2F( aPt1 ), TO_SFVEC2F( aPt2 ),
|
|
|
|
TO_SFVEC2F( aPt3 ), *aOwner ) );
|
|
|
|
} );
|
|
|
|
|
|
|
|
attrs.m_Angle = aText->GetDrawRotation();
|
|
|
|
|
2023-08-06 19:20:53 +00:00
|
|
|
font->Draw( &callback_gal, aText->GetShownText( true ), aText->GetDrawPos(), attrs,
|
|
|
|
aOwner->GetFontMetrics() );
|
2022-03-12 10:53:20 +00:00
|
|
|
}
|
2018-01-28 13:05:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-30 10:52:52 +00:00
|
|
|
void BOARD_ADAPTER::addShape( const PCB_DIMENSION_BASE* aDimension, CONTAINER_2D_BASE* aContainer,
|
|
|
|
const BOARD_ITEM* aOwner )
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
2023-03-04 23:15:43 +00:00
|
|
|
addText( aDimension, aContainer, aDimension );
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2022-01-10 14:03:53 +00:00
|
|
|
const int linewidth = aDimension->GetLineThickness();
|
2020-09-09 03:17:08 +00:00
|
|
|
|
2020-09-12 20:09:40 +00:00
|
|
|
for( const std::shared_ptr<SHAPE>& shape : aDimension->GetShapes() )
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
2020-09-12 20:09:40 +00:00
|
|
|
switch( shape->Type() )
|
|
|
|
{
|
|
|
|
case SH_SEGMENT:
|
|
|
|
{
|
2022-01-30 10:52:52 +00:00
|
|
|
const SEG& seg = static_cast<const SHAPE_SEGMENT*>( shape.get() )->GetSeg();
|
2020-09-12 20:09:40 +00:00
|
|
|
|
2022-01-30 10:52:52 +00:00
|
|
|
aContainer->Add( new ROUND_SEGMENT_2D( TO_SFVEC2F( seg.A ), TO_SFVEC2F( seg.B ),
|
|
|
|
TO_3DU( linewidth ), *aOwner ) );
|
2020-09-12 20:09:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SH_CIRCLE:
|
|
|
|
{
|
|
|
|
int radius = static_cast<const SHAPE_CIRCLE*>( shape.get() )->GetRadius();
|
2022-01-10 14:03:53 +00:00
|
|
|
int delta = aDimension->GetLineThickness() / 2;
|
2020-09-12 20:09:40 +00:00
|
|
|
|
2022-01-30 10:52:52 +00:00
|
|
|
aContainer->Add( new RING_2D( TO_SFVEC2F( shape->Centre() ), TO_3DU( radius - delta ),
|
|
|
|
TO_3DU( radius + delta ), *aOwner ) );
|
2020-09-12 20:09:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2018-01-28 13:05:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-30 10:52:52 +00:00
|
|
|
void BOARD_ADAPTER::addFootprintShapes( const FOOTPRINT* aFootprint, CONTAINER_2D_BASE* aContainer,
|
2023-08-11 17:40:13 +00:00
|
|
|
PCB_LAYER_ID aLayerId,
|
|
|
|
const std::bitset<LAYER_3D_END>& aVisibilityFlags )
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
2022-01-10 14:03:53 +00:00
|
|
|
KIGFX::GAL_DISPLAY_OPTIONS empty_opts;
|
|
|
|
|
2023-06-15 19:37:07 +00:00
|
|
|
for( PCB_FIELD* field : aFootprint->GetFields() )
|
|
|
|
{
|
|
|
|
if( field->GetLayer() == aLayerId && field->IsVisible() )
|
2023-08-11 17:40:13 +00:00
|
|
|
{
|
|
|
|
if( !aVisibilityFlags.test( LAYER_FP_TEXT ) )
|
|
|
|
continue;
|
|
|
|
else if( field->IsReference() && !aVisibilityFlags.test( LAYER_FP_REFERENCES ) )
|
|
|
|
continue;
|
|
|
|
else if( field->IsValue() && !aVisibilityFlags.test( LAYER_FP_VALUES ) )
|
|
|
|
continue;
|
|
|
|
|
2023-06-15 19:37:07 +00:00
|
|
|
addText( field, aContainer, field );
|
2023-08-11 17:40:13 +00:00
|
|
|
}
|
2023-06-15 19:37:07 +00:00
|
|
|
}
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
for( BOARD_ITEM* item : aFootprint->GraphicalItems() )
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
case PCB_TEXT_T:
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
PCB_TEXT* text = static_cast<PCB_TEXT*>( item );
|
2018-01-28 13:05:17 +00:00
|
|
|
|
|
|
|
if( text->GetLayer() == aLayerId && text->IsVisible() )
|
2023-08-11 17:40:13 +00:00
|
|
|
{
|
|
|
|
if( !aVisibilityFlags.test( LAYER_FP_TEXT ) )
|
|
|
|
continue;
|
|
|
|
else if( text->GetText() == wxT( "${REFERENCE}" ) && !aVisibilityFlags.test( LAYER_FP_REFERENCES ) )
|
|
|
|
continue;
|
|
|
|
else if( text->GetText() == wxT( "${VALUE}" ) && !aVisibilityFlags.test( LAYER_FP_VALUES ) )
|
|
|
|
continue;
|
|
|
|
|
2022-01-30 10:52:52 +00:00
|
|
|
addText( text, aContainer, text );
|
2023-08-11 17:40:13 +00:00
|
|
|
}
|
2022-01-30 10:52:52 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
case PCB_TEXTBOX_T:
|
2022-01-30 10:52:52 +00:00
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
PCB_TEXTBOX* textbox = static_cast<PCB_TEXTBOX*>( item );
|
2022-01-30 10:52:52 +00:00
|
|
|
|
|
|
|
if( textbox->GetLayer() == aLayerId )
|
|
|
|
{
|
2023-08-31 02:39:07 +00:00
|
|
|
if( textbox->IsBorderEnabled() )
|
|
|
|
addShape( textbox, aContainer, aFootprint );
|
|
|
|
|
2022-01-30 10:52:52 +00:00
|
|
|
addText( textbox, aContainer, aFootprint );
|
|
|
|
}
|
2021-12-04 23:52:00 +00:00
|
|
|
|
|
|
|
break;
|
2018-01-28 13:05:17 +00:00
|
|
|
}
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
case PCB_DIM_ALIGNED_T:
|
|
|
|
case PCB_DIM_CENTER_T:
|
|
|
|
case PCB_DIM_ORTHOGONAL_T:
|
|
|
|
case PCB_DIM_RADIAL_T:
|
|
|
|
case PCB_DIM_LEADER_T:
|
2021-12-04 23:52:00 +00:00
|
|
|
{
|
|
|
|
PCB_DIMENSION_BASE* dimension = static_cast<PCB_DIMENSION_BASE*>( item );
|
|
|
|
|
|
|
|
if( dimension->GetLayer() == aLayerId )
|
2022-01-30 10:52:52 +00:00
|
|
|
addShape( dimension, aContainer, aFootprint );
|
2021-12-04 23:52:00 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
case PCB_SHAPE_T:
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( item );
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2021-12-04 23:52:00 +00:00
|
|
|
if( shape->GetLayer() == aLayerId )
|
2022-01-30 10:52:52 +00:00
|
|
|
addShape( shape, aContainer, aFootprint );
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2021-12-04 23:52:00 +00:00
|
|
|
break;
|
2018-01-28 13:05:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-12 17:27:11 +00:00
|
|
|
void BOARD_ADAPTER::createViaWithMargin( const PCB_TRACK* aTrack, CONTAINER_2D_BASE* aDstContainer,
|
|
|
|
int aMargin )
|
|
|
|
{
|
|
|
|
SFVEC2F start3DU = TO_SFVEC2F( aTrack->GetStart() );
|
|
|
|
SFVEC2F end3DU = TO_SFVEC2F( aTrack->GetEnd() );
|
|
|
|
|
|
|
|
const float radius3DU = TO_3DU( ( aTrack->GetWidth() / 2 ) + aMargin );
|
|
|
|
|
|
|
|
if( radius3DU > 0.0 )
|
|
|
|
aDstContainer->Add( new FILLED_CIRCLE_2D( start3DU, radius3DU, *aTrack ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-10 14:03:53 +00:00
|
|
|
void BOARD_ADAPTER::createTrack( const PCB_TRACK* aTrack, CONTAINER_2D_BASE* aDstContainer )
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
2022-01-30 10:52:52 +00:00
|
|
|
SFVEC2F start3DU = TO_SFVEC2F( aTrack->GetStart() );
|
|
|
|
SFVEC2F end3DU = TO_SFVEC2F( aTrack->GetEnd() );
|
2018-01-28 13:05:17 +00:00
|
|
|
|
|
|
|
switch( aTrack->Type() )
|
|
|
|
{
|
|
|
|
case PCB_VIA_T:
|
2020-12-16 22:10:42 +00:00
|
|
|
{
|
2023-07-12 17:27:11 +00:00
|
|
|
const float radius3DU = TO_3DU( aTrack->GetWidth() / 2 );
|
2023-01-29 22:39:29 +00:00
|
|
|
|
|
|
|
if( radius3DU > 0.0 )
|
|
|
|
aDstContainer->Add( new FILLED_CIRCLE_2D( start3DU, radius3DU, *aTrack ) );
|
|
|
|
|
2018-01-28 13:05:17 +00:00
|
|
|
break;
|
2020-12-16 22:10:42 +00:00
|
|
|
}
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2020-04-09 08:37:17 +00:00
|
|
|
case PCB_ARC_T:
|
2020-12-16 22:10:42 +00:00
|
|
|
{
|
2021-06-11 21:07:02 +00:00
|
|
|
const PCB_ARC* arc = static_cast<const PCB_ARC*>( aTrack );
|
2022-01-10 15:05:57 +00:00
|
|
|
|
2022-01-14 15:34:41 +00:00
|
|
|
VECTOR2D center( arc->GetCenter() );
|
|
|
|
EDA_ANGLE arc_angle = arc->GetAngle();
|
|
|
|
double radius = arc->GetRadius();
|
|
|
|
int arcsegcount = GetArcToSegmentCount( radius, ARC_HIGH_DEF, arc_angle );
|
|
|
|
int circlesegcount;
|
2020-12-16 22:10:42 +00:00
|
|
|
|
2023-03-13 18:47:02 +00:00
|
|
|
// Avoid arcs that cannot be drawn
|
|
|
|
if( radius < std::numeric_limits<double>::min() || arc_angle.IsZero() )
|
|
|
|
break;
|
|
|
|
|
2020-12-16 22:10:42 +00:00
|
|
|
// We need a circle to segment count. However, the arc angle can be small, and the
|
|
|
|
// radius very big. so we calculate a reasonable value for circlesegcount.
|
|
|
|
if( arcsegcount <= 1 ) // The arc will be approximated by a segment
|
2022-01-10 14:03:53 +00:00
|
|
|
{
|
2020-12-16 22:10:42 +00:00
|
|
|
circlesegcount = 1;
|
2022-01-10 14:03:53 +00:00
|
|
|
}
|
2020-12-16 22:10:42 +00:00
|
|
|
else
|
2020-04-09 08:37:17 +00:00
|
|
|
{
|
2022-01-14 15:34:41 +00:00
|
|
|
circlesegcount = KiROUND( arcsegcount * 360.0 / std::abs( arc_angle.AsDegrees() ) );
|
2023-06-03 15:59:00 +00:00
|
|
|
circlesegcount = alg::clamp( 1, circlesegcount, 128 );
|
2018-01-28 13:05:17 +00:00
|
|
|
}
|
2020-12-16 22:10:42 +00:00
|
|
|
|
2022-01-16 21:15:20 +00:00
|
|
|
transformArcToSegments( VECTOR2I( center.x, center.y ), arc->GetStart(), arc_angle,
|
|
|
|
circlesegcount, arc->GetWidth(), aDstContainer, *arc );
|
2020-04-09 08:37:17 +00:00
|
|
|
break;
|
2020-12-16 22:10:42 +00:00
|
|
|
}
|
2020-04-09 08:37:17 +00:00
|
|
|
|
|
|
|
case PCB_TRACE_T: // Track is a usual straight segment
|
2020-12-16 22:10:42 +00:00
|
|
|
{
|
2023-01-29 22:39:29 +00:00
|
|
|
if( aTrack->GetWidth() == 0 )
|
|
|
|
{
|
|
|
|
// Don't attempt to render degenerate shapes
|
|
|
|
}
|
|
|
|
else if( Is_segment_a_circle( start3DU, end3DU ) )
|
2020-12-16 22:10:42 +00:00
|
|
|
{
|
2023-01-29 22:39:29 +00:00
|
|
|
// Cannot add segments that have the same start and end point
|
2022-01-30 10:52:52 +00:00
|
|
|
aDstContainer->Add( new FILLED_CIRCLE_2D( start3DU, TO_3DU( aTrack->GetWidth() / 2 ),
|
|
|
|
*aTrack ) );
|
2020-12-16 22:10:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-01-30 10:52:52 +00:00
|
|
|
aDstContainer->Add( new ROUND_SEGMENT_2D( start3DU, end3DU, TO_3DU( aTrack->GetWidth() ),
|
|
|
|
*aTrack ) );
|
2018-01-28 13:05:17 +00:00
|
|
|
}
|
2020-12-16 22:10:42 +00:00
|
|
|
|
2018-01-28 13:05:17 +00:00
|
|
|
break;
|
2020-12-16 22:10:42 +00:00
|
|
|
}
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2020-04-09 08:37:17 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2018-01-28 13:05:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-30 10:52:52 +00:00
|
|
|
void BOARD_ADAPTER::createPadWithMargin( const PAD* aPad, CONTAINER_2D_BASE* aContainer,
|
2022-01-10 14:03:53 +00:00
|
|
|
PCB_LAYER_ID aLayer, const VECTOR2I& aMargin ) const
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
2020-06-22 19:35:09 +00:00
|
|
|
SHAPE_POLY_SET poly;
|
2021-07-21 15:40:14 +00:00
|
|
|
int maxError = GetBoard()->GetDesignSettings().m_MaxError;
|
2022-01-10 14:03:53 +00:00
|
|
|
VECTOR2I clearance = aMargin;
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2020-08-28 19:27:44 +00:00
|
|
|
// Our shape-based builder can't handle negative or differing x:y clearance values (the
|
2020-12-16 22:10:42 +00:00
|
|
|
// former are common for solder paste while the later get generated when a relative paste
|
2020-08-28 19:27:44 +00:00
|
|
|
// margin is used with an oblong pad). So we apply this huge hack and fake a larger pad to
|
|
|
|
// run the general-purpose polygon builder on.
|
2020-08-27 17:13:08 +00:00
|
|
|
// Of course being a hack it falls down when dealing with custom shape pads (where the size
|
2022-01-10 14:03:53 +00:00
|
|
|
// is only the size of the anchor), so for those we punt and just use aMargin.x.
|
2020-08-27 17:13:08 +00:00
|
|
|
|
2021-07-26 23:47:26 +00:00
|
|
|
if( ( clearance.x < 0 || clearance.x != clearance.y )
|
2021-05-01 12:22:35 +00:00
|
|
|
&& aPad->GetShape() != PAD_SHAPE::CUSTOM )
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
2021-12-29 19:19:08 +00:00
|
|
|
VECTOR2I dummySize = VECTOR2I( aPad->GetSize() ) + clearance + clearance;
|
2021-11-11 17:35:01 +00:00
|
|
|
|
|
|
|
if( dummySize.x <= 0 || dummySize.y <= 0 )
|
|
|
|
return;
|
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
PAD dummy( *aPad );
|
2023-02-19 03:40:07 +00:00
|
|
|
dummy.SetSize( VECTOR2I( dummySize.x, dummySize.y ) );
|
2022-10-21 12:48:45 +00:00
|
|
|
dummy.TransformShapeToPolygon( poly, aLayer, 0, maxError, ERROR_INSIDE );
|
2021-07-26 23:47:26 +00:00
|
|
|
clearance = { 0, 0 };
|
2023-08-21 09:32:50 +00:00
|
|
|
|
|
|
|
// Remove group membership from dummy item before deleting
|
|
|
|
dummy.SetParentGroup( nullptr );
|
2018-01-28 13:05:17 +00:00
|
|
|
}
|
2020-06-22 19:35:09 +00:00
|
|
|
else
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
2020-07-22 23:05:22 +00:00
|
|
|
auto padShapes = std::static_pointer_cast<SHAPE_COMPOUND>( aPad->GetEffectiveShape() );
|
2020-08-27 17:13:08 +00:00
|
|
|
|
2020-07-22 23:05:22 +00:00
|
|
|
for( const SHAPE* shape : padShapes->Shapes() )
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
2020-06-22 19:35:09 +00:00
|
|
|
switch( shape->Type() )
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
2020-06-22 19:35:09 +00:00
|
|
|
case SH_SEGMENT:
|
2018-09-20 03:18:15 +00:00
|
|
|
{
|
2022-01-30 10:52:52 +00:00
|
|
|
const SHAPE_SEGMENT* seg = static_cast<const SHAPE_SEGMENT*>( shape );
|
2022-01-10 15:05:57 +00:00
|
|
|
|
2022-01-30 10:52:52 +00:00
|
|
|
const SFVEC2F a3DU = TO_SFVEC2F( seg->GetSeg().A );
|
|
|
|
const SFVEC2F b3DU = TO_SFVEC2F( seg->GetSeg().B );
|
|
|
|
const double width3DU = TO_3DU( seg->GetWidth() + clearance.x * 2 );
|
2020-06-22 19:35:09 +00:00
|
|
|
|
2023-01-29 22:39:29 +00:00
|
|
|
if( width3DU == 0.0 )
|
|
|
|
{
|
|
|
|
// Don't attempt to render degenerate shapes
|
|
|
|
}
|
|
|
|
else if( Is_segment_a_circle( a3DU, b3DU ) )
|
|
|
|
{
|
|
|
|
// Cannot add segments that have the same start and end point
|
2022-01-30 10:52:52 +00:00
|
|
|
aContainer->Add( new FILLED_CIRCLE_2D( a3DU, width3DU / 2, *aPad ) );
|
2023-01-29 22:39:29 +00:00
|
|
|
}
|
2020-03-26 12:41:57 +00:00
|
|
|
else
|
2023-01-29 22:39:29 +00:00
|
|
|
{
|
2022-01-30 10:52:52 +00:00
|
|
|
aContainer->Add( new ROUND_SEGMENT_2D( a3DU, b3DU, width3DU, *aPad ) );
|
2023-01-29 22:39:29 +00:00
|
|
|
}
|
|
|
|
|
2020-06-22 19:35:09 +00:00
|
|
|
break;
|
2023-01-29 22:39:29 +00:00
|
|
|
}
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2020-06-22 19:35:09 +00:00
|
|
|
case SH_CIRCLE:
|
2018-09-20 03:18:15 +00:00
|
|
|
{
|
2022-01-30 10:52:52 +00:00
|
|
|
const SHAPE_CIRCLE* circle = static_cast<const SHAPE_CIRCLE*>( shape );
|
2018-08-29 07:13:07 +00:00
|
|
|
|
2022-01-30 10:52:52 +00:00
|
|
|
const double radius3DU = TO_3DU( circle->GetRadius() + clearance.x );
|
|
|
|
const SFVEC2F center3DU = TO_SFVEC2F( circle->GetCenter() );
|
2022-01-10 15:05:57 +00:00
|
|
|
|
2022-04-11 13:49:33 +00:00
|
|
|
// Don't render zero radius circles
|
2023-01-29 22:39:29 +00:00
|
|
|
if( radius3DU > 0.0 )
|
2022-04-11 13:49:33 +00:00
|
|
|
aContainer->Add( new FILLED_CIRCLE_2D( center3DU, radius3DU, *aPad ) );
|
2023-01-29 22:39:29 +00:00
|
|
|
|
2020-06-22 19:35:09 +00:00
|
|
|
break;
|
2023-01-29 22:39:29 +00:00
|
|
|
}
|
2018-08-29 07:13:07 +00:00
|
|
|
|
2020-06-30 12:41:59 +00:00
|
|
|
case SH_RECT:
|
|
|
|
{
|
2022-01-30 10:52:52 +00:00
|
|
|
const SHAPE_RECT* rect = static_cast<const SHAPE_RECT*>( shape );
|
2020-06-30 12:41:59 +00:00
|
|
|
|
|
|
|
poly.NewOutline();
|
|
|
|
poly.Append( rect->GetPosition() );
|
|
|
|
poly.Append( rect->GetPosition().x + rect->GetSize().x, rect->GetPosition().y );
|
|
|
|
poly.Append( rect->GetPosition() + rect->GetSize() );
|
|
|
|
poly.Append( rect->GetPosition().x, rect->GetPosition().y + rect->GetSize().y );
|
|
|
|
break;
|
2023-01-29 22:39:29 +00:00
|
|
|
}
|
2020-06-30 12:41:59 +00:00
|
|
|
|
2020-06-22 19:35:09 +00:00
|
|
|
case SH_SIMPLE:
|
2020-07-22 23:05:22 +00:00
|
|
|
poly.AddOutline( static_cast<const SHAPE_SIMPLE*>( shape )->Vertices() );
|
2020-06-22 19:35:09 +00:00
|
|
|
break;
|
2018-08-29 07:13:07 +00:00
|
|
|
|
2020-06-22 19:35:09 +00:00
|
|
|
case SH_POLY_SET:
|
2020-07-22 23:05:22 +00:00
|
|
|
poly = *(SHAPE_POLY_SET*) shape;
|
2020-06-22 19:35:09 +00:00
|
|
|
break;
|
2018-08-29 07:13:07 +00:00
|
|
|
|
2021-03-20 13:14:09 +00:00
|
|
|
case SH_ARC:
|
|
|
|
{
|
2022-01-30 10:52:52 +00:00
|
|
|
const SHAPE_ARC* arc = static_cast<const SHAPE_ARC*>( shape );
|
2021-07-21 15:40:14 +00:00
|
|
|
SHAPE_LINE_CHAIN l = arc->ConvertToPolyline( maxError );
|
2021-03-20 13:14:09 +00:00
|
|
|
|
|
|
|
for( int i = 0; i < l.SegmentCount(); i++ )
|
|
|
|
{
|
|
|
|
SHAPE_SEGMENT seg( l.Segment( i ).A, l.Segment( i ).B, arc->GetWidth() );
|
2022-01-30 10:52:52 +00:00
|
|
|
const SFVEC2F a3DU = TO_SFVEC2F( seg.GetSeg().A );
|
|
|
|
const SFVEC2F b3DU = TO_SFVEC2F( seg.GetSeg().B );
|
|
|
|
const double width3DU = TO_3DU( arc->GetWidth() + clearance.x * 2 );
|
2021-03-20 13:14:09 +00:00
|
|
|
|
2023-01-29 22:39:29 +00:00
|
|
|
if( width3DU == 0.0 )
|
|
|
|
{
|
|
|
|
// Don't attempt to render degenerate shapes
|
|
|
|
}
|
|
|
|
else if( Is_segment_a_circle( a3DU, b3DU ) )
|
|
|
|
{
|
|
|
|
// Cannot add segments that have the same start and end point
|
2022-01-30 10:52:52 +00:00
|
|
|
aContainer->Add( new FILLED_CIRCLE_2D( a3DU, width3DU / 2, *aPad ) );
|
2023-01-29 22:39:29 +00:00
|
|
|
}
|
2021-03-20 13:14:09 +00:00
|
|
|
else
|
2023-01-29 22:39:29 +00:00
|
|
|
{
|
2022-01-30 10:52:52 +00:00
|
|
|
aContainer->Add( new ROUND_SEGMENT_2D( a3DU, b3DU, width3DU, *aPad ) );
|
2023-01-29 22:39:29 +00:00
|
|
|
}
|
2021-03-20 13:14:09 +00:00
|
|
|
}
|
2023-01-29 22:39:29 +00:00
|
|
|
|
2021-03-20 13:14:09 +00:00
|
|
|
break;
|
2023-01-29 22:39:29 +00:00
|
|
|
}
|
2021-03-20 13:14:09 +00:00
|
|
|
|
2020-06-22 19:35:09 +00:00
|
|
|
default:
|
2021-07-21 15:40:14 +00:00
|
|
|
UNIMPLEMENTED_FOR( SHAPE_TYPE_asString( shape->Type() ) );
|
2020-06-22 19:35:09 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-08-29 07:13:07 +00:00
|
|
|
}
|
|
|
|
|
2020-06-22 19:35:09 +00:00
|
|
|
if( !poly.IsEmpty() )
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
2021-07-26 23:47:26 +00:00
|
|
|
if( clearance.x )
|
2023-05-29 14:28:48 +00:00
|
|
|
poly.Inflate( clearance.x, SHAPE_POLY_SET::ROUND_ALL_CORNERS, maxError );
|
2018-01-28 13:05:17 +00:00
|
|
|
|
|
|
|
// Add the PAD polygon
|
2022-01-30 10:52:52 +00:00
|
|
|
ConvertPolygonToTriangles( poly, *aContainer, m_biuTo3Dunits, *aPad );
|
2018-01-28 13:05:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
OBJECT_2D* BOARD_ADAPTER::createPadWithDrill( const PAD* aPad, int aInflateValue )
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
2022-07-22 22:05:25 +00:00
|
|
|
if( !aPad->HasHole() )
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
2021-01-05 22:19:00 +00:00
|
|
|
wxLogTrace( m_logTrace, wxT( "BOARD_ADAPTER::createPadWithDrill - found an invalid pad" ) );
|
2020-12-16 22:10:42 +00:00
|
|
|
return nullptr;
|
2018-01-28 13:05:17 +00:00
|
|
|
}
|
|
|
|
|
2022-07-22 22:05:25 +00:00
|
|
|
std::shared_ptr<SHAPE_SEGMENT> slot = aPad->GetEffectiveHoleShape();
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2022-07-22 22:05:25 +00:00
|
|
|
if( slot->GetSeg().A == slot->GetSeg().B )
|
|
|
|
{
|
|
|
|
return new FILLED_CIRCLE_2D( TO_SFVEC2F( slot->GetSeg().A ),
|
|
|
|
TO_3DU( slot->GetWidth() / 2 + aInflateValue ),
|
|
|
|
*aPad );
|
2018-01-28 13:05:17 +00:00
|
|
|
}
|
2022-07-22 22:05:25 +00:00
|
|
|
else
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
2022-07-22 22:05:25 +00:00
|
|
|
return new ROUND_SEGMENT_2D( TO_SFVEC2F( slot->GetSeg().A ),
|
|
|
|
TO_SFVEC2F( slot->GetSeg().B ),
|
|
|
|
TO_3DU( slot->GetWidth() + aInflateValue * 2 ),
|
|
|
|
*aPad );
|
2018-01-28 13:05:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-30 10:52:52 +00:00
|
|
|
void BOARD_ADAPTER::addPads( const FOOTPRINT* aFootprint, CONTAINER_2D_BASE* aContainer,
|
2023-04-08 14:02:48 +00:00
|
|
|
PCB_LAYER_ID aLayerId, bool aSkipPlatedPads, bool aSkipNonPlatedPads )
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
2020-11-13 01:12:36 +00:00
|
|
|
for( PAD* pad : aFootprint->Pads() )
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
2022-03-10 11:43:17 +00:00
|
|
|
if( !pad->IsOnLayer( aLayerId ) )
|
|
|
|
continue;
|
|
|
|
|
2023-04-08 14:02:48 +00:00
|
|
|
if( IsCopperLayer( aLayerId ) )
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
2023-04-08 14:02:48 +00:00
|
|
|
// Skip pad annulus when there isn't one (note: this is more discerning than
|
|
|
|
// pad->IsOnLayer(), which doesn't check for NPTH pads with holes that consume
|
|
|
|
// the entire pad).
|
|
|
|
if( !pad->IsOnCopperLayer() )
|
|
|
|
continue;
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2023-04-08 14:02:48 +00:00
|
|
|
// Skip pad annulus when not connected on this layer (if removing is enabled)
|
|
|
|
if( !pad->FlashLayer( aLayerId ) )
|
|
|
|
continue;
|
2018-01-28 13:05:17 +00:00
|
|
|
}
|
|
|
|
|
2022-01-10 14:03:53 +00:00
|
|
|
VECTOR2I margin( 0, 0 );
|
2020-08-28 19:27:44 +00:00
|
|
|
|
2018-01-28 13:05:17 +00:00
|
|
|
switch( aLayerId )
|
|
|
|
{
|
2022-03-06 13:35:46 +00:00
|
|
|
case F_Cu:
|
|
|
|
if( aSkipPlatedPads && pad->FlashLayer( F_Mask ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( aSkipNonPlatedPads && !pad->FlashLayer( F_Mask ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case B_Cu:
|
|
|
|
if( aSkipPlatedPads && pad->FlashLayer( B_Mask ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( aSkipNonPlatedPads && !pad->FlashLayer( B_Mask ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2018-01-28 13:05:17 +00:00
|
|
|
case F_Mask:
|
|
|
|
case B_Mask:
|
2021-08-22 22:05:47 +00:00
|
|
|
margin.x += pad->GetSolderMaskExpansion();
|
|
|
|
margin.y += pad->GetSolderMaskExpansion();
|
2018-01-28 13:05:17 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case F_Paste:
|
|
|
|
case B_Paste:
|
2020-08-28 19:27:44 +00:00
|
|
|
margin += pad->GetSolderPasteMargin();
|
2018-01-28 13:05:17 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-01-30 10:52:52 +00:00
|
|
|
createPadWithMargin( pad, aContainer, aLayerId, margin );
|
2018-01-28 13:05:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-16 22:10:42 +00:00
|
|
|
|
2018-01-28 13:05:17 +00:00
|
|
|
// based on TransformArcToPolygon function from
|
|
|
|
// common/convert_basic_shapes_to_polygon.cpp
|
2021-12-29 19:19:08 +00:00
|
|
|
void BOARD_ADAPTER::transformArcToSegments( const VECTOR2I& aCentre, const VECTOR2I& aStart,
|
2022-01-16 21:15:20 +00:00
|
|
|
const EDA_ANGLE& aArcAngle, int aCircleToSegmentsCount,
|
2022-01-30 10:52:52 +00:00
|
|
|
int aWidth, CONTAINER_2D_BASE* aContainer,
|
|
|
|
const BOARD_ITEM& aOwner )
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
2023-01-29 22:39:29 +00:00
|
|
|
// Don't attempt to render degenerate shapes
|
|
|
|
if( aWidth == 0 )
|
|
|
|
return;
|
|
|
|
|
2022-01-16 21:15:20 +00:00
|
|
|
VECTOR2I arc_start, arc_end;
|
|
|
|
EDA_ANGLE arcAngle( aArcAngle );
|
|
|
|
EDA_ANGLE delta = ANGLE_360 / aCircleToSegmentsCount; // rotate angle
|
2018-01-28 13:05:17 +00:00
|
|
|
|
|
|
|
arc_end = arc_start = aStart;
|
|
|
|
|
2022-01-16 21:15:20 +00:00
|
|
|
if( arcAngle != ANGLE_360 )
|
|
|
|
RotatePoint( arc_end, aCentre, -arcAngle );
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2022-01-16 21:15:20 +00:00
|
|
|
if( arcAngle < ANGLE_0 )
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
|
|
|
std::swap( arc_start, arc_end );
|
2022-01-16 21:15:20 +00:00
|
|
|
arcAngle = -arcAngle;
|
2018-01-28 13:05:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Compute the ends of segments and creates poly
|
2021-12-29 19:19:08 +00:00
|
|
|
VECTOR2I curr_end = arc_start;
|
|
|
|
VECTOR2I curr_start = arc_start;
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2022-01-16 21:15:20 +00:00
|
|
|
for( EDA_ANGLE ii = delta; ii < arcAngle; ii += delta )
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
|
|
|
curr_end = arc_start;
|
2021-12-29 19:19:08 +00:00
|
|
|
RotatePoint( curr_end, aCentre, -ii );
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2022-01-30 10:52:52 +00:00
|
|
|
const SFVEC2F start3DU = TO_SFVEC2F( curr_start );
|
|
|
|
const SFVEC2F end3DU = TO_SFVEC2F( curr_end );
|
2018-01-28 13:05:17 +00:00
|
|
|
|
|
|
|
if( Is_segment_a_circle( start3DU, end3DU ) )
|
2022-01-30 10:52:52 +00:00
|
|
|
aContainer->Add( new FILLED_CIRCLE_2D( start3DU, TO_3DU( aWidth / 2 ), aOwner ) );
|
2018-01-28 13:05:17 +00:00
|
|
|
else
|
2022-01-30 10:52:52 +00:00
|
|
|
aContainer->Add( new ROUND_SEGMENT_2D( start3DU, end3DU, TO_3DU( aWidth ), aOwner ) );
|
2018-01-28 13:05:17 +00:00
|
|
|
|
|
|
|
curr_start = curr_end;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( curr_end != arc_end )
|
|
|
|
{
|
2022-01-30 10:52:52 +00:00
|
|
|
const SFVEC2F start3DU = TO_SFVEC2F( curr_end );
|
|
|
|
const SFVEC2F end3DU = TO_SFVEC2F( arc_end );
|
2018-01-28 13:05:17 +00:00
|
|
|
|
|
|
|
if( Is_segment_a_circle( start3DU, end3DU ) )
|
2022-01-30 10:52:52 +00:00
|
|
|
aContainer->Add( new FILLED_CIRCLE_2D( start3DU, TO_3DU( aWidth / 2 ), aOwner ) );
|
2018-01-28 13:05:17 +00:00
|
|
|
else
|
2022-01-30 10:52:52 +00:00
|
|
|
aContainer->Add( new ROUND_SEGMENT_2D( start3DU, end3DU, TO_3DU( aWidth ), aOwner ) );
|
2018-01-28 13:05:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-16 22:10:42 +00:00
|
|
|
|
2022-01-30 10:52:52 +00:00
|
|
|
void BOARD_ADAPTER::addShape( const PCB_SHAPE* aShape, CONTAINER_2D_BASE* aContainer,
|
|
|
|
const BOARD_ITEM* aOwner )
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
2018-11-04 18:59:36 +00:00
|
|
|
// The full width of the lines to create
|
|
|
|
// The extra 1 protects the inner/outer radius values from degeneracy
|
2022-02-17 17:49:03 +00:00
|
|
|
const int linewidth = aShape->GetWidth() + 1;
|
|
|
|
PLOT_DASH_TYPE lineStyle = aShape->GetStroke().GetPlotStyle();
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2022-02-17 17:49:03 +00:00
|
|
|
if( lineStyle <= PLOT_DASH_TYPE::FIRST_TYPE )
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
2022-02-17 17:49:03 +00:00
|
|
|
switch( aShape->GetShape() )
|
|
|
|
{
|
|
|
|
case SHAPE_T::CIRCLE:
|
|
|
|
{
|
|
|
|
const SFVEC2F center3DU = TO_SFVEC2F( aShape->GetCenter() );
|
|
|
|
float inner_radius3DU = TO_3DU( aShape->GetRadius() - linewidth / 2 );
|
|
|
|
float outer_radius3DU = TO_3DU( aShape->GetRadius() + linewidth / 2 );
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2022-02-17 17:49:03 +00:00
|
|
|
if( inner_radius3DU < 0 )
|
2023-01-29 22:39:29 +00:00
|
|
|
inner_radius3DU = 0.0;
|
2019-08-20 17:02:28 +00:00
|
|
|
|
2023-09-04 21:10:47 +00:00
|
|
|
if( outer_radius3DU <= inner_radius3DU )
|
2023-01-29 22:39:29 +00:00
|
|
|
{
|
|
|
|
// Don't attempt to render degenerate shapes
|
|
|
|
}
|
|
|
|
else if( aShape->IsFilled() )
|
|
|
|
{
|
|
|
|
aContainer->Add( new FILLED_CIRCLE_2D( center3DU, outer_radius3DU,
|
|
|
|
*aOwner ) );
|
|
|
|
}
|
2022-02-17 17:49:03 +00:00
|
|
|
else
|
2023-01-29 22:39:29 +00:00
|
|
|
{
|
|
|
|
aContainer->Add( new RING_2D( center3DU, inner_radius3DU, outer_radius3DU,
|
|
|
|
*aOwner ) );
|
|
|
|
}
|
2022-07-30 10:32:12 +00:00
|
|
|
|
2022-02-17 17:49:03 +00:00
|
|
|
break;
|
2022-07-30 10:32:12 +00:00
|
|
|
}
|
2022-02-17 17:49:03 +00:00
|
|
|
|
2023-07-24 16:07:56 +00:00
|
|
|
case SHAPE_T::RECTANGLE:
|
2022-02-17 17:49:03 +00:00
|
|
|
if( aShape->IsFilled() )
|
|
|
|
{
|
|
|
|
SHAPE_POLY_SET polyList;
|
|
|
|
|
2022-10-21 12:48:45 +00:00
|
|
|
aShape->TransformShapeToPolygon( polyList, UNDEFINED_LAYER, 0, ARC_HIGH_DEF,
|
|
|
|
ERROR_INSIDE );
|
2022-02-17 17:49:03 +00:00
|
|
|
|
|
|
|
polyList.Simplify( SHAPE_POLY_SET::PM_FAST );
|
|
|
|
|
|
|
|
ConvertPolygonToTriangles( polyList, *aContainer, m_biuTo3Dunits, *aOwner );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::vector<VECTOR2I> pts = aShape->GetRectCorners();
|
|
|
|
|
|
|
|
aContainer->Add( new ROUND_SEGMENT_2D( TO_SFVEC2F( pts[0] ), TO_SFVEC2F( pts[1] ),
|
|
|
|
TO_3DU( linewidth ), *aOwner ) );
|
|
|
|
aContainer->Add( new ROUND_SEGMENT_2D( TO_SFVEC2F( pts[1] ), TO_SFVEC2F( pts[2] ),
|
|
|
|
TO_3DU( linewidth ), *aOwner ) );
|
|
|
|
aContainer->Add( new ROUND_SEGMENT_2D( TO_SFVEC2F( pts[2] ), TO_SFVEC2F( pts[3] ),
|
|
|
|
TO_3DU( linewidth ), *aOwner ) );
|
|
|
|
aContainer->Add( new ROUND_SEGMENT_2D( TO_SFVEC2F( pts[3] ), TO_SFVEC2F( pts[0] ),
|
|
|
|
TO_3DU( linewidth ), *aOwner ) );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::ARC:
|
|
|
|
{
|
|
|
|
unsigned int segCount = GetCircleSegmentCount( aShape->GetBoundingBox().GetSizeMax() );
|
|
|
|
|
|
|
|
transformArcToSegments( aShape->GetCenter(), aShape->GetStart(), aShape->GetArcAngle(),
|
|
|
|
segCount, linewidth, aContainer, *aOwner );
|
2023-01-29 22:39:29 +00:00
|
|
|
break;
|
2022-02-17 17:49:03 +00:00
|
|
|
}
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2022-02-17 17:49:03 +00:00
|
|
|
case SHAPE_T::SEGMENT:
|
|
|
|
{
|
|
|
|
const SFVEC2F start3DU = TO_SFVEC2F( aShape->GetStart() );
|
|
|
|
const SFVEC2F end3DU = TO_SFVEC2F( aShape->GetEnd() );
|
|
|
|
const double linewidth3DU = TO_3DU( linewidth );
|
|
|
|
|
2023-01-29 22:39:29 +00:00
|
|
|
if( linewidth3DU == 0.0 )
|
|
|
|
{
|
|
|
|
// Don't attempt to render degenerate shapes
|
|
|
|
}
|
|
|
|
else if( Is_segment_a_circle( start3DU, end3DU ) )
|
|
|
|
{
|
|
|
|
// Cannot add segments that have the same start and end point
|
2022-02-17 17:49:03 +00:00
|
|
|
aContainer->Add( new FILLED_CIRCLE_2D( start3DU, linewidth3DU / 2, *aOwner ) );
|
2023-01-29 22:39:29 +00:00
|
|
|
}
|
2022-02-17 17:49:03 +00:00
|
|
|
else
|
2023-01-29 22:39:29 +00:00
|
|
|
{
|
2022-02-17 17:49:03 +00:00
|
|
|
aContainer->Add( new ROUND_SEGMENT_2D( start3DU, end3DU, linewidth3DU, *aOwner ) );
|
2023-01-29 22:39:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2022-02-17 17:49:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case SHAPE_T::BEZIER:
|
|
|
|
case SHAPE_T::POLY:
|
2020-11-14 01:16:02 +00:00
|
|
|
{
|
|
|
|
SHAPE_POLY_SET polyList;
|
|
|
|
|
2022-10-21 12:48:45 +00:00
|
|
|
aShape->TransformShapeToPolygon( polyList, UNDEFINED_LAYER, 0, ARC_HIGH_DEF,
|
|
|
|
ERROR_INSIDE );
|
2020-11-14 01:16:02 +00:00
|
|
|
|
2022-02-17 17:49:03 +00:00
|
|
|
if( polyList.IsEmpty() ) // Just for caution
|
|
|
|
break;
|
2020-06-19 20:46:43 +00:00
|
|
|
|
2022-02-17 17:49:03 +00:00
|
|
|
ConvertPolygonToTriangles( polyList, *aContainer, m_biuTo3Dunits, *aOwner );
|
2023-01-29 22:39:29 +00:00
|
|
|
break;
|
2020-06-19 20:46:43 +00:00
|
|
|
}
|
2020-06-15 19:50:20 +00:00
|
|
|
|
2022-02-17 17:49:03 +00:00
|
|
|
default:
|
2022-10-21 12:48:45 +00:00
|
|
|
wxFAIL_MSG( wxT( "BOARD_ADAPTER::addShape no implementation for " )
|
2022-02-17 17:49:03 +00:00
|
|
|
+ aShape->SHAPE_T_asString() );
|
|
|
|
break;
|
|
|
|
}
|
2018-01-28 13:05:17 +00:00
|
|
|
}
|
2023-01-29 22:39:29 +00:00
|
|
|
else if( linewidth > 0 )
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
2022-02-17 17:49:03 +00:00
|
|
|
std::vector<SHAPE*> shapes = aShape->MakeEffectiveShapes( true );
|
|
|
|
SFVEC2F a3DU;
|
|
|
|
SFVEC2F b3DU;
|
|
|
|
double width3DU = TO_3DU( linewidth );
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2022-02-17 17:49:03 +00:00
|
|
|
const PCB_PLOT_PARAMS& plotParams = aShape->GetBoard()->GetPlotOptions();
|
|
|
|
KIGFX::PCB_RENDER_SETTINGS renderSettings;
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2022-02-17 17:49:03 +00:00
|
|
|
renderSettings.SetDashLengthRatio( plotParams.GetDashedLineDashRatio() );
|
|
|
|
renderSettings.SetGapLengthRatio( plotParams.GetDashedLineGapRatio() );
|
2018-09-18 11:12:55 +00:00
|
|
|
|
2022-02-17 17:49:03 +00:00
|
|
|
for( SHAPE* shape : shapes )
|
|
|
|
{
|
|
|
|
STROKE_PARAMS::Stroke( shape, lineStyle, linewidth, &renderSettings,
|
|
|
|
[&]( const VECTOR2I& a, const VECTOR2I& b )
|
|
|
|
{
|
|
|
|
a3DU = TO_SFVEC2F( a );
|
|
|
|
b3DU = TO_SFVEC2F( b );
|
|
|
|
|
|
|
|
if( Is_segment_a_circle( a3DU, b3DU ) )
|
|
|
|
aContainer->Add( new FILLED_CIRCLE_2D( a3DU, width3DU / 2, *aOwner ) );
|
|
|
|
else
|
|
|
|
aContainer->Add( new ROUND_SEGMENT_2D( a3DU, b3DU, width3DU, *aOwner ) );
|
|
|
|
} );
|
|
|
|
}
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2022-02-17 17:49:03 +00:00
|
|
|
for( SHAPE* shape : shapes )
|
|
|
|
delete shape;
|
2018-01-28 13:05:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-30 10:52:52 +00:00
|
|
|
void BOARD_ADAPTER::addSolidAreasShapes( const ZONE* aZone, CONTAINER_2D_BASE* aContainer,
|
|
|
|
PCB_LAYER_ID aLayerId )
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
|
|
|
// This convert the poly in outline and holes
|
2022-03-14 15:52:12 +00:00
|
|
|
ConvertPolygonToTriangles( *aZone->GetFilledPolysList( aLayerId ), *aContainer,
|
|
|
|
m_biuTo3Dunits, *aZone );
|
2018-01-28 13:05:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-30 10:52:52 +00:00
|
|
|
void BOARD_ADAPTER::buildPadOutlineAsSegments( const PAD* aPad, CONTAINER_2D_BASE* aContainer,
|
2021-01-05 22:19:00 +00:00
|
|
|
int aWidth )
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
2021-05-01 12:22:35 +00:00
|
|
|
if( aPad->GetShape() == PAD_SHAPE::CIRCLE ) // Draw a ring
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
2022-01-30 10:52:52 +00:00
|
|
|
const SFVEC2F center3DU = TO_SFVEC2F( aPad->ShapePos() );
|
|
|
|
const int radius = aPad->GetSize().x / 2;
|
|
|
|
const float inner_radius3DU = TO_3DU( radius - aWidth / 2 );
|
|
|
|
const float outer_radius3DU = TO_3DU( radius + aWidth / 2 );
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2022-01-30 10:52:52 +00:00
|
|
|
aContainer->Add( new RING_2D( center3DU, inner_radius3DU, outer_radius3DU, *aPad ) );
|
2018-01-28 13:05:17 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-22 19:35:09 +00:00
|
|
|
// For other shapes, add outlines as thick segments in polygon buffer
|
2020-07-25 11:58:17 +00:00
|
|
|
const std::shared_ptr<SHAPE_POLY_SET>& corners = aPad->GetEffectivePolygon();
|
|
|
|
const SHAPE_LINE_CHAIN& path = corners->COutline( 0 );
|
2018-01-28 13:05:17 +00:00
|
|
|
|
|
|
|
for( int j = 0; j < path.PointCount(); j++ )
|
|
|
|
{
|
2022-01-30 10:52:52 +00:00
|
|
|
SFVEC2F start3DU = TO_SFVEC2F( path.CPoint( j ) );
|
|
|
|
SFVEC2F end3DU = TO_SFVEC2F( path.CPoint( j + 1 ) );
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2023-01-29 22:39:29 +00:00
|
|
|
if( aWidth == 0 )
|
|
|
|
{
|
|
|
|
// Don't attempt to render degenerate shapes
|
|
|
|
}
|
|
|
|
else if( Is_segment_a_circle( start3DU, end3DU ) )
|
|
|
|
{
|
|
|
|
// Cannot add segments that have the same start and end point
|
2022-01-30 10:52:52 +00:00
|
|
|
aContainer->Add( new FILLED_CIRCLE_2D( start3DU, TO_3DU( aWidth / 2 ), *aPad ) );
|
2023-01-29 22:39:29 +00:00
|
|
|
}
|
2018-01-28 13:05:17 +00:00
|
|
|
else
|
2023-01-29 22:39:29 +00:00
|
|
|
{
|
2022-01-30 10:52:52 +00:00
|
|
|
aContainer->Add( new ROUND_SEGMENT_2D( start3DU, end3DU, TO_3DU( aWidth ), *aPad ) );
|
2023-01-29 22:39:29 +00:00
|
|
|
}
|
2018-01-28 13:05:17 +00:00
|
|
|
}
|
|
|
|
}
|