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
|
|
|
|
* Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
|
2014-10-19 20:20:16 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <trigo.h>
|
2018-01-29 15:39:40 +00:00
|
|
|
#include <eda_base_frame.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <base_struct.h>
|
|
|
|
#include <common.h>
|
2018-01-28 18:12:26 +00:00
|
|
|
#include <plotter.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <macros.h>
|
|
|
|
#include <kicad_string.h>
|
2016-02-10 16:02:40 +00:00
|
|
|
#include <convert_basic_shapes_to_polygon.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
|
|
|
|
2018-05-17 05:49:38 +00:00
|
|
|
#include <gbr_metadata.h>
|
2016-09-19 11:01:36 +00:00
|
|
|
|
2014-10-19 20:20:16 +00:00
|
|
|
|
2014-07-04 14:22:38 +00:00
|
|
|
GERBER_PLOTTER::GERBER_PLOTTER()
|
|
|
|
{
|
2016-09-19 11:01:36 +00:00
|
|
|
workFile = NULL;
|
|
|
|
finalFile = NULL;
|
2014-07-04 14:22:38 +00:00
|
|
|
currentAperture = apertures.end();
|
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
|
|
|
|
// Be carefull: the Gerber coordinates are stored in an integer
|
|
|
|
// 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;
|
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,
|
|
|
|
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;
|
2012-05-03 18:37:56 +00:00
|
|
|
plotOffset = aOffset;
|
2014-06-30 10:00:21 +00:00
|
|
|
wxASSERT( aScale == 1 ); // aScale parameter is not used in Gerber
|
|
|
|
plotScale = 1; // Plot scale is *always* 1.0
|
|
|
|
|
2012-08-29 20:13:47 +00:00
|
|
|
m_IUsPerDecimil = aIusPerDecimil;
|
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()
|
|
|
|
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
|
2012-05-03 18:37:56 +00:00
|
|
|
paperSize.x = 0;
|
|
|
|
paperSize.y = 0;
|
|
|
|
SetDefaultLineWidth( 100 * aIusPerDecimil ); // Arbitrary default
|
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;
|
|
|
|
|
|
|
|
iuPerDeviceUnit = pow( 10.0, m_gerberUnitFmt ) / ( m_IUsPerDecimil * 10000.0 );
|
|
|
|
|
|
|
|
if( ! m_gerberUnitInch )
|
|
|
|
iuPerDeviceUnit *= 25.4; // gerber output in mm
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
void GERBER_PLOTTER::emitDcode( const DPOINT& pt, int dcode )
|
|
|
|
{
|
|
|
|
|
2012-10-13 18:54:33 +00:00
|
|
|
fprintf( outputFile, "X%dY%dD%02d*\n",
|
2014-07-04 14:22:38 +00:00
|
|
|
KiROUND( pt.x ), KiROUND( pt.y ), dcode );
|
2012-05-03 18:37:56 +00:00
|
|
|
}
|
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::clearNetAttribute()
|
|
|
|
{
|
|
|
|
// disable a Gerber net attribute (exists only in X2 with net attributes mode).
|
|
|
|
if( m_objectAttributesDictionnary.empty() ) // No net attribute or not X2 mode
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Remove all net attributes from object attributes dictionnary
|
2018-12-09 09:23:07 +00:00
|
|
|
if( m_useX2format )
|
2018-05-17 15:32:14 +00:00
|
|
|
fputs( "%TD*%\n", outputFile );
|
|
|
|
else
|
|
|
|
fputs( "G04 #@! TD*\n", outputFile );
|
2016-09-19 11:01:36 +00:00
|
|
|
|
|
|
|
m_objectAttributesDictionnary.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
// Remove all net attributes from object attributes dictionnary
|
|
|
|
clearNetAttribute();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GERBER_PLOTTER::formatNetAttribute( GBR_NETLIST_METADATA* aData )
|
|
|
|
{
|
|
|
|
// print a Gerber net attribute record.
|
|
|
|
// it is added to the object attributes dictionnary
|
|
|
|
// On file, only modified or new attributes are printed.
|
2018-05-17 15:32:14 +00:00
|
|
|
if( aData == NULL )
|
|
|
|
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;
|
|
|
|
|
|
|
|
if( !FormatNetAttribute( short_attribute_string, m_objectAttributesDictionnary,
|
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() )
|
|
|
|
fputs( short_attribute_string.c_str(), outputFile );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-13 18:54:33 +00:00
|
|
|
bool GERBER_PLOTTER::StartPlot()
|
2008-12-23 07:37:39 +00:00
|
|
|
{
|
2012-10-13 18:54:33 +00:00
|
|
|
wxASSERT( outputFile );
|
|
|
|
|
|
|
|
finalFile = outputFile; // the actual gerber file will be created later
|
2010-03-31 16:59:32 +00:00
|
|
|
|
|
|
|
// Create a temporary filename to store gerber file
|
2011-09-20 13:57:40 +00:00
|
|
|
// note tmpfile() does not work under Vista and W7 in user mode
|
2010-03-31 16:59:32 +00:00
|
|
|
m_workFilename = filename + wxT(".tmp");
|
2012-05-03 18:37:56 +00:00
|
|
|
workFile = wxFopen( m_workFilename, wxT( "wt" ));
|
|
|
|
outputFile = workFile;
|
|
|
|
wxASSERT( outputFile );
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
if( outputFile == NULL )
|
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() )
|
|
|
|
fprintf( 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
|
|
|
|
// the number of digits for the integer part of coordintes is needed
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
fprintf( outputFile, "%%FSLAX%d%dY%d%d*%%\n",
|
|
|
|
leadingDigitCount, m_gerberUnitFmt,
|
|
|
|
leadingDigitCount, m_gerberUnitFmt );
|
|
|
|
fprintf( outputFile,
|
|
|
|
"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
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
wxString Title = creator + wxT( " " ) + GetBuildVersion();
|
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();
|
2014-07-01 19:20:38 +00:00
|
|
|
fprintf( 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 )
|
|
|
|
fputs( "%MOIN*%\n", outputFile );
|
|
|
|
else
|
|
|
|
fputs( "%MOMM*%\n", 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:
|
|
|
|
fputs( "%LPD*%\n", outputFile );
|
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
fputs( "G04 APERTURE LIST*\n", outputFile );
|
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;
|
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
wxASSERT( 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 */
|
|
|
|
fputs( "M02*\n", outputFile );
|
|
|
|
fflush( 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 );
|
|
|
|
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
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
fputs( line, outputFile );
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
if( strcmp( strtok( line, "\n\r" ), "G04 APERTURE LIST*" ) == 0 )
|
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
writeApertureList();
|
|
|
|
fputs( "G04 APERTURE END LIST*\n", 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 );
|
2012-05-03 18:37:56 +00:00
|
|
|
outputFile = 0;
|
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
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
void GERBER_PLOTTER::SetDefaultLineWidth( int width )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
defaultPenWidth = width;
|
|
|
|
currentAperture = apertures.end();
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2016-09-19 11:01:36 +00:00
|
|
|
void GERBER_PLOTTER::SetCurrentLineWidth( int width, void* aData )
|
2008-12-23 07:37:39 +00:00
|
|
|
{
|
2016-09-19 11:01:36 +00:00
|
|
|
if( width == DO_NOT_SET_LINE_WIDTH )
|
|
|
|
return;
|
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
int pen_width;
|
|
|
|
|
|
|
|
if( width > 0 )
|
|
|
|
pen_width = width;
|
|
|
|
else
|
2012-05-03 18:37:56 +00:00
|
|
|
pen_width = defaultPenWidth;
|
2009-06-28 16:50:42 +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;
|
|
|
|
|
|
|
|
selectAperture( wxSize( pen_width, pen_width ), APERTURE::Plotting, aperture_attribute );
|
2012-05-03 18:37:56 +00:00
|
|
|
currentPenWidth = pen_width;
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2016-09-19 11:01:36 +00:00
|
|
|
std::vector<APERTURE>::iterator GERBER_PLOTTER::getAperture( const wxSize& aSize,
|
|
|
|
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
|
2009-08-29 10:20:48 +00:00
|
|
|
std::vector<APERTURE>::iterator tool = apertures.begin();
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
while( tool != apertures.end() )
|
|
|
|
{
|
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) &&
|
|
|
|
(tool->m_ApertureAttribute == aApertureAttribute) )
|
2009-06-28 18:13:55 +00:00
|
|
|
return tool;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2016-09-19 11:01:36 +00:00
|
|
|
++tool;
|
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;
|
|
|
|
new_tool.m_DCode = last_D_code + 1;
|
|
|
|
new_tool.m_ApertureAttribute = aApertureAttribute;
|
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
apertures.push_back( new_tool );
|
2016-09-19 11:01:36 +00:00
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
return apertures.end() - 1;
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2016-09-19 11:01:36 +00:00
|
|
|
void GERBER_PLOTTER::selectAperture( const wxSize& aSize,
|
|
|
|
APERTURE::APERTURE_TYPE aType,
|
|
|
|
int aApertureAttribute )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2016-09-19 11:01:36 +00:00
|
|
|
bool change = ( currentAperture == apertures.end() ) ||
|
|
|
|
( currentAperture->m_Type != aType ) ||
|
|
|
|
( currentAperture->m_Size != aSize );
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2018-12-08 16:46:41 +00:00
|
|
|
if( !m_useNetAttributes )
|
2016-09-19 11:01:36 +00:00
|
|
|
aApertureAttribute = 0;
|
|
|
|
else
|
|
|
|
change = change || ( currentAperture->m_ApertureAttribute != aApertureAttribute );
|
|
|
|
|
|
|
|
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
|
2016-09-19 11:01:36 +00:00
|
|
|
currentAperture = getAperture( aSize, aType, aApertureAttribute );
|
|
|
|
fprintf( outputFile, "D%d*\n", currentAperture->m_DCode );
|
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::writeApertureList()
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
wxASSERT( outputFile );
|
2009-06-28 16:50:42 +00:00
|
|
|
char cbuf[1024];
|
|
|
|
|
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
|
2009-08-29 10:20:48 +00:00
|
|
|
for( std::vector<APERTURE>::iterator tool = apertures.begin();
|
2016-09-19 11:01:36 +00:00
|
|
|
tool != apertures.end(); ++tool )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2014-06-30 10:00:21 +00:00
|
|
|
// apertude sizes are in inch or mm, regardless the
|
|
|
|
// coordinates format
|
|
|
|
double fscale = 0.0001 * plotScale / m_IUsPerDecimil; // inches
|
|
|
|
|
|
|
|
if(! m_gerberUnitInch )
|
|
|
|
fscale *= 25.4; // size in mm
|
|
|
|
|
2016-09-19 11:01:36 +00:00
|
|
|
int attribute = tool->m_ApertureAttribute;
|
|
|
|
|
|
|
|
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,
|
|
|
|
useX1StructuredComment ).c_str(), outputFile );
|
|
|
|
}
|
2016-09-19 11:01:36 +00:00
|
|
|
|
|
|
|
char* text = cbuf + sprintf( cbuf, "%%ADD%d", tool->m_DCode );
|
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
|
|
|
|
can't remove trailing zeros but thats not a problem, since nothing
|
|
|
|
forbid it (the file is only slightly longer) */
|
|
|
|
|
2016-09-19 11:01:36 +00:00
|
|
|
switch( tool->m_Type )
|
2009-06-28 18:13:55 +00:00
|
|
|
{
|
2009-08-29 10:20:48 +00:00
|
|
|
case APERTURE::Circle:
|
2016-09-19 11:01:36 +00:00
|
|
|
sprintf( text, "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
|
|
|
|
2009-08-29 10:20:48 +00:00
|
|
|
case APERTURE::Rect:
|
2013-05-06 17:47:01 +00:00
|
|
|
sprintf( text, "R,%#fX%#f*%%\n",
|
2016-09-19 11:01:36 +00:00
|
|
|
tool->m_Size.x * fscale,
|
|
|
|
tool->m_Size.y * fscale );
|
2009-06-28 18:13:55 +00:00
|
|
|
break;
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2009-08-29 10:20:48 +00:00
|
|
|
case APERTURE::Plotting:
|
2016-09-19 11:01:36 +00:00
|
|
|
sprintf( text, "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
|
|
|
|
2009-08-29 10:20:48 +00:00
|
|
|
case APERTURE::Oval:
|
2013-05-06 17:47:01 +00:00
|
|
|
sprintf( text, "O,%#fX%#f*%%\n",
|
2016-09-19 11:01:36 +00:00
|
|
|
tool->m_Size.x * fscale,
|
|
|
|
tool->m_Size.y * fscale );
|
2009-06-28 18:13:55 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
fputs( cbuf, 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 )
|
2018-05-17 15:32:14 +00:00
|
|
|
fputs( "%TD*%\n", outputFile );
|
|
|
|
else
|
|
|
|
fputs( "G04 #@! TD*\n", outputFile );
|
|
|
|
|
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
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
wxASSERT( outputFile );
|
|
|
|
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
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
penState = plume;
|
2008-12-23 07:37:39 +00:00
|
|
|
}
|
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2014-10-19 20:20:16 +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
|
|
|
|
2014-10-19 20:20:16 +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
|
|
|
|
2013-05-05 07:17:48 +00:00
|
|
|
void GERBER_PLOTTER::Arc( const wxPoint& aCenter, double aStAngle, double aEndAngle,
|
2012-07-15 17:28:52 +00:00
|
|
|
int aRadius, FILL_T aFill, int aWidth )
|
|
|
|
{
|
2016-09-19 11:01:36 +00:00
|
|
|
SetCurrentLineWidth( aWidth );
|
|
|
|
|
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 ) );
|
2012-05-03 18:37:56 +00:00
|
|
|
MoveTo( 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
|
|
|
|
2018-11-28 17:43:45 +00:00
|
|
|
fprintf( outputFile, "G75*\n" ); // Multiquadrant (360 degrees) mode
|
2012-07-15 17:28:52 +00:00
|
|
|
|
|
|
|
if( aStAngle < aEndAngle )
|
|
|
|
fprintf( outputFile, "G03" );
|
|
|
|
else
|
|
|
|
fprintf( outputFile, "G02" );
|
2014-07-09 16:31:39 +00:00
|
|
|
|
|
|
|
fprintf( outputFile, "X%dY%dI%dJ%dD01*\n",
|
|
|
|
KiROUND( devEnd.x ), KiROUND( devEnd.y ),
|
|
|
|
KiROUND( devCenter.x ), KiROUND( devCenter.y ) );
|
2018-11-28 17:43:45 +00:00
|
|
|
|
|
|
|
fprintf( outputFile, "G01*\n" ); // Back to linear interpol (perhaps useless here).
|
2008-12-23 07:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-10-23 16:57:21 +00:00
|
|
|
void GERBER_PLOTTER::PlotGerberRegion( const std::vector< wxPoint >& aCornerList,
|
|
|
|
void * aData )
|
|
|
|
{
|
|
|
|
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() )
|
|
|
|
{
|
|
|
|
fputs( attrib.c_str(), outputFile );
|
|
|
|
clearTA_AperFunction = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PlotPoly( aCornerList, FILLED_SHAPE, 0 , gbr_metadata );
|
|
|
|
|
|
|
|
// Clear the TA attribute, to avoid the next item to inherit it:
|
|
|
|
if( clearTA_AperFunction )
|
|
|
|
{
|
|
|
|
if( m_useX2format )
|
|
|
|
{
|
|
|
|
fputs( "%TD.AperFunction*%\n", outputFile );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fputs( "G04 #@! TD.AperFunction*\n", outputFile );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GERBER_PLOTTER::PlotPoly( const std::vector< wxPoint >& aCornerList,
|
2016-09-19 11:01:36 +00:00
|
|
|
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
|
|
|
SetCurrentLineWidth( aWidth, gbr_metadata );
|
|
|
|
|
|
|
|
if( gbr_metadata )
|
|
|
|
formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
|
2009-06-28 18:13:55 +00:00
|
|
|
|
|
|
|
if( aFill )
|
2014-05-16 19:03:45 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
fputs( "G36*\n", outputFile );
|
2011-04-20 08:13:21 +00:00
|
|
|
|
2014-05-16 19:03:45 +00:00
|
|
|
MoveTo( aCornerList[0] );
|
2018-11-28 17:43:45 +00:00
|
|
|
fputs( "G01*\n", 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] );
|
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
fputs( "G37*\n", outputFile );
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
2014-05-16 19:03:45 +00:00
|
|
|
|
|
|
|
if( aWidth > 0 )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
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)
|
|
|
|
if( aFill && ( aCornerList[aCornerList.size()-1] != aCornerList[0] ) )
|
|
|
|
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,
|
|
|
|
EDA_DRAW_MODE_T tracemode, void* aData )
|
|
|
|
{
|
|
|
|
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,
|
|
|
|
int radius, int width, EDA_DRAW_MODE_T tracemode, void* aData )
|
|
|
|
{
|
|
|
|
GBR_METADATA *gbr_metadata = static_cast<GBR_METADATA*>( aData );
|
|
|
|
SetCurrentLineWidth( width, gbr_metadata );
|
|
|
|
|
|
|
|
if( gbr_metadata )
|
|
|
|
formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
|
|
|
|
|
|
|
|
if( tracemode == FILLED )
|
|
|
|
Arc( centre, StAngle, EndAngle, radius, NO_FILL, DO_NOT_SET_LINE_WIDTH );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetCurrentLineWidth( USE_DEFAULT_LINE_WIDTH );
|
|
|
|
Arc( centre, StAngle, EndAngle,
|
|
|
|
radius - ( width - currentPenWidth ) / 2,
|
|
|
|
NO_FILL, DO_NOT_SET_LINE_WIDTH );
|
|
|
|
Arc( centre, StAngle, EndAngle,
|
|
|
|
radius + ( width - currentPenWidth ) / 2, NO_FILL,
|
|
|
|
DO_NOT_SET_LINE_WIDTH );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GERBER_PLOTTER::ThickRect( const wxPoint& p1, const wxPoint& p2, int width,
|
|
|
|
EDA_DRAW_MODE_T tracemode, void* aData )
|
|
|
|
{
|
|
|
|
GBR_METADATA *gbr_metadata = static_cast<GBR_METADATA*>( aData );
|
|
|
|
SetCurrentLineWidth( width, gbr_metadata );
|
|
|
|
|
|
|
|
if( gbr_metadata )
|
|
|
|
formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
|
|
|
|
|
|
|
|
if( tracemode == FILLED )
|
|
|
|
Rect( p1, p2, NO_FILL, DO_NOT_SET_LINE_WIDTH );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetCurrentLineWidth( USE_DEFAULT_LINE_WIDTH );
|
|
|
|
wxPoint offsetp1( p1.x - (width - currentPenWidth) / 2,
|
|
|
|
p1.y - (width - currentPenWidth) / 2 );
|
|
|
|
wxPoint offsetp2( p2.x + (width - currentPenWidth) / 2,
|
|
|
|
p2.y + (width - currentPenWidth) / 2 );
|
|
|
|
Rect( offsetp1, offsetp2, NO_FILL, -1 );
|
|
|
|
offsetp1.x += (width - currentPenWidth);
|
|
|
|
offsetp1.y += (width - currentPenWidth);
|
|
|
|
offsetp2.x -= (width - currentPenWidth);
|
|
|
|
offsetp2.y -= (width - currentPenWidth);
|
|
|
|
Rect( offsetp1, offsetp2, NO_FILL, DO_NOT_SET_LINE_WIDTH );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GERBER_PLOTTER::ThickCircle( const wxPoint& pos, int diametre, int width,
|
|
|
|
EDA_DRAW_MODE_T tracemode, void* aData )
|
|
|
|
{
|
|
|
|
GBR_METADATA *gbr_metadata = static_cast<GBR_METADATA*>( aData );
|
|
|
|
SetCurrentLineWidth( width, gbr_metadata );
|
|
|
|
|
|
|
|
if( gbr_metadata )
|
|
|
|
formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
|
|
|
|
|
|
|
|
if( tracemode == FILLED )
|
|
|
|
Circle( pos, diametre, NO_FILL, DO_NOT_SET_LINE_WIDTH );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetCurrentLineWidth( USE_DEFAULT_LINE_WIDTH, gbr_metadata );
|
|
|
|
Circle( pos, diametre - (width - currentPenWidth),
|
|
|
|
NO_FILL, DO_NOT_SET_LINE_WIDTH );
|
|
|
|
Circle( pos, diametre + (width - currentPenWidth),
|
|
|
|
NO_FILL, DO_NOT_SET_LINE_WIDTH );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GERBER_PLOTTER::FlashPadCircle( const wxPoint& pos, int diametre, EDA_DRAW_MODE_T 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
|
|
|
SetCurrentLineWidth( USE_DEFAULT_LINE_WIDTH, gbr_metadata );
|
|
|
|
|
|
|
|
if( gbr_metadata )
|
|
|
|
formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
|
|
|
|
|
|
|
|
Circle( pos, diametre - currentPenWidth, 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;
|
|
|
|
selectAperture( size, APERTURE::Circle, aperture_attrib );
|
|
|
|
|
|
|
|
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,
|
2016-09-19 11:01:36 +00:00
|
|
|
EDA_DRAW_MODE_T trace_mode, void* aData )
|
2008-12-23 07:37:39 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
wxASSERT( outputFile );
|
|
|
|
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-23 16:57:21 +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;
|
|
|
|
selectAperture( size, APERTURE::Oval, aperture_attrib );
|
|
|
|
|
|
|
|
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-23 16:57:21 +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( size.x > size.y )
|
|
|
|
{
|
2015-06-26 13:41:56 +00:00
|
|
|
std::swap( size.x, size.y );
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
if( orient < 2700 )
|
|
|
|
orient += 900;
|
|
|
|
else
|
|
|
|
orient -= 2700;
|
|
|
|
}
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
if( trace_mode == FILLED )
|
|
|
|
{
|
2016-02-10 16:02:40 +00:00
|
|
|
// TODO: use an aperture macro to declare the rotated pad
|
2019-10-23 16:57:21 +00:00
|
|
|
// to be able to flash the shape
|
|
|
|
// For now, the pad is drawn as segment
|
2016-09-24 16:37:06 +00:00
|
|
|
|
2016-02-10 16:02:40 +00:00
|
|
|
// The pad is reduced to an segment with dy > dx
|
2018-03-16 18:32:49 +00:00
|
|
|
int delta = size.y - size.x;
|
|
|
|
int x0 = 0;
|
|
|
|
int y0 = -delta / 2;
|
|
|
|
int x1 = 0;
|
|
|
|
int y1 = delta / 2;
|
2009-06-28 18:13:55 +00:00
|
|
|
RotatePoint( &x0, &y0, orient );
|
|
|
|
RotatePoint( &x1, &y1, orient );
|
2016-09-19 11:01:36 +00:00
|
|
|
GBR_METADATA metadata;
|
|
|
|
|
|
|
|
if( gbr_metadata )
|
|
|
|
{
|
|
|
|
metadata = *gbr_metadata;
|
|
|
|
|
2017-05-03 18:04:31 +00:00
|
|
|
// If the pad is drawn on a copper layer,
|
|
|
|
// set attribute to GBR_APERTURE_ATTRIB_CONDUCTOR
|
|
|
|
if( metadata.IsCopper() )
|
|
|
|
metadata.SetApertureAttrib( GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB_CONDUCTOR );
|
|
|
|
|
|
|
|
// Clear .P attribute, only allowed for flashed items
|
2016-09-19 11:01:36 +00:00
|
|
|
wxString attrname( ".P" );
|
2016-09-24 16:37:06 +00:00
|
|
|
metadata.m_NetlistMetadata.ClearAttribute( &attrname );
|
2016-09-19 11:01:36 +00:00
|
|
|
}
|
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
ThickSegment( wxPoint( pos.x + x0, pos.y + y0 ),
|
2009-06-28 18:13:55 +00:00
|
|
|
wxPoint( pos.x + x1, pos.y + y1 ),
|
2016-09-19 11:01:36 +00:00
|
|
|
size.x, trace_mode, &metadata );
|
2009-06-28 18:13:55 +00:00
|
|
|
}
|
|
|
|
else
|
2012-05-03 18:37:56 +00:00
|
|
|
sketchOval( pos, size, orient, -1 );
|
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,
|
2016-09-19 11:01:36 +00:00
|
|
|
double orient, EDA_DRAW_MODE_T trace_mode, void* aData )
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
wxASSERT( outputFile );
|
|
|
|
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 );
|
2018-03-16 18:32:49 +00:00
|
|
|
// Pass through
|
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
|
|
|
SetCurrentLineWidth( USE_DEFAULT_LINE_WIDTH, gbr_metadata );
|
|
|
|
|
|
|
|
if( gbr_metadata )
|
|
|
|
formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
|
|
|
|
|
2014-10-19 20:20:16 +00:00
|
|
|
Rect( wxPoint( pos.x - (size.x - currentPenWidth) / 2,
|
|
|
|
pos.y - (size.y - currentPenWidth) / 2 ),
|
|
|
|
wxPoint( pos.x + (size.x - currentPenWidth) / 2,
|
|
|
|
pos.y + (size.y - currentPenWidth) / 2 ),
|
2018-03-16 18:32:49 +00:00
|
|
|
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;
|
|
|
|
selectAperture( size, APERTURE::Rect, aperture_attrib );
|
|
|
|
|
|
|
|
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
|
|
|
|
2012-10-13 18:54:33 +00:00
|
|
|
default: // plot pad shape as polygon
|
2012-05-03 18:37:56 +00:00
|
|
|
{
|
2012-10-13 18:54:33 +00:00
|
|
|
// XXX to do: use an aperture macro to declare the rotated pad
|
2012-05-03 18:37:56 +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
|
|
|
|
|
|
|
|
/* Trace the outline. */
|
|
|
|
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;
|
|
|
|
|
2016-09-19 11:01:36 +00:00
|
|
|
FlashPadTrapez( pos, coord, orient, trace_mode, aData );
|
2012-05-03 18:37:56 +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,
|
2016-09-19 11:01:36 +00:00
|
|
|
EDA_DRAW_MODE_T aTraceMode, void* aData )
|
2016-02-10 16:02:40 +00:00
|
|
|
|
|
|
|
{
|
2019-10-23 16:57:21 +00:00
|
|
|
GBR_METADATA *gbr_metadata = static_cast<GBR_METADATA*>( aData );
|
2018-03-16 18:32:49 +00:00
|
|
|
|
2016-02-10 16:02:40 +00:00
|
|
|
// Currently, a Pad RoundRect is plotted as polygon.
|
|
|
|
// TODO: use Aperture macro and flash it
|
|
|
|
SHAPE_POLY_SET outline;
|
|
|
|
const int segmentToCircleCount = 64;
|
|
|
|
TransformRoundRectToPolygon( outline, aPadPos, aSize, aOrient,
|
|
|
|
aCornerRadius, segmentToCircleCount );
|
|
|
|
|
2018-03-16 18:32:49 +00:00
|
|
|
if( aTraceMode != FILLED )
|
2019-10-23 16:57:21 +00:00
|
|
|
{
|
|
|
|
SetCurrentLineWidth( USE_DEFAULT_LINE_WIDTH, &gbr_metadata );
|
2018-03-16 18:32:49 +00:00
|
|
|
outline.Inflate( -GetCurrentLineWidth()/2, 16 );
|
2019-10-23 16:57:21 +00:00
|
|
|
}
|
2018-03-16 18:32:49 +00:00
|
|
|
|
2016-02-10 16:02:40 +00:00
|
|
|
std::vector< wxPoint > cornerList;
|
|
|
|
// TransformRoundRectToPolygon creates only one convex polygon
|
|
|
|
SHAPE_LINE_CHAIN& poly = outline.Outline( 0 );
|
2018-03-16 18:32:49 +00:00
|
|
|
cornerList.reserve( poly.PointCount() + 1 );
|
2016-02-10 16:02:40 +00:00
|
|
|
|
|
|
|
for( int ii = 0; ii < poly.PointCount(); ++ii )
|
|
|
|
cornerList.push_back( wxPoint( poly.Point( ii ).x, poly.Point( ii ).y ) );
|
|
|
|
|
|
|
|
// Close polygon
|
|
|
|
cornerList.push_back( cornerList[0] );
|
|
|
|
|
2019-10-23 16:57:21 +00:00
|
|
|
if( aTraceMode == SKETCH )
|
|
|
|
PlotPoly( cornerList, NO_FILL, GetCurrentLineWidth(), gbr_metadata );
|
|
|
|
else
|
|
|
|
PlotGerberRegion( cornerList, gbr_metadata );
|
2016-02-10 16:02:40 +00:00
|
|
|
}
|
|
|
|
|
2019-10-23 16:57:21 +00:00
|
|
|
|
2016-02-10 16:02:40 +00:00
|
|
|
void GERBER_PLOTTER::FlashPadCustom( const wxPoint& aPadPos, const wxSize& aSize,
|
|
|
|
SHAPE_POLY_SET* aPolygons,
|
2016-09-19 11:01:36 +00:00
|
|
|
EDA_DRAW_MODE_T aTraceMode, void* aData )
|
2016-02-10 16:02:40 +00:00
|
|
|
|
|
|
|
{
|
2019-10-23 16:57:21 +00:00
|
|
|
// A Pad custom is plotted as Gerber region.
|
2018-03-16 18:32:49 +00:00
|
|
|
|
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 )
|
|
|
|
cornerList.push_back( wxPoint( poly.Point( ii ).x, poly.Point( ii ).y ) );
|
|
|
|
|
|
|
|
// Close polygon
|
|
|
|
cornerList.push_back( cornerList[0] );
|
|
|
|
|
2019-10-23 16:57:21 +00:00
|
|
|
if( aTraceMode == SKETCH )
|
|
|
|
PlotPoly( cornerList, NO_FILL, GetCurrentLineWidth(), &gbr_metadata );
|
|
|
|
else
|
|
|
|
PlotGerberRegion( cornerList, &gbr_metadata );
|
2016-02-10 16:02:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
void GERBER_PLOTTER::FlashPadTrapez( const wxPoint& aPadPos, const wxPoint* aCorners,
|
2016-09-19 11:01:36 +00:00
|
|
|
double aPadOrient, EDA_DRAW_MODE_T aTrace_Mode, void* aData )
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2016-02-10 16:02:40 +00:00
|
|
|
// Currently, a Pad Trapezoid is plotted as polygon.
|
|
|
|
// TODO: use Aperture macro and flash it
|
|
|
|
|
2011-04-20 08:13:21 +00:00
|
|
|
// polygon corners list
|
2012-05-03 18:37:56 +00:00
|
|
|
std::vector< wxPoint > cornerList;
|
2010-09-13 11:51:09 +00:00
|
|
|
|
|
|
|
for( int ii = 0; ii < 4; ii++ )
|
2011-04-20 08:13:21 +00:00
|
|
|
cornerList.push_back( aCorners[ii] );
|
|
|
|
|
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-23 16:57:21 +00:00
|
|
|
if( aTrace_Mode == SKETCH )
|
|
|
|
PlotPoly( cornerList, NO_FILL, USE_DEFAULT_LINE_WIDTH, &metadata );
|
|
|
|
else
|
|
|
|
PlotGerberRegion( cornerList, &metadata );
|
2016-09-19 11:01:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-20 16:57:41 +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,
|
|
|
|
enum EDA_TEXT_HJUSTIFY_T aH_justify, enum EDA_TEXT_VJUSTIFY_T aV_justify,
|
|
|
|
int aWidth, bool aItalic, bool aBold, bool aMultilineAllowed,
|
|
|
|
void* aData )
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2016-09-19 11:01:36 +00:00
|
|
|
PLOTTER::Text( aPos, aColor, aText, aOrient, aSize,
|
|
|
|
aH_justify, aV_justify, aWidth, aItalic, 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 )
|
2012-05-03 18:37:56 +00:00
|
|
|
fprintf( outputFile, "%%LPD*%%\n" );
|
2010-12-06 22:05:12 +00:00
|
|
|
else
|
2012-05-03 18:37:56 +00:00
|
|
|
fprintf( outputFile, "%%LPC*%%\n" );
|
2010-12-06 22:05:12 +00:00
|
|
|
}
|