2016-07-19 17:35:25 +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>
|
2019-05-22 13:33:48 +00:00
|
|
|
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
|
2016-07-19 17:35:25 +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_layer_poly.cpp
|
|
|
|
* @brief This file implements the creation of the pcb board items in the poly
|
|
|
|
* contours format. It is based on the function found in the files:
|
|
|
|
* board_items_to_polygon_shape_transform.cpp
|
|
|
|
* board_items_to_polygon_shape_transform.cpp
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "cinfo3d_visu.h"
|
|
|
|
#include <convert_basic_shapes_to_polygon.h>
|
|
|
|
#include <class_edge_mod.h>
|
|
|
|
#include <class_module.h>
|
|
|
|
|
|
|
|
|
|
|
|
// This is the same function as in board_items_to_polygon_shape_transform.cpp
|
|
|
|
// but it adds the rect/trapezoid shapes with a different winding
|
|
|
|
void CINFO3D_VISU::buildPadShapePolygon( const D_PAD* aPad,
|
|
|
|
SHAPE_POLY_SET& aCornerBuffer,
|
2019-05-17 13:16:15 +00:00
|
|
|
wxSize aInflateValue ) const
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
wxPoint corners[4];
|
|
|
|
wxPoint PadShapePos = aPad->ShapePos(); /* Note: for pad having a shape offset,
|
|
|
|
* the pad position is NOT the shape position */
|
|
|
|
switch( aPad->GetShape() )
|
|
|
|
{
|
|
|
|
case PAD_SHAPE_CIRCLE:
|
|
|
|
case PAD_SHAPE_OVAL:
|
|
|
|
case PAD_SHAPE_ROUNDRECT:
|
2018-08-29 07:13:07 +00:00
|
|
|
case PAD_SHAPE_CHAMFERED_RECT:
|
2018-04-28 18:31:50 +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( *aPad );
|
|
|
|
wxSize new_size = aPad->GetSize() + aInflateValue + aInflateValue;
|
|
|
|
dummy.SetSize( new_size );
|
2019-05-17 13:16:15 +00:00
|
|
|
dummy.TransformShapeWithClearanceToPolygon( aCornerBuffer, 0 );
|
2018-04-28 18:31:50 +00:00
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PAD_SHAPE_TRAPEZOID:
|
|
|
|
case PAD_SHAPE_RECT:
|
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN aLineChain;
|
|
|
|
|
|
|
|
aPad->BuildPadPolygon( corners, aInflateValue, aPad->GetOrientation() );
|
|
|
|
|
|
|
|
for( int ii = 0; ii < 4; ++ii )
|
|
|
|
{
|
|
|
|
corners[3-ii] += PadShapePos; // Shift origin to position
|
|
|
|
aLineChain.Append( corners[3-ii].x, corners[3-ii].y );
|
|
|
|
}
|
|
|
|
|
|
|
|
aLineChain.SetClosed( true );
|
|
|
|
|
|
|
|
aCornerBuffer.AddOutline( aLineChain );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2017-01-13 17:51:22 +00:00
|
|
|
case PAD_SHAPE_CUSTOM:
|
|
|
|
{
|
|
|
|
SHAPE_POLY_SET polyList; // Will contain the pad outlines in board coordinates
|
2019-05-17 13:16:15 +00:00
|
|
|
auto inflate_val = std::max( aInflateValue.x, aInflateValue.y );
|
|
|
|
|
2017-01-13 17:51:22 +00:00
|
|
|
polyList.Append( aPad->GetCustomShapeAsPolygon() );
|
2017-09-20 08:28:52 +00:00
|
|
|
aPad->CustomShapeAsPolygonToBoardPosition( &polyList, aPad->ShapePos(), aPad->GetOrientation() );
|
2019-05-17 13:16:15 +00:00
|
|
|
|
|
|
|
if( inflate_val > 0 )
|
|
|
|
{
|
|
|
|
int numSegs = GetNrSegmentsCircle( inflate_val );
|
|
|
|
polyList.Inflate( inflate_val, numSegs );
|
|
|
|
}
|
|
|
|
|
2017-01-13 17:51:22 +00:00
|
|
|
aCornerBuffer.Append( polyList );
|
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CINFO3D_VISU::buildPadShapeThickOutlineAsPolygon( const D_PAD* aPad,
|
|
|
|
SHAPE_POLY_SET& aCornerBuffer,
|
|
|
|
int aWidth ) const
|
|
|
|
{
|
|
|
|
if( aPad->GetShape() == PAD_SHAPE_CIRCLE ) // Draw a ring
|
|
|
|
{
|
|
|
|
TransformRingToPolygon( aCornerBuffer, aPad->ShapePos(),
|
2019-05-22 13:33:48 +00:00
|
|
|
aPad->GetSize().x / 2, ARC_HIGH_DEF, aWidth );
|
2016-07-19 17:35:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-13 17:51:22 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
// For other shapes, draw polygon outlines
|
|
|
|
SHAPE_POLY_SET corners;
|
|
|
|
|
2019-05-17 13:16:15 +00:00
|
|
|
buildPadShapePolygon( aPad, corners, wxSize( 0, 0 ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
// Add outlines as thick segments in polygon buffer
|
|
|
|
|
|
|
|
const SHAPE_LINE_CHAIN& path = corners.COutline( 0 );
|
|
|
|
|
|
|
|
for( int ii = 0; ii < path.PointCount(); ++ii )
|
|
|
|
{
|
|
|
|
const VECTOR2I& a = path.CPoint( ii );
|
|
|
|
const VECTOR2I& b = path.CPoint( ii + 1 );
|
|
|
|
|
2019-05-22 13:33:48 +00:00
|
|
|
TransformRoundedEndsSegmentToPolygon( aCornerBuffer, wxPoint( a.x, a.y ),
|
|
|
|
wxPoint( b.x, b.y ), ARC_HIGH_DEF, aWidth );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Based on the same function name in board_items_to_polyshape_transform.cpp
|
|
|
|
// It was implemented here to allow dynamic segments count per pad shape
|
2019-06-01 23:23:36 +00:00
|
|
|
void CINFO3D_VISU::transformPadsShapesWithClearanceToPolygon( const PADS& aPads, PCB_LAYER_ID aLayer,
|
2016-07-19 17:35:25 +00:00
|
|
|
SHAPE_POLY_SET& aCornerBuffer,
|
|
|
|
int aInflateValue,
|
|
|
|
bool aSkipNPTHPadsWihNoCopper ) const
|
|
|
|
{
|
|
|
|
wxSize margin;
|
2019-06-01 23:23:36 +00:00
|
|
|
for( auto pad : aPads )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
if( !pad->IsOnLayer(aLayer) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// NPTH pads are not drawn on layers if the shape size and pos is the same
|
|
|
|
// as their hole:
|
|
|
|
if( aSkipNPTHPadsWihNoCopper && (pad->GetAttribute() == PAD_ATTRIB_HOLE_NOT_PLATED) )
|
|
|
|
{
|
|
|
|
if( (pad->GetDrillSize() == pad->GetSize()) &&
|
|
|
|
(pad->GetOffset() == wxPoint( 0, 0 )) )
|
|
|
|
{
|
|
|
|
switch( pad->GetShape() )
|
|
|
|
{
|
|
|
|
case PAD_SHAPE_CIRCLE:
|
|
|
|
if( pad->GetDrillShape() == PAD_DRILL_SHAPE_CIRCLE )
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PAD_SHAPE_OVAL:
|
|
|
|
if( pad->GetDrillShape() != PAD_DRILL_SHAPE_CIRCLE )
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch( aLayer )
|
|
|
|
{
|
|
|
|
case F_Mask:
|
|
|
|
case B_Mask:
|
|
|
|
margin.x = margin.y = pad->GetSolderMaskMargin() + aInflateValue;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case F_Paste:
|
|
|
|
case B_Paste:
|
|
|
|
margin = pad->GetSolderPasteMargin();
|
|
|
|
margin.x += aInflateValue;
|
|
|
|
margin.y += aInflateValue;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
margin.x = margin.y = aInflateValue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-05-17 13:16:15 +00:00
|
|
|
buildPadShapePolygon( pad, aCornerBuffer, margin );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CINFO3D_VISU::transformGraphicModuleEdgeToPolygonSet( const MODULE *aModule,
|
2017-03-13 03:19:33 +00:00
|
|
|
PCB_LAYER_ID aLayer,
|
2016-07-19 17:35:25 +00:00
|
|
|
SHAPE_POLY_SET& aCornerBuffer ) const
|
|
|
|
{
|
2019-06-02 03:55:32 +00:00
|
|
|
for( auto item : aModule->GraphicalItems() )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case PCB_MODULE_EDGE_T:
|
|
|
|
{
|
|
|
|
EDGE_MODULE*outline = (EDGE_MODULE*) item;
|
|
|
|
|
|
|
|
if( outline->GetLayer() != aLayer )
|
|
|
|
break;
|
|
|
|
|
2019-05-17 13:16:15 +00:00
|
|
|
outline->TransformShapeWithClearanceToPolygon( aCornerBuffer, 0 );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|