2019-09-15 15:08:57 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2019 Jean_Pierre Charras <jp.charras at wanadoo.fr>
|
2023-08-31 09:02:50 +00:00
|
|
|
* Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2019-09-15 15:08:57 +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.
|
|
|
|
*
|
|
|
|
* 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file gerber_placefile_writer.cpp
|
|
|
|
* @brief Functions to create place files in gerber X2 format.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gerber_placefile_writer.h"
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
2021-08-18 20:38:14 +00:00
|
|
|
#include <plotters/plotter_gerber.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2020-10-24 01:38:50 +00:00
|
|
|
#include <locale_io.h>
|
2021-03-20 15:35:37 +00:00
|
|
|
#include <macros.h>
|
2019-09-15 15:08:57 +00:00
|
|
|
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <board_design_settings.h>
|
2022-01-30 10:52:52 +00:00
|
|
|
#include <pcb_shape.h>
|
2019-09-15 15:08:57 +00:00
|
|
|
|
|
|
|
#include <pcbplot.h>
|
|
|
|
#include <wildcards_and_files_ext.h>
|
|
|
|
#include <gbr_metadata.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <footprint.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <pad.h>
|
2022-01-30 10:52:52 +00:00
|
|
|
#include <fp_shape.h>
|
2019-09-15 15:08:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
PLACEFILE_GERBER_WRITER::PLACEFILE_GERBER_WRITER( BOARD* aPcb )
|
|
|
|
{
|
2020-11-16 00:04:55 +00:00
|
|
|
m_pcb = aPcb;
|
2020-01-12 13:00:42 +00:00
|
|
|
m_plotPad1Marker = true; // Place a marker to pin 1 (or A1) position
|
|
|
|
m_plotOtherPadsMarker = true; // Place a marker to other pins position
|
|
|
|
m_layer = PCB_LAYER_ID::UNDEFINED_LAYER; // No layer set
|
2019-09-15 15:08:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-01 12:28:10 +00:00
|
|
|
int PLACEFILE_GERBER_WRITER::CreatePlaceFile( wxString& aFullFilename, PCB_LAYER_ID aLayer,
|
|
|
|
bool aIncludeBrdEdges )
|
2019-09-15 15:08:57 +00:00
|
|
|
{
|
|
|
|
m_layer = aLayer;
|
|
|
|
|
2019-11-17 09:11:29 +00:00
|
|
|
PCB_PLOT_PARAMS plotOpts = m_pcb->GetPlotOptions();
|
|
|
|
|
|
|
|
if( plotOpts.GetUseAuxOrigin() )
|
2021-11-09 03:36:40 +00:00
|
|
|
m_offset = m_pcb->GetDesignSettings().GetAuxOrigin();
|
2019-11-17 09:11:29 +00:00
|
|
|
|
2019-09-15 15:08:57 +00:00
|
|
|
// Collect footprints on the right layer
|
2020-11-13 15:15:52 +00:00
|
|
|
std::vector<FOOTPRINT*> fp_list;
|
2019-09-15 15:08:57 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : m_pcb->Footprints() )
|
2019-09-15 15:08:57 +00:00
|
|
|
{
|
2020-11-13 02:09:34 +00:00
|
|
|
if( footprint->GetAttributes() & FP_EXCLUDE_FROM_POS_FILES )
|
2019-09-15 15:08:57 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if( footprint->GetLayer() == aLayer )
|
|
|
|
fp_list.push_back( footprint );
|
|
|
|
}
|
|
|
|
|
2019-11-17 09:11:29 +00:00
|
|
|
LOCALE_IO dummy_io; // Use the standard notation for float numbers
|
2019-09-15 15:08:57 +00:00
|
|
|
|
|
|
|
GERBER_PLOTTER plotter;
|
|
|
|
|
|
|
|
// Gerber drill file imply X2 format:
|
|
|
|
plotter.UseX2format( true );
|
|
|
|
plotter.UseX2NetAttributes( true );
|
|
|
|
|
|
|
|
// Add the standard X2 header, without FileFunction
|
|
|
|
AddGerberX2Header( &plotter, m_pcb );
|
2022-09-16 23:25:07 +00:00
|
|
|
plotter.SetViewport( m_offset, pcbIUScale.IU_PER_MILS/10, /* scale */ 1.0, /* mirror */false );
|
2021-08-17 19:41:08 +00:00
|
|
|
|
2019-09-15 15:08:57 +00:00
|
|
|
// has meaning only for gerber plotter. Must be called only after SetViewport
|
|
|
|
plotter.SetGerberCoordinatesFormat( 6 );
|
|
|
|
plotter.SetCreator( wxT( "PCBNEW" ) );
|
|
|
|
|
|
|
|
// Add the standard X2 FileFunction for P&P files
|
|
|
|
// %TF.FileFunction,Component,Ln,[top][bottom]*%
|
|
|
|
wxString text;
|
2022-02-05 02:06:25 +00:00
|
|
|
text.Printf( wxT( "%%TF.FileFunction,Component,L%d,%s*%%" ),
|
2019-09-15 15:08:57 +00:00
|
|
|
aLayer == B_Cu ? m_pcb->GetCopperLayerCount() : 1,
|
2022-02-05 02:06:25 +00:00
|
|
|
aLayer == B_Cu ? wxT( "Bot" ) : wxT( "Top" ) );
|
2019-09-15 15:08:57 +00:00
|
|
|
plotter.AddLineToHeader( text );
|
|
|
|
|
|
|
|
// Add file polarity (positive)
|
2022-02-05 02:06:25 +00:00
|
|
|
text = wxT( "%TF.FilePolarity,Positive*%" );
|
2019-09-15 15:08:57 +00:00
|
|
|
plotter.AddLineToHeader( text );
|
|
|
|
|
|
|
|
if( !plotter.OpenFile( aFullFilename ) )
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
// We need a BRDITEMS_PLOTTER to plot pads
|
|
|
|
BRDITEMS_PLOTTER brd_plotter( &plotter, m_pcb, plotOpts );
|
|
|
|
|
2022-08-27 18:14:57 +00:00
|
|
|
plotter.StartPlot( wxT( "1" ) );
|
2019-09-15 15:08:57 +00:00
|
|
|
|
2019-11-03 19:23:31 +00:00
|
|
|
// Some tools in P&P files have the type and size defined.
|
|
|
|
// they are position flash (round), pad1 flash (diamond), other pads flash (round)
|
|
|
|
// and component outline thickness (polyline)
|
2023-08-31 09:02:50 +00:00
|
|
|
|
|
|
|
// defined size for footprint position shape (circle)
|
|
|
|
int flash_position_shape_diam = pcbIUScale.mmToIU( 0.3 );
|
|
|
|
|
|
|
|
// defined size for pad 1 position (diamond)
|
|
|
|
int pad1_mark_size = pcbIUScale.mmToIU( 0.36 );
|
|
|
|
|
|
|
|
// Normalized size for other pads (circle)
|
|
|
|
// It was initially the size 0, but was changed later to 0.1 mm in rev 2023-08
|
|
|
|
// See ComponentPin aperture attribute (see 5.6.10 .AperFunction value)
|
|
|
|
int other_pads_mark_size = pcbIUScale.mmToIU( 0.1 );
|
|
|
|
|
|
|
|
// defined size for component outlines
|
|
|
|
int line_thickness = pcbIUScale.mmToIU( 0.1 );
|
2019-11-01 12:35:42 +00:00
|
|
|
|
|
|
|
brd_plotter.SetLayerSet( LSET( aLayer ) );
|
2019-09-15 15:08:57 +00:00
|
|
|
int cmp_count = 0;
|
2019-10-24 16:50:51 +00:00
|
|
|
bool allowUtf8 = true;
|
2023-10-25 07:13:59 +00:00
|
|
|
const bool quoteOption = false;
|
2019-09-15 15:08:57 +00:00
|
|
|
|
2019-11-03 19:23:31 +00:00
|
|
|
// Plot components data: position, outlines, pad1 and other pads.
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : fp_list )
|
2019-09-15 15:08:57 +00:00
|
|
|
{
|
2019-11-03 19:23:31 +00:00
|
|
|
// Manage the aperture attribute component position:
|
2019-09-15 15:08:57 +00:00
|
|
|
GBR_METADATA gbr_metadata;
|
|
|
|
gbr_metadata.SetApertureAttrib( GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB_CMP_POSITION );
|
|
|
|
|
2021-06-09 19:32:58 +00:00
|
|
|
// Add object attribute: component reference to flash (mainly useful for users)
|
2023-10-25 07:13:59 +00:00
|
|
|
// using not quoted UTF8 string
|
2023-05-05 13:21:56 +00:00
|
|
|
wxString ref = ConvertNotAllowedCharsInGerber( footprint->Reference().GetShownText( false ),
|
2023-10-25 07:13:59 +00:00
|
|
|
allowUtf8, quoteOption );
|
2019-09-15 15:08:57 +00:00
|
|
|
|
|
|
|
gbr_metadata.SetCmpReference( ref );
|
|
|
|
gbr_metadata.SetNetAttribType( GBR_NETLIST_METADATA::GBR_NETINFO_CMP );
|
|
|
|
|
|
|
|
// Add P&P specific attributes
|
|
|
|
GBR_CMP_PNP_METADATA pnpAttrib;
|
|
|
|
|
|
|
|
// Add rotation info (rotation is CCW, in degrees):
|
2022-05-16 08:24:13 +00:00
|
|
|
pnpAttrib.m_Orientation = mapRotationAngle( footprint->GetOrientationDegrees(),
|
|
|
|
aLayer == B_Cu ? true : false );
|
2019-09-15 15:08:57 +00:00
|
|
|
|
2020-08-26 21:43:38 +00:00
|
|
|
pnpAttrib.m_MountType = GBR_CMP_PNP_METADATA::MOUNT_TYPE_UNSPECIFIED;
|
2019-09-15 15:08:57 +00:00
|
|
|
|
2020-11-13 02:09:34 +00:00
|
|
|
if( footprint->GetAttributes() & FP_THROUGH_HOLE )
|
2020-08-26 21:43:38 +00:00
|
|
|
pnpAttrib.m_MountType = GBR_CMP_PNP_METADATA::MOUNT_TYPE_TH;
|
2020-11-13 02:09:34 +00:00
|
|
|
else if( footprint->GetAttributes() & FP_SMD )
|
2020-08-26 21:43:38 +00:00
|
|
|
pnpAttrib.m_MountType = GBR_CMP_PNP_METADATA::MOUNT_TYPE_SMD;
|
2019-09-15 15:08:57 +00:00
|
|
|
|
|
|
|
// Add component value info:
|
2023-05-05 13:21:56 +00:00
|
|
|
pnpAttrib.m_Value = ConvertNotAllowedCharsInGerber( footprint->Value().GetShownText( false ),
|
2023-10-25 07:13:59 +00:00
|
|
|
allowUtf8, quoteOption );
|
2019-09-15 15:08:57 +00:00
|
|
|
|
|
|
|
// Add component footprint info:
|
2019-10-06 11:39:50 +00:00
|
|
|
wxString fp_info = FROM_UTF8( footprint->GetFPID().GetLibItemName().c_str() );
|
2023-10-25 07:13:59 +00:00
|
|
|
pnpAttrib.m_Footprint = ConvertNotAllowedCharsInGerber( fp_info, allowUtf8, quoteOption );
|
2019-10-06 11:39:50 +00:00
|
|
|
|
|
|
|
// Add footprint lib name:
|
|
|
|
fp_info = FROM_UTF8( footprint->GetFPID().GetLibNickname().c_str() );
|
2023-10-25 07:13:59 +00:00
|
|
|
pnpAttrib.m_LibraryName = ConvertNotAllowedCharsInGerber( fp_info, allowUtf8, quoteOption );
|
2019-09-15 15:08:57 +00:00
|
|
|
|
|
|
|
gbr_metadata.m_NetlistMetadata.SetExtraData( pnpAttrib.FormatCmpPnPMetadata() );
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I flash_pos = footprint->GetPosition();
|
2019-09-15 15:08:57 +00:00
|
|
|
|
2019-11-03 19:23:31 +00:00
|
|
|
plotter.FlashPadCircle( flash_pos, flash_position_shape_diam, FILLED, &gbr_metadata );
|
2019-09-15 15:08:57 +00:00
|
|
|
gbr_metadata.m_NetlistMetadata.ClearExtraData();
|
|
|
|
|
2019-10-17 10:41:42 +00:00
|
|
|
// Now some extra metadata is output, avoid blindly clearing the full metadata list
|
|
|
|
gbr_metadata.m_NetlistMetadata.m_TryKeepPreviousAttributes = true;
|
|
|
|
|
2019-11-01 12:35:42 +00:00
|
|
|
// We plot the footprint courtyard when possible.
|
|
|
|
// If not, the pads bounding box will be used.
|
|
|
|
bool useFpPadsBbox = true;
|
2020-11-20 13:55:10 +00:00
|
|
|
bool onBack = aLayer == B_Cu;
|
2019-11-01 12:35:42 +00:00
|
|
|
|
2022-07-31 21:14:24 +00:00
|
|
|
footprint->BuildCourtyardCaches();
|
2020-10-25 15:02:49 +00:00
|
|
|
|
2020-11-20 13:55:10 +00:00
|
|
|
int checkFlag = onBack ? MALFORMED_B_COURTYARD : MALFORMED_F_COURTYARD;
|
|
|
|
|
|
|
|
if( ( footprint->GetFlags() & checkFlag ) == 0 )
|
2019-09-15 15:08:57 +00:00
|
|
|
{
|
2021-08-17 19:41:08 +00:00
|
|
|
gbr_metadata.SetApertureAttrib(
|
|
|
|
GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB_CMP_COURTYARD );
|
2019-09-15 15:08:57 +00:00
|
|
|
|
2022-07-31 21:14:24 +00:00
|
|
|
const SHAPE_POLY_SET& courtyard = footprint->GetCourtyard( aLayer );
|
2019-09-15 15:08:57 +00:00
|
|
|
|
|
|
|
for( int ii = 0; ii < courtyard.OutlineCount(); ii++ )
|
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN poly = courtyard.Outline( ii );
|
2019-11-01 12:35:42 +00:00
|
|
|
|
|
|
|
if( !poly.PointCount() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
useFpPadsBbox = false;
|
2021-07-18 23:08:54 +00:00
|
|
|
plotter.PLOTTER::PlotPoly( poly, FILL_T::NO_FILL, line_thickness, &gbr_metadata );
|
2019-09-15 15:08:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-01 12:35:42 +00:00
|
|
|
if( useFpPadsBbox )
|
|
|
|
{
|
2021-08-17 19:41:08 +00:00
|
|
|
gbr_metadata.SetApertureAttrib(
|
|
|
|
GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB_CMP_FOOTPRINT );
|
2019-11-01 12:35:42 +00:00
|
|
|
|
|
|
|
// bbox of fp pads, pos 0, rot 0, non flipped
|
2022-08-30 23:28:18 +00:00
|
|
|
BOX2I bbox = footprint->GetFpPadsLocalBbox();
|
2019-11-01 12:35:42 +00:00
|
|
|
|
|
|
|
// negate bbox Y values if the fp is flipped (always flipped around X axis
|
|
|
|
// in Gerber P&P files).
|
|
|
|
int y_sign = aLayer == B_Cu ? -1 : 1;
|
|
|
|
|
|
|
|
SHAPE_LINE_CHAIN poly;
|
|
|
|
poly.Append( bbox.GetLeft(), y_sign*bbox.GetTop() );
|
|
|
|
poly.Append( bbox.GetLeft(), y_sign*bbox.GetBottom() );
|
|
|
|
poly.Append( bbox.GetRight(), y_sign*bbox.GetBottom() );
|
|
|
|
poly.Append( bbox.GetRight(), y_sign*bbox.GetTop() );
|
|
|
|
poly.SetClosed( true );
|
|
|
|
|
2022-01-20 20:54:22 +00:00
|
|
|
poly.Rotate( footprint->GetOrientation() );
|
2019-11-17 09:11:29 +00:00
|
|
|
poly.Move( footprint->GetPosition() );
|
2021-07-18 23:08:54 +00:00
|
|
|
plotter.PLOTTER::PlotPoly( poly, FILL_T::NO_FILL, line_thickness, &gbr_metadata );
|
2019-11-01 12:35:42 +00:00
|
|
|
}
|
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
std::vector<PAD*>pad_key_list;
|
2019-09-15 15:08:57 +00:00
|
|
|
|
|
|
|
if( m_plotPad1Marker )
|
|
|
|
{
|
2019-10-06 11:39:50 +00:00
|
|
|
findPads1( pad_key_list, footprint );
|
2019-09-15 15:08:57 +00:00
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
for( PAD* pad1 : pad_key_list )
|
2019-09-15 15:08:57 +00:00
|
|
|
{
|
|
|
|
gbr_metadata.SetApertureAttrib(
|
|
|
|
GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB_PAD1_POSITION );
|
|
|
|
|
2023-10-25 07:13:59 +00:00
|
|
|
gbr_metadata.SetPadName( pad1->GetNumber(), allowUtf8, quoteOption );
|
2019-11-17 09:11:29 +00:00
|
|
|
|
2023-10-25 07:13:59 +00:00
|
|
|
gbr_metadata.SetPadPinFunction( pad1->GetPinFunction(), allowUtf8, quoteOption );
|
2019-11-17 09:11:29 +00:00
|
|
|
|
2019-09-15 15:08:57 +00:00
|
|
|
gbr_metadata.SetNetAttribType( GBR_NETLIST_METADATA::GBR_NETINFO_PAD );
|
|
|
|
|
2019-11-03 19:23:31 +00:00
|
|
|
// Flashes a diamond at pad position:
|
2022-01-16 01:06:25 +00:00
|
|
|
plotter.FlashRegularPolygon( pad1->GetPosition(), pad1_mark_size, 4, ANGLE_0,
|
|
|
|
FILLED, &gbr_metadata );
|
2019-09-15 15:08:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_plotOtherPadsMarker )
|
|
|
|
{
|
|
|
|
gbr_metadata.SetApertureAttrib(
|
|
|
|
GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB_PADOTHER_POSITION );
|
|
|
|
gbr_metadata.SetNetAttribType( GBR_NETLIST_METADATA::GBR_NETINFO_PAD );
|
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
for( PAD* pad: footprint->Pads() )
|
2019-09-15 15:08:57 +00:00
|
|
|
{
|
2019-10-06 11:39:50 +00:00
|
|
|
bool skip_pad = false;
|
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
for( PAD* pad1 : pad_key_list )
|
2019-10-06 11:39:50 +00:00
|
|
|
{
|
|
|
|
if( pad == pad1 ) // Already plotted
|
|
|
|
{
|
|
|
|
skip_pad = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( skip_pad )
|
2019-09-15 15:08:57 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// Skip also pads not on the current layer, like pads only
|
|
|
|
// on a tech layer
|
|
|
|
if( !pad->IsOnLayer( aLayer ) )
|
|
|
|
continue;
|
|
|
|
|
2023-10-25 07:13:59 +00:00
|
|
|
gbr_metadata.SetPadName( pad->GetNumber(), allowUtf8, quoteOption );
|
2019-11-17 09:11:29 +00:00
|
|
|
|
2023-10-25 07:13:59 +00:00
|
|
|
gbr_metadata.SetPadPinFunction( pad->GetPinFunction(), allowUtf8, quoteOption );
|
2019-09-15 15:08:57 +00:00
|
|
|
|
|
|
|
// Flashes a round, 0 sized round shape at pad position
|
2021-09-19 18:30:09 +00:00
|
|
|
plotter.FlashPadCircle( pad->GetPosition(), other_pads_mark_size, FILLED,
|
|
|
|
&gbr_metadata );
|
2019-09-15 15:08:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-06 11:39:50 +00:00
|
|
|
plotter.ClearAllAttributes(); // Unconditionally close all .TO attributes
|
2019-09-15 15:08:57 +00:00
|
|
|
|
|
|
|
cmp_count++;
|
|
|
|
}
|
|
|
|
|
2019-11-03 19:23:31 +00:00
|
|
|
// Plot board outlines, if requested
|
|
|
|
if( aIncludeBrdEdges )
|
|
|
|
{
|
|
|
|
brd_plotter.SetLayerSet( LSET( Edge_Cuts ) );
|
|
|
|
|
|
|
|
// Plot edge layer and graphic items
|
|
|
|
brd_plotter.PlotBoardGraphicItems();
|
|
|
|
|
|
|
|
// Draw footprint other graphic items:
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : fp_list )
|
2019-11-03 19:23:31 +00:00
|
|
|
{
|
2020-10-04 14:19:33 +00:00
|
|
|
for( BOARD_ITEM* item : footprint->GraphicalItems() )
|
2019-11-03 19:23:31 +00:00
|
|
|
{
|
2020-10-04 14:19:33 +00:00
|
|
|
if( item->Type() == PCB_FP_SHAPE_T && item->GetLayer() == Edge_Cuts )
|
2022-01-30 10:52:52 +00:00
|
|
|
brd_plotter.PlotFootprintShape( static_cast<FP_SHAPE*>( item ) );
|
2019-11-03 19:23:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-15 15:08:57 +00:00
|
|
|
plotter.EndPlot();
|
|
|
|
|
|
|
|
return cmp_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-05-16 08:24:13 +00:00
|
|
|
double PLACEFILE_GERBER_WRITER::mapRotationAngle( double aAngle, bool aIsFlipped )
|
2019-09-15 15:08:57 +00:00
|
|
|
{
|
2021-08-17 19:41:08 +00:00
|
|
|
// Convert a KiCad footprint orientation to gerber rotation, depending on the layer
|
2022-05-16 08:24:13 +00:00
|
|
|
// Gerber rotation is:
|
|
|
|
// rot angle > 0 for rot CW, seen from Top side
|
|
|
|
// same a Pcbnew for Top side
|
|
|
|
// (angle + 180) for Bottom layer i.e flipped around Y axis: X axis coordinates mirrored.
|
|
|
|
// because Pcbnew flip around the X axis : Y coord mirrored, that is similar to mirror
|
|
|
|
// around Y axis + 180 deg rotation
|
|
|
|
if( aIsFlipped )
|
|
|
|
{
|
|
|
|
double gbr_angle = 180.0 + aAngle;
|
|
|
|
|
|
|
|
// Normalize between -180 ... + 180 deg
|
|
|
|
// Not mandatory, but the angle is more easy to read
|
|
|
|
if( gbr_angle <= -180 )
|
|
|
|
gbr_angle += 360.0;
|
|
|
|
else if( gbr_angle > 180 )
|
|
|
|
gbr_angle -= 360.0;
|
|
|
|
|
|
|
|
return gbr_angle;
|
|
|
|
}
|
|
|
|
|
2019-09-15 15:08:57 +00:00
|
|
|
return aAngle;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void PLACEFILE_GERBER_WRITER::findPads1( std::vector<PAD*>& aPadList, FOOTPRINT* aFootprint ) const
|
2019-09-15 15:08:57 +00:00
|
|
|
{
|
|
|
|
// Fint the pad "1" or pad "A1"
|
|
|
|
// this is possible only if only one pad is found
|
2021-06-09 19:32:58 +00:00
|
|
|
// useful to place a marker in this position
|
2019-09-15 15:08:57 +00:00
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
for( PAD* pad : aFootprint->Pads() )
|
2019-09-15 15:08:57 +00:00
|
|
|
{
|
|
|
|
if( !pad->IsOnLayer( m_layer ) )
|
|
|
|
continue;
|
|
|
|
|
2022-02-05 02:06:25 +00:00
|
|
|
if( pad->GetNumber() == wxT( "1" ) || pad->GetNumber() == wxT( "A1" ) )
|
2019-10-06 11:39:50 +00:00
|
|
|
aPadList.push_back( pad );
|
2019-09-15 15:08:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const wxString PLACEFILE_GERBER_WRITER::GetPlaceFileName( const wxString& aFullBaseFilename,
|
|
|
|
PCB_LAYER_ID aLayer ) const
|
|
|
|
{
|
|
|
|
// Gerber files extension is always .gbr.
|
|
|
|
// Therefore, to mark pnp files, add "-pnp" to the filename, and a layer id.
|
|
|
|
wxFileName fn = aFullBaseFilename;
|
|
|
|
|
2022-02-05 02:06:25 +00:00
|
|
|
wxString post_id = wxT( "-pnp_" );
|
|
|
|
post_id += aLayer == B_Cu ? wxT( "bottom" ) : wxT( "top" );
|
2019-09-15 15:08:57 +00:00
|
|
|
fn.SetName( fn.GetName() + post_id );
|
|
|
|
fn.SetExt( GerberFileExtension );
|
|
|
|
|
|
|
|
return fn.GetFullPath();
|
|
|
|
}
|