2019-06-30 11:54:35 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2022-01-13 13:45:48 +00:00
|
|
|
* Copyright (C) 2015-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2019-06-30 11:54:35 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 1 - create ascii/csv files for automatic placement of smd components
|
2020-11-13 11:17:15 +00:00
|
|
|
* 2 - create a footprint report (pos and footprint descr) (ascii file)
|
2019-06-30 11:54:35 +00:00
|
|
|
*/
|
|
|
|
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2021-03-20 15:35:37 +00:00
|
|
|
#include <macros.h>
|
2020-10-24 01:38:50 +00:00
|
|
|
#include <locale_io.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <board_design_settings.h>
|
2019-06-30 11:54:35 +00:00
|
|
|
#include <build_version.h>
|
2022-11-07 12:15:55 +00:00
|
|
|
#include <exporters/place_file_exporter.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <pad.h>
|
2019-06-30 11:54:35 +00:00
|
|
|
|
2021-06-07 07:26:13 +00:00
|
|
|
#include <wx/dirdlg.h>
|
|
|
|
|
2019-06-30 11:54:35 +00:00
|
|
|
class LIST_MOD // An helper class used to build a list of useful footprints.
|
|
|
|
{
|
|
|
|
public:
|
2021-07-21 23:14:56 +00:00
|
|
|
FOOTPRINT* m_Footprint; // Link to the actual footprint
|
|
|
|
wxString m_Reference; // Its schematic reference
|
|
|
|
wxString m_Value; // Its schematic value
|
|
|
|
int m_Layer; // its side (B_Cu, or F_Cu)
|
2019-06-30 11:54:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Defined values to write coordinates using inches or mm:
|
2022-09-16 23:25:07 +00:00
|
|
|
static const double conv_unit_inch = 0.001 / pcbIUScale.IU_PER_MILS ; // units = INCHES
|
2019-06-30 11:54:35 +00:00
|
|
|
static const char unit_text_inch[] = "## Unit = inches, Angle = deg.\n";
|
|
|
|
|
2022-09-17 00:45:14 +00:00
|
|
|
static const double conv_unit_mm = 1.0 / pcbIUScale.IU_PER_MM; // units = mm
|
2019-06-30 11:54:35 +00:00
|
|
|
static const char unit_text_mm[] = "## Unit = mm, Angle = deg.\n";
|
|
|
|
|
2020-10-21 03:48:06 +00:00
|
|
|
// Sort function use by GenerefootprintsPosition()
|
2019-06-30 11:54:35 +00:00
|
|
|
// sort is made by side (layer) top layer first
|
|
|
|
// then by reference increasing order
|
|
|
|
static bool sortFPlist( const LIST_MOD& ref, const LIST_MOD& tst )
|
|
|
|
{
|
|
|
|
if( ref.m_Layer == tst.m_Layer )
|
|
|
|
return StrNumCmp( ref.m_Reference, tst.m_Reference ) < 0;
|
|
|
|
|
|
|
|
return ref.m_Layer > tst.m_Layer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
enum SELECT_SIDE
|
|
|
|
{
|
|
|
|
PCB_NO_SIDE,
|
|
|
|
PCB_BACK_SIDE,
|
|
|
|
PCB_FRONT_SIDE,
|
|
|
|
PCB_BOTH_SIDES
|
|
|
|
};
|
|
|
|
|
2021-07-20 08:23:21 +00:00
|
|
|
PLACE_FILE_EXPORTER::PLACE_FILE_EXPORTER( BOARD* aBoard, bool aUnitsMM, bool aOnlySMD,
|
|
|
|
bool aExcludeAllTH, bool aTopSide, bool aBottomSide,
|
2022-08-02 09:22:12 +00:00
|
|
|
bool aFormatCSV, bool aUseAuxOrigin, bool aNegateBottomX )
|
2019-06-30 11:54:35 +00:00
|
|
|
{
|
2022-08-02 09:22:12 +00:00
|
|
|
m_board = aBoard;
|
|
|
|
m_unitsMM = aUnitsMM;
|
|
|
|
m_onlySMD = aOnlySMD;
|
|
|
|
m_excludeAllTH = aExcludeAllTH;
|
|
|
|
m_fpCount = 0;
|
|
|
|
m_negateBottomX = aNegateBottomX;
|
2019-06-30 11:54:35 +00:00
|
|
|
|
|
|
|
if( aTopSide && aBottomSide )
|
|
|
|
m_side = PCB_BOTH_SIDES;
|
|
|
|
else if( aTopSide )
|
|
|
|
m_side = PCB_FRONT_SIDE;
|
|
|
|
else if( aBottomSide )
|
|
|
|
m_side = PCB_BACK_SIDE;
|
|
|
|
else
|
|
|
|
m_side = PCB_NO_SIDE;
|
|
|
|
|
|
|
|
m_formatCSV = aFormatCSV;
|
2021-06-27 16:39:09 +00:00
|
|
|
|
|
|
|
if( aUseAuxOrigin )
|
2021-11-09 03:36:40 +00:00
|
|
|
m_place_Offset = m_board->GetDesignSettings().GetAuxOrigin();
|
2021-06-27 16:39:09 +00:00
|
|
|
else
|
2021-12-29 21:30:11 +00:00
|
|
|
m_place_Offset = VECTOR2I( 0, 0 );
|
2019-06-30 11:54:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string PLACE_FILE_EXPORTER::GenPositionData()
|
|
|
|
{
|
|
|
|
std::string buffer;
|
|
|
|
char line[1024]; // A line to print intermediate data
|
|
|
|
|
|
|
|
// Minimal text lengths:
|
|
|
|
m_fpCount = 0;
|
|
|
|
int lenRefText = 8;
|
|
|
|
int lenValText = 8;
|
|
|
|
int lenPkgText = 16;
|
|
|
|
|
|
|
|
// Calculating the number of useful footprints (CMS attribute, not VIRTUAL)
|
|
|
|
m_fpCount = 0;
|
|
|
|
|
|
|
|
// Select units:
|
|
|
|
double conv_unit = m_unitsMM ? conv_unit_mm : conv_unit_inch;
|
|
|
|
const char *unit_text = m_unitsMM ? unit_text_mm : unit_text_inch;
|
|
|
|
|
|
|
|
// Build and sort the list of footprints alphabetically
|
|
|
|
std::vector<LIST_MOD> list;
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : m_board->Footprints() )
|
2019-06-30 11:54:35 +00:00
|
|
|
{
|
|
|
|
if( m_side != PCB_BOTH_SIDES )
|
|
|
|
{
|
|
|
|
if( footprint->GetLayer() == B_Cu && m_side != PCB_BACK_SIDE )
|
|
|
|
continue;
|
|
|
|
if( footprint->GetLayer() == F_Cu && m_side != PCB_FRONT_SIDE )
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-11-13 02:09:34 +00:00
|
|
|
if( footprint->GetAttributes() & FP_EXCLUDE_FROM_POS_FILES )
|
2020-08-26 21:43:38 +00:00
|
|
|
continue;
|
2019-06-30 11:54:35 +00:00
|
|
|
|
2021-07-20 08:23:21 +00:00
|
|
|
if( m_onlySMD && !( footprint->GetAttributes() & FP_SMD ) )
|
|
|
|
continue;
|
|
|
|
|
2020-08-26 21:43:38 +00:00
|
|
|
if( m_excludeAllTH && footprint->HasThroughHolePads() )
|
|
|
|
continue;
|
2019-06-30 11:54:35 +00:00
|
|
|
|
|
|
|
m_fpCount++;
|
|
|
|
|
|
|
|
LIST_MOD item;
|
2020-11-13 11:17:15 +00:00
|
|
|
item.m_Footprint = footprint;
|
2020-08-20 12:04:46 +00:00
|
|
|
item.m_Reference = footprint->Reference().GetShownText();
|
|
|
|
item.m_Value = footprint->Value().GetShownText();
|
2019-06-30 11:54:35 +00:00
|
|
|
item.m_Layer = footprint->GetLayer();
|
|
|
|
list.push_back( item );
|
|
|
|
|
2020-08-20 12:04:46 +00:00
|
|
|
lenRefText = std::max( lenRefText, (int) item.m_Reference.length() );
|
|
|
|
lenValText = std::max( lenValText, (int) item.m_Value.length() );
|
2020-11-13 11:17:15 +00:00
|
|
|
lenPkgText = std::max( lenPkgText, (int) item.m_Footprint->GetFPID().GetLibItemName().length() );
|
2019-06-30 11:54:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( list.size() > 1 )
|
|
|
|
sort( list.begin(), list.end(), sortFPlist );
|
|
|
|
|
|
|
|
// Switch the locale to standard C (needed to print floating point numbers)
|
|
|
|
LOCALE_IO toggle;
|
|
|
|
|
|
|
|
if( m_formatCSV )
|
|
|
|
{
|
|
|
|
wxChar csv_sep = ',';
|
|
|
|
|
|
|
|
// Set first line:;
|
2023-01-29 01:55:11 +00:00
|
|
|
snprintf( line, sizeof(line), "Ref%cVal%cPackage%cPosX%cPosY%cRot%cSide\n",
|
2019-06-30 11:54:35 +00:00
|
|
|
csv_sep, csv_sep, csv_sep, csv_sep, csv_sep, csv_sep );
|
|
|
|
|
|
|
|
buffer += line;
|
|
|
|
|
|
|
|
for( int ii = 0; ii < m_fpCount; ii++ )
|
|
|
|
{
|
2021-12-29 21:30:11 +00:00
|
|
|
VECTOR2I footprint_pos;
|
2020-11-13 11:17:15 +00:00
|
|
|
footprint_pos = list[ii].m_Footprint->GetPosition();
|
2019-06-30 11:54:35 +00:00
|
|
|
footprint_pos -= m_place_Offset;
|
|
|
|
|
2021-07-21 23:14:56 +00:00
|
|
|
int layer = list[ii].m_Footprint->GetLayer();
|
2019-06-30 11:54:35 +00:00
|
|
|
wxASSERT( layer == F_Cu || layer == B_Cu );
|
|
|
|
|
2022-08-02 09:22:12 +00:00
|
|
|
if( layer == B_Cu && m_negateBottomX )
|
2020-03-29 13:07:53 +00:00
|
|
|
footprint_pos.x = - footprint_pos.x;
|
|
|
|
|
2022-02-05 02:06:25 +00:00
|
|
|
wxString tmp = wxT( "\"" ) + list[ii].m_Reference;
|
|
|
|
tmp << wxT( "\"" ) << csv_sep;
|
|
|
|
tmp << wxT( "\"" ) << list[ii].m_Value;
|
|
|
|
tmp << wxT( "\"" ) << csv_sep;
|
|
|
|
tmp << wxT( "\"" ) << list[ii].m_Footprint->GetFPID().GetLibItemName().wx_str();
|
|
|
|
tmp << wxT( "\"" ) << csv_sep;
|
|
|
|
|
|
|
|
tmp << wxString::Format( wxT( "%f%c%f%c%f" ),
|
2022-01-13 17:27:36 +00:00
|
|
|
footprint_pos.x * conv_unit,
|
|
|
|
csv_sep,
|
|
|
|
// Keep the Y axis oriented from bottom to top,
|
|
|
|
// ( change y coordinate sign )
|
|
|
|
-footprint_pos.y * conv_unit,
|
|
|
|
csv_sep,
|
|
|
|
list[ii].m_Footprint->GetOrientation().AsDegrees() );
|
2019-06-30 11:54:35 +00:00
|
|
|
tmp << csv_sep;
|
|
|
|
|
|
|
|
tmp << ( (layer == F_Cu ) ? PLACE_FILE_EXPORTER::GetFrontSideName()
|
|
|
|
: PLACE_FILE_EXPORTER::GetBackSideName() );
|
|
|
|
tmp << '\n';
|
|
|
|
|
|
|
|
buffer += TO_UTF8( tmp );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Write file header
|
2023-01-29 01:55:11 +00:00
|
|
|
snprintf( line, sizeof(line), "### Footprint positions - created on %s ###\n", TO_UTF8( DateAndTime() ) );
|
2019-06-30 11:54:35 +00:00
|
|
|
|
|
|
|
buffer += line;
|
|
|
|
|
|
|
|
wxString Title = GetBuildVersion();
|
2023-01-29 01:55:11 +00:00
|
|
|
snprintf( line, sizeof(line), "### Printed by KiCad version %s\n", TO_UTF8( Title ) );
|
2019-06-30 11:54:35 +00:00
|
|
|
buffer += line;
|
|
|
|
|
|
|
|
buffer += unit_text;
|
|
|
|
buffer += "## Side : ";
|
|
|
|
|
|
|
|
if( m_side == PCB_BACK_SIDE )
|
|
|
|
buffer += GetBackSideName().c_str();
|
|
|
|
else if( m_side == PCB_FRONT_SIDE )
|
|
|
|
buffer += GetFrontSideName().c_str();
|
|
|
|
else if( m_side == PCB_BOTH_SIDES )
|
|
|
|
buffer += "All";
|
|
|
|
else
|
|
|
|
buffer += "---";
|
|
|
|
|
|
|
|
buffer += "\n";
|
|
|
|
|
2023-01-29 01:55:11 +00:00
|
|
|
snprintf(line, sizeof(line), "%-*s %-*s %-*s %9.9s %9.9s %8.8s %s\n",
|
2019-06-30 11:54:35 +00:00
|
|
|
int(lenRefText), "# Ref",
|
|
|
|
int(lenValText), "Val",
|
|
|
|
int(lenPkgText), "Package",
|
|
|
|
"PosX", "PosY", "Rot", "Side" );
|
|
|
|
buffer += line;
|
|
|
|
|
|
|
|
for( int ii = 0; ii < m_fpCount; ii++ )
|
|
|
|
{
|
2021-12-29 21:30:11 +00:00
|
|
|
VECTOR2I footprint_pos;
|
2020-11-13 11:17:15 +00:00
|
|
|
footprint_pos = list[ii].m_Footprint->GetPosition();
|
2019-06-30 11:54:35 +00:00
|
|
|
footprint_pos -= m_place_Offset;
|
|
|
|
|
2021-07-21 23:14:56 +00:00
|
|
|
int layer = list[ii].m_Footprint->GetLayer();
|
2019-06-30 11:54:35 +00:00
|
|
|
wxASSERT( layer == F_Cu || layer == B_Cu );
|
|
|
|
|
2022-08-02 09:22:12 +00:00
|
|
|
if( layer == B_Cu && m_negateBottomX )
|
2019-06-30 11:54:35 +00:00
|
|
|
footprint_pos.x = - footprint_pos.x;
|
|
|
|
|
|
|
|
wxString ref = list[ii].m_Reference;
|
|
|
|
wxString val = list[ii].m_Value;
|
2020-11-13 11:17:15 +00:00
|
|
|
wxString pkg = list[ii].m_Footprint->GetFPID().GetLibItemName();
|
2019-06-30 11:54:35 +00:00
|
|
|
ref.Replace( wxT( " " ), wxT( "_" ) );
|
|
|
|
val.Replace( wxT( " " ), wxT( "_" ) );
|
|
|
|
pkg.Replace( wxT( " " ), wxT( "_" ) );
|
2023-01-29 01:55:11 +00:00
|
|
|
snprintf(line, sizeof(line), "%-*s %-*s %-*s %9.4f %9.4f %8.4f %s\n",
|
2019-06-30 11:54:35 +00:00
|
|
|
lenRefText, TO_UTF8( ref ),
|
|
|
|
lenValText, TO_UTF8( val ),
|
|
|
|
lenPkgText, TO_UTF8( pkg ),
|
|
|
|
footprint_pos.x * conv_unit,
|
|
|
|
// Keep the coordinates in the first quadrant,
|
|
|
|
// (i.e. change y sign
|
|
|
|
-footprint_pos.y * conv_unit,
|
2022-01-13 17:27:36 +00:00
|
|
|
list[ii].m_Footprint->GetOrientation().AsDegrees(),
|
2019-06-30 11:54:35 +00:00
|
|
|
(layer == F_Cu ) ? GetFrontSideName().c_str() : GetBackSideName().c_str() );
|
|
|
|
buffer += line;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write EOF
|
|
|
|
buffer += "## End\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string PLACE_FILE_EXPORTER::GenReportData()
|
|
|
|
{
|
|
|
|
std::string buffer;
|
|
|
|
|
2021-12-29 21:30:11 +00:00
|
|
|
m_place_Offset = VECTOR2I( 0, 0 );
|
2019-06-30 11:54:35 +00:00
|
|
|
|
|
|
|
// Select units:
|
|
|
|
double conv_unit = m_unitsMM ? conv_unit_mm : conv_unit_inch;
|
|
|
|
const char *unit_text = m_unitsMM ? unit_text_mm : unit_text_inch;
|
|
|
|
|
|
|
|
LOCALE_IO toggle;
|
|
|
|
|
|
|
|
// Generate header file comments.)
|
|
|
|
char line[1024];
|
2023-01-29 01:55:11 +00:00
|
|
|
snprintf( line, sizeof(line), "## Footprint report - date %s\n", TO_UTF8( DateAndTime() ) );
|
2019-06-30 11:54:35 +00:00
|
|
|
buffer += line;
|
|
|
|
|
|
|
|
wxString Title = GetBuildVersion();
|
2023-01-29 01:55:11 +00:00
|
|
|
snprintf( line, sizeof(line), "## Created by KiCad version %s\n", TO_UTF8( Title ) );
|
2019-06-30 11:54:35 +00:00
|
|
|
buffer += line;
|
|
|
|
|
|
|
|
buffer += unit_text;
|
|
|
|
|
|
|
|
buffer += "\n$BeginDESCRIPTION\n";
|
|
|
|
|
2022-08-30 23:28:18 +00:00
|
|
|
BOX2I bbbox = m_board->ComputeBoundingBox();
|
2019-06-30 11:54:35 +00:00
|
|
|
|
|
|
|
buffer += "\n$BOARD\n";
|
|
|
|
|
2023-01-29 01:55:11 +00:00
|
|
|
snprintf( line, sizeof(line), "upper_left_corner %9.6f %9.6f\n",
|
2019-06-30 11:54:35 +00:00
|
|
|
bbbox.GetX() * conv_unit, bbbox.GetY() * conv_unit );
|
|
|
|
buffer += line;
|
|
|
|
|
2023-01-29 01:55:11 +00:00
|
|
|
snprintf( line, sizeof(line), "lower_right_corner %9.6f %9.6f\n",
|
2019-06-30 11:54:35 +00:00
|
|
|
bbbox.GetRight() * conv_unit, bbbox.GetBottom() * conv_unit );
|
|
|
|
buffer += line;
|
|
|
|
|
|
|
|
buffer += "$EndBOARD\n\n";
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
std::vector<FOOTPRINT*> sortedFootprints;
|
2019-08-26 10:02:13 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : m_board->Footprints() )
|
2020-11-12 23:50:33 +00:00
|
|
|
sortedFootprints.push_back( footprint );
|
2019-08-26 10:02:13 +00:00
|
|
|
|
2020-11-12 23:50:33 +00:00
|
|
|
std::sort( sortedFootprints.begin(), sortedFootprints.end(),
|
2020-11-13 15:15:52 +00:00
|
|
|
[]( FOOTPRINT* a, FOOTPRINT* b ) -> bool
|
2019-08-26 10:02:13 +00:00
|
|
|
{
|
|
|
|
return StrNumCmp( a->GetReference(), b->GetReference(), true ) < 0;
|
|
|
|
});
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : sortedFootprints )
|
2019-06-30 11:54:35 +00:00
|
|
|
{
|
2020-11-12 23:50:33 +00:00
|
|
|
wxString ref = footprint->Reference().GetShownText();
|
2020-08-20 12:04:46 +00:00
|
|
|
|
2023-01-29 01:55:11 +00:00
|
|
|
snprintf( line, sizeof(line), "$MODULE %s\n", TO_UTF8( ref ) );
|
2019-06-30 11:54:35 +00:00
|
|
|
buffer += line;
|
|
|
|
|
2023-01-29 01:55:11 +00:00
|
|
|
snprintf( line, sizeof(line), "reference %s\n", TO_UTF8( ref ) );
|
|
|
|
snprintf( line, sizeof(line), "value %s\n", EscapedUTF8( footprint->Value().GetShownText() ).c_str() );
|
|
|
|
snprintf( line, sizeof(line), "footprint %s\n", footprint->GetFPID().Format().c_str() );
|
2019-06-30 11:54:35 +00:00
|
|
|
buffer += line;
|
|
|
|
|
|
|
|
buffer += "attribut";
|
|
|
|
|
2020-11-13 02:09:34 +00:00
|
|
|
if(( footprint->GetAttributes() & ( FP_THROUGH_HOLE | FP_SMD ) ) == 0 )
|
2019-06-30 11:54:35 +00:00
|
|
|
buffer += " virtual";
|
|
|
|
|
2020-11-13 02:09:34 +00:00
|
|
|
if( footprint->GetAttributes() & FP_SMD )
|
2019-06-30 11:54:35 +00:00
|
|
|
buffer += " smd";
|
|
|
|
|
2020-11-13 02:09:34 +00:00
|
|
|
if( footprint->GetAttributes() & FP_THROUGH_HOLE )
|
2019-06-30 11:54:35 +00:00
|
|
|
buffer += " none";
|
|
|
|
|
|
|
|
buffer += "\n";
|
|
|
|
|
2021-12-29 21:30:11 +00:00
|
|
|
VECTOR2I footprint_pos = footprint->GetPosition();
|
2020-11-14 22:00:12 +00:00
|
|
|
footprint_pos -= m_place_Offset;
|
2019-06-30 11:54:35 +00:00
|
|
|
|
2023-01-29 01:55:11 +00:00
|
|
|
snprintf( line, sizeof(line), "position %9.6f %9.6f orientation %.2f\n",
|
2020-11-14 22:00:12 +00:00
|
|
|
footprint_pos.x * conv_unit,
|
|
|
|
footprint_pos.y * conv_unit,
|
2022-01-13 17:27:36 +00:00
|
|
|
footprint->GetOrientation().AsDegrees() );
|
2019-06-30 11:54:35 +00:00
|
|
|
buffer += line;
|
|
|
|
|
2020-11-12 23:50:33 +00:00
|
|
|
if( footprint->GetLayer() == F_Cu )
|
2019-06-30 11:54:35 +00:00
|
|
|
buffer += "layer front\n";
|
2020-11-12 23:50:33 +00:00
|
|
|
else if( footprint->GetLayer() == B_Cu )
|
2019-06-30 11:54:35 +00:00
|
|
|
buffer += "layer back\n";
|
|
|
|
else
|
|
|
|
buffer += "layer other\n";
|
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
std::vector<PAD*> sortedPads;
|
2019-08-26 10:02:13 +00:00
|
|
|
|
2020-11-12 23:50:33 +00:00
|
|
|
for( PAD* pad : footprint->Pads() )
|
2019-08-26 10:02:13 +00:00
|
|
|
sortedPads.push_back( pad );
|
|
|
|
|
|
|
|
std::sort( sortedPads.begin(), sortedPads.end(),
|
2020-11-12 22:30:02 +00:00
|
|
|
[]( PAD* a, PAD* b ) -> bool
|
2019-08-26 10:02:13 +00:00
|
|
|
{
|
2021-08-23 23:10:21 +00:00
|
|
|
return StrNumCmp( a->GetNumber(), b->GetNumber(), true ) < 0;
|
2019-08-26 10:02:13 +00:00
|
|
|
});
|
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
for( PAD* pad : sortedPads )
|
2019-06-30 11:54:35 +00:00
|
|
|
{
|
2023-01-29 01:55:11 +00:00
|
|
|
snprintf( line, sizeof(line), "$PAD \"%s\"\n", TO_UTF8( pad->GetNumber() ) );
|
2019-06-30 11:54:35 +00:00
|
|
|
buffer += line;
|
|
|
|
|
|
|
|
int layer = 0;
|
|
|
|
|
|
|
|
if( pad->GetLayerSet()[B_Cu] )
|
|
|
|
layer = 1;
|
|
|
|
|
|
|
|
if( pad->GetLayerSet()[F_Cu] )
|
|
|
|
layer |= 2;
|
|
|
|
|
|
|
|
static const char* layer_name[4] = { "nocopper", "back", "front", "both" };
|
2023-01-29 01:55:11 +00:00
|
|
|
snprintf( line, sizeof(line), "Shape %s Layer %s\n",
|
2019-08-26 10:02:13 +00:00
|
|
|
TO_UTF8( pad->ShowPadShape() ),
|
|
|
|
layer_name[layer] );
|
2019-06-30 11:54:35 +00:00
|
|
|
buffer += line;
|
|
|
|
|
2023-01-29 01:55:11 +00:00
|
|
|
snprintf( line, sizeof(line), "position %9.6f %9.6f size %9.6f %9.6f orientation %.2f\n",
|
2019-08-26 10:02:13 +00:00
|
|
|
pad->GetPos0().x * conv_unit,
|
|
|
|
pad->GetPos0().y * conv_unit,
|
|
|
|
pad->GetSize().x * conv_unit,
|
|
|
|
pad->GetSize().y * conv_unit,
|
2022-01-13 17:27:36 +00:00
|
|
|
( pad->GetOrientation() - footprint->GetOrientation() ).AsDegrees() );
|
2019-06-30 11:54:35 +00:00
|
|
|
buffer += line;
|
|
|
|
|
2023-01-29 01:55:11 +00:00
|
|
|
snprintf( line, sizeof(line), "drill %9.6f\n", pad->GetDrillSize().x * conv_unit );
|
2019-06-30 11:54:35 +00:00
|
|
|
buffer += line;
|
|
|
|
|
2023-01-29 01:55:11 +00:00
|
|
|
snprintf( line, sizeof(line), "shape_offset %9.6f %9.6f\n",
|
2019-08-26 10:02:13 +00:00
|
|
|
pad->GetOffset().x * conv_unit,
|
|
|
|
pad->GetOffset().y * conv_unit );
|
2019-06-30 11:54:35 +00:00
|
|
|
buffer += line;
|
|
|
|
|
|
|
|
buffer += "$EndPAD\n";
|
|
|
|
}
|
|
|
|
|
2023-01-29 01:55:11 +00:00
|
|
|
snprintf( line, sizeof(line), "$EndMODULE %s\n\n", TO_UTF8( ref ) );
|
2019-06-30 11:54:35 +00:00
|
|
|
buffer += line;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate EOF.
|
|
|
|
buffer += "$EndDESCRIPTION\n";
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|