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>
|
2021-05-15 11:18:06 +00:00
|
|
|
* Copyright (C) 1992-2021 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file create_graphic_brd_items.cpp
|
|
|
|
* @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 <board.h>
|
|
|
|
#include <footprint.h>
|
|
|
|
#include <pad.h>
|
2020-10-04 23:34:59 +00:00
|
|
|
#include <pcb_text.h>
|
|
|
|
#include <fp_shape.h>
|
2020-11-11 23:05:59 +00:00
|
|
|
#include <zone.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2020-10-04 23:34:59 +00:00
|
|
|
#include <fp_text.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>
|
2019-05-31 12:15:25 +00:00
|
|
|
#include <gr_text.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>
|
2018-01-28 13:05:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
// These variables are parameters used in addTextSegmToContainer.
|
|
|
|
// But addTextSegmToContainer is a call-back function,
|
|
|
|
// so we cannot send them as arguments.
|
|
|
|
static int s_textWidth;
|
2021-01-02 21:05:29 +00:00
|
|
|
static CONTAINER_2D_BASE* s_dstcontainer = nullptr;
|
2018-01-28 13:05:17 +00:00
|
|
|
static float s_biuTo3Dunits;
|
2020-12-16 22:10:42 +00:00
|
|
|
static const BOARD_ITEM* s_boardItem = nullptr;
|
|
|
|
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2019-05-31 12:15:25 +00:00
|
|
|
// This is a call back function, used by GRText to draw the 3D text shape:
|
2018-04-06 13:30:52 +00:00
|
|
|
void addTextSegmToContainer( int x0, int y0, int xf, int yf, void* aData )
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
|
|
|
const SFVEC2F start3DU( x0 * s_biuTo3Dunits, -y0 * s_biuTo3Dunits );
|
|
|
|
const SFVEC2F end3DU ( xf * s_biuTo3Dunits, -yf * s_biuTo3Dunits );
|
|
|
|
|
|
|
|
if( Is_segment_a_circle( start3DU, end3DU ) )
|
2021-01-02 21:05:29 +00:00
|
|
|
s_dstcontainer->Add( new FILLED_CIRCLE_2D( start3DU, ( s_textWidth / 2 ) * s_biuTo3Dunits,
|
|
|
|
*s_boardItem) );
|
2018-01-28 13:05:17 +00:00
|
|
|
else
|
2021-01-02 21:05:29 +00:00
|
|
|
s_dstcontainer->Add( new ROUND_SEGMENT_2D( start3DU, end3DU, s_textWidth * s_biuTo3Dunits,
|
|
|
|
*s_boardItem ) );
|
2018-01-28 13:05:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Based on
|
2020-11-29 14:00:39 +00:00
|
|
|
// void PCB_TEXT::TransformTextShapeWithClearanceToPolygon
|
2018-01-28 13:05:17 +00:00
|
|
|
// board_items_to_polygon_shape_transform.cpp
|
2021-01-05 22:19:00 +00:00
|
|
|
void BOARD_ADAPTER::addShapeWithClearance( const PCB_TEXT* aText, CONTAINER_2D_BASE* aDstContainer,
|
|
|
|
PCB_LAYER_ID aLayerId, int aClearanceValue )
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
2019-05-31 12:15:25 +00:00
|
|
|
wxSize size = aText->GetTextSize();
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2019-05-31 12:15:25 +00:00
|
|
|
if( aText->IsMirrored() )
|
2018-01-28 13:05:17 +00:00
|
|
|
size.x = -size.x;
|
|
|
|
|
2019-05-31 12:15:25 +00:00
|
|
|
s_boardItem = (const BOARD_ITEM *) &aText;
|
2018-01-28 13:05:17 +00:00
|
|
|
s_dstcontainer = aDstContainer;
|
2020-04-14 12:25:00 +00:00
|
|
|
s_textWidth = aText->GetEffectiveTextPenWidth() + ( 2 * aClearanceValue );
|
2018-01-28 13:05:17 +00:00
|
|
|
s_biuTo3Dunits = m_biuTo3Dunits;
|
|
|
|
|
2019-05-31 12:15:25 +00:00
|
|
|
// not actually used, but needed by GRText
|
2021-05-15 11:18:06 +00:00
|
|
|
const COLOR4D dummy_color;
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2021-05-15 11:18:06 +00:00
|
|
|
// Use the actual text width to generate segments. The segment position depend on
|
|
|
|
// text thickness and justification
|
|
|
|
bool isBold = aText->IsBold();
|
|
|
|
int penWidth = aText->GetEffectiveTextPenWidth();
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2021-05-15 11:18:06 +00:00
|
|
|
GRText( nullptr, aText->GetTextPos(), dummy_color, aText->GetShownText(),
|
|
|
|
aText->GetTextAngle(), size, aText->GetHorizJustify(), aText->GetVertJustify(),
|
|
|
|
penWidth, aText->IsItalic(), isBold, addTextSegmToContainer );
|
2018-01-28 13:05:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-11 16:59:28 +00:00
|
|
|
void BOARD_ADAPTER::addShapeWithClearance( const PCB_DIMENSION_BASE* aDimension,
|
2021-01-05 22:19:00 +00:00
|
|
|
CONTAINER_2D_BASE* aDstContainer,
|
|
|
|
PCB_LAYER_ID aLayerId, int aClearanceValue )
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
2021-01-05 22:19:00 +00:00
|
|
|
addShapeWithClearance( &aDimension->Text(), aDstContainer, aLayerId, aClearanceValue );
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2020-12-16 22:10:42 +00:00
|
|
|
const int linewidth = aDimension->GetLineThickness() + ( 2 * aClearanceValue );
|
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:
|
|
|
|
{
|
|
|
|
const SEG& seg = static_cast<const SHAPE_SEGMENT*>( shape.get() )->GetSeg();
|
|
|
|
|
2020-12-16 22:10:42 +00:00
|
|
|
const SFVEC2F start3DU( seg.A.x * m_biuTo3Dunits, -seg.A.y * m_biuTo3Dunits );
|
2020-09-12 20:09:40 +00:00
|
|
|
|
2020-12-16 22:10:42 +00:00
|
|
|
const SFVEC2F end3DU( seg.B.x * m_biuTo3Dunits, -seg.B.y * m_biuTo3Dunits );
|
2020-09-12 20:09:40 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
aDstContainer->Add( new ROUND_SEGMENT_2D( start3DU, end3DU, linewidth * m_biuTo3Dunits,
|
|
|
|
*aDimension ) );
|
2020-09-12 20:09:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SH_CIRCLE:
|
|
|
|
{
|
|
|
|
int radius = static_cast<const SHAPE_CIRCLE*>( shape.get() )->GetRadius();
|
|
|
|
int deltar = aDimension->GetLineThickness();
|
|
|
|
|
|
|
|
SFVEC2F center( shape->Centre().x * m_biuTo3Dunits,
|
|
|
|
shape->Centre().y * m_biuTo3Dunits );
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
aDstContainer->Add( new RING_2D( center, ( radius - deltar ) * m_biuTo3Dunits,
|
2020-09-12 20:09:40 +00:00
|
|
|
( radius + deltar ) * m_biuTo3Dunits, *aDimension ) );
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2018-01-28 13:05:17 +00:00
|
|
|
|
|
|
|
}
|
2020-09-12 20:09:40 +00:00
|
|
|
|
2018-01-28 13:05:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Based on
|
2020-11-13 00:43:45 +00:00
|
|
|
// void FOOTPRINT::TransformFPShapesWithClearanceToPolygonSet
|
2018-01-28 13:05:17 +00:00
|
|
|
// board_items_to_polygon_shape_transform.cpp#L204
|
2021-01-05 22:19:00 +00:00
|
|
|
void BOARD_ADAPTER::addFootprintShapesWithClearance( const FOOTPRINT* aFootprint,
|
|
|
|
CONTAINER_2D_BASE* aDstContainer,
|
|
|
|
PCB_LAYER_ID aLayerId, int aInflateValue )
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
std::vector<FP_TEXT*> texts; // List of FP_TEXT to convert
|
|
|
|
FP_SHAPE* outline;
|
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() )
|
|
|
|
{
|
2020-10-04 14:19:33 +00:00
|
|
|
case PCB_FP_TEXT_T:
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
FP_TEXT* text = static_cast<FP_TEXT*>( item );
|
2018-01-28 13:05:17 +00:00
|
|
|
|
|
|
|
if( text->GetLayer() == aLayerId && text->IsVisible() )
|
|
|
|
texts.push_back( text );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
2020-10-04 14:19:33 +00:00
|
|
|
case PCB_FP_SHAPE_T:
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
outline = (FP_SHAPE*) item;
|
2018-01-28 13:05:17 +00:00
|
|
|
|
|
|
|
if( outline->GetLayer() != aLayerId )
|
|
|
|
break;
|
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
addShapeWithClearance( (const PCB_SHAPE*) outline, aDstContainer, aLayerId, 0 );
|
2018-01-28 13:05:17 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-16 22:10:42 +00:00
|
|
|
// Convert texts for footprints
|
2020-11-13 01:12:36 +00:00
|
|
|
if( aFootprint->Reference().GetLayer() == aLayerId && aFootprint->Reference().IsVisible() )
|
|
|
|
texts.push_back( &aFootprint->Reference() );
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
if( aFootprint->Value().GetLayer() == aLayerId && aFootprint->Value().IsVisible() )
|
|
|
|
texts.push_back( &aFootprint->Value() );
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
s_boardItem = (const BOARD_ITEM *)&aFootprint->Value();
|
2018-01-28 13:05:17 +00:00
|
|
|
s_dstcontainer = aDstContainer;
|
|
|
|
s_biuTo3Dunits = m_biuTo3Dunits;
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
for( FP_TEXT* text : texts )
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
2020-04-14 12:25:00 +00:00
|
|
|
s_textWidth = text->GetEffectiveTextPenWidth() + ( 2 * aInflateValue );
|
2019-05-31 12:15:25 +00:00
|
|
|
wxSize size = text->GetTextSize();
|
2021-05-15 11:18:06 +00:00
|
|
|
bool isBold = text->IsBold();
|
|
|
|
int penWidth = text->GetEffectiveTextPenWidth();
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2019-05-31 12:15:25 +00:00
|
|
|
if( text->IsMirrored() )
|
2018-01-28 13:05:17 +00:00
|
|
|
size.x = -size.x;
|
|
|
|
|
2020-12-16 22:10:42 +00:00
|
|
|
GRText( nullptr, text->GetTextPos(), BLACK, text->GetShownText(), text->GetDrawRotation(),
|
2020-04-13 19:55:27 +00:00
|
|
|
size, text->GetHorizJustify(), text->GetVertJustify(), penWidth, text->IsItalic(),
|
2021-05-15 11:18:06 +00:00
|
|
|
isBold, addTextSegmToContainer );
|
2018-01-28 13:05:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
void BOARD_ADAPTER::createTrack( const PCB_TRACK* aTrack, CONTAINER_2D_BASE* aDstContainer,
|
2021-01-05 22:19:00 +00:00
|
|
|
int aClearanceValue )
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
2020-12-16 22:10:42 +00:00
|
|
|
SFVEC2F start3DU( aTrack->GetStart().x * m_biuTo3Dunits,
|
2018-01-28 13:05:17 +00:00
|
|
|
-aTrack->GetStart().y * m_biuTo3Dunits ); // y coord is inverted
|
|
|
|
|
|
|
|
switch( aTrack->Type() )
|
|
|
|
{
|
|
|
|
case PCB_VIA_T:
|
2020-12-16 22:10:42 +00:00
|
|
|
{
|
2018-01-28 13:05:17 +00:00
|
|
|
const float radius = ( ( aTrack->GetWidth() / 2 ) + aClearanceValue ) * m_biuTo3Dunits;
|
2021-01-02 21:05:29 +00:00
|
|
|
aDstContainer->Add( new FILLED_CIRCLE_2D( start3DU, radius, *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 );
|
2020-12-16 22:10:42 +00:00
|
|
|
VECTOR2D center( arc->GetCenter() );
|
|
|
|
double arc_angle = arc->GetAngle();
|
|
|
|
double radius = arc->GetRadius();
|
|
|
|
int arcsegcount = GetArcToSegmentCount( radius, Millimeter2iu( 0.005), arc_angle/10 );
|
|
|
|
int circlesegcount;
|
|
|
|
|
|
|
|
// 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
|
|
|
|
circlesegcount = 1;
|
|
|
|
else
|
2020-04-09 08:37:17 +00:00
|
|
|
{
|
2020-12-16 22:10:42 +00:00
|
|
|
double cnt = arcsegcount * 3600/std::abs( arc_angle );
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2020-12-16 22:10:42 +00:00
|
|
|
#define SEG_CNT_MAX 128
|
|
|
|
if( cnt < SEG_CNT_MAX )
|
|
|
|
{
|
|
|
|
circlesegcount = (int)cnt;
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2020-12-16 22:10:42 +00:00
|
|
|
if( circlesegcount == 0 )
|
|
|
|
circlesegcount = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
circlesegcount = SEG_CNT_MAX;
|
2020-04-09 08:37:17 +00:00
|
|
|
}
|
2018-01-28 13:05:17 +00:00
|
|
|
}
|
2020-12-16 22:10:42 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
transformArcToSegments( wxPoint( center.x, center.y ), arc->GetStart(),
|
2020-12-16 22:10:42 +00:00
|
|
|
arc_angle, circlesegcount,
|
|
|
|
arc->GetWidth() + 2 * aClearanceValue, 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
|
|
|
{
|
|
|
|
SFVEC2F end3DU( aTrack->GetEnd().x * m_biuTo3Dunits, -aTrack->GetEnd().y * m_biuTo3Dunits );
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2020-12-16 22:10:42 +00:00
|
|
|
// Cannot add segments that have the same start and end point
|
|
|
|
if( Is_segment_a_circle( start3DU, end3DU ) )
|
|
|
|
{
|
|
|
|
const float radius = ((aTrack->GetWidth() / 2) + aClearanceValue) * m_biuTo3Dunits;
|
2020-04-09 08:37:17 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
aDstContainer->Add( new FILLED_CIRCLE_2D( start3DU, radius, *aTrack ) );
|
2020-12-16 22:10:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const float width = (aTrack->GetWidth() + 2 * aClearanceValue ) * m_biuTo3Dunits;
|
2020-04-09 08:37:17 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
aDstContainer->Add( new ROUND_SEGMENT_2D( start3DU, end3DU, width, *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
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
void BOARD_ADAPTER::createPadWithClearance( const PAD* aPad, CONTAINER_2D_BASE* aDstContainer,
|
2021-07-26 23:47:26 +00:00
|
|
|
PCB_LAYER_ID aLayer,
|
|
|
|
const wxSize& aClearanceValue ) const
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
2020-06-22 19:35:09 +00:00
|
|
|
SHAPE_POLY_SET poly;
|
2021-07-26 23:47:26 +00:00
|
|
|
wxSize clearance = aClearanceValue;
|
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
|
|
|
|
// is only the size of the anchor), so for those we punt and just use aClearanceValue.x.
|
|
|
|
|
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-11-11 17:35:01 +00:00
|
|
|
wxSize dummySize = aPad->GetSize() + clearance + clearance;
|
|
|
|
|
|
|
|
if( dummySize.x <= 0 || dummySize.y <= 0 )
|
|
|
|
return;
|
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
PAD dummy( *aPad );
|
2021-11-11 17:35:01 +00:00
|
|
|
dummy.SetSize( dummySize );
|
2020-10-13 10:55:24 +00:00
|
|
|
dummy.TransformShapeWithClearanceToPolygon( poly, aLayer, 0, ARC_HIGH_DEF, ERROR_INSIDE );
|
2021-07-26 23:47:26 +00:00
|
|
|
clearance = { 0, 0 };
|
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
|
|
|
{
|
2020-07-22 23:05:22 +00:00
|
|
|
const SHAPE_SEGMENT* seg = (SHAPE_SEGMENT*) shape;
|
2020-06-22 19:35:09 +00:00
|
|
|
const SFVEC2F start3DU( seg->GetSeg().A.x * m_biuTo3Dunits,
|
|
|
|
-seg->GetSeg().A.y * m_biuTo3Dunits );
|
|
|
|
const SFVEC2F end3DU ( seg->GetSeg().B.x * m_biuTo3Dunits,
|
|
|
|
-seg->GetSeg().B.y * m_biuTo3Dunits );
|
2022-01-11 21:49:57 +00:00
|
|
|
const double width = seg->GetWidth() + clearance.x * 2;
|
2020-06-22 19:35:09 +00:00
|
|
|
|
|
|
|
// Cannot add segments that have the same start and end point
|
|
|
|
if( Is_segment_a_circle( start3DU, end3DU ) )
|
2020-03-26 12:41:57 +00:00
|
|
|
{
|
2021-01-02 21:05:29 +00:00
|
|
|
aDstContainer->Add( new FILLED_CIRCLE_2D( start3DU,
|
2021-07-26 23:47:26 +00:00
|
|
|
( width / 2 ) * m_biuTo3Dunits,
|
|
|
|
*aPad ) );
|
2020-03-26 12:41:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-01-02 21:05:29 +00:00
|
|
|
aDstContainer->Add( new ROUND_SEGMENT_2D( start3DU, end3DU,
|
|
|
|
width * m_biuTo3Dunits,
|
|
|
|
*aPad ) );
|
2020-03-26 12:41:57 +00:00
|
|
|
}
|
2018-09-20 03:18:15 +00:00
|
|
|
}
|
2020-06-22 19:35:09 +00:00
|
|
|
break;
|
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
|
|
|
{
|
2020-07-22 23:05:22 +00:00
|
|
|
const SHAPE_CIRCLE* circle = (SHAPE_CIRCLE*) shape;
|
2022-01-11 21:49:57 +00:00
|
|
|
const double radius = circle->GetRadius() + clearance.x;
|
2020-06-22 19:35:09 +00:00
|
|
|
const SFVEC2F center( circle->GetCenter().x * m_biuTo3Dunits,
|
2020-12-16 22:10:42 +00:00
|
|
|
-circle->GetCenter().y * m_biuTo3Dunits );
|
2018-08-29 07:13:07 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
aDstContainer->Add( new FILLED_CIRCLE_2D( center, radius * m_biuTo3Dunits,
|
|
|
|
*aPad ) );
|
2020-06-22 19:35:09 +00:00
|
|
|
}
|
|
|
|
break;
|
2018-08-29 07:13:07 +00:00
|
|
|
|
2020-06-30 12:41:59 +00:00
|
|
|
case SH_RECT:
|
|
|
|
{
|
2020-07-22 23:05:22 +00:00
|
|
|
SHAPE_RECT* rect = (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;
|
|
|
|
|
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:
|
|
|
|
{
|
|
|
|
SHAPE_ARC* arc = (SHAPE_ARC*) shape;
|
|
|
|
SHAPE_LINE_CHAIN l = arc->ConvertToPolyline();
|
|
|
|
|
|
|
|
for( int i = 0; i < l.SegmentCount(); i++ )
|
|
|
|
{
|
|
|
|
SHAPE_SEGMENT seg( l.Segment( i ).A, l.Segment( i ).B, arc->GetWidth() );
|
|
|
|
const SFVEC2F start3DU( seg.GetSeg().A.x * m_biuTo3Dunits,
|
|
|
|
-seg.GetSeg().A.y * m_biuTo3Dunits );
|
|
|
|
const SFVEC2F end3DU( seg.GetSeg().B.x * m_biuTo3Dunits,
|
|
|
|
-seg.GetSeg().B.y * m_biuTo3Dunits );
|
2022-01-11 21:49:57 +00:00
|
|
|
const double width = arc->GetWidth() + clearance.x * 2;
|
2021-03-20 13:14:09 +00:00
|
|
|
|
|
|
|
// Cannot add segments that have the same start and end point
|
|
|
|
if( Is_segment_a_circle( start3DU, end3DU ) )
|
|
|
|
{
|
|
|
|
aDstContainer->Add( new FILLED_CIRCLE_2D( start3DU,
|
2021-07-26 23:47:26 +00:00
|
|
|
( width / 2 ) * m_biuTo3Dunits,
|
|
|
|
*aPad ) );
|
2021-03-20 13:14:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aDstContainer->Add( new ROUND_SEGMENT_2D( start3DU, end3DU,
|
|
|
|
width * m_biuTo3Dunits,
|
|
|
|
*aPad ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2020-06-22 19:35:09 +00:00
|
|
|
default:
|
2022-02-04 20:21:07 +00:00
|
|
|
wxFAIL_MSG( wxT( "BOARD_ADAPTER::createPadWithClearance no implementation for " )
|
2020-06-30 12:41:59 +00:00
|
|
|
+ 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 )
|
|
|
|
poly.Inflate( clearance.x, 32 );
|
2018-01-28 13:05:17 +00:00
|
|
|
|
|
|
|
// Add the PAD polygon
|
2021-01-05 22:19:00 +00:00
|
|
|
ConvertPolygonToTriangles( poly, *aDstContainer, 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
|
|
|
{
|
|
|
|
wxSize drillSize = aPad->GetDrillSize();
|
|
|
|
|
|
|
|
if( !drillSize.x || !drillSize.y )
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
if( drillSize.x == drillSize.y ) // usual round hole
|
|
|
|
{
|
2022-01-11 21:49:57 +00:00
|
|
|
const double radius = ( drillSize.x / 2.0 ) + aInflateValue;
|
2018-01-28 13:05:17 +00:00
|
|
|
|
|
|
|
const SFVEC2F center( aPad->GetPosition().x * m_biuTo3Dunits,
|
|
|
|
-aPad->GetPosition().y * m_biuTo3Dunits );
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
return new FILLED_CIRCLE_2D( center, radius * m_biuTo3Dunits, *aPad );
|
2018-01-28 13:05:17 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
else // Oblong hole
|
|
|
|
{
|
2020-07-04 18:48:22 +00:00
|
|
|
const SHAPE_SEGMENT* seg = aPad->GetEffectiveHoleShape();
|
2022-01-11 21:49:57 +00:00
|
|
|
double width = seg->GetWidth() + aInflateValue * 2;
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2020-06-22 19:35:09 +00:00
|
|
|
SFVEC2F start3DU( seg->GetSeg().A.x * m_biuTo3Dunits,
|
|
|
|
-seg->GetSeg().A.y * m_biuTo3Dunits );
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2020-06-22 19:35:09 +00:00
|
|
|
SFVEC2F end3DU ( seg->GetSeg().B.x * m_biuTo3Dunits,
|
|
|
|
-seg->GetSeg().B.y * m_biuTo3Dunits );
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
return new ROUND_SEGMENT_2D( start3DU, end3DU, width * m_biuTo3Dunits, *aPad );
|
2018-01-28 13:05:17 +00:00
|
|
|
}
|
|
|
|
|
2020-12-16 22:10:42 +00:00
|
|
|
return nullptr;
|
2018-01-28 13:05:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
void BOARD_ADAPTER::addPadsWithClearance( const FOOTPRINT* aFootprint,
|
|
|
|
CONTAINER_2D_BASE* aDstContainer,
|
|
|
|
PCB_LAYER_ID aLayerId, int aInflateValue,
|
|
|
|
bool aSkipNPTHPadsWihNoCopper, 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
|
|
|
{
|
|
|
|
if( !pad->IsOnLayer( aLayerId ) )
|
|
|
|
continue;
|
|
|
|
|
2020-08-11 09:26:00 +00:00
|
|
|
// Skip pad annulus when not connected on this layer (if removing is enabled)
|
2020-09-29 20:40:17 +00:00
|
|
|
if( !pad->FlashLayer( aLayerId ) && IsCopperLayer( aLayerId ) )
|
2020-08-11 09:26:00 +00:00
|
|
|
continue;
|
|
|
|
|
2018-01-28 13:05:17 +00:00
|
|
|
// NPTH pads are not drawn on layers if the
|
|
|
|
// shape size and pos is the same as their hole:
|
2021-05-01 14:46:50 +00:00
|
|
|
if( aSkipNPTHPadsWihNoCopper && ( pad->GetAttribute() == PAD_ATTRIB::NPTH ) )
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
2020-11-24 22:16:41 +00:00
|
|
|
if( pad->GetDrillSize() == pad->GetSize() && pad->GetOffset() == wxPoint( 0, 0 ) )
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
|
|
|
switch( pad->GetShape() )
|
|
|
|
{
|
2021-05-01 12:22:35 +00:00
|
|
|
case PAD_SHAPE::CIRCLE:
|
2018-01-28 13:05:17 +00:00
|
|
|
if( pad->GetDrillShape() == PAD_DRILL_SHAPE_CIRCLE )
|
|
|
|
continue;
|
2021-07-26 23:47:26 +00:00
|
|
|
|
2018-01-28 13:05:17 +00:00
|
|
|
break;
|
|
|
|
|
2021-05-01 12:22:35 +00:00
|
|
|
case PAD_SHAPE::OVAL:
|
2018-01-28 13:05:17 +00:00
|
|
|
if( pad->GetDrillShape() != PAD_DRILL_SHAPE_CIRCLE )
|
|
|
|
continue;
|
2021-07-26 23:47:26 +00:00
|
|
|
|
2018-01-28 13:05:17 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-29 20:40:17 +00:00
|
|
|
const bool isPlated = ( ( aLayerId == F_Cu ) && pad->FlashLayer( F_Mask ) ) ||
|
|
|
|
( ( aLayerId == B_Cu ) && pad->FlashLayer( B_Mask ) );
|
2020-09-06 19:09:43 +00:00
|
|
|
|
|
|
|
if( aSkipPlatedPads && isPlated )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( aSkipNonPlatedPads && !isPlated )
|
|
|
|
continue;
|
|
|
|
|
2020-08-28 19:27:44 +00:00
|
|
|
wxSize margin( aInflateValue, aInflateValue );
|
|
|
|
|
2018-01-28 13:05:17 +00:00
|
|
|
switch( aLayerId )
|
|
|
|
{
|
|
|
|
case F_Mask:
|
|
|
|
case B_Mask:
|
2020-08-28 19:27:44 +00:00
|
|
|
margin.x += pad->GetSolderMaskMargin();
|
|
|
|
margin.y += pad->GetSolderMaskMargin();
|
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;
|
|
|
|
}
|
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
createPadWithClearance( pad, aDstContainer, 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-01-05 22:19:00 +00:00
|
|
|
void BOARD_ADAPTER::transformArcToSegments( const wxPoint& aCentre, const wxPoint& aStart,
|
2020-12-16 22:10:42 +00:00
|
|
|
double aArcAngle, int aCircleToSegmentsCount,
|
2021-01-02 21:05:29 +00:00
|
|
|
int aWidth, CONTAINER_2D_BASE* aDstContainer,
|
2020-12-16 22:10:42 +00:00
|
|
|
const BOARD_ITEM& aBoardItem )
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
|
|
|
wxPoint arc_start, arc_end;
|
2022-01-11 21:49:57 +00:00
|
|
|
double delta = 3600 / aCircleToSegmentsCount; // rotate angle in 0.1 degree
|
2018-01-28 13:05:17 +00:00
|
|
|
|
|
|
|
arc_end = arc_start = aStart;
|
|
|
|
|
|
|
|
if( aArcAngle != 3600 )
|
|
|
|
{
|
|
|
|
RotatePoint( &arc_end, aCentre, -aArcAngle );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aArcAngle < 0 )
|
|
|
|
{
|
|
|
|
std::swap( arc_start, arc_end );
|
|
|
|
aArcAngle = -aArcAngle;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compute the ends of segments and creates poly
|
|
|
|
wxPoint curr_end = arc_start;
|
|
|
|
wxPoint curr_start = arc_start;
|
|
|
|
|
2022-01-11 21:49:57 +00:00
|
|
|
for( double ii = delta; ii < aArcAngle; ii += delta )
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
|
|
|
curr_end = arc_start;
|
|
|
|
RotatePoint( &curr_end, aCentre, -ii );
|
|
|
|
|
|
|
|
const SFVEC2F start3DU( curr_start.x * m_biuTo3Dunits, -curr_start.y * m_biuTo3Dunits );
|
|
|
|
const SFVEC2F end3DU ( curr_end.x * m_biuTo3Dunits, -curr_end.y * m_biuTo3Dunits );
|
|
|
|
|
|
|
|
if( Is_segment_a_circle( start3DU, end3DU ) )
|
|
|
|
{
|
2021-01-02 21:05:29 +00:00
|
|
|
aDstContainer->Add( new FILLED_CIRCLE_2D( start3DU, ( aWidth / 2 ) * m_biuTo3Dunits,
|
|
|
|
aBoardItem ) );
|
2018-01-28 13:05:17 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-01-02 21:05:29 +00:00
|
|
|
aDstContainer->Add( new ROUND_SEGMENT_2D( start3DU, end3DU, aWidth * m_biuTo3Dunits,
|
|
|
|
aBoardItem ) );
|
2018-01-28 13:05:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
curr_start = curr_end;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( curr_end != arc_end )
|
|
|
|
{
|
|
|
|
const SFVEC2F start3DU( curr_end.x * m_biuTo3Dunits, -curr_end.y * m_biuTo3Dunits );
|
|
|
|
const SFVEC2F end3DU ( arc_end.x * m_biuTo3Dunits, -arc_end.y * m_biuTo3Dunits );
|
|
|
|
|
|
|
|
if( Is_segment_a_circle( start3DU, end3DU ) )
|
|
|
|
{
|
2021-01-02 21:05:29 +00:00
|
|
|
aDstContainer->Add( new FILLED_CIRCLE_2D( start3DU, ( aWidth / 2 ) * m_biuTo3Dunits,
|
|
|
|
aBoardItem ) );
|
2018-01-28 13:05:17 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-01-02 21:05:29 +00:00
|
|
|
aDstContainer->Add( new ROUND_SEGMENT_2D( start3DU, end3DU, aWidth * m_biuTo3Dunits,
|
|
|
|
aBoardItem ) );
|
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
|
|
|
|
// TransformShapeWithClearanceToPolygon
|
|
|
|
// board_items_to_polygon_shape_transform.cpp#L431
|
2021-01-05 22:19:00 +00:00
|
|
|
void BOARD_ADAPTER::addShapeWithClearance( const PCB_SHAPE* aShape,
|
|
|
|
CONTAINER_2D_BASE* aDstContainer, PCB_LAYER_ID aLayerId,
|
|
|
|
int aClearanceValue )
|
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-01-11 21:49:57 +00:00
|
|
|
const double linewidth = aShape->GetWidth() + ( 2 * aClearanceValue ) + 1;
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2020-11-14 01:16:02 +00:00
|
|
|
switch( aShape->GetShape() )
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::CIRCLE:
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
2020-11-14 01:16:02 +00:00
|
|
|
const SFVEC2F center3DU( aShape->GetCenter().x * m_biuTo3Dunits,
|
|
|
|
-aShape->GetCenter().y * m_biuTo3Dunits );
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2020-11-14 01:16:02 +00:00
|
|
|
float inner_radius = ( aShape->GetRadius() - linewidth / 2 ) * m_biuTo3Dunits;
|
|
|
|
float outer_radius = ( aShape->GetRadius() + linewidth / 2 ) * m_biuTo3Dunits;
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2019-08-20 17:02:28 +00:00
|
|
|
if( inner_radius < 0 )
|
|
|
|
inner_radius = 0;
|
|
|
|
|
2020-11-14 01:16:02 +00:00
|
|
|
if( aShape->IsFilled() )
|
2021-01-02 21:05:29 +00:00
|
|
|
aDstContainer->Add( new FILLED_CIRCLE_2D( center3DU, outer_radius, *aShape ) );
|
2020-06-19 20:46:43 +00:00
|
|
|
else
|
2021-01-02 21:05:29 +00:00
|
|
|
aDstContainer->Add( new RING_2D( center3DU, inner_radius, outer_radius, *aShape ) );
|
2018-01-28 13:05:17 +00:00
|
|
|
}
|
2020-11-14 01:16:02 +00:00
|
|
|
break;
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::RECT:
|
2020-11-14 01:16:02 +00:00
|
|
|
if( aShape->IsFilled() )
|
|
|
|
{
|
|
|
|
SHAPE_POLY_SET polyList;
|
|
|
|
|
2021-01-14 16:53:57 +00:00
|
|
|
aShape->TransformShapeWithClearanceToPolygon( polyList, aLayerId, 0,
|
2020-11-14 01:16:02 +00:00
|
|
|
ARC_HIGH_DEF, ERROR_INSIDE );
|
|
|
|
|
|
|
|
polyList.Simplify( SHAPE_POLY_SET::PM_FAST );
|
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
ConvertPolygonToTriangles( polyList, *aDstContainer, m_biuTo3Dunits, *aShape );
|
2020-11-14 01:16:02 +00:00
|
|
|
}
|
|
|
|
else
|
2020-06-19 20:46:43 +00:00
|
|
|
{
|
2020-11-14 01:16:02 +00:00
|
|
|
std::vector<wxPoint> pts = aShape->GetRectCorners();
|
2020-06-19 20:46:43 +00:00
|
|
|
|
|
|
|
const SFVEC2F topLeft3DU( pts[0].x * m_biuTo3Dunits, -pts[0].y * m_biuTo3Dunits );
|
|
|
|
const SFVEC2F topRight3DU( pts[1].x * m_biuTo3Dunits, -pts[1].y * m_biuTo3Dunits );
|
|
|
|
const SFVEC2F botRight3DU( pts[2].x * m_biuTo3Dunits, -pts[2].y * m_biuTo3Dunits );
|
|
|
|
const SFVEC2F botLeft3DU( pts[3].x * m_biuTo3Dunits, -pts[3].y * m_biuTo3Dunits );
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
aDstContainer->Add( new ROUND_SEGMENT_2D( topLeft3DU, topRight3DU,
|
|
|
|
linewidth * m_biuTo3Dunits, *aShape ) );
|
|
|
|
aDstContainer->Add( new ROUND_SEGMENT_2D( topRight3DU, botRight3DU,
|
|
|
|
linewidth * m_biuTo3Dunits, *aShape ) );
|
|
|
|
aDstContainer->Add( new ROUND_SEGMENT_2D( botRight3DU, botLeft3DU,
|
|
|
|
linewidth * m_biuTo3Dunits, *aShape ) );
|
|
|
|
aDstContainer->Add( new ROUND_SEGMENT_2D( botLeft3DU, topLeft3DU,
|
|
|
|
linewidth * m_biuTo3Dunits, *aShape ) );
|
2020-06-19 20:46:43 +00:00
|
|
|
}
|
2020-06-15 19:50:20 +00:00
|
|
|
break;
|
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::ARC:
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
2021-01-05 22:19:00 +00:00
|
|
|
unsigned int segCount = GetCircleSegmentCount( aShape->GetBoundingBox().GetSizeMax() );
|
2020-11-14 01:16:02 +00:00
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
transformArcToSegments( aShape->GetCenter(), aShape->GetStart(), aShape->GetArcAngle(),
|
2020-11-14 01:16:02 +00:00
|
|
|
segCount, linewidth, aDstContainer, *aShape );
|
2018-01-28 13:05:17 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::SEGMENT:
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
2020-11-14 01:16:02 +00:00
|
|
|
const SFVEC2F start3DU( aShape->GetStart().x * m_biuTo3Dunits,
|
|
|
|
-aShape->GetStart().y * m_biuTo3Dunits );
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2020-11-14 01:16:02 +00:00
|
|
|
const SFVEC2F end3DU ( aShape->GetEnd().x * m_biuTo3Dunits,
|
|
|
|
-aShape->GetEnd().y * m_biuTo3Dunits );
|
2018-01-28 13:05:17 +00:00
|
|
|
|
|
|
|
if( Is_segment_a_circle( start3DU, end3DU ) )
|
|
|
|
{
|
2021-01-02 21:05:29 +00:00
|
|
|
aDstContainer->Add( new FILLED_CIRCLE_2D( start3DU, ( linewidth / 2 ) * m_biuTo3Dunits,
|
2020-11-14 01:16:02 +00:00
|
|
|
*aShape ) );
|
2018-01-28 13:05:17 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-01-02 21:05:29 +00:00
|
|
|
aDstContainer->Add( new ROUND_SEGMENT_2D( start3DU, end3DU, linewidth * m_biuTo3Dunits,
|
|
|
|
*aShape ) );
|
2018-01-28 13:05:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::BEZIER:
|
|
|
|
case SHAPE_T::POLY:
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
|
|
|
SHAPE_POLY_SET polyList;
|
|
|
|
|
2021-01-15 17:47:17 +00:00
|
|
|
aShape->TransformShapeWithClearanceToPolygon( polyList, aLayerId, 0,
|
2020-11-14 01:16:02 +00:00
|
|
|
ARC_HIGH_DEF, ERROR_INSIDE );
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2018-09-18 11:12:55 +00:00
|
|
|
polyList.Simplify( SHAPE_POLY_SET::PM_FAST );
|
|
|
|
|
2018-01-28 13:05:17 +00:00
|
|
|
if( polyList.IsEmpty() ) // Just for caution
|
|
|
|
break;
|
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
ConvertPolygonToTriangles( polyList, *aDstContainer, m_biuTo3Dunits, *aShape );
|
2018-01-28 13:05:17 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2022-02-04 20:21:07 +00:00
|
|
|
wxFAIL_MSG( wxT( "BOARD_ADAPTER::addShapeWithClearance no implementation for " )
|
2021-07-14 20:03:32 +00:00
|
|
|
+ aShape->SHAPE_T_asString() );
|
2018-01-28 13:05:17 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Based on
|
|
|
|
// TransformSolidAreasShapesToPolygonSet
|
|
|
|
// board_items_to_polygon_shape_transform.cpp
|
2021-01-05 22:19:00 +00:00
|
|
|
void BOARD_ADAPTER::addSolidAreasShapes( const ZONE* aZoneContainer,
|
|
|
|
CONTAINER_2D_BASE* aDstContainer, PCB_LAYER_ID aLayerId )
|
2018-01-28 13:05:17 +00:00
|
|
|
{
|
|
|
|
// Copy the polys list because we have to simplify it
|
2020-06-24 02:19:08 +00:00
|
|
|
SHAPE_POLY_SET polyList = SHAPE_POLY_SET( aZoneContainer->GetFilledPolysList( aLayerId ) );
|
2018-01-28 13:05:17 +00:00
|
|
|
|
|
|
|
// This convert the poly in outline and holes
|
2021-01-05 22:19:00 +00:00
|
|
|
ConvertPolygonToTriangles( polyList, *aDstContainer, m_biuTo3Dunits, *aZoneContainer );
|
2018-01-28 13:05:17 +00:00
|
|
|
|
|
|
|
// add filled areas outlines, which are drawn with thick lines segments
|
2019-06-04 07:23:12 +00:00
|
|
|
// but only if filled polygons outlines have thickness
|
|
|
|
if( !aZoneContainer->GetFilledPolysUseThickness() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
float line_thickness = aZoneContainer->GetMinThickness() * m_biuTo3Dunits;
|
|
|
|
|
2018-01-28 13:05:17 +00:00
|
|
|
for( int i = 0; i < polyList.OutlineCount(); ++i )
|
|
|
|
{
|
|
|
|
// Add outline
|
|
|
|
const SHAPE_LINE_CHAIN& pathOutline = polyList.COutline( i );
|
|
|
|
|
|
|
|
for( int j = 0; j < pathOutline.PointCount(); ++j )
|
|
|
|
{
|
|
|
|
const VECTOR2I& a = pathOutline.CPoint( j );
|
|
|
|
const VECTOR2I& b = pathOutline.CPoint( j + 1 );
|
|
|
|
|
|
|
|
SFVEC2F start3DU( a.x * m_biuTo3Dunits, -a.y * m_biuTo3Dunits );
|
|
|
|
SFVEC2F end3DU ( b.x * m_biuTo3Dunits, -b.y * m_biuTo3Dunits );
|
|
|
|
|
|
|
|
if( Is_segment_a_circle( start3DU, end3DU ) )
|
|
|
|
{
|
2019-06-04 07:23:12 +00:00
|
|
|
float radius = line_thickness/2;
|
2018-11-05 07:30:54 +00:00
|
|
|
|
|
|
|
if( radius > 0.0 ) // degenerated circles crash 3D viewer
|
2021-01-02 21:05:29 +00:00
|
|
|
aDstContainer->Add( new FILLED_CIRCLE_2D( start3DU, radius, *aZoneContainer ) );
|
2018-01-28 13:05:17 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-01-02 21:05:29 +00:00
|
|
|
aDstContainer->Add( new ROUND_SEGMENT_2D( start3DU, end3DU, line_thickness,
|
|
|
|
*aZoneContainer ) );
|
2018-01-28 13:05:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add holes (of the poly, ie: the open parts) for this outline
|
|
|
|
for( int h = 0; h < polyList.HoleCount( i ); ++h )
|
|
|
|
{
|
|
|
|
const SHAPE_LINE_CHAIN& pathHole = polyList.CHole( i, h );
|
|
|
|
|
|
|
|
for( int j = 0; j < pathHole.PointCount(); j++ )
|
|
|
|
{
|
|
|
|
const VECTOR2I& a = pathHole.CPoint( j );
|
|
|
|
const VECTOR2I& b = pathHole.CPoint( j + 1 );
|
|
|
|
|
|
|
|
SFVEC2F start3DU( a.x * m_biuTo3Dunits, -a.y * m_biuTo3Dunits );
|
|
|
|
SFVEC2F end3DU ( b.x * m_biuTo3Dunits, -b.y * m_biuTo3Dunits );
|
|
|
|
|
|
|
|
if( Is_segment_a_circle( start3DU, end3DU ) )
|
|
|
|
{
|
2019-06-04 07:23:12 +00:00
|
|
|
float radius = line_thickness/2;
|
2018-11-05 07:30:54 +00:00
|
|
|
|
|
|
|
if( radius > 0.0 ) // degenerated circles crash 3D viewer
|
2021-01-02 21:05:29 +00:00
|
|
|
aDstContainer->Add( new FILLED_CIRCLE_2D( start3DU, radius,
|
|
|
|
*aZoneContainer ) );
|
2018-01-28 13:05:17 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-01-02 21:05:29 +00:00
|
|
|
aDstContainer->Add( new ROUND_SEGMENT_2D( start3DU, end3DU, line_thickness,
|
|
|
|
*aZoneContainer ) );
|
2018-01-28 13:05:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
void BOARD_ADAPTER::buildPadOutlineAsSegments( const PAD* aPad, CONTAINER_2D_BASE* aDstContainer,
|
|
|
|
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
|
|
|
{
|
2020-12-16 22:10:42 +00:00
|
|
|
const SFVEC2F center3DU( aPad->ShapePos().x * m_biuTo3Dunits,
|
2018-01-28 13:05:17 +00:00
|
|
|
-aPad->ShapePos().y * m_biuTo3Dunits );
|
|
|
|
|
2022-01-11 21:49:57 +00:00
|
|
|
const double radius = aPad->GetSize().x / 2.0;
|
|
|
|
const float inner_radius = ( radius - aWidth / 2.0 ) * m_biuTo3Dunits;
|
|
|
|
const float outer_radius = ( radius + aWidth / 2.0 ) * m_biuTo3Dunits;
|
2018-01-28 13:05:17 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
aDstContainer->Add( new RING_2D( center3DU, inner_radius, outer_radius, *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++ )
|
|
|
|
{
|
|
|
|
const VECTOR2I& a = path.CPoint( j );
|
|
|
|
const VECTOR2I& b = path.CPoint( j + 1 );
|
|
|
|
|
|
|
|
SFVEC2F start3DU( a.x * m_biuTo3Dunits, -a.y * m_biuTo3Dunits );
|
|
|
|
SFVEC2F end3DU ( b.x * m_biuTo3Dunits, -b.y * m_biuTo3Dunits );
|
|
|
|
|
|
|
|
if( Is_segment_a_circle( start3DU, end3DU ) )
|
|
|
|
{
|
2021-01-02 21:05:29 +00:00
|
|
|
aDstContainer->Add( new FILLED_CIRCLE_2D( start3DU, ( aWidth / 2 ) * m_biuTo3Dunits,
|
|
|
|
*aPad ) );
|
2018-01-28 13:05:17 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-01-02 21:05:29 +00:00
|
|
|
aDstContainer->Add( new ROUND_SEGMENT_2D( start3DU, end3DU, aWidth * m_biuTo3Dunits,
|
|
|
|
*aPad ) );
|
2018-01-28 13:05:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|