2011-10-17 20:01:27 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2016-07-27 13:27:19 +00:00
|
|
|
* Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2021-06-03 18:32:24 +00:00
|
|
|
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
|
2022-01-28 22:51:34 +00:00
|
|
|
* Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-10-17 20:01:27 +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 dcode.cpp
|
|
|
|
* @brief D_CODE class implementation
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <trigo.h>
|
2014-06-27 17:07:42 +00:00
|
|
|
#include <gerbview_frame.h>
|
2018-01-29 12:26:58 +00:00
|
|
|
#include <gerber_file_image.h>
|
2022-09-17 01:07:36 +00:00
|
|
|
#include <eda_units.h>
|
2017-09-17 22:43:20 +00:00
|
|
|
#include <convert_basic_shapes_to_polygon.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2022-09-16 11:33:56 +00:00
|
|
|
#define DCODE_DEFAULT_SIZE gerbIUScale.mmToIU( 0.1 )
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-11-09 14:00:22 +00:00
|
|
|
/* Format Gerber: NOTES:
|
|
|
|
* Tools and D_CODES
|
|
|
|
* tool number (identification of shapes)
|
|
|
|
* 1 to 999
|
|
|
|
*
|
|
|
|
* D_CODES:
|
2010-09-29 19:00:35 +00:00
|
|
|
* D01 ... D9 = command codes:
|
|
|
|
* D01 = activating light (pen down) while moving
|
|
|
|
* D02 = light extinction (pen up) while moving
|
|
|
|
* D03 = Flash
|
|
|
|
* D04 to D09 = non used
|
2011-10-17 20:01:27 +00:00
|
|
|
* D10 ... D999 = Identification Tool (Shape id)
|
2010-09-28 14:42:05 +00:00
|
|
|
*
|
2010-09-29 19:00:35 +00:00
|
|
|
* For tools defining a shape):
|
2010-09-28 14:42:05 +00:00
|
|
|
* DCode min = D10
|
|
|
|
* DCode max = 999
|
2009-11-09 14:00:22 +00:00
|
|
|
*/
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-04-17 16:25:29 +00:00
|
|
|
D_CODE::D_CODE( int num_dcode )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-04-17 16:25:29 +00:00
|
|
|
m_Num_Dcode = num_dcode;
|
|
|
|
Clear_D_CODE_Data();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2008-04-17 16:25:29 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
D_CODE::~D_CODE()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-04-17 16:25:29 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
void D_CODE::Clear_D_CODE_Data()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2016-05-25 09:45:55 +00:00
|
|
|
m_Size.x = DCODE_DEFAULT_SIZE;
|
|
|
|
m_Size.y = DCODE_DEFAULT_SIZE;
|
2008-11-08 06:44:07 +00:00
|
|
|
m_Shape = APT_CIRCLE;
|
2008-04-17 16:25:29 +00:00
|
|
|
m_Drill.x = m_Drill.y = 0;
|
2010-09-28 19:34:16 +00:00
|
|
|
m_DrillShape = APT_DEF_NO_HOLE;
|
2012-01-22 17:20:22 +00:00
|
|
|
m_InUse = false;
|
|
|
|
m_Defined = false;
|
2021-07-16 20:13:26 +00:00
|
|
|
m_Macro = nullptr;
|
2022-01-20 20:54:22 +00:00
|
|
|
m_Rotation = ANGLE_0;
|
2010-09-28 19:34:16 +00:00
|
|
|
m_EdgesCount = 0;
|
2017-09-17 22:43:20 +00:00
|
|
|
m_Polygon.RemoveAllContours();
|
2008-11-09 02:57:42 +00:00
|
|
|
}
|
|
|
|
|
2009-11-09 14:00:22 +00:00
|
|
|
|
2008-11-09 02:57:42 +00:00
|
|
|
const wxChar* D_CODE::ShowApertureType( APERTURE_T aType )
|
|
|
|
{
|
|
|
|
const wxChar* ret;
|
|
|
|
|
|
|
|
switch( aType )
|
|
|
|
{
|
2009-11-09 14:00:22 +00:00
|
|
|
case APT_CIRCLE:
|
|
|
|
ret = wxT( "Round" ); break;
|
|
|
|
|
|
|
|
case APT_RECT:
|
|
|
|
ret = wxT( "Rect" ); break;
|
|
|
|
|
|
|
|
case APT_OVAL:
|
|
|
|
ret = wxT( "Oval" ); break;
|
|
|
|
|
|
|
|
case APT_POLYGON:
|
|
|
|
ret = wxT( "Poly" ); break;
|
|
|
|
|
|
|
|
case APT_MACRO:
|
|
|
|
ret = wxT( "Macro" ); break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ret = wxT( "???" ); break;
|
2008-11-09 02:57:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2021-06-03 18:32:24 +00:00
|
|
|
|
2010-10-23 18:12:11 +00:00
|
|
|
int D_CODE::GetShapeDim( GERBER_DRAW_ITEM* aParent )
|
|
|
|
{
|
|
|
|
int dim = -1;
|
2021-06-03 18:32:24 +00:00
|
|
|
|
2010-10-23 18:12:11 +00:00
|
|
|
switch( m_Shape )
|
|
|
|
{
|
|
|
|
case APT_CIRCLE:
|
|
|
|
dim = m_Size.x;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case APT_RECT:
|
|
|
|
case APT_OVAL:
|
2012-09-22 11:19:37 +00:00
|
|
|
dim = std::min( m_Size.x, m_Size.y );
|
2010-10-23 18:12:11 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case APT_POLYGON:
|
2012-09-22 11:19:37 +00:00
|
|
|
dim = std::min( m_Size.x, m_Size.y );
|
2010-10-23 18:12:11 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case APT_MACRO:
|
|
|
|
if( m_Macro )
|
|
|
|
dim = m_Macro->GetShapeDim( aParent );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dim;
|
|
|
|
}
|
|
|
|
|
2010-10-01 19:11:30 +00:00
|
|
|
|
2022-09-07 16:54:04 +00:00
|
|
|
void D_CODE::DrawFlashedShape( const GERBER_DRAW_ITEM* aParent, wxDC* aDC, const COLOR4D& aColor,
|
2022-01-28 22:51:34 +00:00
|
|
|
const VECTOR2I& aShapePos, bool aFilledShape )
|
2010-09-28 14:42:05 +00:00
|
|
|
{
|
|
|
|
int radius;
|
|
|
|
|
|
|
|
switch( m_Shape )
|
|
|
|
{
|
2010-10-01 19:11:30 +00:00
|
|
|
case APT_MACRO:
|
2022-01-28 22:51:34 +00:00
|
|
|
GetMacro()->DrawApertureMacroShape( aParent, aDC, aColor, aShapePos, aFilledShape );
|
2010-10-01 19:11:30 +00:00
|
|
|
break;
|
2010-09-28 19:34:16 +00:00
|
|
|
|
2010-09-28 14:42:05 +00:00
|
|
|
case APT_CIRCLE:
|
|
|
|
radius = m_Size.x >> 1;
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2010-09-28 14:42:05 +00:00
|
|
|
if( !aFilledShape )
|
2021-07-16 20:13:26 +00:00
|
|
|
{
|
2022-01-28 22:51:34 +00:00
|
|
|
GRCircle( aDC, aParent->GetABPosition(aShapePos), radius, 0, aColor );
|
2021-07-16 20:13:26 +00:00
|
|
|
}
|
|
|
|
else if( m_DrillShape == APT_DEF_NO_HOLE )
|
|
|
|
{
|
2022-01-28 22:51:34 +00:00
|
|
|
GRFilledCircle( aDC, aParent->GetABPosition(aShapePos), radius, 0, aColor, aColor );
|
2021-07-16 20:13:26 +00:00
|
|
|
}
|
|
|
|
else if( m_DrillShape == APT_DEF_ROUND_HOLE ) // round hole in shape
|
|
|
|
{
|
|
|
|
int width = (m_Size.x - m_Drill.x ) / 2;
|
2022-01-28 22:51:34 +00:00
|
|
|
GRCircle( aDC, aParent->GetABPosition(aShapePos), radius - (width / 2), width, aColor );
|
2021-07-16 20:13:26 +00:00
|
|
|
}
|
|
|
|
else // rectangular hole
|
|
|
|
{
|
|
|
|
if( m_Polygon.OutlineCount() == 0 )
|
2022-09-07 16:54:04 +00:00
|
|
|
ConvertShapeToPolygon( aParent );
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2022-01-28 22:51:34 +00:00
|
|
|
DrawFlashedPolygon( aParent, aDC, aColor, aFilledShape, aShapePos );
|
2021-07-16 20:13:26 +00:00
|
|
|
}
|
|
|
|
|
2010-09-28 14:42:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case APT_RECT:
|
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I start;
|
2010-09-28 19:34:16 +00:00
|
|
|
start.x = aShapePos.x - m_Size.x / 2;
|
|
|
|
start.y = aShapePos.y - m_Size.y / 2;
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I end = start + m_Size;
|
2010-10-10 17:57:54 +00:00
|
|
|
start = aParent->GetABPosition( start );
|
|
|
|
end = aParent->GetABPosition( end );
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2010-09-28 14:42:05 +00:00
|
|
|
if( !aFilledShape )
|
|
|
|
{
|
2022-01-28 22:51:34 +00:00
|
|
|
GRRect( aDC, start, end, 0, aColor );
|
2010-09-28 14:42:05 +00:00
|
|
|
}
|
2010-09-28 19:34:16 +00:00
|
|
|
else if( m_DrillShape == APT_DEF_NO_HOLE )
|
2010-09-28 14:42:05 +00:00
|
|
|
{
|
2022-01-28 22:51:34 +00:00
|
|
|
GRFilledRect( aDC, start, end, 0, aColor, aColor );
|
2010-09-28 14:42:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-09-17 22:43:20 +00:00
|
|
|
if( m_Polygon.OutlineCount() == 0 )
|
2022-09-07 16:54:04 +00:00
|
|
|
ConvertShapeToPolygon( aParent );
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2022-01-28 22:51:34 +00:00
|
|
|
DrawFlashedPolygon( aParent, aDC, aColor, aFilledShape, aShapePos );
|
2008-04-17 16:25:29 +00:00
|
|
|
}
|
|
|
|
}
|
2010-09-28 19:34:16 +00:00
|
|
|
break;
|
2010-09-28 14:42:05 +00:00
|
|
|
|
|
|
|
case APT_OVAL:
|
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I start = aShapePos;
|
|
|
|
VECTOR2I end = aShapePos;
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2010-09-28 14:42:05 +00:00
|
|
|
if( m_Size.x > m_Size.y ) // horizontal oval
|
|
|
|
{
|
2021-07-28 17:52:07 +00:00
|
|
|
int delta = ( m_Size.x - m_Size.y ) / 2;
|
2010-09-28 14:42:05 +00:00
|
|
|
start.x -= delta;
|
|
|
|
end.x += delta;
|
2020-04-10 13:57:02 +00:00
|
|
|
radius = m_Size.y; // Width in fact
|
2010-09-28 14:42:05 +00:00
|
|
|
}
|
2020-04-10 13:57:02 +00:00
|
|
|
else // vertical oval
|
2010-09-28 14:42:05 +00:00
|
|
|
{
|
2021-07-28 17:52:07 +00:00
|
|
|
int delta = ( m_Size.y - m_Size.x ) / 2;
|
2010-09-28 14:42:05 +00:00
|
|
|
start.y -= delta;
|
|
|
|
end.y += delta;
|
2020-04-10 13:57:02 +00:00
|
|
|
radius = m_Size.x; // Width in fact
|
2010-09-28 14:42:05 +00:00
|
|
|
}
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2010-10-10 17:57:54 +00:00
|
|
|
start = aParent->GetABPosition( start );
|
|
|
|
end = aParent->GetABPosition( end );
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2010-09-28 14:42:05 +00:00
|
|
|
if( !aFilledShape )
|
|
|
|
{
|
2022-01-28 22:51:34 +00:00
|
|
|
GRCSegm( aDC, start, end, radius, aColor );
|
2010-09-28 14:42:05 +00:00
|
|
|
}
|
2010-09-28 19:34:16 +00:00
|
|
|
else if( m_DrillShape == APT_DEF_NO_HOLE )
|
2010-09-28 14:42:05 +00:00
|
|
|
{
|
2022-01-28 22:51:34 +00:00
|
|
|
GRFilledSegment( aDC, start, end, radius, aColor );
|
2010-09-28 14:42:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-09-17 22:43:20 +00:00
|
|
|
if( m_Polygon.OutlineCount() == 0 )
|
2022-09-07 16:54:04 +00:00
|
|
|
ConvertShapeToPolygon( aParent );
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2022-01-28 22:51:34 +00:00
|
|
|
DrawFlashedPolygon( aParent, aDC, aColor, aFilledShape, aShapePos );
|
2010-09-28 14:42:05 +00:00
|
|
|
}
|
|
|
|
}
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2010-09-28 14:42:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case APT_POLYGON:
|
2017-09-17 22:43:20 +00:00
|
|
|
if( m_Polygon.OutlineCount() == 0 )
|
2022-09-07 16:54:04 +00:00
|
|
|
ConvertShapeToPolygon( aParent );
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2022-01-28 22:51:34 +00:00
|
|
|
DrawFlashedPolygon( aParent, aDC, aColor, aFilledShape, aShapePos );
|
2010-09-28 14:42:05 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-07 16:54:04 +00:00
|
|
|
void D_CODE::DrawFlashedPolygon( const GERBER_DRAW_ITEM* aParent, wxDC* aDC,
|
|
|
|
const COLOR4D& aColor,
|
2022-01-28 22:51:34 +00:00
|
|
|
bool aFilled, const VECTOR2I& aPosition )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2017-09-17 22:43:20 +00:00
|
|
|
if( m_Polygon.OutlineCount() == 0 )
|
2010-09-28 14:42:05 +00:00
|
|
|
return;
|
2009-11-09 14:00:22 +00:00
|
|
|
|
2017-09-17 22:43:20 +00:00
|
|
|
int pointCount = m_Polygon.VertexCount();
|
2022-01-01 06:04:08 +00:00
|
|
|
std::vector<VECTOR2I> points;
|
2017-09-17 22:43:20 +00:00
|
|
|
points.reserve( pointCount );
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2017-09-17 22:43:20 +00:00
|
|
|
for( int ii = 0; ii < pointCount; ii++ )
|
2010-09-28 14:42:05 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I p( m_Polygon.CVertex( ii ).x, m_Polygon.CVertex( ii ).y );
|
2017-09-17 22:43:20 +00:00
|
|
|
points[ii] = p + aPosition;
|
2010-10-10 17:57:54 +00:00
|
|
|
points[ii] = aParent->GetABPosition( points[ii] );
|
2010-09-28 14:42:05 +00:00
|
|
|
}
|
2008-04-17 16:25:29 +00:00
|
|
|
|
2022-01-28 22:51:34 +00:00
|
|
|
GRClosedPoly( aDC, pointCount, &points[0], aFilled, aColor );
|
2010-09-28 14:42:05 +00:00
|
|
|
}
|
|
|
|
|
2021-06-03 18:32:24 +00:00
|
|
|
|
2019-05-22 13:33:48 +00:00
|
|
|
// TODO(snh): Remove the hard-coded count
|
2017-09-17 22:43:20 +00:00
|
|
|
#define SEGS_CNT 64 // number of segments to approximate a circle
|
2010-09-28 19:34:16 +00:00
|
|
|
|
2011-10-17 20:01:27 +00:00
|
|
|
|
|
|
|
// A helper function for D_CODE::ConvertShapeToPolygon(). Add a hole to a polygon
|
2022-01-01 06:04:08 +00:00
|
|
|
static void addHoleToPolygon( SHAPE_POLY_SET* aPolygon, APERTURE_DEF_HOLETYPE aHoleShape,
|
|
|
|
const VECTOR2I& aSize, const VECTOR2I& aAnchorPos );
|
2010-09-28 19:34:16 +00:00
|
|
|
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2022-09-07 16:54:04 +00:00
|
|
|
void D_CODE::ConvertShapeToPolygon( const GERBER_DRAW_ITEM* aParent )
|
2010-09-28 14:42:05 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I initialpos;
|
|
|
|
VECTOR2I currpos;
|
2010-10-01 19:11:30 +00:00
|
|
|
|
2017-09-17 22:43:20 +00:00
|
|
|
m_Polygon.RemoveAllContours();
|
2010-09-28 14:42:05 +00:00
|
|
|
|
|
|
|
switch( m_Shape )
|
2008-04-17 16:25:29 +00:00
|
|
|
{
|
2010-09-28 14:42:05 +00:00
|
|
|
case APT_CIRCLE: // creates only a circle with rectangular hole
|
2020-10-13 10:55:24 +00:00
|
|
|
TransformCircleToPolygon( m_Polygon, initialpos, m_Size.x >> 1, ARC_HIGH_DEF,
|
|
|
|
ERROR_INSIDE );
|
2017-09-17 22:43:20 +00:00
|
|
|
addHoleToPolygon( &m_Polygon, m_DrillShape, m_Drill, initialpos );
|
2010-09-28 14:42:05 +00:00
|
|
|
break;
|
2008-11-08 06:44:07 +00:00
|
|
|
|
2010-09-28 14:42:05 +00:00
|
|
|
case APT_RECT:
|
2017-09-17 22:43:20 +00:00
|
|
|
m_Polygon.NewOutline();
|
2010-09-28 19:34:16 +00:00
|
|
|
currpos.x = m_Size.x / 2;
|
|
|
|
currpos.y = m_Size.y / 2;
|
2010-09-28 14:42:05 +00:00
|
|
|
initialpos = currpos;
|
2017-09-17 22:43:20 +00:00
|
|
|
m_Polygon.Append( VECTOR2I( currpos ) );
|
2010-09-28 14:42:05 +00:00
|
|
|
currpos.x -= m_Size.x;
|
2017-09-17 22:43:20 +00:00
|
|
|
m_Polygon.Append( VECTOR2I( currpos ) );
|
2010-09-28 14:42:05 +00:00
|
|
|
currpos.y -= m_Size.y;
|
2017-09-17 22:43:20 +00:00
|
|
|
m_Polygon.Append( VECTOR2I( currpos ) );
|
2010-09-28 14:42:05 +00:00
|
|
|
currpos.x += m_Size.x;
|
2017-09-17 22:43:20 +00:00
|
|
|
m_Polygon.Append( VECTOR2I( currpos ) );
|
2010-09-28 14:42:05 +00:00
|
|
|
currpos.y += m_Size.y;
|
2017-09-17 22:43:20 +00:00
|
|
|
m_Polygon.Append( VECTOR2I( currpos ) ); // close polygon
|
|
|
|
m_Polygon.Append( VECTOR2I( initialpos ) );
|
2010-09-28 19:34:16 +00:00
|
|
|
|
2017-09-17 22:43:20 +00:00
|
|
|
addHoleToPolygon( &m_Polygon, m_DrillShape, m_Drill, initialpos );
|
2010-09-28 14:42:05 +00:00
|
|
|
break;
|
2008-04-17 16:25:29 +00:00
|
|
|
|
2010-09-28 14:42:05 +00:00
|
|
|
case APT_OVAL:
|
|
|
|
{
|
2017-09-17 22:43:20 +00:00
|
|
|
m_Polygon.NewOutline();
|
2010-09-28 14:42:05 +00:00
|
|
|
int delta, radius;
|
|
|
|
|
|
|
|
// we create an horizontal oval shape. then rotate if needed
|
|
|
|
if( m_Size.x > m_Size.y ) // horizontal oval
|
2008-04-17 16:25:29 +00:00
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
delta = ( m_Size.x - m_Size.y ) / 2;
|
2010-09-28 14:42:05 +00:00
|
|
|
radius = m_Size.y / 2;
|
|
|
|
}
|
|
|
|
else // vertical oval
|
|
|
|
{
|
|
|
|
delta = (m_Size.y - m_Size.x) / 2;
|
|
|
|
radius = m_Size.x / 2;
|
|
|
|
}
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2010-09-28 14:42:05 +00:00
|
|
|
currpos.y = radius;
|
|
|
|
initialpos = currpos;
|
2017-09-17 22:43:20 +00:00
|
|
|
m_Polygon.Append( VECTOR2I( currpos ) );
|
2010-09-28 14:42:05 +00:00
|
|
|
|
|
|
|
// build the right arc of the shape
|
|
|
|
unsigned ii = 0;
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2010-09-28 14:42:05 +00:00
|
|
|
for( ; ii <= SEGS_CNT / 2; ii++ )
|
|
|
|
{
|
|
|
|
currpos = initialpos;
|
2022-01-18 02:14:09 +00:00
|
|
|
RotatePoint( currpos, ANGLE_360 * ii / SEGS_CNT );
|
2010-09-28 14:42:05 +00:00
|
|
|
currpos.x += delta;
|
2017-09-17 22:43:20 +00:00
|
|
|
m_Polygon.Append( VECTOR2I( currpos ) );
|
2010-09-28 14:42:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// build the left arc of the shape
|
|
|
|
for( ii = SEGS_CNT / 2; ii <= SEGS_CNT; ii++ )
|
|
|
|
{
|
|
|
|
currpos = initialpos;
|
2022-01-18 02:14:09 +00:00
|
|
|
RotatePoint( currpos, ANGLE_360 * ii / SEGS_CNT );
|
2010-09-28 14:42:05 +00:00
|
|
|
currpos.x -= delta;
|
2022-01-18 02:14:09 +00:00
|
|
|
m_Polygon.Append( currpos );
|
2010-09-28 14:42:05 +00:00
|
|
|
}
|
2010-09-28 19:34:16 +00:00
|
|
|
|
2022-01-18 02:14:09 +00:00
|
|
|
m_Polygon.Append( initialpos ); // close outline
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2010-09-28 19:34:16 +00:00
|
|
|
if( m_Size.y > m_Size.x ) // vertical oval, rotate polygon.
|
2022-01-20 20:54:22 +00:00
|
|
|
m_Polygon.Rotate( ANGLE_90 );
|
2010-09-28 19:34:16 +00:00
|
|
|
|
2017-09-17 22:43:20 +00:00
|
|
|
addHoleToPolygon( &m_Polygon, m_DrillShape, m_Drill, initialpos );
|
2010-09-28 19:34:16 +00:00
|
|
|
}
|
2022-09-07 16:54:04 +00:00
|
|
|
break;
|
2010-09-28 19:34:16 +00:00
|
|
|
|
|
|
|
case APT_POLYGON:
|
2017-09-17 22:43:20 +00:00
|
|
|
m_Polygon.NewOutline();
|
2010-09-28 19:34:16 +00:00
|
|
|
currpos.x = m_Size.x >> 1; // first point is on X axis
|
|
|
|
initialpos = currpos;
|
2010-10-01 19:11:30 +00:00
|
|
|
|
2010-09-28 19:34:16 +00:00
|
|
|
// rs274x said: m_EdgesCount = 3 ... 12
|
|
|
|
if( m_EdgesCount < 3 )
|
|
|
|
m_EdgesCount = 3;
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2010-09-28 19:34:16 +00:00
|
|
|
if( m_EdgesCount > 12 )
|
|
|
|
m_EdgesCount = 12;
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2017-09-17 22:43:20 +00:00
|
|
|
for( int ii = 0; ii < m_EdgesCount; ii++ )
|
2010-09-28 14:42:05 +00:00
|
|
|
{
|
2010-09-28 19:34:16 +00:00
|
|
|
currpos = initialpos;
|
2022-01-18 02:14:09 +00:00
|
|
|
RotatePoint( currpos, ANGLE_360 * ii / m_EdgesCount );
|
|
|
|
m_Polygon.Append( currpos );
|
2010-09-28 14:42:05 +00:00
|
|
|
}
|
2010-10-01 19:11:30 +00:00
|
|
|
|
2017-09-17 22:43:20 +00:00
|
|
|
addHoleToPolygon( &m_Polygon, m_DrillShape, m_Drill, initialpos );
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2022-01-20 20:54:22 +00:00
|
|
|
if( !m_Rotation.IsZero() ) // rotate polygonal shape:
|
|
|
|
m_Polygon.Rotate( m_Rotation );
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2010-09-28 14:42:05 +00:00
|
|
|
break;
|
2008-04-17 16:25:29 +00:00
|
|
|
|
2010-09-28 14:42:05 +00:00
|
|
|
case APT_MACRO:
|
2022-09-07 16:54:04 +00:00
|
|
|
APERTURE_MACRO* macro = GetMacro();
|
|
|
|
SHAPE_POLY_SET* macroShape = macro->GetApertureMacroShape( aParent, initialpos );
|
|
|
|
m_Polygon.Append( *macroShape );
|
2010-09-28 14:42:05 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2010-09-28 19:34:16 +00:00
|
|
|
|
2010-10-01 19:11:30 +00:00
|
|
|
|
2010-09-28 19:34:16 +00:00
|
|
|
// The helper function for D_CODE::ConvertShapeToPolygon().
|
|
|
|
// Add a hole to a polygon
|
2022-01-01 06:04:08 +00:00
|
|
|
static void addHoleToPolygon( SHAPE_POLY_SET* aPolygon, APERTURE_DEF_HOLETYPE aHoleShape,
|
|
|
|
const VECTOR2I& aSize, const VECTOR2I& aAnchorPos )
|
2010-09-28 19:34:16 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I currpos;
|
2017-09-17 22:43:20 +00:00
|
|
|
SHAPE_POLY_SET holeBuffer;
|
2010-10-01 19:11:30 +00:00
|
|
|
|
2017-09-17 22:43:20 +00:00
|
|
|
if( aHoleShape == APT_DEF_ROUND_HOLE )
|
2010-09-28 19:34:16 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
TransformCircleToPolygon( holeBuffer, VECTOR2I( 0, 0 ), aSize.x / 2, ARC_HIGH_DEF,
|
2020-10-13 10:55:24 +00:00
|
|
|
ERROR_INSIDE );
|
2010-09-28 19:34:16 +00:00
|
|
|
}
|
2017-09-17 22:43:20 +00:00
|
|
|
else if( aHoleShape == APT_DEF_RECT_HOLE )
|
2010-09-28 19:34:16 +00:00
|
|
|
{
|
2017-09-17 22:43:20 +00:00
|
|
|
holeBuffer.NewOutline();
|
2010-09-28 19:34:16 +00:00
|
|
|
currpos.x = aSize.x / 2;
|
|
|
|
currpos.y = aSize.y / 2;
|
2017-09-17 22:43:20 +00:00
|
|
|
holeBuffer.Append( VECTOR2I( currpos ) ); // link to hole and begin hole
|
2010-09-28 19:34:16 +00:00
|
|
|
currpos.x -= aSize.x;
|
2017-09-17 22:43:20 +00:00
|
|
|
holeBuffer.Append( VECTOR2I( currpos ) );
|
2010-09-28 19:34:16 +00:00
|
|
|
currpos.y -= aSize.y;
|
2017-09-17 22:43:20 +00:00
|
|
|
holeBuffer.Append( VECTOR2I( currpos ) );
|
2010-09-28 19:34:16 +00:00
|
|
|
currpos.x += aSize.x;
|
2017-09-17 22:43:20 +00:00
|
|
|
holeBuffer.Append( VECTOR2I( currpos ) );
|
2010-09-28 19:34:16 +00:00
|
|
|
currpos.y += aSize.y;
|
2017-09-17 22:43:20 +00:00
|
|
|
holeBuffer.Append( VECTOR2I( currpos ) ); // close hole
|
2010-09-28 19:34:16 +00:00
|
|
|
}
|
2017-09-17 22:43:20 +00:00
|
|
|
|
|
|
|
aPolygon->BooleanSubtract( holeBuffer, SHAPE_POLY_SET::PM_FAST );
|
2019-12-14 09:14:50 +00:00
|
|
|
aPolygon->Fracture( SHAPE_POLY_SET::PM_FAST );
|
2010-09-28 19:34:16 +00:00
|
|
|
}
|