2014-10-19 20:20:16 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2019-01-27 08:49:40 +00:00
|
|
|
* Copyright (C) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2021-01-30 08:59:53 +00:00
|
|
|
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2014-10-19 20:20:16 +00:00
|
|
|
*
|
2020-09-23 18:58:13 +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 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
2014-10-19 20:20:16 +00:00
|
|
|
*
|
2020-09-23 18:58:13 +00:00
|
|
|
* 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.
|
2014-10-19 20:20:16 +00:00
|
|
|
*
|
2020-09-23 18:58:13 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
2014-10-19 20:20:16 +00:00
|
|
|
*/
|
|
|
|
|
2011-09-20 13:57:40 +00:00
|
|
|
/**
|
2018-05-17 15:32:14 +00:00
|
|
|
* @file GERBER_plotter.cpp
|
|
|
|
* @brief specialized plotter for GERBER files format
|
2011-09-20 13:57:40 +00:00
|
|
|
*/
|
2008-12-23 07:37:39 +00:00
|
|
|
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2016-02-10 16:02:40 +00:00
|
|
|
#include <convert_basic_shapes_to_polygon.h>
|
2020-10-24 14:45:37 +00:00
|
|
|
#include <macros.h>
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <math/util.h> // for KiROUND
|
2020-10-14 03:37:48 +00:00
|
|
|
#include <trigo.h>
|
2021-06-03 12:11:15 +00:00
|
|
|
#include <wx/log.h>
|
2008-12-23 07:37:39 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <build_version.h>
|
2010-01-05 08:48:49 +00:00
|
|
|
|
2021-08-18 20:38:14 +00:00
|
|
|
#include <plotters/plotter_gerber.h>
|
|
|
|
#include <plotters/gbr_plotter_aperture_macros.h>
|
2020-09-23 18:58:13 +00:00
|
|
|
|
2018-05-17 05:49:38 +00:00
|
|
|
#include <gbr_metadata.h>
|
2016-09-19 11:01:36 +00:00
|
|
|
|
2021-01-30 08:59:53 +00:00
|
|
|
|
2020-09-28 13:36:52 +00:00
|
|
|
// if GBR_USE_MACROS is defined, pads having a shape that is not a Gerber primitive
|
|
|
|
// will use a macro when possible
|
2020-10-05 08:52:47 +00:00
|
|
|
// Old code will be removed only after many tests
|
2020-10-10 12:39:54 +00:00
|
|
|
//
|
|
|
|
// Note also: setting m_gerberDisableApertMacros to true disable all aperture macros
|
|
|
|
// in Gerber files
|
|
|
|
//
|
2020-10-11 10:53:45 +00:00
|
|
|
#define GBR_USE_MACROS_FOR_CHAMFERED_ROUND_RECT
|
2020-10-08 12:51:25 +00:00
|
|
|
#define GBR_USE_MACROS_FOR_CHAMFERED_RECT
|
2020-10-05 18:34:33 +00:00
|
|
|
#define GBR_USE_MACROS_FOR_ROUNDRECT
|
|
|
|
#define GBR_USE_MACROS_FOR_TRAPEZOID
|
|
|
|
#define GBR_USE_MACROS_FOR_ROTATED_OVAL
|
|
|
|
#define GBR_USE_MACROS_FOR_ROTATED_RECT
|
2021-01-30 08:59:53 +00:00
|
|
|
#define GBR_USE_MACROS_FOR_CUSTOM_PAD
|
2021-01-23 17:02:58 +00:00
|
|
|
|
|
|
|
// max count of corners to create a aperture macro for a custom shape.
|
|
|
|
// provided just in case a aperture macro type free polygon creates issues
|
|
|
|
// when the number of corners is too high.
|
|
|
|
// (1 corner = up to 24 chars)
|
2021-01-30 08:59:53 +00:00
|
|
|
// Gerber doc say max corners 5000. We use a slightly smaller value.
|
|
|
|
// if a custom shape needs more than GBR_MACRO_FOR_CUSTOM_PAD_MAX_CORNER_COUNT, it
|
|
|
|
// will be plot using a region.
|
|
|
|
#define GBR_MACRO_FOR_CUSTOM_PAD_MAX_CORNER_COUNT 4990
|
|
|
|
#define AM_FREEPOLY_BASENAME "FreePoly"
|
|
|
|
|
2021-06-07 18:31:53 +00:00
|
|
|
|
|
|
|
// A helper function to compare 2 polygons: polygons are similar if they have the same
|
2021-01-30 08:59:53 +00:00
|
|
|
// number of vertices and each vertex coordinate are similar, i.e. if the difference
|
|
|
|
// between coordinates is small ( <= margin to accept rounding issues coming from polygon
|
|
|
|
// geometric transforms like rotation
|
|
|
|
static bool polyCompare( const std::vector<wxPoint>& aPolygon,
|
|
|
|
const std::vector<wxPoint>& aTestPolygon )
|
|
|
|
{
|
|
|
|
// fast test: polygon sizes must be the same:
|
|
|
|
if( aTestPolygon.size() != aPolygon.size() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const int margin = 2;
|
|
|
|
|
|
|
|
for( size_t jj = 0; jj < aPolygon.size(); jj++ )
|
|
|
|
{
|
|
|
|
if( std::abs( aPolygon[jj].x - aTestPolygon[jj].x ) > margin ||
|
|
|
|
std::abs( aPolygon[jj].y - aTestPolygon[jj].y ) > margin )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-10-19 20:20:16 +00:00
|
|
|
|
2014-07-04 14:22:38 +00:00
|
|
|
GERBER_PLOTTER::GERBER_PLOTTER()
|
|
|
|
{
|
2021-04-22 21:20:34 +00:00
|
|
|
workFile = nullptr;
|
|
|
|
finalFile = nullptr;
|
2019-11-03 19:23:31 +00:00
|
|
|
m_currentApertureIdx = -1;
|
2016-09-19 11:01:36 +00:00
|
|
|
m_apertureAttribute = 0;
|
2014-07-04 14:22:38 +00:00
|
|
|
|
|
|
|
// number of digits after the point (number of digits of the mantissa
|
2021-04-05 13:24:57 +00:00
|
|
|
// Be careful: the Gerber coordinates are stored in an integer
|
2014-07-04 14:22:38 +00:00
|
|
|
// so 6 digits (inches) or 5 digits (mm) is a good value
|
|
|
|
// To avoid overflow, 7 digits (inches) or 6 digits is a max.
|
|
|
|
// with lower values than 6 digits (inches) or 5 digits (mm),
|
|
|
|
// Creating self-intersecting polygons from non-intersecting polygons
|
|
|
|
// happen easily.
|
|
|
|
m_gerberUnitInch = false;
|
|
|
|
m_gerberUnitFmt = 6;
|
2018-12-09 09:23:07 +00:00
|
|
|
m_useX2format = true;
|
2016-09-19 11:01:36 +00:00
|
|
|
m_useNetAttributes = true;
|
2020-10-10 12:39:54 +00:00
|
|
|
m_gerberDisableApertMacros = false;
|
2020-10-03 10:47:41 +00:00
|
|
|
|
|
|
|
m_hasApertureRoundRect = false; // true is at least one round rect aperture is in use
|
|
|
|
m_hasApertureRotOval = false; // true is at least one oval rotated aperture is in use
|
|
|
|
m_hasApertureRotRect = false; // true is at least one rect. rotated aperture is in use
|
2020-10-08 12:51:25 +00:00
|
|
|
m_hasApertureOutline4P = false; // true is at least one rotated rect or trapezoid pad
|
|
|
|
// aperture is in use
|
|
|
|
m_hasApertureChamferedRect = false; // true is at least one chamfered rect
|
|
|
|
// (no rounded corner) is in use
|
2014-07-04 14:22:38 +00:00
|
|
|
}
|
2008-12-23 07:37:39 +00:00
|
|
|
|
2014-10-19 20:20:16 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
void GERBER_PLOTTER::SetViewport( const wxPoint& aOffset, double aIusPerDecimil,
|
2021-06-07 18:31:53 +00:00
|
|
|
double aScale, bool aMirror )
|
2008-12-23 07:37:39 +00:00
|
|
|
{
|
2010-12-11 18:40:39 +00:00
|
|
|
wxASSERT( aMirror == false );
|
2013-12-06 18:31:15 +00:00
|
|
|
m_plotMirror = false;
|
2020-11-16 00:04:55 +00:00
|
|
|
m_plotOffset = aOffset;
|
|
|
|
wxASSERT( aScale == 1 ); // aScale parameter is not used in Gerber
|
|
|
|
m_plotScale = 1; // Plot scale is *always* 1.0
|
2014-06-30 10:00:21 +00:00
|
|
|
|
2012-08-29 20:13:47 +00:00
|
|
|
m_IUsPerDecimil = aIusPerDecimil;
|
2021-06-07 18:31:53 +00:00
|
|
|
|
2014-07-21 09:42:36 +00:00
|
|
|
// gives now a default value to iuPerDeviceUnit (because the units of the caller is now known)
|
|
|
|
// which could be modified later by calling SetGerberCoordinatesFormat()
|
2020-11-16 00:04:55 +00:00
|
|
|
m_iuPerDeviceUnit = pow( 10.0, m_gerberUnitFmt ) / ( m_IUsPerDecimil * 10000.0 );
|
2014-06-30 10:00:21 +00:00
|
|
|
|
2014-07-04 14:22:38 +00:00
|
|
|
// We don't handle the filmbox, and it's more useful to keep the
|
|
|
|
// origin at the origin
|
2020-11-16 00:04:55 +00:00
|
|
|
m_paperSize.x = 0;
|
|
|
|
m_paperSize.y = 0;
|
2008-12-23 07:37:39 +00:00
|
|
|
}
|
|
|
|
|
2014-10-19 20:20:16 +00:00
|
|
|
|
2014-07-04 14:22:38 +00:00
|
|
|
void GERBER_PLOTTER::SetGerberCoordinatesFormat( int aResolution, bool aUseInches )
|
|
|
|
{
|
|
|
|
m_gerberUnitInch = aUseInches;
|
|
|
|
m_gerberUnitFmt = aResolution;
|
|
|
|
|
2020-11-16 00:04:55 +00:00
|
|
|
m_iuPerDeviceUnit = pow( 10.0, m_gerberUnitFmt ) / ( m_IUsPerDecimil * 10000.0 );
|
2014-07-04 14:22:38 +00:00
|
|
|
|
|
|
|
if( ! m_gerberUnitInch )
|
2020-11-16 00:04:55 +00:00
|
|
|
m_iuPerDeviceUnit *= 25.4; // gerber output in mm
|
2014-07-04 14:22:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
void GERBER_PLOTTER::emitDcode( const DPOINT& pt, int dcode )
|
|
|
|
{
|
|
|
|
|
2020-11-16 00:04:55 +00:00
|
|
|
fprintf( m_outputFile, "X%dY%dD%02d*\n", KiROUND( pt.x ), KiROUND( pt.y ), dcode );
|
2012-05-03 18:37:56 +00:00
|
|
|
}
|
2008-12-23 07:37:39 +00:00
|
|
|
|
2019-10-06 11:39:50 +00:00
|
|
|
void GERBER_PLOTTER::ClearAllAttributes()
|
|
|
|
{
|
|
|
|
// Remove all attributes from object attributes dictionary (TO. and TA commands)
|
|
|
|
if( m_useX2format )
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( "%TD*%\n", m_outputFile );
|
2019-10-06 11:39:50 +00:00
|
|
|
else
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( "G04 #@! TD*\n", m_outputFile );
|
2019-10-06 11:39:50 +00:00
|
|
|
|
2021-04-05 13:24:57 +00:00
|
|
|
m_objectAttributesDictionary.clear();
|
2019-10-06 11:39:50 +00:00
|
|
|
}
|
|
|
|
|
2014-10-19 20:20:16 +00:00
|
|
|
|
2016-09-19 11:01:36 +00:00
|
|
|
void GERBER_PLOTTER::clearNetAttribute()
|
|
|
|
{
|
|
|
|
// disable a Gerber net attribute (exists only in X2 with net attributes mode).
|
2021-04-05 13:24:57 +00:00
|
|
|
if( m_objectAttributesDictionary.empty() ) // No net attribute or not X2 mode
|
2016-09-19 11:01:36 +00:00
|
|
|
return;
|
|
|
|
|
2019-08-20 17:22:30 +00:00
|
|
|
// Remove all net attributes from object attributes dictionary
|
2018-12-09 09:23:07 +00:00
|
|
|
if( m_useX2format )
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( "%TD*%\n", m_outputFile );
|
2018-05-17 15:32:14 +00:00
|
|
|
else
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( "G04 #@! TD*\n", m_outputFile );
|
2016-09-19 11:01:36 +00:00
|
|
|
|
2021-04-05 13:24:57 +00:00
|
|
|
m_objectAttributesDictionary.clear();
|
2016-09-19 11:01:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GERBER_PLOTTER::StartBlock( void* aData )
|
|
|
|
{
|
|
|
|
// Currently, it is the same as EndBlock(): clear all aperture net attributes
|
|
|
|
EndBlock( aData );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GERBER_PLOTTER::EndBlock( void* aData )
|
|
|
|
{
|
2019-08-20 17:22:30 +00:00
|
|
|
// Remove all net attributes from object attributes dictionary
|
2016-09-19 11:01:36 +00:00
|
|
|
clearNetAttribute();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GERBER_PLOTTER::formatNetAttribute( GBR_NETLIST_METADATA* aData )
|
|
|
|
{
|
|
|
|
// print a Gerber net attribute record.
|
2019-08-20 17:22:30 +00:00
|
|
|
// it is added to the object attributes dictionary
|
2016-09-19 11:01:36 +00:00
|
|
|
// On file, only modified or new attributes are printed.
|
2021-04-22 21:20:34 +00:00
|
|
|
if( aData == nullptr )
|
2018-05-17 15:32:14 +00:00
|
|
|
return;
|
|
|
|
|
2018-12-08 16:46:41 +00:00
|
|
|
if( !m_useNetAttributes )
|
2016-09-19 11:01:36 +00:00
|
|
|
return;
|
|
|
|
|
2018-12-09 09:23:07 +00:00
|
|
|
bool useX1StructuredComment = !m_useX2format;
|
2018-12-08 16:46:41 +00:00
|
|
|
|
2016-09-19 11:01:36 +00:00
|
|
|
bool clearDict;
|
|
|
|
std::string short_attribute_string;
|
|
|
|
|
2021-04-05 13:24:57 +00:00
|
|
|
if( !FormatNetAttribute( short_attribute_string, m_objectAttributesDictionary,
|
2018-05-17 15:32:14 +00:00
|
|
|
aData, clearDict, useX1StructuredComment ) )
|
2016-09-19 11:01:36 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if( clearDict )
|
|
|
|
clearNetAttribute();
|
|
|
|
|
|
|
|
if( !short_attribute_string.empty() )
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( short_attribute_string.c_str(), m_outputFile );
|
2019-09-18 09:48:49 +00:00
|
|
|
|
|
|
|
if( m_useX2format && !aData->m_ExtraData.IsEmpty() )
|
|
|
|
{
|
|
|
|
std::string extra_data = TO_UTF8( aData->m_ExtraData );
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( extra_data.c_str(), m_outputFile );
|
2019-09-18 09:48:49 +00:00
|
|
|
}
|
2016-09-19 11:01:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-13 18:54:33 +00:00
|
|
|
bool GERBER_PLOTTER::StartPlot()
|
2008-12-23 07:37:39 +00:00
|
|
|
{
|
2020-10-03 10:47:41 +00:00
|
|
|
m_hasApertureRoundRect = false; // true is at least one round rect aperture is in use
|
|
|
|
m_hasApertureRotOval = false; // true is at least one oval rotated aperture is in use
|
|
|
|
m_hasApertureRotRect = false; // true is at least one rect. rotated aperture is in use
|
2021-06-07 18:31:53 +00:00
|
|
|
m_hasApertureOutline4P = false; // true is at least one rotated rect/trapezoid aperture
|
|
|
|
// is in use
|
2020-11-16 00:04:55 +00:00
|
|
|
m_hasApertureChamferedRect = false; // true is at least one chamfered rect is in use
|
2021-01-30 08:59:53 +00:00
|
|
|
m_am_freepoly_list.ClearList();
|
2020-10-03 10:47:41 +00:00
|
|
|
|
2020-11-16 00:04:55 +00:00
|
|
|
wxASSERT( m_outputFile );
|
2012-10-13 18:54:33 +00:00
|
|
|
|
2020-11-16 00:04:55 +00:00
|
|
|
finalFile = m_outputFile; // the actual gerber file will be created later
|
2010-03-31 16:59:32 +00:00
|
|
|
|
2021-06-07 18:31:53 +00:00
|
|
|
// Create a temp file in system temp to avoid potential network share buffer issues for
|
|
|
|
// the final read and save.
|
2020-08-20 03:46:25 +00:00
|
|
|
m_workFilename = wxFileName::CreateTempFileName( "" );
|
2012-05-03 18:37:56 +00:00
|
|
|
workFile = wxFopen( m_workFilename, wxT( "wt" ));
|
2020-11-16 00:04:55 +00:00
|
|
|
m_outputFile = workFile;
|
|
|
|
wxASSERT( m_outputFile );
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2021-04-22 21:20:34 +00:00
|
|
|
if( m_outputFile == nullptr )
|
2010-03-31 16:59:32 +00:00
|
|
|
return false;
|
|
|
|
|
2015-03-25 13:07:05 +00:00
|
|
|
for( unsigned ii = 0; ii < m_headerExtraLines.GetCount(); ii++ )
|
2014-06-19 06:26:53 +00:00
|
|
|
{
|
2015-03-25 13:07:05 +00:00
|
|
|
if( ! m_headerExtraLines[ii].IsEmpty() )
|
2020-11-16 00:04:55 +00:00
|
|
|
fprintf( m_outputFile, "%s\n", TO_UTF8( m_headerExtraLines[ii] ) );
|
2014-06-19 06:26:53 +00:00
|
|
|
}
|
|
|
|
|
2014-06-30 10:00:21 +00:00
|
|
|
// Set coordinate format to 3.6 or 4.5 absolute, leading zero omitted
|
2019-08-20 17:22:30 +00:00
|
|
|
// the number of digits for the integer part of coordinates is needed
|
2014-06-30 10:00:21 +00:00
|
|
|
// in gerber format, but is not very important when omitting leading zeros
|
|
|
|
// It is fixed here to 3 (inch) or 4 (mm), but is not actually used
|
|
|
|
int leadingDigitCount = m_gerberUnitInch ? 3 : 4;
|
|
|
|
|
2020-11-16 00:04:55 +00:00
|
|
|
fprintf( m_outputFile, "%%FSLAX%d%dY%d%d*%%\n",
|
2014-06-30 10:00:21 +00:00
|
|
|
leadingDigitCount, m_gerberUnitFmt,
|
|
|
|
leadingDigitCount, m_gerberUnitFmt );
|
2020-11-16 00:04:55 +00:00
|
|
|
fprintf( m_outputFile,
|
2014-06-30 10:00:21 +00:00
|
|
|
"G04 Gerber Fmt %d.%d, Leading zero omitted, Abs format (unit %s)*\n",
|
|
|
|
leadingDigitCount, m_gerberUnitFmt,
|
|
|
|
m_gerberUnitInch ? "inch" : "mm" );
|
2013-10-04 08:42:09 +00:00
|
|
|
|
2020-11-16 00:04:55 +00:00
|
|
|
wxString Title = m_creator + wxT( " " ) + GetBuildVersion();
|
2021-06-07 18:31:53 +00:00
|
|
|
|
2019-01-27 08:49:40 +00:00
|
|
|
// In gerber files, ASCII7 chars only are allowed.
|
|
|
|
// So use a ISO date format (using a space as separator between date and time),
|
|
|
|
// not a localized date format
|
|
|
|
wxDateTime date = wxDateTime::Now();
|
2020-11-16 00:04:55 +00:00
|
|
|
fprintf( m_outputFile, "G04 Created by KiCad (%s) date %s*\n",
|
2019-01-27 08:49:40 +00:00
|
|
|
TO_UTF8( Title ), TO_UTF8( date.FormatISOCombined( ' ') ) );
|
2008-12-23 07:37:39 +00:00
|
|
|
|
2014-06-30 10:00:21 +00:00
|
|
|
/* Mass parameter: unit = INCHES/MM */
|
|
|
|
if( m_gerberUnitInch )
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( "%MOIN*%\n", m_outputFile );
|
2014-06-30 10:00:21 +00:00
|
|
|
else
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( "%MOMM*%\n", m_outputFile );
|
2008-12-23 07:37:39 +00:00
|
|
|
|
2016-04-14 07:32:35 +00:00
|
|
|
// Be sure the usual dark polarity is selected:
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( "%LPD*%\n", m_outputFile );
|
2016-04-14 07:32:35 +00:00
|
|
|
|
2020-02-03 16:40:08 +00:00
|
|
|
// Set initial interpolation mode: always G01 (linear):
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( "G01*\n", m_outputFile );
|
2020-02-03 16:40:08 +00:00
|
|
|
|
2020-09-28 13:36:52 +00:00
|
|
|
// Add aperture list start point
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( "G04 APERTURE LIST*\n", m_outputFile );
|
2010-03-31 16:59:32 +00:00
|
|
|
|
2020-09-28 13:36:52 +00:00
|
|
|
// Give a minimal value to the default pen size, used to plot items in sketch mode
|
|
|
|
if( m_renderSettings )
|
|
|
|
{
|
|
|
|
const int pen_min = 0.1 * m_IUsPerDecimil * 10000 / 25.4; // for min width = 0.1 mm
|
|
|
|
m_renderSettings->SetDefaultPenWidth( std::max( m_renderSettings->GetDefaultPenWidth(),
|
|
|
|
pen_min ) );
|
|
|
|
}
|
|
|
|
|
2010-03-31 16:59:32 +00:00
|
|
|
return true;
|
2008-12-23 07:37:39 +00:00
|
|
|
}
|
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
bool GERBER_PLOTTER::EndPlot()
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
|
|
|
char line[1024];
|
|
|
|
wxString msg;
|
|
|
|
|
2020-11-16 00:04:55 +00:00
|
|
|
wxASSERT( m_outputFile );
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
/* Outfile is actually a temporary file i.e. workFile */
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( "M02*\n", m_outputFile );
|
|
|
|
fflush( m_outputFile );
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
fclose( workFile );
|
|
|
|
workFile = wxFopen( m_workFilename, wxT( "rt" ));
|
|
|
|
wxASSERT( workFile );
|
2020-11-16 00:04:55 +00:00
|
|
|
m_outputFile = finalFile;
|
2008-12-23 07:37:39 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
// Placement of apertures in RS274X
|
2012-05-03 18:37:56 +00:00
|
|
|
while( fgets( line, 1024, workFile ) )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( line, m_outputFile );
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2019-09-15 09:10:53 +00:00
|
|
|
char* substr = strtok( line, "\n\r" );
|
|
|
|
|
|
|
|
if( substr && strcmp( substr, "G04 APERTURE LIST*" ) == 0 )
|
2009-06-28 18:13:55 +00:00
|
|
|
{
|
2020-09-28 13:36:52 +00:00
|
|
|
// Add aperture list macro:
|
|
|
|
if( m_hasApertureRoundRect | m_hasApertureRotOval ||
|
2020-10-08 12:51:25 +00:00
|
|
|
m_hasApertureOutline4P || m_hasApertureRotRect ||
|
2021-01-30 08:59:53 +00:00
|
|
|
m_hasApertureChamferedRect || m_am_freepoly_list.AmCount() )
|
2020-09-28 13:36:52 +00:00
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( "G04 Aperture macros list*\n", m_outputFile );
|
2020-09-28 13:36:52 +00:00
|
|
|
|
|
|
|
if( m_hasApertureRoundRect )
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( APER_MACRO_ROUNDRECT_HEADER, m_outputFile );
|
2020-09-28 13:36:52 +00:00
|
|
|
|
|
|
|
if( m_hasApertureRotOval )
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( APER_MACRO_SHAPE_OVAL_HEADER, m_outputFile );
|
2020-09-28 13:36:52 +00:00
|
|
|
|
|
|
|
if( m_hasApertureRotRect )
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( APER_MACRO_ROT_RECT_HEADER, m_outputFile );
|
2020-09-28 13:36:52 +00:00
|
|
|
|
2020-10-08 12:51:25 +00:00
|
|
|
if( m_hasApertureOutline4P )
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( APER_MACRO_OUTLINE4P_HEADER, m_outputFile );
|
2020-09-28 13:36:52 +00:00
|
|
|
|
2020-10-08 12:51:25 +00:00
|
|
|
if( m_hasApertureChamferedRect )
|
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( APER_MACRO_OUTLINE5P_HEADER, m_outputFile );
|
|
|
|
fputs( APER_MACRO_OUTLINE6P_HEADER, m_outputFile );
|
|
|
|
fputs( APER_MACRO_OUTLINE7P_HEADER, m_outputFile );
|
|
|
|
fputs( APER_MACRO_OUTLINE8P_HEADER, m_outputFile );
|
2020-10-08 12:51:25 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 08:59:53 +00:00
|
|
|
if( m_am_freepoly_list.AmCount() )
|
|
|
|
{
|
2021-06-07 18:31:53 +00:00
|
|
|
// aperture sizes are in inch or mm, regardless the
|
2021-01-30 08:59:53 +00:00
|
|
|
// coordinates format
|
|
|
|
double fscale = 0.0001 * m_plotScale / m_IUsPerDecimil; // inches
|
|
|
|
|
|
|
|
if(! m_gerberUnitInch )
|
|
|
|
fscale *= 25.4; // size in mm
|
|
|
|
|
|
|
|
m_am_freepoly_list.Format( m_outputFile, fscale );
|
|
|
|
}
|
|
|
|
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( "G04 Aperture macros list end*\n", m_outputFile );
|
2020-09-28 13:36:52 +00:00
|
|
|
}
|
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
writeApertureList();
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( "G04 APERTURE END LIST*\n", m_outputFile );
|
2009-06-28 18:13:55 +00:00
|
|
|
}
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
fclose( workFile );
|
|
|
|
fclose( finalFile );
|
2010-03-31 16:59:32 +00:00
|
|
|
::wxRemoveFile( m_workFilename );
|
2021-04-22 21:20:34 +00:00
|
|
|
m_outputFile = nullptr;
|
2010-03-31 16:59:32 +00:00
|
|
|
|
|
|
|
return true;
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
void GERBER_PLOTTER::SetCurrentLineWidth( int aWidth, void* aData )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2020-04-20 22:41:18 +00:00
|
|
|
if( aWidth == DO_NOT_SET_LINE_WIDTH )
|
|
|
|
return;
|
2020-05-13 16:44:21 +00:00
|
|
|
else if( aWidth == USE_DEFAULT_LINE_WIDTH )
|
2020-09-28 13:36:52 +00:00
|
|
|
aWidth = m_renderSettings->GetDefaultPenWidth();
|
2020-05-13 16:44:21 +00:00
|
|
|
|
|
|
|
wxASSERT_MSG( aWidth >= 0, "Plotter called to set negative pen width" );
|
2020-04-20 22:41:18 +00:00
|
|
|
|
2016-09-19 11:01:36 +00:00
|
|
|
GBR_METADATA* gbr_metadata = static_cast<GBR_METADATA*>( aData );
|
|
|
|
int aperture_attribute = gbr_metadata ? gbr_metadata->GetApertureAttrib() : 0;
|
|
|
|
|
2020-09-28 13:36:52 +00:00
|
|
|
selectAperture( wxSize( aWidth, aWidth ), 0, 0.0, APERTURE::AT_PLOTTING, aperture_attribute );
|
2020-11-16 00:04:55 +00:00
|
|
|
m_currentPenWidth = aWidth;
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2020-09-28 13:36:52 +00:00
|
|
|
int GERBER_PLOTTER::GetOrCreateAperture( const wxSize& aSize, int aRadius, double aRotDegree,
|
2016-09-19 11:01:36 +00:00
|
|
|
APERTURE::APERTURE_TYPE aType, int aApertureAttribute )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
|
|
|
int last_D_code = 9;
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
// Search an existing aperture
|
2019-11-03 19:23:31 +00:00
|
|
|
for( int idx = 0; idx < (int)m_apertures.size(); ++idx )
|
2009-06-28 18:13:55 +00:00
|
|
|
{
|
2019-11-03 19:23:31 +00:00
|
|
|
APERTURE* tool = &m_apertures[idx];
|
2016-09-19 11:01:36 +00:00
|
|
|
last_D_code = tool->m_DCode;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2018-05-17 15:32:14 +00:00
|
|
|
if( (tool->m_Type == aType) && (tool->m_Size == aSize) &&
|
2020-09-28 13:36:52 +00:00
|
|
|
(tool->m_Radius == aRadius) && (tool->m_Rotation == aRotDegree) &&
|
2018-05-17 15:32:14 +00:00
|
|
|
(tool->m_ApertureAttribute == aApertureAttribute) )
|
2019-11-03 19:23:31 +00:00
|
|
|
return idx;
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
// Allocate a new aperture
|
2009-08-29 10:20:48 +00:00
|
|
|
APERTURE new_tool;
|
2016-09-19 11:01:36 +00:00
|
|
|
new_tool.m_Size = aSize;
|
|
|
|
new_tool.m_Type = aType;
|
2020-09-28 13:36:52 +00:00
|
|
|
new_tool.m_Radius = aRadius;
|
|
|
|
new_tool.m_Rotation = aRotDegree;
|
2016-09-19 11:01:36 +00:00
|
|
|
new_tool.m_DCode = last_D_code + 1;
|
|
|
|
new_tool.m_ApertureAttribute = aApertureAttribute;
|
|
|
|
|
2019-11-03 19:23:31 +00:00
|
|
|
m_apertures.push_back( new_tool );
|
2016-09-19 11:01:36 +00:00
|
|
|
|
2019-11-03 19:23:31 +00:00
|
|
|
return m_apertures.size() - 1;
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2020-09-28 13:36:52 +00:00
|
|
|
int GERBER_PLOTTER::GetOrCreateAperture( const std::vector<wxPoint>& aCorners, double aRotDegree,
|
2021-06-07 18:31:53 +00:00
|
|
|
APERTURE::APERTURE_TYPE aType, int aApertureAttribute )
|
2020-09-28 13:36:52 +00:00
|
|
|
{
|
|
|
|
int last_D_code = 9;
|
|
|
|
|
2021-01-30 08:59:53 +00:00
|
|
|
// For APERTURE::AM_FREE_POLYGON aperture macros, we need to create the macro
|
2021-06-07 18:31:53 +00:00
|
|
|
// on the fly, because due to the fact the vertex count is not a constant we
|
2021-01-30 08:59:53 +00:00
|
|
|
// cannot create a static definition.
|
|
|
|
if( APERTURE::AM_FREE_POLYGON == aType )
|
|
|
|
{
|
|
|
|
int idx = m_am_freepoly_list.FindAm( aCorners );
|
|
|
|
|
|
|
|
if( idx < 0 )
|
|
|
|
m_am_freepoly_list.Append( aCorners );
|
|
|
|
}
|
|
|
|
|
2020-09-28 13:36:52 +00:00
|
|
|
// Search an existing aperture
|
|
|
|
for( int idx = 0; idx < (int)m_apertures.size(); ++idx )
|
|
|
|
{
|
|
|
|
APERTURE* tool = &m_apertures[idx];
|
2020-10-08 12:51:25 +00:00
|
|
|
|
|
|
|
last_D_code = tool->m_DCode;
|
2020-09-28 13:36:52 +00:00
|
|
|
|
2020-11-19 08:16:56 +00:00
|
|
|
if( (tool->m_Type == aType) &&
|
|
|
|
(tool->m_Corners.size() == aCorners.size() ) &&
|
|
|
|
(tool->m_Rotation == aRotDegree) &&
|
2020-09-28 13:36:52 +00:00
|
|
|
(tool->m_ApertureAttribute == aApertureAttribute) )
|
|
|
|
{
|
2021-01-30 08:59:53 +00:00
|
|
|
// A candidate is found. the corner lists must be similar
|
|
|
|
bool is_same = polyCompare( tool->m_Corners, aCorners );
|
2020-09-28 13:36:52 +00:00
|
|
|
|
|
|
|
if( is_same )
|
|
|
|
return idx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allocate a new aperture
|
|
|
|
APERTURE new_tool;
|
|
|
|
|
|
|
|
new_tool.m_Corners = aCorners;
|
|
|
|
new_tool.m_Size = wxSize( 0, 0 ); // Not used
|
|
|
|
new_tool.m_Type = aType;
|
|
|
|
new_tool.m_Radius = 0; // Not used
|
|
|
|
new_tool.m_Rotation = aRotDegree;
|
|
|
|
new_tool.m_DCode = last_D_code + 1;
|
|
|
|
new_tool.m_ApertureAttribute = aApertureAttribute;
|
|
|
|
|
|
|
|
m_apertures.push_back( new_tool );
|
|
|
|
|
|
|
|
return m_apertures.size() - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GERBER_PLOTTER::selectAperture( const wxSize& aSize, int aRadius, double aRotDegree,
|
2021-06-07 18:31:53 +00:00
|
|
|
APERTURE::APERTURE_TYPE aType, int aApertureAttribute )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2019-11-03 19:23:31 +00:00
|
|
|
bool change = ( m_currentApertureIdx < 0 ) ||
|
|
|
|
( m_apertures[m_currentApertureIdx].m_Type != aType ) ||
|
2020-09-28 13:36:52 +00:00
|
|
|
( m_apertures[m_currentApertureIdx].m_Size != aSize ) ||
|
|
|
|
( m_apertures[m_currentApertureIdx].m_Radius != aRadius ) ||
|
|
|
|
( m_apertures[m_currentApertureIdx].m_Rotation != aRotDegree );
|
|
|
|
|
|
|
|
if( !change )
|
|
|
|
change = m_apertures[m_currentApertureIdx].m_ApertureAttribute != aApertureAttribute;
|
|
|
|
|
|
|
|
if( change )
|
|
|
|
{
|
|
|
|
// Pick an existing aperture or create a new one
|
|
|
|
m_currentApertureIdx = GetOrCreateAperture( aSize, aRadius, aRotDegree,
|
|
|
|
aType, aApertureAttribute );
|
2020-11-16 00:04:55 +00:00
|
|
|
fprintf( m_outputFile, "D%d*\n", m_apertures[m_currentApertureIdx].m_DCode );
|
2020-09-28 13:36:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GERBER_PLOTTER::selectAperture( const std::vector<wxPoint>& aCorners, double aRotDegree,
|
2021-06-07 18:31:53 +00:00
|
|
|
APERTURE::APERTURE_TYPE aType, int aApertureAttribute )
|
2020-09-28 13:36:52 +00:00
|
|
|
{
|
|
|
|
bool change = ( m_currentApertureIdx < 0 ) ||
|
|
|
|
( m_apertures[m_currentApertureIdx].m_Type != aType ) ||
|
|
|
|
( m_apertures[m_currentApertureIdx].m_Corners.size() != aCorners.size() ) ||
|
|
|
|
( m_apertures[m_currentApertureIdx].m_Rotation != aRotDegree );
|
|
|
|
|
|
|
|
if( !change ) // Compare corner lists
|
|
|
|
{
|
|
|
|
for( size_t ii = 0; ii < aCorners.size(); ii++ )
|
|
|
|
{
|
|
|
|
if( aCorners[ii] != m_apertures[m_currentApertureIdx].m_Corners[ii] )
|
|
|
|
{
|
|
|
|
change = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2020-03-12 15:48:44 +00:00
|
|
|
if( !change )
|
2019-11-03 19:23:31 +00:00
|
|
|
change = m_apertures[m_currentApertureIdx].m_ApertureAttribute != aApertureAttribute;
|
2016-09-19 11:01:36 +00:00
|
|
|
|
|
|
|
if( change )
|
2009-06-28 18:13:55 +00:00
|
|
|
{
|
2013-05-06 17:47:01 +00:00
|
|
|
// Pick an existing aperture or create a new one
|
2020-09-28 13:36:52 +00:00
|
|
|
m_currentApertureIdx = GetOrCreateAperture( aCorners, aRotDegree,
|
|
|
|
aType, aApertureAttribute );
|
2020-11-16 00:04:55 +00:00
|
|
|
fprintf( m_outputFile, "D%d*\n", m_apertures[m_currentApertureIdx].m_DCode );
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-23 18:58:13 +00:00
|
|
|
|
2019-10-02 15:16:27 +00:00
|
|
|
void GERBER_PLOTTER::selectAperture( int aDiameter, double aPolygonRotation,
|
2021-06-07 18:31:53 +00:00
|
|
|
APERTURE::APERTURE_TYPE aType, int aApertureAttribute )
|
2019-10-02 15:16:27 +00:00
|
|
|
{
|
|
|
|
// Pick an existing aperture or create a new one, matching the
|
|
|
|
// aDiameter, aPolygonRotation, type and attributes for type =
|
|
|
|
// AT_REGULAR_POLY3 to AT_REGULAR_POLY12
|
|
|
|
|
|
|
|
wxASSERT( aType>= APERTURE::APERTURE_TYPE::AT_REGULAR_POLY3 &&
|
2021-06-07 18:31:53 +00:00
|
|
|
aType <= APERTURE::APERTURE_TYPE::AT_REGULAR_POLY12 );
|
2019-10-02 15:16:27 +00:00
|
|
|
|
|
|
|
wxSize size( aDiameter, (int)( aPolygonRotation * 1000.0 ) );
|
2020-09-28 13:36:52 +00:00
|
|
|
selectAperture( wxSize( 0, 0), aDiameter/2, aPolygonRotation, aType, aApertureAttribute );
|
2019-10-02 15:16:27 +00:00
|
|
|
}
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
void GERBER_PLOTTER::writeApertureList()
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
wxASSERT( m_outputFile );
|
2009-06-28 16:50:42 +00:00
|
|
|
char cbuf[1024];
|
2020-09-28 13:36:52 +00:00
|
|
|
std::string buffer;
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2018-05-17 15:32:14 +00:00
|
|
|
bool useX1StructuredComment = false;
|
|
|
|
|
2018-12-09 09:23:07 +00:00
|
|
|
if( !m_useX2format )
|
2018-05-17 15:32:14 +00:00
|
|
|
useX1StructuredComment = true;
|
|
|
|
|
2013-05-06 17:47:01 +00:00
|
|
|
// Init
|
2019-11-03 19:23:31 +00:00
|
|
|
for( APERTURE& tool : m_apertures )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2021-06-07 18:31:53 +00:00
|
|
|
// aperture sizes are in inch or mm, regardless the
|
2014-06-30 10:00:21 +00:00
|
|
|
// coordinates format
|
2020-11-16 00:04:55 +00:00
|
|
|
double fscale = 0.0001 * m_plotScale / m_IUsPerDecimil; // inches
|
2014-06-30 10:00:21 +00:00
|
|
|
|
|
|
|
if(! m_gerberUnitInch )
|
|
|
|
fscale *= 25.4; // size in mm
|
|
|
|
|
2019-11-03 19:23:31 +00:00
|
|
|
int attribute = tool.m_ApertureAttribute;
|
2016-09-19 11:01:36 +00:00
|
|
|
|
|
|
|
if( attribute != m_apertureAttribute )
|
2018-05-17 15:32:14 +00:00
|
|
|
{
|
2016-09-19 11:01:36 +00:00
|
|
|
fputs( GBR_APERTURE_METADATA::FormatAttribute(
|
2018-05-17 15:32:14 +00:00
|
|
|
(GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB) attribute,
|
2020-11-16 00:04:55 +00:00
|
|
|
useX1StructuredComment ).c_str(), m_outputFile );
|
2018-05-17 15:32:14 +00:00
|
|
|
}
|
2016-09-19 11:01:36 +00:00
|
|
|
|
2020-09-28 13:36:52 +00:00
|
|
|
sprintf( cbuf, "%%ADD%d", tool.m_DCode );
|
|
|
|
buffer = cbuf;
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2013-05-06 17:47:01 +00:00
|
|
|
/* Please note: the Gerber specs for mass parameters say that
|
|
|
|
exponential syntax is *not* allowed and the decimal point should
|
|
|
|
also be always inserted. So the %g format is ruled out, but %f is fine
|
|
|
|
(the # modifier forces the decimal point). Sadly the %f formatter
|
2021-06-07 18:31:53 +00:00
|
|
|
can't remove trailing zeros but that's not a problem, since nothing
|
2013-05-06 17:47:01 +00:00
|
|
|
forbid it (the file is only slightly longer) */
|
|
|
|
|
2019-11-03 19:23:31 +00:00
|
|
|
switch( tool.m_Type )
|
2009-06-28 18:13:55 +00:00
|
|
|
{
|
2019-10-02 15:16:27 +00:00
|
|
|
case APERTURE::AT_CIRCLE:
|
2020-09-28 13:36:52 +00:00
|
|
|
sprintf( cbuf, "C,%#f*%%\n", tool.GetDiameter() * fscale );
|
2009-06-28 18:13:55 +00:00
|
|
|
break;
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2019-10-02 15:16:27 +00:00
|
|
|
case APERTURE::AT_RECT:
|
2020-09-28 13:36:52 +00:00
|
|
|
sprintf( cbuf, "R,%#fX%#f*%%\n", tool.m_Size.x * fscale,
|
2019-11-03 19:23:31 +00:00
|
|
|
tool.m_Size.y * fscale );
|
2009-06-28 18:13:55 +00:00
|
|
|
break;
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2019-10-02 15:16:27 +00:00
|
|
|
case APERTURE::AT_PLOTTING:
|
2020-09-28 13:36:52 +00:00
|
|
|
sprintf( cbuf, "C,%#f*%%\n", tool.m_Size.x * fscale );
|
2009-06-28 18:13:55 +00:00
|
|
|
break;
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2019-10-02 15:16:27 +00:00
|
|
|
case APERTURE::AT_OVAL:
|
2020-09-28 13:36:52 +00:00
|
|
|
sprintf( cbuf, "O,%#fX%#f*%%\n", tool.m_Size.x * fscale,
|
2019-11-03 19:23:31 +00:00
|
|
|
tool.m_Size.y * fscale );
|
2019-10-02 15:16:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case APERTURE::AT_REGULAR_POLY:
|
|
|
|
case APERTURE::AT_REGULAR_POLY3:
|
|
|
|
case APERTURE::AT_REGULAR_POLY4:
|
|
|
|
case APERTURE::AT_REGULAR_POLY5:
|
|
|
|
case APERTURE::AT_REGULAR_POLY6:
|
|
|
|
case APERTURE::AT_REGULAR_POLY7:
|
|
|
|
case APERTURE::AT_REGULAR_POLY8:
|
|
|
|
case APERTURE::AT_REGULAR_POLY9:
|
|
|
|
case APERTURE::AT_REGULAR_POLY10:
|
|
|
|
case APERTURE::AT_REGULAR_POLY11:
|
|
|
|
case APERTURE::AT_REGULAR_POLY12:
|
2020-09-28 13:36:52 +00:00
|
|
|
sprintf( cbuf, "P,%#fX%dX%#f*%%\n", tool.GetDiameter() * fscale,
|
|
|
|
tool.GetRegPolyVerticeCount(), tool.GetRotation() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case APERTURE::AM_ROUND_RECT: // Aperture macro for round rect pads
|
2021-06-07 18:31:53 +00:00
|
|
|
{
|
2020-10-05 18:34:33 +00:00
|
|
|
// The aperture macro needs coordinates of the centers of the 4 corners
|
|
|
|
std::vector<VECTOR2I> corners;
|
|
|
|
wxSize half_size( tool.m_Size.x/2-tool.m_Radius, tool.m_Size.y/2-tool.m_Radius );
|
|
|
|
|
|
|
|
corners.emplace_back( -half_size.x, -half_size.y );
|
|
|
|
corners.emplace_back( half_size.x, -half_size.y );
|
|
|
|
corners.emplace_back( half_size.x, half_size.y );
|
|
|
|
corners.emplace_back( -half_size.x, half_size.y );
|
|
|
|
|
|
|
|
// Rotate the corner coordinates:
|
|
|
|
for( int ii = 0; ii < 4; ii++ )
|
2020-10-08 12:48:24 +00:00
|
|
|
RotatePoint( corners[ii], -tool.m_Rotation*10.0 );
|
2020-10-05 18:34:33 +00:00
|
|
|
|
|
|
|
sprintf( cbuf, "%s,%#fX", APER_MACRO_ROUNDRECT_NAME,
|
|
|
|
tool.m_Radius * fscale );
|
|
|
|
buffer += cbuf;
|
|
|
|
|
|
|
|
// Add each corner
|
|
|
|
for( int ii = 0; ii < 4; ii++ )
|
|
|
|
{
|
|
|
|
sprintf( cbuf, "%#fX%#fX",
|
|
|
|
corners[ii].x * fscale, corners[ii].y * fscale );
|
|
|
|
buffer += cbuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
sprintf( cbuf, "0*%%\n" );
|
2021-06-07 18:31:53 +00:00
|
|
|
}
|
2020-09-28 13:36:52 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case APERTURE::AM_ROT_RECT: // Aperture macro for rotated rect pads
|
|
|
|
sprintf( cbuf, "%s,%#fX%#fX%#f*%%\n", APER_MACRO_ROT_RECT_NAME,
|
|
|
|
tool.m_Size.x * fscale, tool.m_Size.y * fscale,
|
|
|
|
tool.m_Rotation );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case APERTURE::APER_MACRO_OUTLINE4P: // Aperture macro for trapezoid pads
|
2020-10-08 12:51:25 +00:00
|
|
|
case APERTURE::APER_MACRO_OUTLINE5P: // Aperture macro for chamfered rect pads
|
|
|
|
case APERTURE::APER_MACRO_OUTLINE6P: // Aperture macro for chamfered rect pads
|
|
|
|
case APERTURE::APER_MACRO_OUTLINE7P: // Aperture macro for chamfered rect pads
|
|
|
|
case APERTURE::APER_MACRO_OUTLINE8P: // Aperture macro for chamfered rect pads
|
|
|
|
switch( tool.m_Type )
|
|
|
|
{
|
|
|
|
case APERTURE::APER_MACRO_OUTLINE4P:
|
|
|
|
sprintf( cbuf, "%s,", APER_MACRO_OUTLINE4P_NAME ); break;
|
|
|
|
case APERTURE::APER_MACRO_OUTLINE5P:
|
|
|
|
sprintf( cbuf, "%s,", APER_MACRO_OUTLINE5P_NAME ); break;
|
|
|
|
case APERTURE::APER_MACRO_OUTLINE6P:
|
|
|
|
sprintf( cbuf, "%s,", APER_MACRO_OUTLINE6P_NAME ); break;
|
|
|
|
case APERTURE::APER_MACRO_OUTLINE7P:
|
|
|
|
sprintf( cbuf, "%s,", APER_MACRO_OUTLINE7P_NAME ); break;
|
|
|
|
case APERTURE::APER_MACRO_OUTLINE8P:
|
|
|
|
sprintf( cbuf, "%s,", APER_MACRO_OUTLINE8P_NAME ); break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2020-09-28 13:36:52 +00:00
|
|
|
|
|
|
|
buffer += cbuf;
|
|
|
|
|
2020-10-08 12:51:25 +00:00
|
|
|
// Output all corners (should be 4 to 8 corners)
|
2020-09-28 13:36:52 +00:00
|
|
|
// Remember: the Y coordinate must be negated, due to the fact in Pcbnew
|
|
|
|
// the Y axis is from top to bottom
|
|
|
|
for( size_t ii = 0; ii < tool.m_Corners.size(); ii++ )
|
|
|
|
{
|
|
|
|
sprintf( cbuf, "%#fX%#fX",
|
|
|
|
tool.m_Corners[ii].x * fscale, -tool.m_Corners[ii].y * fscale );
|
|
|
|
buffer += cbuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
// close outline and output rotation
|
|
|
|
sprintf( cbuf, "%#f*%%\n", tool.m_Rotation );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case APERTURE::AM_ROTATED_OVAL: // Aperture macro for rotated oval pads
|
|
|
|
// (not rotated is a primitive)
|
2021-06-07 18:31:53 +00:00
|
|
|
// m_Size.x = full length; m_Size.y = width, and the macro aperture expects
|
2020-10-05 18:34:33 +00:00
|
|
|
// the position of ends
|
2021-06-07 18:31:53 +00:00
|
|
|
{
|
2020-10-08 12:48:24 +00:00
|
|
|
// the seg_len is the distance between the 2 circle centers
|
|
|
|
int seg_len = tool.m_Size.x - tool.m_Size.y;
|
|
|
|
// Center of the circle on the segment start point:
|
|
|
|
VECTOR2I start( seg_len/2, 0 );
|
|
|
|
// Center of the circle on the segment end point:
|
|
|
|
VECTOR2I end( - seg_len/2, 0 );
|
2020-10-05 18:34:33 +00:00
|
|
|
|
|
|
|
RotatePoint( start, tool.m_Rotation*10.0 );
|
|
|
|
RotatePoint( end, tool.m_Rotation*10.0 );
|
|
|
|
|
|
|
|
sprintf( cbuf, "%s,%#fX%#fX%#fX%#fX%#fX0*%%\n", APER_MACRO_SHAPE_OVAL_NAME,
|
2020-10-08 12:48:24 +00:00
|
|
|
tool.m_Size.y * fscale, // width
|
|
|
|
start.x * fscale, -start.y * fscale, // X,Y corner start pos
|
|
|
|
end.x * fscale, -end.y * fscale ); // X,Y cornerend pos
|
2021-06-07 18:31:53 +00:00
|
|
|
}
|
2009-06-28 18:13:55 +00:00
|
|
|
break;
|
2020-10-11 10:53:45 +00:00
|
|
|
|
2021-06-07 18:31:53 +00:00
|
|
|
case APERTURE::AM_FREE_POLYGON:
|
|
|
|
{
|
|
|
|
// Find the aperture macro name in the list of aperture macro
|
|
|
|
// created on the fly for this polygon:
|
|
|
|
int idx = m_am_freepoly_list.FindAm( tool.m_Corners );
|
2020-10-11 10:53:45 +00:00
|
|
|
|
2021-06-07 18:31:53 +00:00
|
|
|
// Write DCODE id ( "%ADDxx" is already in buffer) and rotation
|
|
|
|
// the full line is something like :%ADD12FreePoly1,45.000000*%
|
|
|
|
sprintf( cbuf, "%s%d,%#f*%%\n", AM_FREEPOLY_BASENAME, idx, tool.m_Rotation );
|
2020-10-11 10:53:45 +00:00
|
|
|
break;
|
2009-06-28 18:13:55 +00:00
|
|
|
}
|
2021-06-07 18:31:53 +00:00
|
|
|
}
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2020-09-28 13:36:52 +00:00
|
|
|
buffer += cbuf;
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( buffer.c_str(), m_outputFile );
|
2016-09-19 11:01:36 +00:00
|
|
|
|
|
|
|
m_apertureAttribute = attribute;
|
|
|
|
|
|
|
|
// Currently reset the aperture attribute. Perhaps a better optimization
|
|
|
|
// is to store the last attribute
|
|
|
|
if( attribute )
|
|
|
|
{
|
2018-12-09 09:23:07 +00:00
|
|
|
if( m_useX2format )
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( "%TD*%\n", m_outputFile );
|
2018-05-17 15:32:14 +00:00
|
|
|
else
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( "G04 #@! TD*\n", m_outputFile );
|
2018-05-17 15:32:14 +00:00
|
|
|
|
2016-09-19 11:01:36 +00:00
|
|
|
m_apertureAttribute = 0;
|
|
|
|
}
|
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
void GERBER_PLOTTER::PenTo( const wxPoint& aPos, char plume )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
wxASSERT( m_outputFile );
|
2012-05-03 18:37:56 +00:00
|
|
|
DPOINT pos_dev = userToDeviceCoordinates( aPos );
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
switch( plume )
|
|
|
|
{
|
|
|
|
case 'Z':
|
|
|
|
break;
|
2008-12-23 07:37:39 +00:00
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
case 'U':
|
2014-10-19 20:20:16 +00:00
|
|
|
emitDcode( pos_dev, 2 );
|
2009-06-28 18:13:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'D':
|
2014-10-19 20:20:16 +00:00
|
|
|
emitDcode( pos_dev, 1 );
|
2009-06-28 18:13:55 +00:00
|
|
|
}
|
2008-12-23 07:37:39 +00:00
|
|
|
|
2020-11-16 00:04:55 +00:00
|
|
|
m_penState = plume;
|
2008-12-23 07:37:39 +00:00
|
|
|
}
|
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
void GERBER_PLOTTER::Rect( const wxPoint& p1, const wxPoint& p2, FILL_T fill, int width )
|
2008-12-23 07:37:39 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
std::vector< wxPoint > cornerList;
|
2011-04-20 08:13:21 +00:00
|
|
|
|
|
|
|
// Build corners list
|
|
|
|
cornerList.push_back( p1 );
|
|
|
|
wxPoint corner(p1.x, p2.y);
|
|
|
|
cornerList.push_back( corner );
|
|
|
|
cornerList.push_back( p2 );
|
|
|
|
corner.x = p2.x;
|
|
|
|
corner.y = p1.y;
|
|
|
|
cornerList.push_back( corner );
|
|
|
|
cornerList.push_back( p1 );
|
|
|
|
|
|
|
|
PlotPoly( cornerList, fill, width );
|
2008-12-23 07:37:39 +00:00
|
|
|
}
|
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
void GERBER_PLOTTER::Circle( const wxPoint& aCenter, int aDiameter, FILL_T aFill, int aWidth )
|
2008-12-23 07:37:39 +00:00
|
|
|
{
|
2012-07-15 17:28:52 +00:00
|
|
|
Arc( aCenter, 0, 3600, aDiameter / 2, aFill, aWidth );
|
|
|
|
}
|
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2021-06-03 22:03:00 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
void GERBER_PLOTTER::Arc( const wxPoint& aCenter, double aStAngle, double aEndAngle, int aRadius,
|
|
|
|
FILL_T aFill, int aWidth )
|
2012-07-15 17:28:52 +00:00
|
|
|
{
|
2016-09-19 11:01:36 +00:00
|
|
|
SetCurrentLineWidth( aWidth );
|
|
|
|
|
2020-03-19 11:53:52 +00:00
|
|
|
// aFill is not used here.
|
|
|
|
plotArc( aCenter, aStAngle, aEndAngle, aRadius, false );
|
|
|
|
}
|
|
|
|
|
2021-06-07 18:31:53 +00:00
|
|
|
|
2021-06-03 22:03:00 +00:00
|
|
|
void GERBER_PLOTTER::Arc( const SHAPE_ARC& aArc )
|
|
|
|
{
|
|
|
|
SetCurrentLineWidth( aArc.GetWidth() );
|
|
|
|
|
|
|
|
// aFill is not used here.
|
|
|
|
plotArc( aArc, false );
|
|
|
|
}
|
|
|
|
|
2020-03-19 11:53:52 +00:00
|
|
|
|
2021-06-03 20:31:25 +00:00
|
|
|
void GERBER_PLOTTER::plotArc( const SHAPE_ARC& aArc, bool aPlotInRegion )
|
|
|
|
{
|
|
|
|
wxPoint start( aArc.GetP0() );
|
|
|
|
wxPoint end( aArc.GetP1() );
|
|
|
|
wxPoint center( aArc.GetCenter() );
|
|
|
|
double start_angle = aArc.GetStartAngle();
|
|
|
|
double end_angle = aArc.GetEndAngle();
|
|
|
|
|
|
|
|
if( !aPlotInRegion )
|
|
|
|
MoveTo( start);
|
|
|
|
else
|
|
|
|
LineTo( start );
|
|
|
|
|
|
|
|
DPOINT devEnd = userToDeviceCoordinates( end );
|
|
|
|
DPOINT devCenter = userToDeviceCoordinates( center ) - userToDeviceCoordinates( start );
|
|
|
|
|
2021-08-06 15:45:57 +00:00
|
|
|
fprintf( m_outputFile, "G75*\n" ); // Multiquadrant (360 degrees) mode
|
|
|
|
|
2021-06-03 20:31:25 +00:00
|
|
|
if( start_angle < end_angle )
|
|
|
|
fprintf( m_outputFile, "G03*\n" ); // Active circular interpolation, CCW
|
|
|
|
else
|
|
|
|
fprintf( m_outputFile, "G02*\n" ); // Active circular interpolation, CW
|
|
|
|
|
|
|
|
fprintf( m_outputFile, "X%dY%dI%dJ%dD01*\n",
|
|
|
|
KiROUND( devEnd.x ), KiROUND( devEnd.y ),
|
|
|
|
KiROUND( devCenter.x ), KiROUND( devCenter.y ) );
|
|
|
|
|
2021-06-07 18:31:53 +00:00
|
|
|
fprintf( m_outputFile, "G01*\n" ); // Back to linear interpolate (perhaps useless here).
|
2021-06-03 20:31:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-19 11:53:52 +00:00
|
|
|
void GERBER_PLOTTER::plotArc( const wxPoint& aCenter, double aStAngle, double aEndAngle,
|
2021-06-07 18:31:53 +00:00
|
|
|
int aRadius, bool aPlotInRegion )
|
2020-03-19 11:53:52 +00:00
|
|
|
{
|
2012-07-15 17:28:52 +00:00
|
|
|
wxPoint start, end;
|
2013-05-02 18:06:58 +00:00
|
|
|
start.x = aCenter.x + KiROUND( cosdecideg( aRadius, aStAngle ) );
|
|
|
|
start.y = aCenter.y - KiROUND( sindecideg( aRadius, aStAngle ) );
|
2020-03-19 11:53:52 +00:00
|
|
|
|
|
|
|
if( !aPlotInRegion )
|
|
|
|
MoveTo( start );
|
|
|
|
else
|
|
|
|
LineTo( start );
|
|
|
|
|
2013-05-02 18:06:58 +00:00
|
|
|
end.x = aCenter.x + KiROUND( cosdecideg( aRadius, aEndAngle ) );
|
|
|
|
end.y = aCenter.y - KiROUND( sindecideg( aRadius, aEndAngle ) );
|
2012-07-15 17:28:52 +00:00
|
|
|
DPOINT devEnd = userToDeviceCoordinates( end );
|
2014-10-19 20:20:16 +00:00
|
|
|
DPOINT devCenter = userToDeviceCoordinates( aCenter ) - userToDeviceCoordinates( start );
|
2014-07-09 16:31:39 +00:00
|
|
|
|
2020-11-16 00:04:55 +00:00
|
|
|
fprintf( m_outputFile, "G75*\n" ); // Multiquadrant (360 degrees) mode
|
2012-07-15 17:28:52 +00:00
|
|
|
|
|
|
|
if( aStAngle < aEndAngle )
|
2020-11-16 00:04:55 +00:00
|
|
|
fprintf( m_outputFile, "G03*\n" ); // Active circular interpolation, CCW
|
2012-07-15 17:28:52 +00:00
|
|
|
else
|
2020-11-16 00:04:55 +00:00
|
|
|
fprintf( m_outputFile, "G02*\n" ); // Active circular interpolation, CW
|
2014-07-09 16:31:39 +00:00
|
|
|
|
2020-11-16 00:04:55 +00:00
|
|
|
fprintf( m_outputFile, "X%dY%dI%dJ%dD01*\n",
|
2014-07-09 16:31:39 +00:00
|
|
|
KiROUND( devEnd.x ), KiROUND( devEnd.y ),
|
|
|
|
KiROUND( devCenter.x ), KiROUND( devCenter.y ) );
|
2018-11-28 17:43:45 +00:00
|
|
|
|
2021-06-07 18:31:53 +00:00
|
|
|
fprintf( m_outputFile, "G01*\n" ); // Back to linear interpolate (perhaps useless here).
|
2008-12-23 07:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-07 18:31:53 +00:00
|
|
|
void GERBER_PLOTTER::PlotGerberRegion( const SHAPE_LINE_CHAIN& aPoly, void* aData )
|
2021-06-03 20:31:25 +00:00
|
|
|
{
|
|
|
|
if( aPoly.PointCount() <= 2 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
GBR_METADATA* gbr_metadata = static_cast<GBR_METADATA*>( aData );
|
|
|
|
|
|
|
|
bool clearTA_AperFunction = false; // true if a TA.AperFunction is used
|
|
|
|
|
|
|
|
if( gbr_metadata )
|
|
|
|
{
|
|
|
|
std::string attrib = gbr_metadata->m_ApertureMetadata.FormatAttribute( !m_useX2format );
|
|
|
|
|
|
|
|
if( !attrib.empty() )
|
|
|
|
{
|
|
|
|
fputs( attrib.c_str(), m_outputFile );
|
|
|
|
clearTA_AperFunction = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
PlotPoly( aPoly, FILL_T::FILLED_SHAPE, 0 , gbr_metadata );
|
2021-06-03 20:31:25 +00:00
|
|
|
|
|
|
|
// Clear the TA attribute, to avoid the next item to inherit it:
|
|
|
|
if( clearTA_AperFunction )
|
|
|
|
{
|
|
|
|
if( m_useX2format )
|
|
|
|
{
|
|
|
|
fputs( "%TD.AperFunction*%\n", m_outputFile );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fputs( "G04 #@! TD.AperFunction*\n", m_outputFile );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-07 18:31:53 +00:00
|
|
|
void GERBER_PLOTTER::PlotGerberRegion( const std::vector< wxPoint >& aCornerList, void* aData )
|
2019-10-06 11:39:50 +00:00
|
|
|
{
|
|
|
|
if( aCornerList.size() <= 2 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
GBR_METADATA* gbr_metadata = static_cast<GBR_METADATA*>( aData );
|
|
|
|
|
|
|
|
bool clearTA_AperFunction = false; // true if a TA.AperFunction is used
|
|
|
|
|
|
|
|
if( gbr_metadata )
|
|
|
|
{
|
|
|
|
std::string attrib = gbr_metadata->m_ApertureMetadata.FormatAttribute( !m_useX2format );
|
|
|
|
|
|
|
|
if( !attrib.empty() )
|
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( attrib.c_str(), m_outputFile );
|
2019-10-06 11:39:50 +00:00
|
|
|
clearTA_AperFunction = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
PlotPoly( aCornerList, FILL_T::FILLED_SHAPE, 0, gbr_metadata );
|
2019-10-06 11:39:50 +00:00
|
|
|
|
|
|
|
// Clear the TA attribute, to avoid the next item to inherit it:
|
|
|
|
if( clearTA_AperFunction )
|
|
|
|
{
|
|
|
|
if( m_useX2format )
|
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( "%TD.AperFunction*%\n", m_outputFile );
|
2019-10-06 11:39:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( "G04 #@! TD.AperFunction*\n", m_outputFile );
|
2019-10-06 11:39:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-07 18:31:53 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
void GERBER_PLOTTER::PlotPoly( const SHAPE_LINE_CHAIN& aPoly, FILL_T aFill, int aWidth,
|
2021-06-07 18:31:53 +00:00
|
|
|
void* aData )
|
2021-06-03 20:31:25 +00:00
|
|
|
{
|
|
|
|
if( aPoly.CPoints().size() <= 1 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Gerber format does not know filled polygons with thick outline
|
|
|
|
// Therefore, to plot a filled polygon with outline having a thickness,
|
|
|
|
// one should plot outline as thick segments
|
|
|
|
GBR_METADATA* gbr_metadata = static_cast<GBR_METADATA*>( aData );
|
|
|
|
|
|
|
|
if( gbr_metadata )
|
|
|
|
formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
if( aFill != FILL_T::NO_FILL )
|
2021-06-03 20:31:25 +00:00
|
|
|
{
|
|
|
|
fputs( "G36*\n", m_outputFile );
|
|
|
|
|
|
|
|
MoveTo( wxPoint( aPoly.CPoint( 0 ) ) );
|
|
|
|
|
|
|
|
fputs( "G01*\n", m_outputFile ); // Set linear interpolation.
|
|
|
|
|
|
|
|
for( int ii = 1; ii < aPoly.PointCount(); ii++ )
|
|
|
|
{
|
|
|
|
int arcindex = aPoly.ArcIndex( ii );
|
|
|
|
|
|
|
|
if( arcindex < 0 )
|
|
|
|
{
|
|
|
|
/// Plain point
|
|
|
|
LineTo( wxPoint( aPoly.CPoint( ii ) ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const SHAPE_ARC& arc = aPoly.Arc( arcindex );
|
|
|
|
|
|
|
|
plotArc( arc, ii > 0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the polygon is not closed, close it:
|
|
|
|
if( aPoly.CPoint( 0 ) != aPoly.CPoint( -1 ) )
|
|
|
|
FinishTo( wxPoint( aPoly.CPoint( 0 ) ) );
|
|
|
|
|
|
|
|
fputs( "G37*\n", m_outputFile );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aWidth > 0 ) // Draw the polyline/polygon outline
|
|
|
|
{
|
|
|
|
SetCurrentLineWidth( aWidth, gbr_metadata );
|
|
|
|
|
|
|
|
MoveTo( wxPoint( aPoly.CPoint( 0 ) ) );
|
|
|
|
|
|
|
|
for( int ii = 1; ii < aPoly.PointCount(); ii++ )
|
|
|
|
{
|
|
|
|
int arcindex = aPoly.ArcIndex( ii );
|
|
|
|
|
|
|
|
if( arcindex < 0 )
|
|
|
|
{
|
|
|
|
/// Plain point
|
|
|
|
LineTo( wxPoint( aPoly.CPoint( ii ) ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const SHAPE_ARC& arc = aPoly.Arc( arcindex );
|
|
|
|
|
|
|
|
plotArc( arc, ii > 0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure the thick outline is closed for filled polygons
|
|
|
|
// (if not filled, could be only a polyline)
|
2021-07-18 23:08:54 +00:00
|
|
|
if( aFill != FILL_T::NO_FILL && ( aPoly.CPoint( 0 ) != aPoly.CPoint( -1 ) ) )
|
2021-06-03 20:31:25 +00:00
|
|
|
LineTo( wxPoint( aPoly.CPoint( 0 ) ) );
|
|
|
|
|
|
|
|
PenFinish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
void GERBER_PLOTTER::PlotPoly( const std::vector< wxPoint >& aCornerList, FILL_T aFill, int aWidth,
|
|
|
|
void * aData )
|
2008-12-23 07:37:39 +00:00
|
|
|
{
|
2011-04-20 08:13:21 +00:00
|
|
|
if( aCornerList.size() <= 1 )
|
|
|
|
return;
|
|
|
|
|
2014-05-16 19:03:45 +00:00
|
|
|
// Gerber format does not know filled polygons with thick outline
|
2014-07-04 14:22:38 +00:00
|
|
|
// Therefore, to plot a filled polygon with outline having a thickness,
|
2014-05-16 19:03:45 +00:00
|
|
|
// one should plot outline as thick segments
|
2016-09-19 11:01:36 +00:00
|
|
|
GBR_METADATA* gbr_metadata = static_cast<GBR_METADATA*>( aData );
|
2014-05-16 19:03:45 +00:00
|
|
|
|
2016-09-19 11:01:36 +00:00
|
|
|
if( gbr_metadata )
|
|
|
|
formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
if( aFill != FILL_T::NO_FILL )
|
2014-05-16 19:03:45 +00:00
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( "G36*\n", m_outputFile );
|
2011-04-20 08:13:21 +00:00
|
|
|
|
2014-05-16 19:03:45 +00:00
|
|
|
MoveTo( aCornerList[0] );
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( "G01*\n", m_outputFile ); // Set linear interpolation.
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2014-05-16 19:03:45 +00:00
|
|
|
for( unsigned ii = 1; ii < aCornerList.size(); ii++ )
|
|
|
|
LineTo( aCornerList[ii] );
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2019-10-11 18:59:23 +00:00
|
|
|
// If the polygon is not closed, close it:
|
|
|
|
if( aCornerList[0] != aCornerList[aCornerList.size()-1] )
|
|
|
|
FinishTo( aCornerList[0] );
|
|
|
|
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( "G37*\n", m_outputFile );
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
2014-05-16 19:03:45 +00:00
|
|
|
|
2019-10-20 19:11:06 +00:00
|
|
|
if( aWidth > 0 ) // Draw the polyline/polygon outline
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2019-10-20 19:11:06 +00:00
|
|
|
SetCurrentLineWidth( aWidth, gbr_metadata );
|
|
|
|
|
2014-05-16 19:03:45 +00:00
|
|
|
MoveTo( aCornerList[0] );
|
|
|
|
|
|
|
|
for( unsigned ii = 1; ii < aCornerList.size(); ii++ )
|
|
|
|
LineTo( aCornerList[ii] );
|
|
|
|
|
2014-10-17 18:30:56 +00:00
|
|
|
// Ensure the thick outline is closed for filled polygons
|
|
|
|
// (if not filled, could be only a polyline)
|
2021-07-18 23:08:54 +00:00
|
|
|
if( aFill != FILL_T::NO_FILL && ( aCornerList[aCornerList.size() - 1] != aCornerList[0] ) )
|
2014-10-17 18:30:56 +00:00
|
|
|
LineTo( aCornerList[0] );
|
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
PenFinish();
|
2008-12-23 07:37:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-19 20:20:16 +00:00
|
|
|
|
2016-09-19 11:01:36 +00:00
|
|
|
void GERBER_PLOTTER::ThickSegment( const wxPoint& start, const wxPoint& end, int width,
|
2021-06-07 18:31:53 +00:00
|
|
|
OUTLINE_MODE tracemode, void* aData )
|
2016-09-19 11:01:36 +00:00
|
|
|
{
|
|
|
|
if( tracemode == FILLED )
|
|
|
|
{
|
|
|
|
GBR_METADATA *gbr_metadata = static_cast<GBR_METADATA*>( aData );
|
|
|
|
SetCurrentLineWidth( width, gbr_metadata );
|
|
|
|
|
|
|
|
if( gbr_metadata )
|
|
|
|
formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
|
|
|
|
|
|
|
|
MoveTo( start );
|
|
|
|
FinishTo( end );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetCurrentLineWidth( USE_DEFAULT_LINE_WIDTH );
|
|
|
|
segmentAsOval( start, end, width, tracemode );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GERBER_PLOTTER::ThickArc( const wxPoint& centre, double StAngle, double EndAngle,
|
2020-10-15 23:33:18 +00:00
|
|
|
int radius, int width, OUTLINE_MODE tracemode, void* aData )
|
2016-09-19 11:01:36 +00:00
|
|
|
{
|
|
|
|
GBR_METADATA *gbr_metadata = static_cast<GBR_METADATA*>( aData );
|
|
|
|
SetCurrentLineWidth( width, gbr_metadata );
|
|
|
|
|
|
|
|
if( gbr_metadata )
|
|
|
|
formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
|
|
|
|
|
|
|
|
if( tracemode == FILLED )
|
2021-06-07 18:31:53 +00:00
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
Arc( centre, StAngle, EndAngle, radius, FILL_T::NO_FILL, DO_NOT_SET_LINE_WIDTH );
|
2021-06-07 18:31:53 +00:00
|
|
|
}
|
2016-09-19 11:01:36 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
SetCurrentLineWidth( USE_DEFAULT_LINE_WIDTH );
|
2021-07-18 23:08:54 +00:00
|
|
|
Arc( centre, StAngle, EndAngle, radius - ( width - m_currentPenWidth ) / 2, FILL_T::NO_FILL,
|
|
|
|
DO_NOT_SET_LINE_WIDTH );
|
|
|
|
Arc( centre, StAngle, EndAngle, radius + ( width - m_currentPenWidth ) / 2, FILL_T::NO_FILL,
|
2020-11-16 00:04:55 +00:00
|
|
|
DO_NOT_SET_LINE_WIDTH );
|
2016-09-19 11:01:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GERBER_PLOTTER::ThickRect( const wxPoint& p1, const wxPoint& p2, int width,
|
2020-10-15 23:33:18 +00:00
|
|
|
OUTLINE_MODE tracemode, void* aData )
|
2016-09-19 11:01:36 +00:00
|
|
|
{
|
|
|
|
GBR_METADATA *gbr_metadata = static_cast<GBR_METADATA*>( aData );
|
|
|
|
SetCurrentLineWidth( width, gbr_metadata );
|
|
|
|
|
|
|
|
if( gbr_metadata )
|
|
|
|
formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
|
|
|
|
|
|
|
|
if( tracemode == FILLED )
|
2021-06-07 18:31:53 +00:00
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
Rect( p1, p2, FILL_T::NO_FILL, DO_NOT_SET_LINE_WIDTH );
|
2021-06-07 18:31:53 +00:00
|
|
|
}
|
2016-09-19 11:01:36 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
SetCurrentLineWidth( USE_DEFAULT_LINE_WIDTH );
|
2020-11-16 00:04:55 +00:00
|
|
|
wxPoint offsetp1( p1.x - (width - m_currentPenWidth) / 2,
|
|
|
|
p1.y - (width - m_currentPenWidth) / 2 );
|
|
|
|
wxPoint offsetp2( p2.x + (width - m_currentPenWidth) / 2,
|
2021-06-07 18:31:53 +00:00
|
|
|
p2.y + (width - m_currentPenWidth) / 2 );
|
2021-07-18 23:08:54 +00:00
|
|
|
Rect( offsetp1, offsetp2, FILL_T::NO_FILL, -1 );
|
2020-11-16 00:04:55 +00:00
|
|
|
offsetp1.x += (width - m_currentPenWidth);
|
|
|
|
offsetp1.y += (width - m_currentPenWidth);
|
|
|
|
offsetp2.x -= (width - m_currentPenWidth);
|
|
|
|
offsetp2.y -= (width - m_currentPenWidth);
|
2021-07-18 23:08:54 +00:00
|
|
|
Rect( offsetp1, offsetp2, FILL_T::NO_FILL, DO_NOT_SET_LINE_WIDTH );
|
2016-09-19 11:01:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GERBER_PLOTTER::ThickCircle( const wxPoint& pos, int diametre, int width,
|
2021-06-07 18:31:53 +00:00
|
|
|
OUTLINE_MODE tracemode, void* aData )
|
2016-09-19 11:01:36 +00:00
|
|
|
{
|
|
|
|
GBR_METADATA *gbr_metadata = static_cast<GBR_METADATA*>( aData );
|
|
|
|
SetCurrentLineWidth( width, gbr_metadata );
|
|
|
|
|
|
|
|
if( gbr_metadata )
|
|
|
|
formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
|
|
|
|
|
|
|
|
if( tracemode == FILLED )
|
2021-06-07 18:31:53 +00:00
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
Circle( pos, diametre, FILL_T::NO_FILL, DO_NOT_SET_LINE_WIDTH );
|
2021-06-07 18:31:53 +00:00
|
|
|
}
|
2016-09-19 11:01:36 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
SetCurrentLineWidth( USE_DEFAULT_LINE_WIDTH, gbr_metadata );
|
2021-07-18 23:08:54 +00:00
|
|
|
Circle( pos, diametre - (width - m_currentPenWidth), FILL_T::NO_FILL,
|
|
|
|
DO_NOT_SET_LINE_WIDTH );
|
|
|
|
Circle( pos, diametre + (width - m_currentPenWidth), FILL_T::NO_FILL,
|
|
|
|
DO_NOT_SET_LINE_WIDTH );
|
2016-09-19 11:01:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-12 09:30:43 +00:00
|
|
|
void GERBER_PLOTTER::FilledCircle( const wxPoint& pos, int diametre,
|
2020-10-15 23:33:18 +00:00
|
|
|
OUTLINE_MODE tracemode, void* aData )
|
2020-10-12 09:30:43 +00:00
|
|
|
{
|
|
|
|
// A filled circle is a graphic item, not a pad.
|
|
|
|
// So it is drawn, not flashed.
|
|
|
|
GBR_METADATA *gbr_metadata = static_cast<GBR_METADATA*>( aData );
|
|
|
|
|
|
|
|
if( gbr_metadata )
|
|
|
|
formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
|
|
|
|
|
|
|
|
if( tracemode == FILLED )
|
|
|
|
{
|
2021-06-07 18:31:53 +00:00
|
|
|
// Draw a circle of diameter = diameter/2 with a line thickness = radius,
|
2020-10-12 09:30:43 +00:00
|
|
|
// To create a filled circle
|
|
|
|
SetCurrentLineWidth( diametre/2, gbr_metadata );
|
2021-07-18 23:08:54 +00:00
|
|
|
Circle( pos, diametre/2, FILL_T::NO_FILL, DO_NOT_SET_LINE_WIDTH );
|
2020-10-12 09:30:43 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetCurrentLineWidth( USE_DEFAULT_LINE_WIDTH, gbr_metadata );
|
2021-07-18 23:08:54 +00:00
|
|
|
Circle( pos, diametre, FILL_T::NO_FILL, DO_NOT_SET_LINE_WIDTH );
|
2020-10-12 09:30:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
void GERBER_PLOTTER::FlashPadCircle( const wxPoint& pos, int diametre, OUTLINE_MODE trace_mode,
|
|
|
|
void* aData )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2009-06-28 18:13:55 +00:00
|
|
|
wxSize size( diametre, diametre );
|
2016-09-19 11:01:36 +00:00
|
|
|
GBR_METADATA* gbr_metadata = static_cast<GBR_METADATA*>( aData );
|
2008-12-23 07:37:39 +00:00
|
|
|
|
2015-02-02 08:06:39 +00:00
|
|
|
if( trace_mode == SKETCH )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2016-09-19 11:01:36 +00:00
|
|
|
if( gbr_metadata )
|
|
|
|
formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
|
|
|
|
|
2020-09-28 13:36:52 +00:00
|
|
|
SetCurrentLineWidth( USE_DEFAULT_LINE_WIDTH );
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
Circle( pos, diametre - m_currentPenWidth, FILL_T::NO_FILL, DO_NOT_SET_LINE_WIDTH );
|
2015-02-02 08:06:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-10-19 20:20:16 +00:00
|
|
|
DPOINT pos_dev = userToDeviceCoordinates( pos );
|
2016-09-19 11:01:36 +00:00
|
|
|
|
|
|
|
int aperture_attrib = gbr_metadata ? gbr_metadata->GetApertureAttrib() : 0;
|
2020-09-28 13:36:52 +00:00
|
|
|
selectAperture( size, 0, 0.0, APERTURE::AT_CIRCLE, aperture_attrib );
|
2016-09-19 11:01:36 +00:00
|
|
|
|
|
|
|
if( gbr_metadata )
|
|
|
|
formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
|
|
|
|
|
2014-10-19 20:20:16 +00:00
|
|
|
emitDcode( pos_dev, 3 );
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2013-05-05 07:17:48 +00:00
|
|
|
void GERBER_PLOTTER::FlashPadOval( const wxPoint& pos, const wxSize& aSize, double orient,
|
2020-10-15 23:33:18 +00:00
|
|
|
OUTLINE_MODE trace_mode, void* aData )
|
2008-12-23 07:37:39 +00:00
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
wxASSERT( m_outputFile );
|
2012-05-03 18:37:56 +00:00
|
|
|
wxSize size( aSize );
|
2016-09-19 11:01:36 +00:00
|
|
|
GBR_METADATA* gbr_metadata = static_cast<GBR_METADATA*>( aData );
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2019-10-06 11:39:50 +00:00
|
|
|
// Flash a vertical or horizontal shape (this is a basic aperture).
|
2009-06-28 18:13:55 +00:00
|
|
|
if( ( orient == 0 || orient == 900 || orient == 1800 || orient == 2700 )
|
2017-05-03 18:04:31 +00:00
|
|
|
&& trace_mode == FILLED )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2009-11-23 15:16:50 +00:00
|
|
|
if( orient == 900 || orient == 2700 ) /* orientation turned 90 deg. */
|
2015-06-26 13:41:56 +00:00
|
|
|
std::swap( size.x, size.y );
|
2012-10-13 18:54:33 +00:00
|
|
|
|
2014-10-19 20:20:16 +00:00
|
|
|
DPOINT pos_dev = userToDeviceCoordinates( pos );
|
2016-09-19 11:01:36 +00:00
|
|
|
int aperture_attrib = gbr_metadata ? gbr_metadata->GetApertureAttrib() : 0;
|
2020-09-28 13:36:52 +00:00
|
|
|
selectAperture( size, 0, 0.0, APERTURE::AT_OVAL, aperture_attrib );
|
2016-09-19 11:01:36 +00:00
|
|
|
|
|
|
|
if( gbr_metadata )
|
|
|
|
formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
|
|
|
|
|
2014-10-19 20:20:16 +00:00
|
|
|
emitDcode( pos_dev, 3 );
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
2019-10-16 08:13:54 +00:00
|
|
|
else // Plot pad as region.
|
|
|
|
// Only regions and flashed items accept a object attribute TO.P for the pin name
|
2008-12-23 07:37:39 +00:00
|
|
|
{
|
2009-06-28 18:13:55 +00:00
|
|
|
if( trace_mode == FILLED )
|
|
|
|
{
|
2020-10-05 18:34:33 +00:00
|
|
|
#ifdef GBR_USE_MACROS_FOR_ROTATED_OVAL
|
2020-10-10 12:39:54 +00:00
|
|
|
if( !m_gerberDisableApertMacros )
|
|
|
|
#endif
|
2020-09-28 13:36:52 +00:00
|
|
|
{
|
2020-10-10 12:39:54 +00:00
|
|
|
m_hasApertureRotOval = true;
|
|
|
|
// We are using a aperture macro that expect size.y < size.x
|
|
|
|
// i.e draw a horizontal line for rotation = 0.0
|
|
|
|
// size.x = length, size.y = width
|
|
|
|
if( size.x < size.y )
|
|
|
|
{
|
|
|
|
std::swap( size.x, size.y );
|
|
|
|
orient += 900;
|
2020-09-28 13:36:52 +00:00
|
|
|
|
2020-10-10 12:39:54 +00:00
|
|
|
if( orient > 1800 )
|
|
|
|
orient -= 1800;
|
|
|
|
}
|
2020-09-28 13:36:52 +00:00
|
|
|
|
2020-10-10 12:39:54 +00:00
|
|
|
DPOINT pos_dev = userToDeviceCoordinates( pos );
|
|
|
|
int aperture_attrib = gbr_metadata ? gbr_metadata->GetApertureAttrib() : 0;
|
|
|
|
selectAperture( size, 0, orient/10.0, APERTURE::AM_ROTATED_OVAL, aperture_attrib );
|
2020-09-28 13:36:52 +00:00
|
|
|
|
2020-10-10 12:39:54 +00:00
|
|
|
if( gbr_metadata )
|
|
|
|
formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
|
2020-09-28 13:36:52 +00:00
|
|
|
|
2020-10-10 12:39:54 +00:00
|
|
|
emitDcode( pos_dev, 3 );
|
|
|
|
return;
|
|
|
|
}
|
2020-03-27 08:56:07 +00:00
|
|
|
// Draw the oval as round rect pad with a radius = 50% min size)
|
|
|
|
// In gerber file, it will be drawn as a region with arcs, and can be
|
|
|
|
// detected as pads (similar to a flashed pad)
|
2021-06-07 18:31:53 +00:00
|
|
|
FlashPadRoundRect( pos, aSize, std::min( aSize.x, aSize.y ) / 2,
|
2020-03-27 08:56:07 +00:00
|
|
|
orient, FILLED, aData );
|
2009-06-28 18:13:55 +00:00
|
|
|
}
|
2020-03-27 08:56:07 +00:00
|
|
|
else // Non filled shape: plot outlines:
|
|
|
|
{
|
|
|
|
if( size.x > size.y )
|
|
|
|
{
|
|
|
|
std::swap( size.x, size.y );
|
|
|
|
|
|
|
|
if( orient < 2700 )
|
|
|
|
orient += 900;
|
|
|
|
else
|
|
|
|
orient -= 2700;
|
|
|
|
}
|
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
sketchOval( pos, size, orient, -1 );
|
2020-03-27 08:56:07 +00:00
|
|
|
}
|
2008-12-23 07:37:39 +00:00
|
|
|
}
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
void GERBER_PLOTTER::FlashPadRect( const wxPoint& pos, const wxSize& aSize,
|
2020-10-15 23:33:18 +00:00
|
|
|
double orient, OUTLINE_MODE trace_mode, void* aData )
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
wxASSERT( m_outputFile );
|
2012-05-03 18:37:56 +00:00
|
|
|
wxSize size( aSize );
|
2016-09-19 11:01:36 +00:00
|
|
|
GBR_METADATA* gbr_metadata = static_cast<GBR_METADATA*>( aData );
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2013-05-01 17:32:36 +00:00
|
|
|
// Plot as an aperture flash
|
|
|
|
switch( int( orient ) )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
|
|
|
case 900:
|
2013-05-01 17:32:36 +00:00
|
|
|
case 2700: // rotation of 90 degrees or 270 swaps sizes
|
2015-06-26 13:41:56 +00:00
|
|
|
std::swap( size.x, size.y );
|
2020-04-24 23:44:09 +00:00
|
|
|
KI_FALLTHROUGH;
|
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
case 0:
|
|
|
|
case 1800:
|
2015-02-02 08:06:39 +00:00
|
|
|
if( trace_mode == SKETCH )
|
2014-10-19 20:20:16 +00:00
|
|
|
{
|
2016-09-19 11:01:36 +00:00
|
|
|
if( gbr_metadata )
|
|
|
|
formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
|
|
|
|
|
2020-09-28 13:36:52 +00:00
|
|
|
SetCurrentLineWidth( USE_DEFAULT_LINE_WIDTH );
|
|
|
|
Rect( wxPoint( pos.x - (size.x - GetCurrentLineWidth()) / 2,
|
|
|
|
pos.y - (size.y - GetCurrentLineWidth()) / 2 ),
|
|
|
|
wxPoint( pos.x + (size.x - GetCurrentLineWidth()) / 2,
|
|
|
|
pos.y + (size.y - GetCurrentLineWidth()) / 2 ),
|
2021-07-18 23:08:54 +00:00
|
|
|
FILL_T::NO_FILL, GetCurrentLineWidth() );
|
2015-02-02 08:06:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-10-19 20:20:16 +00:00
|
|
|
DPOINT pos_dev = userToDeviceCoordinates( pos );
|
2016-09-19 11:01:36 +00:00
|
|
|
int aperture_attrib = gbr_metadata ? gbr_metadata->GetApertureAttrib() : 0;
|
2020-09-28 13:36:52 +00:00
|
|
|
selectAperture( size, 0, 0.0, APERTURE::AT_RECT, aperture_attrib );
|
2016-09-19 11:01:36 +00:00
|
|
|
|
|
|
|
if( gbr_metadata )
|
|
|
|
formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
|
|
|
|
|
2014-10-19 20:20:16 +00:00
|
|
|
emitDcode( pos_dev, 3 );
|
|
|
|
}
|
|
|
|
break;
|
2012-05-03 18:37:56 +00:00
|
|
|
|
2020-09-28 13:36:52 +00:00
|
|
|
default:
|
2020-10-05 18:34:33 +00:00
|
|
|
#ifdef GBR_USE_MACROS_FOR_ROTATED_RECT
|
2020-10-10 12:39:54 +00:00
|
|
|
if( trace_mode != SKETCH && !m_gerberDisableApertMacros )
|
2020-09-28 13:36:52 +00:00
|
|
|
{
|
|
|
|
m_hasApertureRotRect = true;
|
|
|
|
DPOINT pos_dev = userToDeviceCoordinates( pos );
|
|
|
|
int aperture_attrib = gbr_metadata ? gbr_metadata->GetApertureAttrib() : 0;
|
|
|
|
selectAperture( size, 0, orient/10.0, APERTURE::AM_ROT_RECT, aperture_attrib );
|
|
|
|
|
|
|
|
if( gbr_metadata )
|
|
|
|
formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
|
|
|
|
|
|
|
|
emitDcode( pos_dev, 3 );
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2020-03-27 08:56:07 +00:00
|
|
|
{
|
2020-09-28 13:36:52 +00:00
|
|
|
// plot pad shape as Gerber region
|
2019-11-03 19:23:31 +00:00
|
|
|
wxPoint coord[4];
|
|
|
|
// coord[0] is assumed the lower left
|
|
|
|
// coord[1] is assumed the upper left
|
|
|
|
// coord[2] is assumed the upper right
|
|
|
|
// coord[3] is assumed the lower right
|
|
|
|
|
|
|
|
coord[0].x = -size.x/2; // lower left
|
|
|
|
coord[0].y = size.y/2;
|
|
|
|
coord[1].x = -size.x/2; // upper left
|
|
|
|
coord[1].y = -size.y/2;
|
|
|
|
coord[2].x = size.x/2; // upper right
|
|
|
|
coord[2].y = -size.y/2;
|
|
|
|
coord[3].x = size.x/2; // lower right
|
|
|
|
coord[3].y = size.y/2;
|
|
|
|
|
|
|
|
FlashPadTrapez( pos, coord, orient, trace_mode, aData );
|
2020-03-27 08:56:07 +00:00
|
|
|
}
|
2019-11-03 19:23:31 +00:00
|
|
|
break;
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
2008-12-23 07:37:39 +00:00
|
|
|
}
|
|
|
|
|
2016-02-10 16:02:40 +00:00
|
|
|
void GERBER_PLOTTER::FlashPadRoundRect( const wxPoint& aPadPos, const wxSize& aSize,
|
|
|
|
int aCornerRadius, double aOrient,
|
2020-10-15 23:33:18 +00:00
|
|
|
OUTLINE_MODE aTraceMode, void* aData )
|
2016-02-10 16:02:40 +00:00
|
|
|
|
|
|
|
{
|
2019-10-19 13:44:40 +00:00
|
|
|
GBR_METADATA* gbr_metadata = static_cast<GBR_METADATA*>( aData );
|
2018-03-16 18:32:49 +00:00
|
|
|
|
|
|
|
if( aTraceMode != FILLED )
|
2019-10-20 19:11:06 +00:00
|
|
|
{
|
2020-03-19 11:53:52 +00:00
|
|
|
SHAPE_POLY_SET outline;
|
2021-06-07 18:31:53 +00:00
|
|
|
TransformRoundChamferedRectToPolygon( outline, aPadPos, aSize, aOrient, aCornerRadius,
|
2021-07-04 12:48:32 +00:00
|
|
|
0.0, 0, 0, GetPlotterArcHighDef(), ERROR_INSIDE );
|
2020-03-19 11:53:52 +00:00
|
|
|
|
2019-10-20 19:11:06 +00:00
|
|
|
SetCurrentLineWidth( USE_DEFAULT_LINE_WIDTH, &gbr_metadata );
|
2018-03-16 18:32:49 +00:00
|
|
|
outline.Inflate( -GetCurrentLineWidth()/2, 16 );
|
|
|
|
|
2020-03-19 11:53:52 +00:00
|
|
|
std::vector< wxPoint > cornerList;
|
|
|
|
// TransformRoundRectToPolygon creates only one convex polygon
|
|
|
|
SHAPE_LINE_CHAIN& poly = outline.Outline( 0 );
|
|
|
|
cornerList.reserve( poly.PointCount() + 1 );
|
2016-02-10 16:02:40 +00:00
|
|
|
|
2020-03-19 11:53:52 +00:00
|
|
|
for( int ii = 0; ii < poly.PointCount(); ++ii )
|
|
|
|
cornerList.emplace_back( poly.CPoint( ii ).x, poly.CPoint( ii ).y );
|
2016-02-10 16:02:40 +00:00
|
|
|
|
2020-03-19 11:53:52 +00:00
|
|
|
// Close polygon
|
|
|
|
cornerList.push_back( cornerList[0] );
|
2016-02-10 16:02:40 +00:00
|
|
|
|
2020-03-19 11:53:52 +00:00
|
|
|
// plot outlines
|
2021-07-18 23:08:54 +00:00
|
|
|
PlotPoly( cornerList, FILL_T::NO_FILL, GetCurrentLineWidth(), gbr_metadata );
|
2020-03-19 11:53:52 +00:00
|
|
|
}
|
2019-10-06 11:39:50 +00:00
|
|
|
else
|
2020-03-19 11:53:52 +00:00
|
|
|
{
|
2020-10-05 18:34:33 +00:00
|
|
|
#ifdef GBR_USE_MACROS_FOR_ROUNDRECT
|
2020-10-10 12:39:54 +00:00
|
|
|
if( !m_gerberDisableApertMacros )
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
m_hasApertureRoundRect = true;
|
2020-09-28 13:36:52 +00:00
|
|
|
|
2020-10-10 12:39:54 +00:00
|
|
|
DPOINT pos_dev = userToDeviceCoordinates( aPadPos );
|
|
|
|
int aperture_attrib = gbr_metadata ? gbr_metadata->GetApertureAttrib() : 0;
|
|
|
|
selectAperture( aSize, aCornerRadius, aOrient/10.0,
|
|
|
|
APERTURE::AM_ROUND_RECT, aperture_attrib );
|
2020-09-28 13:36:52 +00:00
|
|
|
|
2020-10-10 12:39:54 +00:00
|
|
|
if( gbr_metadata )
|
|
|
|
formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
|
2020-09-28 13:36:52 +00:00
|
|
|
|
2020-10-10 12:39:54 +00:00
|
|
|
emitDcode( pos_dev, 3 );
|
|
|
|
return;
|
|
|
|
}
|
2021-06-07 18:31:53 +00:00
|
|
|
|
2020-03-19 11:53:52 +00:00
|
|
|
// A Pad RoundRect is plotted as a Gerber region.
|
|
|
|
// Initialize region metadata:
|
|
|
|
bool clearTA_AperFunction = false; // true if a TA.AperFunction is used
|
|
|
|
|
|
|
|
if( gbr_metadata )
|
|
|
|
{
|
|
|
|
formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
|
|
|
|
std::string attrib = gbr_metadata->m_ApertureMetadata.FormatAttribute( !m_useX2format );
|
|
|
|
|
|
|
|
if( !attrib.empty() )
|
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( attrib.c_str(), m_outputFile );
|
2020-03-19 11:53:52 +00:00
|
|
|
clearTA_AperFunction = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Plot the region using arcs in corners.
|
|
|
|
plotRoundRectAsRegion( aPadPos, aSize, aCornerRadius, aOrient );
|
|
|
|
|
|
|
|
// Clear the TA attribute, to avoid the next item to inherit it:
|
|
|
|
if( clearTA_AperFunction )
|
|
|
|
{
|
|
|
|
if( m_useX2format )
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( "%TD.AperFunction*%\n", m_outputFile );
|
2020-03-19 11:53:52 +00:00
|
|
|
else
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( "G04 #@! TD.AperFunction*\n", m_outputFile );
|
2020-03-19 11:53:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GERBER_PLOTTER::plotRoundRectAsRegion( const wxPoint& aRectCenter, const wxSize& aSize,
|
|
|
|
int aCornerRadius, double aOrient )
|
|
|
|
{
|
|
|
|
// The region outline is generated by 4 sides and 4 90 deg arcs
|
|
|
|
// 1 --- 2
|
|
|
|
// | c |
|
|
|
|
// 4 --- 3
|
|
|
|
|
|
|
|
// Note also in user coordinates the Y axis is from top to bottom
|
|
|
|
// for historical reasons.
|
|
|
|
|
|
|
|
// A helper structure to handle outlines coordinates (segments and arcs)
|
|
|
|
// in user coordinates
|
|
|
|
struct RR_EDGE
|
|
|
|
{
|
|
|
|
wxPoint m_start;
|
|
|
|
wxPoint m_end;
|
|
|
|
wxPoint m_center;
|
|
|
|
// in decidegrees: angle start. angle end = m_arc_angle_start+arc_angle
|
|
|
|
double m_arc_angle_start;
|
|
|
|
};
|
|
|
|
|
|
|
|
const double arc_angle = -900.0; // in decidegrees
|
|
|
|
int hsizeX = aSize.x/2;
|
|
|
|
int hsizeY = aSize.y/2;
|
|
|
|
|
|
|
|
RR_EDGE curr_edge;
|
|
|
|
std::vector<RR_EDGE> rr_outline;
|
|
|
|
|
|
|
|
// Build outline coordinates, relative to rectangle center, rotation 0:
|
|
|
|
|
|
|
|
// Top left corner 1 (and 4 to 1 left vertical side @ x=-hsizeX)
|
|
|
|
curr_edge.m_start.x = -hsizeX;
|
|
|
|
curr_edge.m_start.y = hsizeY - aCornerRadius;
|
|
|
|
curr_edge.m_end.x = curr_edge.m_start.x;
|
|
|
|
curr_edge.m_end.y = -hsizeY + aCornerRadius;
|
|
|
|
curr_edge.m_center.x = -hsizeX + aCornerRadius;
|
|
|
|
curr_edge.m_center.y = curr_edge.m_end.y;
|
|
|
|
curr_edge.m_arc_angle_start = aOrient + 1800.0; // En decidegree
|
|
|
|
|
|
|
|
rr_outline.push_back( curr_edge );
|
|
|
|
|
|
|
|
// Top right corner 2 (and 1 to 2 top horizontal side @ y=-hsizeY)
|
|
|
|
curr_edge.m_start.x = -hsizeX + aCornerRadius;
|
|
|
|
curr_edge.m_start.y = -hsizeY;
|
|
|
|
curr_edge.m_end.x = hsizeX - aCornerRadius;
|
|
|
|
curr_edge.m_end.y = curr_edge.m_start.y;
|
|
|
|
curr_edge.m_center.x = curr_edge.m_end.x;
|
|
|
|
curr_edge.m_center.y = -hsizeY + aCornerRadius;
|
|
|
|
curr_edge.m_arc_angle_start = aOrient + 900.0; // En decidegree
|
|
|
|
|
|
|
|
rr_outline.push_back( curr_edge );
|
|
|
|
|
|
|
|
// bottom right corner 3 (and 2 to 3 right vertical side @ x=hsizeX)
|
|
|
|
curr_edge.m_start.x = hsizeX;
|
|
|
|
curr_edge.m_start.y = -hsizeY + aCornerRadius;
|
|
|
|
curr_edge.m_end.x = curr_edge.m_start.x;
|
|
|
|
curr_edge.m_end.y = hsizeY - aCornerRadius;
|
|
|
|
curr_edge.m_center.x = hsizeX - aCornerRadius;
|
|
|
|
curr_edge.m_center.y = curr_edge.m_end.y;
|
|
|
|
curr_edge.m_arc_angle_start = aOrient + 0.0; // En decidegree
|
|
|
|
|
|
|
|
rr_outline.push_back( curr_edge );
|
|
|
|
|
|
|
|
// bottom left corner 4 (and 3 to 4 bottom horizontal side @ y=hsizeY)
|
|
|
|
curr_edge.m_start.x = hsizeX - aCornerRadius;
|
|
|
|
curr_edge.m_start.y = hsizeY;
|
|
|
|
curr_edge.m_end.x = -hsizeX + aCornerRadius;
|
|
|
|
curr_edge.m_end.y = curr_edge.m_start.y;
|
|
|
|
curr_edge.m_center.x = curr_edge.m_end.x;
|
|
|
|
curr_edge.m_center.y = hsizeY - aCornerRadius;
|
|
|
|
curr_edge.m_arc_angle_start = aOrient - 900.0; // En decidegree
|
|
|
|
|
|
|
|
rr_outline.push_back( curr_edge );
|
|
|
|
|
|
|
|
// Move relative coordinates to the actual location and rotation:
|
2020-06-12 08:22:19 +00:00
|
|
|
wxPoint arc_last_center;
|
|
|
|
int arc_last_angle = curr_edge.m_arc_angle_start+arc_angle;
|
|
|
|
|
2020-03-19 11:53:52 +00:00
|
|
|
for( RR_EDGE& rr_edge: rr_outline )
|
|
|
|
{
|
|
|
|
RotatePoint( &rr_edge.m_start, aOrient );
|
|
|
|
RotatePoint( &rr_edge.m_end, aOrient );
|
|
|
|
RotatePoint( &rr_edge.m_center, aOrient );
|
|
|
|
rr_edge.m_start += aRectCenter;
|
|
|
|
rr_edge.m_end += aRectCenter;
|
|
|
|
rr_edge.m_center += aRectCenter;
|
2020-06-12 08:22:19 +00:00
|
|
|
arc_last_center = rr_edge.m_center;
|
2020-03-19 11:53:52 +00:00
|
|
|
}
|
|
|
|
|
2020-06-12 08:22:19 +00:00
|
|
|
// Ensure the region is a closed polygon, i.e. the end point of last segment
|
|
|
|
// (end of arc) is the same as the first point. Rounding issues can create a
|
|
|
|
// small difference, mainly for rotated pads.
|
|
|
|
// calculate last point (end of last arc):
|
|
|
|
wxPoint last_pt;
|
|
|
|
last_pt.x = arc_last_center.x + KiROUND( cosdecideg( aCornerRadius, arc_last_angle ) );
|
|
|
|
last_pt.y = arc_last_center.y - KiROUND( sindecideg( aCornerRadius, arc_last_angle ) );
|
|
|
|
|
|
|
|
wxPoint first_pt = rr_outline[0].m_start;
|
|
|
|
|
|
|
|
#if 0 // For test only:
|
|
|
|
if( last_pt != first_pt )
|
|
|
|
wxLogMessage( "first pt %d %d last pt %d %d",
|
|
|
|
first_pt.x, first_pt.y, last_pt.x, last_pt.y );
|
|
|
|
#endif
|
|
|
|
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( "G36*\n", m_outputFile ); // Start region
|
|
|
|
fputs( "G01*\n", m_outputFile ); // Set linear interpolation.
|
2020-06-12 08:22:19 +00:00
|
|
|
first_pt = last_pt;
|
|
|
|
MoveTo( first_pt ); // Start point of region, must be same as end point
|
2020-03-19 11:53:52 +00:00
|
|
|
|
|
|
|
for( RR_EDGE& rr_edge: rr_outline )
|
|
|
|
{
|
|
|
|
if( aCornerRadius ) // Guard: ensure we do not create arcs with radius = 0
|
|
|
|
{
|
|
|
|
// LineTo( rr_edge.m_end ); // made in plotArc()
|
2021-06-07 18:31:53 +00:00
|
|
|
plotArc( rr_edge.m_center, rr_edge.m_arc_angle_start,
|
|
|
|
rr_edge.m_arc_angle_start+arc_angle, aCornerRadius, true );
|
2020-03-19 11:53:52 +00:00
|
|
|
}
|
|
|
|
else
|
2021-06-07 18:31:53 +00:00
|
|
|
{
|
2020-03-19 11:53:52 +00:00
|
|
|
LineTo( rr_edge.m_end );
|
2021-06-07 18:31:53 +00:00
|
|
|
}
|
2020-03-19 11:53:52 +00:00
|
|
|
}
|
|
|
|
|
2020-11-16 00:04:55 +00:00
|
|
|
fputs( "G37*\n", m_outputFile ); // Close region
|
2016-02-10 16:02:40 +00:00
|
|
|
}
|
|
|
|
|
2020-03-19 11:53:52 +00:00
|
|
|
|
2016-02-10 16:02:40 +00:00
|
|
|
void GERBER_PLOTTER::FlashPadCustom( const wxPoint& aPadPos, const wxSize& aSize,
|
2021-01-23 17:02:58 +00:00
|
|
|
double aOrient, SHAPE_POLY_SET* aPolygons,
|
2020-10-15 23:33:18 +00:00
|
|
|
OUTLINE_MODE aTraceMode, void* aData )
|
2016-02-10 16:02:40 +00:00
|
|
|
|
|
|
|
{
|
2019-10-06 11:39:50 +00:00
|
|
|
// A Pad custom is plotted as polygon (a region in Gerber language).
|
2016-09-19 11:01:36 +00:00
|
|
|
GBR_METADATA gbr_metadata;
|
|
|
|
|
|
|
|
if( aData )
|
|
|
|
gbr_metadata = *static_cast<GBR_METADATA*>( aData );
|
2016-02-10 16:02:40 +00:00
|
|
|
|
2018-03-16 18:32:49 +00:00
|
|
|
SHAPE_POLY_SET polyshape = *aPolygons;
|
|
|
|
|
|
|
|
if( aTraceMode != FILLED )
|
|
|
|
{
|
|
|
|
SetCurrentLineWidth( USE_DEFAULT_LINE_WIDTH, &gbr_metadata );
|
|
|
|
polyshape.Inflate( -GetCurrentLineWidth()/2, 16 );
|
|
|
|
}
|
|
|
|
|
2016-02-10 16:02:40 +00:00
|
|
|
std::vector< wxPoint > cornerList;
|
|
|
|
|
2018-03-16 18:32:49 +00:00
|
|
|
for( int cnt = 0; cnt < polyshape.OutlineCount(); ++cnt )
|
2016-02-10 16:02:40 +00:00
|
|
|
{
|
2018-03-16 18:32:49 +00:00
|
|
|
SHAPE_LINE_CHAIN& poly = polyshape.Outline( cnt );
|
|
|
|
|
2016-02-10 16:02:40 +00:00
|
|
|
cornerList.clear();
|
|
|
|
|
|
|
|
for( int ii = 0; ii < poly.PointCount(); ++ii )
|
2019-03-23 18:26:44 +00:00
|
|
|
cornerList.emplace_back( poly.CPoint( ii ).x, poly.CPoint( ii ).y );
|
2016-02-10 16:02:40 +00:00
|
|
|
|
|
|
|
// Close polygon
|
|
|
|
cornerList.push_back( cornerList[0] );
|
|
|
|
|
2019-10-06 11:39:50 +00:00
|
|
|
if( aTraceMode == SKETCH )
|
2021-06-07 18:31:53 +00:00
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
PlotPoly( cornerList, FILL_T::NO_FILL, GetCurrentLineWidth(), &gbr_metadata );
|
2021-06-07 18:31:53 +00:00
|
|
|
}
|
2019-10-06 11:39:50 +00:00
|
|
|
else
|
2021-01-23 17:02:58 +00:00
|
|
|
{
|
|
|
|
#ifdef GBR_USE_MACROS_FOR_CUSTOM_PAD
|
|
|
|
if( m_gerberDisableApertMacros
|
|
|
|
|| cornerList.size() > GBR_MACRO_FOR_CUSTOM_PAD_MAX_CORNER_COUNT )
|
|
|
|
PlotGerberRegion( cornerList, &gbr_metadata );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// An AM will be created. the shape must be in position 0,0 and orientation 0
|
|
|
|
// to be able to reuse the same AM for pads having the same shape
|
|
|
|
for( size_t ii = 0; ii < cornerList.size(); ii++ )
|
|
|
|
{
|
|
|
|
cornerList[ii] -= aPadPos;
|
|
|
|
RotatePoint( &cornerList[ii], -aOrient );
|
|
|
|
}
|
|
|
|
|
|
|
|
DPOINT pos_dev = userToDeviceCoordinates( aPadPos );
|
|
|
|
selectAperture( cornerList, aOrient/10.0,
|
|
|
|
APERTURE::AM_FREE_POLYGON, gbr_metadata.GetApertureAttrib() );
|
|
|
|
formatNetAttribute( &gbr_metadata.m_NetlistMetadata );
|
|
|
|
|
|
|
|
emitDcode( pos_dev, 3 );
|
|
|
|
}
|
|
|
|
#else
|
2019-10-06 11:39:50 +00:00
|
|
|
PlotGerberRegion( cornerList, &gbr_metadata );
|
2021-01-23 17:02:58 +00:00
|
|
|
#endif
|
|
|
|
}
|
2016-02-10 16:02:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2020-10-08 12:51:25 +00:00
|
|
|
void GERBER_PLOTTER::FlashPadChamferRoundRect( const wxPoint& aShapePos, const wxSize& aPadSize,
|
2021-06-07 18:31:53 +00:00
|
|
|
int aCornerRadius, double aChamferRatio,
|
|
|
|
int aChamferPositions, double aPadOrient,
|
|
|
|
OUTLINE_MODE aPlotMode, void* aData )
|
2020-10-08 12:51:25 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
GBR_METADATA gbr_metadata;
|
|
|
|
|
|
|
|
if( aData )
|
|
|
|
gbr_metadata = *static_cast<GBR_METADATA*>( aData );
|
|
|
|
|
|
|
|
DPOINT pos_dev = userToDeviceCoordinates( aShapePos );
|
|
|
|
|
|
|
|
SHAPE_POLY_SET outline;
|
|
|
|
// polygon corners list
|
|
|
|
std::vector<wxPoint> cornerList;
|
|
|
|
|
|
|
|
bool hasRoundedCorner = aCornerRadius != 0 && aChamferPositions != 15;
|
|
|
|
|
|
|
|
#ifdef GBR_USE_MACROS_FOR_CHAMFERED_RECT
|
2020-10-10 12:39:54 +00:00
|
|
|
// Sketch mode or round rect shape or Apert Macros disabled
|
|
|
|
if( aPlotMode != FILLED || hasRoundedCorner || m_gerberDisableApertMacros )
|
2020-10-08 12:51:25 +00:00
|
|
|
#endif
|
|
|
|
{
|
2020-10-13 10:55:24 +00:00
|
|
|
TransformRoundChamferedRectToPolygon( outline, aShapePos, aPadSize, aPadOrient,
|
2021-07-04 12:48:32 +00:00
|
|
|
aCornerRadius, aChamferRatio, aChamferPositions, 0,
|
2020-10-13 10:55:24 +00:00
|
|
|
GetPlotterArcHighDef(), ERROR_INSIDE );
|
2020-10-08 12:51:25 +00:00
|
|
|
|
|
|
|
// Build the corner list
|
|
|
|
const SHAPE_LINE_CHAIN& corners = outline.Outline(0);
|
|
|
|
|
|
|
|
for( int ii = 0; ii < corners.PointCount(); ii++ )
|
|
|
|
cornerList.emplace_back( corners.CPoint( ii ).x, corners.CPoint( ii ).y );
|
|
|
|
|
|
|
|
// Close the polygon
|
|
|
|
cornerList.push_back( cornerList[0] );
|
|
|
|
|
|
|
|
if( aPlotMode == SKETCH )
|
2021-07-18 23:08:54 +00:00
|
|
|
PlotPoly( cornerList, FILL_T::NO_FILL, GetCurrentLineWidth(), &gbr_metadata );
|
2020-10-11 10:53:45 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
#ifdef GBR_USE_MACROS_FOR_CHAMFERED_ROUND_RECT
|
|
|
|
if( m_gerberDisableApertMacros )
|
2021-06-07 18:31:53 +00:00
|
|
|
{
|
2020-10-11 10:53:45 +00:00
|
|
|
PlotGerberRegion( cornerList, &gbr_metadata );
|
2021-06-07 18:31:53 +00:00
|
|
|
}
|
2020-10-11 10:53:45 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// An AM will be created. the shape must be in position 0,0 and orientation 0
|
|
|
|
// to be able to reuse the same AM for pads having the same shape
|
|
|
|
for( size_t ii = 0; ii < cornerList.size(); ii++ )
|
|
|
|
{
|
|
|
|
cornerList[ii] -= aShapePos;
|
|
|
|
RotatePoint( &cornerList[ii], -aPadOrient );
|
|
|
|
}
|
|
|
|
|
|
|
|
selectAperture( cornerList, aPadOrient/10.0,
|
|
|
|
APERTURE::AM_FREE_POLYGON, gbr_metadata.GetApertureAttrib() );
|
|
|
|
formatNetAttribute( &gbr_metadata.m_NetlistMetadata );
|
|
|
|
|
|
|
|
emitDcode( pos_dev, 3 );
|
|
|
|
}
|
|
|
|
#else
|
2020-10-08 12:51:25 +00:00
|
|
|
PlotGerberRegion( cornerList, &gbr_metadata );
|
2020-10-11 10:53:45 +00:00
|
|
|
#endif
|
|
|
|
}
|
2020-10-08 12:51:25 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build the chamfered polygon (4 to 8 corners )
|
2020-10-13 10:55:24 +00:00
|
|
|
TransformRoundChamferedRectToPolygon( outline, wxPoint( 0, 0 ), aPadSize, 0.0, 0,
|
2021-07-04 12:48:32 +00:00
|
|
|
aChamferRatio, aChamferPositions, 0,
|
2020-10-13 10:55:24 +00:00
|
|
|
GetPlotterArcHighDef(), ERROR_INSIDE );
|
2020-10-08 12:51:25 +00:00
|
|
|
|
|
|
|
// Build the corner list
|
|
|
|
const SHAPE_LINE_CHAIN& corners = outline.Outline(0);
|
|
|
|
|
|
|
|
// Generate the polygon (4 to 8 corners )
|
|
|
|
for( int ii = 0; ii < corners.PointCount(); ii++ )
|
|
|
|
cornerList.emplace_back( corners.CPoint( ii ).x, corners.CPoint( ii ).y );
|
|
|
|
|
|
|
|
switch( cornerList.size() )
|
|
|
|
{
|
|
|
|
case 4:
|
|
|
|
m_hasApertureOutline4P = true;
|
|
|
|
selectAperture( cornerList, aPadOrient/10.0,
|
|
|
|
APERTURE::APER_MACRO_OUTLINE4P, gbr_metadata.GetApertureAttrib() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
m_hasApertureChamferedRect = true;
|
|
|
|
selectAperture( cornerList, aPadOrient/10.0,
|
|
|
|
APERTURE::APER_MACRO_OUTLINE5P, gbr_metadata.GetApertureAttrib() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 6:
|
|
|
|
m_hasApertureChamferedRect = true;
|
|
|
|
selectAperture( cornerList, aPadOrient/10.0,
|
|
|
|
APERTURE::APER_MACRO_OUTLINE6P, gbr_metadata.GetApertureAttrib() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 7:
|
|
|
|
m_hasApertureChamferedRect = true;
|
|
|
|
selectAperture( cornerList, aPadOrient/10.0,
|
|
|
|
APERTURE::APER_MACRO_OUTLINE7P, gbr_metadata.GetApertureAttrib() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 8:
|
|
|
|
m_hasApertureChamferedRect = true;
|
|
|
|
selectAperture( cornerList, aPadOrient/10.0,
|
|
|
|
APERTURE::APER_MACRO_OUTLINE8P, gbr_metadata.GetApertureAttrib() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
wxLogMessage( "FlashPadChamferRoundRect(): Unexpected number of corners (%d)",
|
|
|
|
(int)cornerList.size() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
formatNetAttribute( &gbr_metadata.m_NetlistMetadata );
|
|
|
|
|
|
|
|
emitDcode( pos_dev, 3 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
void GERBER_PLOTTER::FlashPadTrapez( const wxPoint& aPadPos, const wxPoint* aCorners,
|
2020-10-15 23:33:18 +00:00
|
|
|
double aPadOrient, OUTLINE_MODE aTrace_Mode, void* aData )
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2011-04-20 08:13:21 +00:00
|
|
|
// polygon corners list
|
2019-12-05 15:20:59 +00:00
|
|
|
std::vector<wxPoint> cornerList = { aCorners[0], aCorners[1], aCorners[2], aCorners[3] };
|
2011-04-20 08:13:21 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
// Draw the polygon and fill the interior as required
|
2011-04-20 08:13:21 +00:00
|
|
|
for( unsigned ii = 0; ii < 4; ii++ )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2011-04-20 08:13:21 +00:00
|
|
|
RotatePoint( &cornerList[ii], aPadOrient );
|
|
|
|
cornerList[ii] += aPadPos;
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2010-09-13 11:51:09 +00:00
|
|
|
// Close the polygon
|
2011-04-20 08:13:21 +00:00
|
|
|
cornerList.push_back( cornerList[0] );
|
2016-09-19 11:01:36 +00:00
|
|
|
GBR_METADATA* gbr_metadata = static_cast<GBR_METADATA*>( aData );
|
|
|
|
|
|
|
|
GBR_METADATA metadata;
|
|
|
|
|
|
|
|
if( gbr_metadata )
|
|
|
|
metadata = *gbr_metadata;
|
2017-05-03 18:04:31 +00:00
|
|
|
|
2019-10-06 11:39:50 +00:00
|
|
|
if( aTrace_Mode == SKETCH )
|
2020-10-10 12:39:54 +00:00
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
PlotPoly( cornerList, FILL_T::NO_FILL, GetCurrentLineWidth(), &metadata );
|
2020-10-10 12:39:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Plot a filled polygon:
|
2020-10-05 18:34:33 +00:00
|
|
|
#ifdef GBR_USE_MACROS_FOR_TRAPEZOID
|
2020-10-10 12:39:54 +00:00
|
|
|
if( !m_gerberDisableApertMacros )
|
|
|
|
#endif
|
2020-09-28 13:36:52 +00:00
|
|
|
{
|
2020-10-08 12:51:25 +00:00
|
|
|
m_hasApertureOutline4P = true;
|
2020-09-28 13:36:52 +00:00
|
|
|
DPOINT pos_dev = userToDeviceCoordinates( aPadPos );
|
|
|
|
// polygon corners list
|
|
|
|
std::vector<wxPoint> corners = { aCorners[0], aCorners[1], aCorners[2], aCorners[3] };
|
|
|
|
int aperture_attrib = gbr_metadata ? gbr_metadata->GetApertureAttrib() : 0;
|
|
|
|
selectAperture( corners, aPadOrient/10.0, APERTURE::APER_MACRO_OUTLINE4P, aperture_attrib );
|
|
|
|
|
|
|
|
if( gbr_metadata )
|
|
|
|
formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
|
|
|
|
|
|
|
|
emitDcode( pos_dev, 3 );
|
2020-10-10 12:39:54 +00:00
|
|
|
return;
|
2020-09-28 13:36:52 +00:00
|
|
|
}
|
2020-10-10 12:39:54 +00:00
|
|
|
|
|
|
|
PlotGerberRegion( cornerList, &metadata );
|
2016-09-19 11:01:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-07 18:31:53 +00:00
|
|
|
void GERBER_PLOTTER::FlashRegularPolygon( const wxPoint& aShapePos, int aDiameter,
|
|
|
|
int aCornerCount, double aOrient,
|
|
|
|
OUTLINE_MODE aTraceMode, void* aData )
|
2019-10-02 15:16:27 +00:00
|
|
|
{
|
|
|
|
GBR_METADATA* gbr_metadata = static_cast<GBR_METADATA*>( aData );
|
|
|
|
|
2020-10-08 12:51:25 +00:00
|
|
|
GBR_METADATA metadata;
|
|
|
|
|
|
|
|
if( gbr_metadata )
|
|
|
|
metadata = *gbr_metadata;
|
|
|
|
|
2019-10-02 15:16:27 +00:00
|
|
|
if( aTraceMode == SKETCH )
|
|
|
|
{
|
|
|
|
// Build the polygon:
|
|
|
|
std::vector< wxPoint > cornerList;
|
|
|
|
|
|
|
|
double angle_delta = 3600.0 / aCornerCount; // in 0.1 degree
|
|
|
|
|
|
|
|
for( int ii = 0; ii < aCornerCount; ii++ )
|
|
|
|
{
|
|
|
|
double rot = aOrient + (angle_delta*ii);
|
|
|
|
wxPoint vertice( aDiameter/2, 0 );
|
|
|
|
RotatePoint( &vertice, rot );
|
|
|
|
vertice += aShapePos;
|
|
|
|
cornerList.push_back( vertice );
|
|
|
|
}
|
|
|
|
|
|
|
|
cornerList.push_back( cornerList[0] ); // Close the shape
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
PlotPoly( cornerList, FILL_T::NO_FILL, GetCurrentLineWidth(), &gbr_metadata );
|
2019-10-02 15:16:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DPOINT pos_dev = userToDeviceCoordinates( aShapePos );
|
|
|
|
|
|
|
|
int aperture_attrib = gbr_metadata ? gbr_metadata->GetApertureAttrib() : 0;
|
|
|
|
|
|
|
|
APERTURE::APERTURE_TYPE apert_type =
|
|
|
|
(APERTURE::APERTURE_TYPE)(APERTURE::AT_REGULAR_POLY3 + aCornerCount - 3);
|
|
|
|
selectAperture( aDiameter, aOrient, apert_type, aperture_attrib );
|
|
|
|
|
|
|
|
if( gbr_metadata )
|
|
|
|
formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
|
|
|
|
|
|
|
|
emitDcode( pos_dev, 3 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-07 18:31:53 +00:00
|
|
|
void GERBER_PLOTTER::Text( const wxPoint& aPos, const COLOR4D& aColor,
|
2016-09-19 11:01:36 +00:00
|
|
|
const wxString& aText, double aOrient, const wxSize& aSize,
|
2020-04-18 20:04:41 +00:00
|
|
|
enum EDA_TEXT_HJUSTIFY_T aH_justify,
|
|
|
|
enum EDA_TEXT_VJUSTIFY_T aV_justify, int aWidth, bool aItalic,
|
|
|
|
bool aBold, bool aMultilineAllowed, void* aData )
|
2016-09-19 11:01:36 +00:00
|
|
|
{
|
|
|
|
GBR_METADATA* gbr_metadata = static_cast<GBR_METADATA*>( aData );
|
|
|
|
|
|
|
|
if( gbr_metadata )
|
|
|
|
formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
|
2008-12-23 07:37:39 +00:00
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
PLOTTER::Text( aPos, aColor, aText, aOrient, aSize, aH_justify, aV_justify, aWidth, aItalic,
|
2020-04-18 20:04:41 +00:00
|
|
|
aBold, aMultilineAllowed, aData );
|
2009-06-28 18:13:55 +00:00
|
|
|
}
|
2010-12-06 22:05:12 +00:00
|
|
|
|
2014-10-19 20:20:16 +00:00
|
|
|
|
2010-12-06 22:05:12 +00:00
|
|
|
void GERBER_PLOTTER::SetLayerPolarity( bool aPositive )
|
|
|
|
{
|
|
|
|
if( aPositive )
|
2020-11-16 00:04:55 +00:00
|
|
|
fprintf( m_outputFile, "%%LPD*%%\n" );
|
2010-12-06 22:05:12 +00:00
|
|
|
else
|
2020-11-16 00:04:55 +00:00
|
|
|
fprintf( m_outputFile, "%%LPC*%%\n" );
|
2010-12-06 22:05:12 +00:00
|
|
|
}
|
2021-01-30 08:59:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool APER_MACRO_FREEPOLY::IsSamePoly( const std::vector<wxPoint>& aPolygon ) const
|
|
|
|
{
|
|
|
|
return polyCompare( m_Corners, aPolygon );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void APER_MACRO_FREEPOLY::Format( FILE * aOutput, double aIu2GbrMacroUnit )
|
|
|
|
{
|
|
|
|
// Write aperture header
|
|
|
|
fprintf( aOutput, "%%AM%s%d*\n", AM_FREEPOLY_BASENAME, m_Id );
|
|
|
|
fprintf( aOutput, "4,1,%d,", (int)m_Corners.size() );
|
|
|
|
|
|
|
|
// Insert a newline after curr_line_count_max coordinates.
|
|
|
|
int curr_line_corner_count = 0;
|
|
|
|
const int curr_line_count_max = 20; // <= 0 to disable newlines
|
|
|
|
|
|
|
|
for( size_t ii = 0; ii <= m_Corners.size(); ii++ )
|
|
|
|
{
|
|
|
|
int jj = ii;
|
|
|
|
|
|
|
|
if( ii >= m_Corners.size() )
|
|
|
|
jj = 0;
|
|
|
|
|
|
|
|
// Note: parameter values are always mm or inches
|
|
|
|
fprintf( aOutput, "%#f,%#f,",
|
|
|
|
m_Corners[jj].x * aIu2GbrMacroUnit, -m_Corners[jj].y * aIu2GbrMacroUnit );
|
|
|
|
|
2021-06-07 18:31:53 +00:00
|
|
|
if( curr_line_count_max >= 0 && ++curr_line_corner_count >= curr_line_count_max )
|
2021-01-30 08:59:53 +00:00
|
|
|
{
|
|
|
|
fprintf( aOutput, "\n" );
|
|
|
|
curr_line_corner_count = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// output rotation parameter
|
|
|
|
fputs( "$1*%\n", aOutput );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void APER_MACRO_FREEPOLY_LIST::Format( FILE * aOutput, double aIu2GbrMacroUnit )
|
|
|
|
{
|
|
|
|
for( int idx = 0; idx < AmCount(); idx++ )
|
|
|
|
m_AMList[idx].Format( aOutput, aIu2GbrMacroUnit );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void APER_MACRO_FREEPOLY_LIST::Append( const std::vector<wxPoint>& aPolygon )
|
|
|
|
{
|
|
|
|
m_AMList.emplace_back( aPolygon, AmCount() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int APER_MACRO_FREEPOLY_LIST::FindAm( const std::vector<wxPoint>& aPolygon ) const
|
|
|
|
{
|
|
|
|
for( int idx = 0; idx < AmCount(); idx++ )
|
|
|
|
{
|
|
|
|
if( m_AMList[idx].IsSamePoly( aPolygon ) )
|
|
|
|
return idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|