2014-10-23 17:53:38 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2018-04-06 13:30:52 +00:00
|
|
|
* Copyright (C) 2009-2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2019-05-22 13:33:48 +00:00
|
|
|
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
|
2014-10-23 17:53:38 +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
|
|
|
|
*/
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
2019-09-09 12:44:41 +00:00
|
|
|
#include <vector>
|
2018-07-07 11:04:01 +00:00
|
|
|
#include <bezier_curves.h>
|
2018-02-16 14:25:38 +00:00
|
|
|
#include <base_units.h> // for IU_PER_MM
|
2019-05-31 12:15:25 +00:00
|
|
|
#include <gr_text.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <pcbnew.h>
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <trigo.h>
|
2014-05-17 19:29:15 +00:00
|
|
|
#include <class_board.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_pad.h>
|
|
|
|
#include <class_track.h>
|
|
|
|
#include <class_drawsegment.h>
|
|
|
|
#include <class_pcb_text.h>
|
2012-01-29 19:29:19 +00:00
|
|
|
#include <class_zone.h>
|
2013-05-01 19:01:14 +00:00
|
|
|
#include <class_module.h>
|
|
|
|
#include <class_edge_mod.h>
|
2012-08-23 19:15:58 +00:00
|
|
|
#include <convert_basic_shapes_to_polygon.h>
|
2018-03-08 12:48:29 +00:00
|
|
|
#include <geometry/geometry_utils.h>
|
2009-11-16 08:13:40 +00:00
|
|
|
|
2018-04-06 13:30:52 +00:00
|
|
|
// A helper struct for the callback function
|
2014-02-28 10:51:47 +00:00
|
|
|
// These variables are parameters used in addTextSegmToPoly.
|
|
|
|
// But addTextSegmToPoly is a call-back function,
|
|
|
|
// so we cannot send them as arguments.
|
2018-04-06 13:30:52 +00:00
|
|
|
struct TSEGM_2_POLY_PRMS {
|
|
|
|
int m_textWidth;
|
2019-05-22 13:33:48 +00:00
|
|
|
int m_error;
|
2018-04-06 13:30:52 +00:00
|
|
|
SHAPE_POLY_SET* m_cornerBuffer;
|
|
|
|
};
|
|
|
|
TSEGM_2_POLY_PRMS prms;
|
2014-02-28 10:51:47 +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
|
|
|
static void addTextSegmToPoly( int x0, int y0, int xf, int yf, void* aData )
|
2014-02-28 10:51:47 +00:00
|
|
|
{
|
2018-04-06 13:30:52 +00:00
|
|
|
TSEGM_2_POLY_PRMS* prm = static_cast<TSEGM_2_POLY_PRMS*>( aData );
|
2019-09-09 12:44:41 +00:00
|
|
|
TransformSegmentToPolygon( *prm->m_cornerBuffer,
|
|
|
|
wxPoint( x0, y0 ), wxPoint( xf, yf ),
|
|
|
|
prm->m_error, prm->m_textWidth );
|
2014-02-28 10:51:47 +00:00
|
|
|
}
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2017-03-13 03:19:33 +00:00
|
|
|
void BOARD::ConvertBrdLayerToPolygonalContours( PCB_LAYER_ID aLayer, SHAPE_POLY_SET& aOutlines )
|
2014-05-17 19:29:15 +00:00
|
|
|
{
|
|
|
|
// convert tracks and vias:
|
2019-05-31 02:30:28 +00:00
|
|
|
for( auto track : m_tracks )
|
2014-05-17 19:29:15 +00:00
|
|
|
{
|
|
|
|
if( !track->IsOnLayer( aLayer ) )
|
|
|
|
continue;
|
|
|
|
|
2019-05-14 12:39:34 +00:00
|
|
|
track->TransformShapeWithClearanceToPolygon( aOutlines, 0 );
|
2014-05-17 19:29:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// convert pads
|
2019-05-31 00:15:57 +00:00
|
|
|
for( auto module : m_modules )
|
2014-05-17 19:29:15 +00:00
|
|
|
{
|
2019-05-14 12:39:34 +00:00
|
|
|
module->TransformPadsShapesWithClearanceToPolygon( aLayer, aOutlines, 0 );
|
2014-05-17 19:29:15 +00:00
|
|
|
|
|
|
|
// Micro-wave modules may have items on copper layers
|
2019-05-14 12:39:34 +00:00
|
|
|
module->TransformGraphicShapesWithClearanceToPolygonSet( aLayer, aOutlines, 0 );
|
2014-05-17 19:29:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// convert copper zones
|
|
|
|
for( int ii = 0; ii < GetAreaCount(); ii++ )
|
|
|
|
{
|
|
|
|
ZONE_CONTAINER* zone = GetArea( ii );
|
2019-09-09 12:44:41 +00:00
|
|
|
PCB_LAYER_ID zonelayer = zone->GetLayer();
|
2014-05-17 19:29:15 +00:00
|
|
|
|
|
|
|
if( zonelayer == aLayer )
|
2019-05-14 12:39:34 +00:00
|
|
|
zone->TransformSolidAreasShapesToPolygonSet( aOutlines );
|
2014-05-17 19:29:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// convert graphic items on copper layers (texts)
|
2019-05-30 13:33:59 +00:00
|
|
|
for( auto item : m_drawings )
|
2014-05-17 19:29:15 +00:00
|
|
|
{
|
|
|
|
if( !item->IsOnLayer( aLayer ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
2019-04-05 16:10:59 +00:00
|
|
|
case PCB_LINE_T:
|
2019-05-14 12:39:34 +00:00
|
|
|
( (DRAWSEGMENT*) item )->TransformShapeWithClearanceToPolygon( aOutlines, 0 );
|
2014-05-17 19:29:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PCB_TEXT_T:
|
2019-05-14 12:39:34 +00:00
|
|
|
( (TEXTE_PCB*) item )->TransformShapeWithClearanceToPolygonSet( aOutlines, 0 );
|
2014-05-17 19:29:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2017-03-13 03:19:33 +00:00
|
|
|
void MODULE::TransformPadsShapesWithClearanceToPolygon( PCB_LAYER_ID aLayer,
|
2019-05-14 12:39:34 +00:00
|
|
|
SHAPE_POLY_SET& aCornerBuffer, int aInflateValue, int aMaxError,
|
|
|
|
bool aSkipNPTHPadsWihNoCopper ) const
|
2013-05-01 19:01:14 +00:00
|
|
|
{
|
2019-06-01 23:23:36 +00:00
|
|
|
for( auto pad : m_pads )
|
2013-05-01 19:01:14 +00:00
|
|
|
{
|
2018-02-19 00:00:29 +00:00
|
|
|
if( aLayer != UNDEFINED_LAYER && !pad->IsOnLayer(aLayer) )
|
2013-05-01 19:01:14 +00:00
|
|
|
continue;
|
|
|
|
|
2015-03-23 08:28:12 +00:00
|
|
|
// NPTH pads are not drawn on layers if the shape size and pos is the same
|
|
|
|
// as their hole:
|
2015-08-23 19:40:33 +00:00
|
|
|
if( aSkipNPTHPadsWihNoCopper && pad->GetAttribute() == PAD_ATTRIB_HOLE_NOT_PLATED )
|
2015-03-23 08:28:12 +00:00
|
|
|
{
|
|
|
|
if( pad->GetDrillSize() == pad->GetSize() && pad->GetOffset() == wxPoint( 0, 0 ) )
|
|
|
|
{
|
|
|
|
switch( pad->GetShape() )
|
|
|
|
{
|
2015-08-23 19:40:33 +00:00
|
|
|
case PAD_SHAPE_CIRCLE:
|
|
|
|
if( pad->GetDrillShape() == PAD_DRILL_SHAPE_CIRCLE )
|
2015-03-23 08:28:12 +00:00
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
|
2015-08-23 19:40:33 +00:00
|
|
|
case PAD_SHAPE_OVAL:
|
|
|
|
if( pad->GetDrillShape() != PAD_DRILL_SHAPE_CIRCLE )
|
2015-03-23 08:28:12 +00:00
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-05-01 19:01:14 +00:00
|
|
|
|
2019-06-20 22:37:41 +00:00
|
|
|
wxSize margin;
|
|
|
|
int clearance = aInflateValue;
|
|
|
|
|
2013-05-01 19:01:14 +00:00
|
|
|
switch( aLayer )
|
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
case F_Mask:
|
|
|
|
case B_Mask:
|
2019-06-20 22:37:41 +00:00
|
|
|
clearance += pad->GetSolderMaskMargin();
|
2013-05-01 19:01:14 +00:00
|
|
|
break;
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
case F_Paste:
|
|
|
|
case B_Paste:
|
2013-05-01 19:01:14 +00:00
|
|
|
margin = pad->GetSolderPasteMargin();
|
2019-06-20 22:37:41 +00:00
|
|
|
clearance += ( margin.x + margin.y ) / 2;
|
2013-05-01 19:01:14 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-06-20 22:37:41 +00:00
|
|
|
pad->TransformShapeWithClearanceToPolygon( aCornerBuffer, clearance );
|
2013-05-01 19:01:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-09 12:44:41 +00:00
|
|
|
/**
|
|
|
|
* Generate shapes of graphic items (outlines) as polygons added to a buffer.
|
|
|
|
* @aCornerBuffer = the buffer to store polygons
|
|
|
|
* @aInflateValue = a value to inflate shapes
|
|
|
|
* @aError = the maximum error to allow when approximating curves with segments
|
|
|
|
* @aIncludeText = indicates footprint text items (reference, value, etc.) should be included
|
|
|
|
* in the outline
|
2013-05-01 19:01:14 +00:00
|
|
|
*/
|
2019-05-14 12:39:34 +00:00
|
|
|
void MODULE::TransformGraphicShapesWithClearanceToPolygonSet( PCB_LAYER_ID aLayer,
|
2019-09-09 12:44:41 +00:00
|
|
|
SHAPE_POLY_SET& aCornerBuffer,
|
|
|
|
int aInflateValue,
|
|
|
|
int aError, bool aIncludeText ) const
|
2013-05-01 19:01:14 +00:00
|
|
|
{
|
2014-02-28 10:51:47 +00:00
|
|
|
std::vector<TEXTE_MODULE *> texts; // List of TEXTE_MODULE to convert
|
|
|
|
|
2019-06-02 03:55:32 +00:00
|
|
|
for( auto item : GraphicalItems() )
|
2013-05-01 19:01:14 +00:00
|
|
|
{
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case PCB_MODULE_TEXT_T:
|
2019-05-14 12:39:34 +00:00
|
|
|
{
|
|
|
|
TEXTE_MODULE* text = static_cast<TEXTE_MODULE*>( item );
|
2015-03-11 13:59:43 +00:00
|
|
|
|
2019-05-14 12:39:34 +00:00
|
|
|
if( ( aLayer != UNDEFINED_LAYER && text->GetLayer() == aLayer ) && text->IsVisible() )
|
|
|
|
texts.push_back( text );
|
|
|
|
}
|
2019-09-09 12:44:41 +00:00
|
|
|
break;
|
2013-05-01 19:01:14 +00:00
|
|
|
|
|
|
|
case PCB_MODULE_EDGE_T:
|
2019-09-09 12:44:41 +00:00
|
|
|
{
|
|
|
|
EDGE_MODULE* outline = (EDGE_MODULE*) item;
|
2013-05-01 19:01:14 +00:00
|
|
|
|
2018-02-19 00:00:29 +00:00
|
|
|
if( aLayer != UNDEFINED_LAYER && outline->GetLayer() != aLayer )
|
2013-05-01 19:01:14 +00:00
|
|
|
break;
|
2016-06-07 12:42:42 +00:00
|
|
|
|
2019-05-14 12:39:34 +00:00
|
|
|
outline->TransformShapeWithClearanceToPolygon( aCornerBuffer, 0, aError );
|
2019-09-09 12:44:41 +00:00
|
|
|
}
|
2016-06-07 12:42:42 +00:00
|
|
|
break;
|
2013-05-01 19:01:14 +00:00
|
|
|
|
2019-05-14 12:39:34 +00:00
|
|
|
default:
|
|
|
|
break;
|
2013-05-01 19:01:14 +00:00
|
|
|
}
|
|
|
|
}
|
2014-02-28 10:51:47 +00:00
|
|
|
|
2018-02-19 00:00:29 +00:00
|
|
|
if( !aIncludeText )
|
|
|
|
return;
|
|
|
|
|
2014-02-28 10:51:47 +00:00
|
|
|
// Convert texts sur modules
|
|
|
|
if( Reference().GetLayer() == aLayer && Reference().IsVisible() )
|
|
|
|
texts.push_back( &Reference() );
|
|
|
|
|
|
|
|
if( Value().GetLayer() == aLayer && Value().IsVisible() )
|
|
|
|
texts.push_back( &Value() );
|
|
|
|
|
2018-04-06 13:30:52 +00:00
|
|
|
prms.m_cornerBuffer = &aCornerBuffer;
|
2015-08-11 11:56:02 +00:00
|
|
|
|
2019-09-09 12:44:41 +00:00
|
|
|
for( TEXTE_MODULE* textmod : texts )
|
2014-02-28 10:51:47 +00:00
|
|
|
{
|
2018-04-06 13:30:52 +00:00
|
|
|
prms.m_textWidth = textmod->GetThickness() + ( 2 * aInflateValue );
|
2019-05-22 13:33:48 +00:00
|
|
|
prms.m_error = aError;
|
2017-01-23 20:30:11 +00:00
|
|
|
wxSize size = textmod->GetTextSize();
|
2014-02-28 17:46:18 +00:00
|
|
|
|
|
|
|
if( textmod->IsMirrored() )
|
2015-06-26 13:41:56 +00:00
|
|
|
size.x = -size.x;
|
2014-02-28 17:46:18 +00:00
|
|
|
|
2019-05-31 12:15:25 +00:00
|
|
|
GRText( NULL, textmod->GetTextPos(), BLACK, textmod->GetShownText(),
|
|
|
|
textmod->GetDrawRotation(), size, textmod->GetHorizJustify(),
|
|
|
|
textmod->GetVertJustify(), textmod->GetThickness(), textmod->IsItalic(),
|
|
|
|
true, addTextSegmToPoly, &prms );
|
2014-02-28 10:51:47 +00:00
|
|
|
}
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-09 12:44:41 +00:00
|
|
|
// Same as function TransformGraphicShapesWithClearanceToPolygonSet but this only for text
|
|
|
|
void MODULE::TransformGraphicTextWithClearanceToPolygonSet( PCB_LAYER_ID aLayer,
|
|
|
|
SHAPE_POLY_SET& aCornerBuffer,
|
|
|
|
int aInflateValue, int aError ) const
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
std::vector<TEXTE_MODULE *> texts; // List of TEXTE_MODULE to convert
|
|
|
|
|
2019-06-02 03:55:32 +00:00
|
|
|
for( auto item : GraphicalItems() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case PCB_MODULE_TEXT_T:
|
2019-09-09 12:44:41 +00:00
|
|
|
{
|
|
|
|
TEXTE_MODULE* text = static_cast<TEXTE_MODULE*>( item );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2019-09-09 12:44:41 +00:00
|
|
|
if( text->GetLayer() == aLayer && text->IsVisible() )
|
|
|
|
texts.push_back( text );
|
|
|
|
}
|
|
|
|
break;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
case PCB_MODULE_EDGE_T:
|
2019-09-09 12:44:41 +00:00
|
|
|
// This function does not render this
|
|
|
|
break;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2019-09-09 12:44:41 +00:00
|
|
|
default:
|
|
|
|
break;
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert texts sur modules
|
|
|
|
if( Reference().GetLayer() == aLayer && Reference().IsVisible() )
|
|
|
|
texts.push_back( &Reference() );
|
|
|
|
|
|
|
|
if( Value().GetLayer() == aLayer && Value().IsVisible() )
|
|
|
|
texts.push_back( &Value() );
|
|
|
|
|
2018-04-06 13:30:52 +00:00
|
|
|
prms.m_cornerBuffer = &aCornerBuffer;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2019-09-09 12:44:41 +00:00
|
|
|
for( TEXTE_MODULE* textmod : texts )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2018-04-06 13:30:52 +00:00
|
|
|
prms.m_textWidth = textmod->GetThickness() + ( 2 * aInflateValue );
|
2019-05-22 13:33:48 +00:00
|
|
|
prms.m_error = aError;
|
2017-01-23 20:30:11 +00:00
|
|
|
wxSize size = textmod->GetTextSize();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
if( textmod->IsMirrored() )
|
|
|
|
size.x = -size.x;
|
|
|
|
|
2019-05-31 12:15:25 +00:00
|
|
|
GRText( NULL, textmod->GetTextPos(), BLACK, textmod->GetShownText(),
|
|
|
|
textmod->GetDrawRotation(), size, textmod->GetHorizJustify(),
|
|
|
|
textmod->GetVertJustify(), textmod->GetThickness(), textmod->IsItalic(),
|
|
|
|
true, addTextSegmToPoly, &prms );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
2013-05-01 19:01:14 +00:00
|
|
|
}
|
|
|
|
|
2019-05-14 12:39:34 +00:00
|
|
|
|
2019-09-09 12:44:41 +00:00
|
|
|
void ZONE_CONTAINER::TransformSolidAreasShapesToPolygonSet( SHAPE_POLY_SET& aCornerBuffer,
|
|
|
|
int aError ) const
|
2013-05-01 19:01:14 +00:00
|
|
|
{
|
2015-07-27 19:45:57 +00:00
|
|
|
if( GetFilledPolysList().IsEmpty() )
|
2013-05-01 19:01:14 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// add filled areas polygons
|
2013-05-08 18:20:58 +00:00
|
|
|
aCornerBuffer.Append( m_FilledPolysList );
|
2019-05-22 14:47:38 +00:00
|
|
|
auto board = GetBoard();
|
|
|
|
int maxError = ARC_HIGH_DEF;
|
|
|
|
|
|
|
|
if( board )
|
|
|
|
maxError = board->GetDesignSettings().m_MaxError;
|
2013-05-01 19:01:14 +00:00
|
|
|
|
2015-04-09 18:53:36 +00:00
|
|
|
// add filled areas outlines, which are drawn with thick lines
|
2015-07-27 19:45:57 +00:00
|
|
|
for( int i = 0; i < m_FilledPolysList.OutlineCount(); i++ )
|
2013-05-01 19:01:14 +00:00
|
|
|
{
|
2015-07-27 19:45:57 +00:00
|
|
|
const SHAPE_LINE_CHAIN& path = m_FilledPolysList.COutline( i );
|
2013-05-01 19:01:14 +00:00
|
|
|
|
2015-07-27 19:45:57 +00:00
|
|
|
for( int j = 0; j < path.PointCount(); j++ )
|
2015-07-14 20:23:13 +00:00
|
|
|
{
|
2015-07-27 19:45:57 +00:00
|
|
|
const VECTOR2I& a = path.CPoint( j );
|
|
|
|
const VECTOR2I& b = path.CPoint( j + 1 );
|
2019-09-09 12:44:41 +00:00
|
|
|
int width = GetMinThickness();
|
2015-07-14 20:23:13 +00:00
|
|
|
|
2019-09-09 12:44:41 +00:00
|
|
|
TransformSegmentToPolygon( aCornerBuffer, (wxPoint) a, (wxPoint) b, maxError, width );
|
2015-07-27 19:45:57 +00:00
|
|
|
}
|
2013-05-01 19:01:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-14 12:39:34 +00:00
|
|
|
|
2019-09-09 12:44:41 +00:00
|
|
|
void EDA_TEXT::TransformBoundingBoxWithClearanceToPolygon( SHAPE_POLY_SET* aCornerBuffer,
|
|
|
|
int aClearanceValue ) const
|
2009-11-16 08:13:40 +00:00
|
|
|
{
|
2013-03-18 19:36:07 +00:00
|
|
|
if( GetText().Length() == 0 )
|
2009-11-16 08:13:40 +00:00
|
|
|
return;
|
|
|
|
|
2015-07-27 19:45:57 +00:00
|
|
|
wxPoint corners[4]; // Buffer of polygon corners
|
2009-11-16 08:13:40 +00:00
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT rect = GetTextBox( -1 );
|
2009-11-28 09:24:37 +00:00
|
|
|
rect.Inflate( aClearanceValue );
|
2009-11-16 08:13:40 +00:00
|
|
|
corners[0].x = rect.GetOrigin().x;
|
|
|
|
corners[0].y = rect.GetOrigin().y;
|
|
|
|
corners[1].y = corners[0].y;
|
|
|
|
corners[1].x = rect.GetRight();
|
|
|
|
corners[2].x = corners[1].x;
|
|
|
|
corners[2].y = rect.GetBottom();
|
|
|
|
corners[3].y = corners[2].y;
|
|
|
|
corners[3].x = corners[0].x;
|
|
|
|
|
2018-08-23 22:41:57 +00:00
|
|
|
aCornerBuffer->NewOutline();
|
2015-07-27 19:45:57 +00:00
|
|
|
|
2019-09-09 12:44:41 +00:00
|
|
|
for( wxPoint& corner : corners )
|
2009-11-16 08:13:40 +00:00
|
|
|
{
|
|
|
|
// Rotate polygon
|
2019-09-09 12:44:41 +00:00
|
|
|
RotatePoint( &corner.x, &corner.y, GetTextPos().x, GetTextPos().y, GetTextAngle() );
|
|
|
|
aCornerBuffer->Append( corner.x, corner.y );
|
2009-11-16 08:13:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-29 19:29:19 +00:00
|
|
|
|
2019-09-09 12:44:41 +00:00
|
|
|
/**
|
|
|
|
* Function TransformShapeWithClearanceToPolygonSet
|
|
|
|
* Convert the text shape to a set of polygons (one per segment).
|
|
|
|
* @aCornerBuffer = SHAPE_POLY_SET to store the polygon corners
|
|
|
|
* @aClearanceValue = the clearance around the text
|
|
|
|
* @aError = the maximum error to allow when approximating curves
|
2013-05-01 19:01:14 +00:00
|
|
|
*/
|
2019-09-09 12:44:41 +00:00
|
|
|
void TEXTE_PCB::TransformShapeWithClearanceToPolygonSet( SHAPE_POLY_SET& aCornerBuffer,
|
|
|
|
int aClearanceValue, int aError ) const
|
2013-05-01 19:01:14 +00:00
|
|
|
{
|
2017-01-23 20:30:11 +00:00
|
|
|
wxSize size = GetTextSize();
|
2012-01-29 19:29:19 +00:00
|
|
|
|
2013-05-01 19:01:14 +00:00
|
|
|
if( IsMirrored() )
|
2015-06-26 13:41:56 +00:00
|
|
|
size.x = -size.x;
|
2012-01-29 19:29:19 +00:00
|
|
|
|
2018-04-06 13:30:52 +00:00
|
|
|
prms.m_cornerBuffer = &aCornerBuffer;
|
2019-05-14 12:39:34 +00:00
|
|
|
prms.m_textWidth = GetThickness() + ( 2 * aClearanceValue );
|
2019-05-22 13:33:48 +00:00
|
|
|
prms.m_error = aError;
|
2019-05-31 12:15:25 +00:00
|
|
|
COLOR4D color = COLOR4D::BLACK; // not actually used, but needed by GRText
|
2012-01-29 19:29:19 +00:00
|
|
|
|
2013-05-01 19:01:14 +00:00
|
|
|
if( IsMultilineAllowed() )
|
2012-01-29 19:29:19 +00:00
|
|
|
{
|
2015-01-15 20:01:53 +00:00
|
|
|
wxArrayString strings_list;
|
|
|
|
wxStringSplit( GetShownText(), strings_list, '\n' );
|
2013-12-27 07:24:36 +00:00
|
|
|
std::vector<wxPoint> positions;
|
2015-01-15 20:01:53 +00:00
|
|
|
positions.reserve( strings_list.Count() );
|
|
|
|
GetPositionsOfLinesOfMultilineText( positions, strings_list.Count() );
|
2012-01-29 19:29:19 +00:00
|
|
|
|
2015-01-15 20:01:53 +00:00
|
|
|
for( unsigned ii = 0; ii < strings_list.Count(); ii++ )
|
2012-01-29 19:29:19 +00:00
|
|
|
{
|
2015-01-15 20:01:53 +00:00
|
|
|
wxString txt = strings_list.Item( ii );
|
2019-05-31 12:15:25 +00:00
|
|
|
GRText( NULL, positions[ii], color, txt, GetTextAngle(), size, GetHorizJustify(),
|
|
|
|
GetVertJustify(), GetThickness(), IsItalic(), true, addTextSegmToPoly, &prms );
|
2012-01-29 19:29:19 +00:00
|
|
|
}
|
2013-05-01 19:01:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-05-31 12:15:25 +00:00
|
|
|
GRText( NULL, GetTextPos(), color, GetShownText(), GetTextAngle(), size, GetHorizJustify(),
|
|
|
|
GetVertJustify(), GetThickness(), IsItalic(), true, addTextSegmToPoly, &prms );
|
2012-01-29 19:29:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-09 12:44:41 +00:00
|
|
|
void DRAWSEGMENT::TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
|
|
|
int aClearanceValue, int aError,
|
|
|
|
bool ignoreLineWidth ) const
|
2009-11-16 08:13:40 +00:00
|
|
|
{
|
2019-09-09 12:44:41 +00:00
|
|
|
int width = ignoreLineWidth ? 0 : m_Width;
|
2018-11-14 23:34:32 +00:00
|
|
|
|
2019-09-09 12:44:41 +00:00
|
|
|
width += 2 * aClearanceValue;
|
2015-04-09 18:53:36 +00:00
|
|
|
|
2018-03-09 14:56:00 +00:00
|
|
|
// Creating a reliable clearance shape for circles and arcs is not so easy, due to
|
|
|
|
// the error created by segment approximation.
|
2019-05-14 12:39:34 +00:00
|
|
|
// for a circle this is not so hard: create a polygon from a circle slightly bigger:
|
2019-09-09 12:44:41 +00:00
|
|
|
// thickness = width + s_error_max, and radius = initial radius + s_error_max/2
|
2018-03-09 14:56:00 +00:00
|
|
|
// giving a shape with a suitable internal radius and external radius
|
|
|
|
// For an arc this is more tricky: TODO
|
2018-02-16 14:25:38 +00:00
|
|
|
|
2009-11-16 08:13:40 +00:00
|
|
|
switch( m_Shape )
|
|
|
|
{
|
|
|
|
case S_CIRCLE:
|
2019-09-09 12:44:41 +00:00
|
|
|
TransformRingToPolygon( aCornerBuffer, GetCenter(), GetRadius(), aError, width );
|
2009-11-16 08:13:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case S_ARC:
|
2019-09-09 12:44:41 +00:00
|
|
|
TransformArcToPolygon( aCornerBuffer, GetCenter(), GetArcStart(), m_Angle, aError, width );
|
2009-11-16 08:13:40 +00:00
|
|
|
break;
|
|
|
|
|
2015-04-09 18:53:36 +00:00
|
|
|
case S_SEGMENT:
|
2019-09-09 12:44:41 +00:00
|
|
|
TransformOvalToPolygon( aCornerBuffer, m_Start, m_End, width, aError );
|
2015-04-09 18:53:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case S_POLYGON:
|
2018-01-24 13:22:43 +00:00
|
|
|
if( IsPolyShapeValid() )
|
2015-04-09 18:53:36 +00:00
|
|
|
{
|
2018-01-24 13:22:43 +00:00
|
|
|
// The polygon is expected to be a simple polygon
|
|
|
|
// not self intersecting, no hole.
|
|
|
|
MODULE* module = GetParentModule(); // NULL for items not in footprints
|
|
|
|
double orientation = module ? module->GetOrientation() : 0.0;
|
|
|
|
wxPoint offset;
|
2017-12-21 14:06:29 +00:00
|
|
|
|
2018-01-24 13:22:43 +00:00
|
|
|
if( module )
|
|
|
|
offset = module->GetPosition();
|
2015-04-09 18:53:36 +00:00
|
|
|
|
2018-01-24 13:22:43 +00:00
|
|
|
// Build the polygon with the actual position and orientation:
|
|
|
|
std::vector< wxPoint> poly;
|
|
|
|
poly = BuildPolyPointsList();
|
2015-04-09 18:53:36 +00:00
|
|
|
|
2019-09-09 12:44:41 +00:00
|
|
|
for( wxPoint& point : poly )
|
2018-01-24 13:22:43 +00:00
|
|
|
{
|
2019-09-09 12:44:41 +00:00
|
|
|
RotatePoint( &point, orientation );
|
|
|
|
point += offset;
|
2018-01-24 13:22:43 +00:00
|
|
|
}
|
2015-11-02 09:24:32 +00:00
|
|
|
|
2018-12-05 11:13:52 +00:00
|
|
|
// If the polygon is not filled, treat it as a closed set of lines
|
|
|
|
if( !IsPolygonFilled() )
|
2018-12-02 04:41:17 +00:00
|
|
|
{
|
|
|
|
for( size_t ii = 1; ii < poly.size(); ii++ )
|
2019-09-09 12:44:41 +00:00
|
|
|
TransformOvalToPolygon( aCornerBuffer, poly[ii-1], poly[ii], width, aError );
|
2018-12-02 04:41:17 +00:00
|
|
|
|
2019-09-09 12:44:41 +00:00
|
|
|
TransformOvalToPolygon( aCornerBuffer, poly.back(), poly.front(), width, aError );
|
2018-12-02 04:41:17 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-01-24 13:22:43 +00:00
|
|
|
// Generate polygons for the outline + clearance
|
|
|
|
// This code is compatible with a polygon with holes linked to external outline
|
|
|
|
// by overlapping segments.
|
2015-11-02 09:24:32 +00:00
|
|
|
|
2018-01-24 13:22:43 +00:00
|
|
|
// Insert the initial polygon:
|
|
|
|
aCornerBuffer.NewOutline();
|
2015-04-09 18:53:36 +00:00
|
|
|
|
2019-09-09 12:44:41 +00:00
|
|
|
for( wxPoint& point : poly )
|
|
|
|
aCornerBuffer.Append( point.x, point.y );
|
2018-01-24 13:22:43 +00:00
|
|
|
|
2019-09-09 12:44:41 +00:00
|
|
|
if( width != 0 ) // Add thick outlines
|
2015-04-09 18:53:36 +00:00
|
|
|
{
|
2019-09-09 12:44:41 +00:00
|
|
|
wxPoint pt1( poly[ poly.size() - 1] );
|
2015-04-09 18:53:36 +00:00
|
|
|
|
2019-09-09 12:44:41 +00:00
|
|
|
for( wxPoint pt2 : poly )
|
2015-04-09 18:53:36 +00:00
|
|
|
{
|
2019-09-09 12:44:41 +00:00
|
|
|
if( pt2 != pt1 )
|
|
|
|
TransformSegmentToPolygon( aCornerBuffer, pt1, pt2, aError, width );
|
2015-04-09 18:53:36 +00:00
|
|
|
|
2019-09-09 12:44:41 +00:00
|
|
|
pt1 = pt2;
|
2018-01-24 13:22:43 +00:00
|
|
|
}
|
2015-04-09 18:53:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2018-07-07 11:04:01 +00:00
|
|
|
case S_CURVE: // Bezier curve
|
|
|
|
{
|
|
|
|
std::vector<wxPoint> ctrlPoints = { m_Start, m_BezierC1, m_BezierC2, m_End };
|
|
|
|
BEZIER_POLY converter( ctrlPoints );
|
|
|
|
std::vector< wxPoint> poly;
|
|
|
|
converter.GetPoly( poly, m_Width );
|
|
|
|
|
2019-09-09 12:44:41 +00:00
|
|
|
if( width != 0 )
|
2018-07-07 11:04:01 +00:00
|
|
|
{
|
2019-09-09 12:44:41 +00:00
|
|
|
for( unsigned ii = 1; ii < poly.size(); ii++ )
|
|
|
|
TransformSegmentToPolygon( aCornerBuffer, poly[ii-1], poly[ii], aError, width );
|
2018-07-07 11:04:01 +00:00
|
|
|
}
|
|
|
|
}
|
2015-04-09 18:53:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2009-11-16 08:13:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-09 12:44:41 +00:00
|
|
|
void TRACK::TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
|
|
|
int aClearanceValue, int aError,
|
|
|
|
bool ignoreLineWidth ) const
|
2009-11-14 19:47:52 +00:00
|
|
|
{
|
2018-11-14 23:34:32 +00:00
|
|
|
wxASSERT_MSG( !ignoreLineWidth, "IgnoreLineWidth has no meaning for tracks." );
|
|
|
|
|
2009-11-14 19:47:52 +00:00
|
|
|
switch( Type() )
|
|
|
|
{
|
2011-10-01 19:24:27 +00:00
|
|
|
case PCB_VIA_T:
|
2012-08-23 19:15:58 +00:00
|
|
|
{
|
2019-09-09 12:44:41 +00:00
|
|
|
int radius = ( m_Width / 2 ) + aClearanceValue;
|
2019-05-22 13:33:48 +00:00
|
|
|
TransformCircleToPolygon( aCornerBuffer, m_Start, radius, aError );
|
2012-08-23 19:15:58 +00:00
|
|
|
}
|
2009-11-14 19:47:52 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2019-09-09 12:44:41 +00:00
|
|
|
{
|
|
|
|
int width = m_Width + ( 2 * aClearanceValue );
|
|
|
|
TransformOvalToPolygon( aCornerBuffer, m_Start, m_End, width, aError );
|
|
|
|
}
|
2009-11-14 19:47:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-09 12:44:41 +00:00
|
|
|
void D_PAD::TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
|
|
|
int aClearanceValue, int aError,
|
|
|
|
bool ignoreLineWidth ) const
|
2009-11-14 19:47:52 +00:00
|
|
|
{
|
2018-11-14 23:34:32 +00:00
|
|
|
wxASSERT_MSG( !ignoreLineWidth, "IgnoreLineWidth has no meaning for pads." );
|
|
|
|
|
2019-06-17 15:26:15 +00:00
|
|
|
// minimal segment count to approximate a circle to create the polygonal pad shape
|
|
|
|
// This minimal value is mainly for very small pads, like SM0402.
|
|
|
|
// Most of time pads are using the segment count given by aError value.
|
|
|
|
const int pad_min_seg_per_circle_count = 16;
|
2014-11-29 12:58:34 +00:00
|
|
|
double angle = m_Orient;
|
2011-11-24 17:32:51 +00:00
|
|
|
int dx = (m_Size.x / 2) + aClearanceValue;
|
|
|
|
int dy = (m_Size.y / 2) + aClearanceValue;
|
2009-11-14 19:47:52 +00:00
|
|
|
|
2019-09-09 12:44:41 +00:00
|
|
|
wxPoint padShapePos = ShapePos(); // Note: for pad having a shape offset,
|
|
|
|
// the pad position is NOT the shape position
|
2009-11-14 19:47:52 +00:00
|
|
|
|
2014-01-26 14:20:58 +00:00
|
|
|
switch( GetShape() )
|
2009-11-14 19:47:52 +00:00
|
|
|
{
|
2015-08-23 19:40:33 +00:00
|
|
|
case PAD_SHAPE_CIRCLE:
|
2019-05-22 13:33:48 +00:00
|
|
|
TransformCircleToPolygon( aCornerBuffer, padShapePos, dx, aError );
|
2009-11-14 19:47:52 +00:00
|
|
|
break;
|
|
|
|
|
2015-08-23 19:40:33 +00:00
|
|
|
case PAD_SHAPE_OVAL:
|
2019-09-09 12:44:41 +00:00
|
|
|
|
2019-10-25 14:26:10 +00:00
|
|
|
// If the oval is actually a circle (same x/y size), treat it the same
|
|
|
|
if( dx == dy )
|
2009-11-14 19:47:52 +00:00
|
|
|
{
|
2019-10-25 14:26:10 +00:00
|
|
|
TransformCircleToPolygon( aCornerBuffer, padShapePos, dx, aError );
|
2009-11-14 19:47:52 +00:00
|
|
|
}
|
2019-10-25 14:26:10 +00:00
|
|
|
else
|
2009-11-14 19:47:52 +00:00
|
|
|
{
|
2019-10-25 14:26:10 +00:00
|
|
|
int width;
|
|
|
|
wxPoint shape_offset;
|
|
|
|
if( dy > dx ) // Oval pad X/Y ratio for choosing translation axis
|
|
|
|
{
|
|
|
|
shape_offset.y = dy - dx;
|
|
|
|
width = dx * 2;
|
|
|
|
}
|
|
|
|
else //if( dy <= dx )
|
|
|
|
{
|
|
|
|
shape_offset.x = dy - dx;
|
|
|
|
width = dy * 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
RotatePoint( &shape_offset, angle );
|
|
|
|
wxPoint start = padShapePos - shape_offset;
|
|
|
|
wxPoint end = padShapePos + shape_offset;
|
|
|
|
TransformOvalToPolygon( aCornerBuffer, start, end, width, aError );
|
2012-08-23 19:15:58 +00:00
|
|
|
}
|
2009-11-14 19:47:52 +00:00
|
|
|
|
2012-08-23 19:15:58 +00:00
|
|
|
break;
|
2009-11-14 19:47:52 +00:00
|
|
|
|
2015-08-23 19:40:33 +00:00
|
|
|
case PAD_SHAPE_TRAPEZOID:
|
|
|
|
case PAD_SHAPE_RECT:
|
2014-11-29 12:58:34 +00:00
|
|
|
{
|
|
|
|
wxPoint corners[4];
|
|
|
|
BuildPadPolygon( corners, wxSize( 0, 0 ), angle );
|
2009-11-14 19:47:52 +00:00
|
|
|
|
2015-07-27 19:45:57 +00:00
|
|
|
SHAPE_POLY_SET outline;
|
|
|
|
outline.NewOutline();
|
2009-11-14 19:47:52 +00:00
|
|
|
|
2019-09-09 12:44:41 +00:00
|
|
|
for( wxPoint& corner : corners )
|
2014-12-01 14:54:33 +00:00
|
|
|
{
|
2019-09-09 12:44:41 +00:00
|
|
|
corner += padShapePos;
|
|
|
|
outline.Append( corner.x, corner.y );
|
2014-12-01 14:54:33 +00:00
|
|
|
}
|
2014-11-29 12:58:34 +00:00
|
|
|
|
2019-09-09 12:44:41 +00:00
|
|
|
if( aClearanceValue )
|
|
|
|
{
|
|
|
|
int numSegs = std::max( GetArcToSegmentCount( aClearanceValue, aError, 360.0 ),
|
|
|
|
pad_min_seg_per_circle_count );
|
|
|
|
double correction = GetCircletoPolyCorrectionFactor( numSegs );
|
|
|
|
int clearance = KiROUND( aClearanceValue * correction );
|
|
|
|
outline.Inflate( clearance, numSegs );
|
|
|
|
}
|
2016-04-06 18:15:49 +00:00
|
|
|
|
|
|
|
aCornerBuffer.Append( outline );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2018-08-29 07:13:07 +00:00
|
|
|
case PAD_SHAPE_CHAMFERED_RECT:
|
2016-04-06 18:15:49 +00:00
|
|
|
case PAD_SHAPE_ROUNDRECT:
|
|
|
|
{
|
2019-06-17 12:28:52 +00:00
|
|
|
int radius = GetRoundRectCornerRadius() + aClearanceValue;
|
2019-06-17 15:26:15 +00:00
|
|
|
int numSegs = std::max( GetArcToSegmentCount( radius, aError, 360.0 ),
|
|
|
|
pad_min_seg_per_circle_count );
|
2019-06-17 12:28:52 +00:00
|
|
|
double correction = GetCircletoPolyCorrectionFactor( numSegs );
|
|
|
|
int clearance = KiROUND( aClearanceValue * correction );
|
|
|
|
wxSize shapesize( m_Size );
|
2019-05-14 12:39:34 +00:00
|
|
|
|
2019-09-09 12:44:41 +00:00
|
|
|
radius = KiROUND( radius * correction );
|
2019-05-22 13:33:48 +00:00
|
|
|
shapesize.x += clearance * 2;
|
|
|
|
shapesize.y += clearance * 2;
|
2018-08-29 07:13:07 +00:00
|
|
|
bool doChamfer = GetShape() == PAD_SHAPE_CHAMFERED_RECT;
|
2015-07-14 20:23:13 +00:00
|
|
|
|
2019-06-17 12:28:52 +00:00
|
|
|
SHAPE_POLY_SET outline;
|
2019-09-09 12:44:41 +00:00
|
|
|
TransformRoundChamferedRectToPolygon( outline, padShapePos, shapesize, angle, radius,
|
|
|
|
doChamfer ? GetChamferRectRatio() : 0.0,
|
|
|
|
doChamfer ? GetChamferPositions() : 0, aError );
|
2015-07-27 19:45:57 +00:00
|
|
|
|
|
|
|
aCornerBuffer.Append( outline );
|
2014-11-29 12:58:34 +00:00
|
|
|
}
|
2009-11-14 19:47:52 +00:00
|
|
|
break;
|
2017-01-13 17:51:22 +00:00
|
|
|
|
|
|
|
case PAD_SHAPE_CUSTOM:
|
|
|
|
{
|
2019-06-17 15:26:15 +00:00
|
|
|
int numSegs = std::max( GetArcToSegmentCount( aClearanceValue, aError, 360.0 ),
|
|
|
|
pad_min_seg_per_circle_count );
|
2019-05-14 12:39:34 +00:00
|
|
|
double correction = GetCircletoPolyCorrectionFactor( numSegs );
|
|
|
|
int clearance = KiROUND( aClearanceValue * correction );
|
2017-01-13 17:51:22 +00:00
|
|
|
SHAPE_POLY_SET outline; // Will contain the corners in board coordinates
|
|
|
|
outline.Append( m_customShapeAsPolygon );
|
2017-09-20 08:28:52 +00:00
|
|
|
CustomShapeAsPolygonToBoardPosition( &outline, GetPosition(), GetOrientation() );
|
2019-05-09 14:23:18 +00:00
|
|
|
outline.Simplify( SHAPE_POLY_SET::PM_FAST );
|
2019-05-14 12:39:34 +00:00
|
|
|
outline.Inflate( clearance, numSegs );
|
2019-05-09 14:23:18 +00:00
|
|
|
outline.Fracture( SHAPE_POLY_SET::PM_FAST );
|
2017-01-13 17:51:22 +00:00
|
|
|
aCornerBuffer.Append( outline );
|
|
|
|
}
|
|
|
|
break;
|
2009-11-14 19:47:52 +00:00
|
|
|
}
|
|
|
|
}
|
2009-11-16 08:13:40 +00:00
|
|
|
|
2016-04-06 18:15:49 +00:00
|
|
|
|
|
|
|
|
2013-05-01 19:01:14 +00:00
|
|
|
/*
|
|
|
|
* Function BuildPadShapePolygon
|
2019-09-09 12:44:41 +00:00
|
|
|
* Build the corner list of the polygonal shape, depending on shape, clearance and orientation
|
|
|
|
* Note: for round & oval pads this function is equivalent to TransformShapeWithClearanceToPolygon,
|
|
|
|
* but not for other shapes
|
2013-05-01 19:01:14 +00:00
|
|
|
*/
|
2019-09-09 12:44:41 +00:00
|
|
|
void D_PAD::BuildPadShapePolygon( SHAPE_POLY_SET& aCornerBuffer, wxSize aInflateValue,
|
|
|
|
int aError ) const
|
2013-05-01 19:01:14 +00:00
|
|
|
{
|
2014-01-26 14:20:58 +00:00
|
|
|
switch( GetShape() )
|
2013-05-01 19:01:14 +00:00
|
|
|
{
|
2015-08-23 19:40:33 +00:00
|
|
|
case PAD_SHAPE_CIRCLE:
|
|
|
|
case PAD_SHAPE_OVAL:
|
2016-04-06 18:15:49 +00:00
|
|
|
case PAD_SHAPE_ROUNDRECT:
|
2018-08-29 07:13:07 +00:00
|
|
|
case PAD_SHAPE_CHAMFERED_RECT:
|
2018-04-29 17:51:18 +00:00
|
|
|
{
|
|
|
|
// We are using TransformShapeWithClearanceToPolygon to build the shape.
|
|
|
|
// Currently, this method uses only the same inflate value for X and Y dirs.
|
|
|
|
// so because here this is not the case, we use a inflated dummy pad to build
|
|
|
|
// the polygonal shape
|
|
|
|
// TODO: remove this dummy pad when TransformShapeWithClearanceToPolygon will use
|
|
|
|
// a wxSize to inflate the pad size
|
|
|
|
D_PAD dummy( *this );
|
|
|
|
dummy.SetSize( GetSize() + aInflateValue + aInflateValue );
|
2019-05-14 12:39:34 +00:00
|
|
|
dummy.TransformShapeWithClearanceToPolygon( aCornerBuffer, 0 );
|
2018-04-29 17:51:18 +00:00
|
|
|
}
|
2013-05-01 19:01:14 +00:00
|
|
|
break;
|
|
|
|
|
2015-08-23 19:40:33 +00:00
|
|
|
case PAD_SHAPE_TRAPEZOID:
|
|
|
|
case PAD_SHAPE_RECT:
|
2019-09-09 12:44:41 +00:00
|
|
|
{
|
|
|
|
wxPoint corners[4];
|
|
|
|
wxPoint padShapePos = ShapePos(); // Note: for pad having a shape offset,
|
|
|
|
// the pad position is NOT the shape position
|
2015-07-27 19:45:57 +00:00
|
|
|
|
2019-09-09 12:44:41 +00:00
|
|
|
aCornerBuffer.NewOutline();
|
2013-05-01 19:01:14 +00:00
|
|
|
BuildPadPolygon( corners, aInflateValue, m_Orient );
|
2019-09-09 12:44:41 +00:00
|
|
|
|
|
|
|
for( wxPoint& corner : corners )
|
2013-05-01 19:01:14 +00:00
|
|
|
{
|
2019-09-09 12:44:41 +00:00
|
|
|
corner += padShapePos; // Shift origin to position
|
|
|
|
aCornerBuffer.Append( corner.x, corner.y );
|
2013-05-01 19:01:14 +00:00
|
|
|
}
|
2019-09-09 12:44:41 +00:00
|
|
|
}
|
2013-05-01 19:01:14 +00:00
|
|
|
break;
|
2018-07-30 10:52:03 +00:00
|
|
|
|
|
|
|
case PAD_SHAPE_CUSTOM:
|
2019-09-09 12:44:41 +00:00
|
|
|
{
|
|
|
|
// For a custom shape, that is in fact a polygon (with holes), we use only a single
|
|
|
|
// inflate value (different values for X and Y have no definition for a custom pad).
|
|
|
|
int inflate = ( aInflateValue.x + aInflateValue.y ) / 2;
|
|
|
|
|
|
|
|
TransformShapeWithClearanceToPolygon( aCornerBuffer, inflate );
|
|
|
|
}
|
2018-07-30 10:52:03 +00:00
|
|
|
break;
|
2013-05-01 19:01:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-14 12:39:34 +00:00
|
|
|
|
|
|
|
bool D_PAD::BuildPadDrillShapePolygon(
|
|
|
|
SHAPE_POLY_SET& aCornerBuffer, int aInflateValue, int aError ) const
|
2013-05-01 19:01:14 +00:00
|
|
|
{
|
|
|
|
wxSize drillsize = GetDrillSize();
|
|
|
|
|
2014-05-17 19:29:15 +00:00
|
|
|
if( !drillsize.x || !drillsize.y )
|
2013-05-01 19:01:14 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if( drillsize.x == drillsize.y ) // usual round hole
|
|
|
|
{
|
2019-05-14 12:39:34 +00:00
|
|
|
int radius = ( drillsize.x / 2 ) + aInflateValue;
|
2019-05-22 13:33:48 +00:00
|
|
|
TransformCircleToPolygon( aCornerBuffer, GetPosition(), radius, aError );
|
2013-05-01 19:01:14 +00:00
|
|
|
}
|
|
|
|
else // Oblong hole
|
|
|
|
{
|
2014-05-17 19:29:15 +00:00
|
|
|
wxPoint start, end;
|
2013-05-01 19:01:14 +00:00
|
|
|
int width;
|
|
|
|
|
2014-05-17 19:29:15 +00:00
|
|
|
GetOblongDrillGeometry( start, end, width );
|
2013-05-01 19:01:14 +00:00
|
|
|
|
2019-09-09 12:44:41 +00:00
|
|
|
start += GetPosition();
|
|
|
|
end += GetPosition();
|
2014-05-17 19:29:15 +00:00
|
|
|
width += aInflateValue * 2;
|
2013-05-01 19:01:14 +00:00
|
|
|
|
2019-09-09 12:44:41 +00:00
|
|
|
TransformSegmentToPolygon( aCornerBuffer, start, end, aError, width );
|
2013-05-01 19:01:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2009-11-16 08:13:40 +00:00
|
|
|
|
2017-11-29 18:51:01 +00:00
|
|
|
|
2019-09-09 12:44:41 +00:00
|
|
|
void ZONE_CONTAINER::TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
|
|
|
|
int aClearanceValue, int aError,
|
|
|
|
bool ignoreLineWidth ) const
|
2017-11-29 18:51:01 +00:00
|
|
|
{
|
2018-11-14 23:34:32 +00:00
|
|
|
wxASSERT_MSG( !ignoreLineWidth, "IgnoreLineWidth has no meaning for zones." );
|
|
|
|
|
2017-11-29 18:51:01 +00:00
|
|
|
aCornerBuffer = m_FilledPolysList;
|
|
|
|
aCornerBuffer.Simplify( SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
|
|
|
|
}
|