37#include <fmt/format.h>
79 bool aExcludeAllTH,
bool aExcludeDNP,
bool aExcludeBOM,
80 bool aTopSide,
bool aBottomSide,
bool aFormatCSV,
81 bool aUseAuxOrigin,
bool aNegateBottomX )
92 if( aTopSide && aBottomSide )
96 else if( aBottomSide )
129 std::vector<LIST_MOD> list;
160 item.
m_Reference = footprint->Reference().GetShownText(
false );
161 item.
m_Value = footprint->Value().GetShownText(
false );
162 item.
m_Layer = footprint->GetLayer();
163 list.push_back( item );
165 lenRefText = std::max( lenRefText, (
int) item.
m_Reference.length() );
166 lenValText = std::max( lenValText, (
int) item.
m_Value.length() );
170 if( list.size() > 1 )
178 wxChar csv_sep =
',';
181 snprintf( line,
sizeof(line),
"Ref%cVal%cPackage%cPosX%cPosY%cRot%cSide\n",
182 csv_sep, csv_sep, csv_sep, csv_sep, csv_sep, csv_sep );
189 footprint_pos = list[ii].m_Footprint->GetPosition();
192 int layer = list[ii].m_Footprint->GetLayer();
196 footprint_pos.
x = - footprint_pos.
x;
198 wxString tmp = wxT(
"\"" ) + list[ii].m_Reference;
199 tmp << wxT(
"\"" ) << csv_sep;
200 tmp << wxT(
"\"" ) << list[ii].m_Value;
201 tmp << wxT(
"\"" ) << csv_sep;
202 tmp << wxT(
"\"" ) << list[ii].m_Footprint->GetFPID().GetLibItemName().wx_str();
203 tmp << wxT(
"\"" ) << csv_sep;
205 tmp << wxString::Format( wxT(
"%f%c%f%c%f" ),
206 footprint_pos.
x * conv_unit,
210 -footprint_pos.
y * conv_unit,
212 list[ii].m_Footprint->GetOrientation().AsDegrees() );
225 snprintf( line,
sizeof(line),
"### Footprint positions - created on %s ###\n",
231 snprintf( line,
sizeof(line),
"### Printed by KiCad version %s\n",
TO_UTF8( Title ) );
235 buffer +=
"## Side : ";
248 snprintf( line,
sizeof(line),
"%-*s %-*s %-*s %9.9s %9.9s %8.8s %s\n",
249 int(lenRefText),
"# Ref",
250 int(lenValText),
"Val",
251 int(lenPkgText),
"Package",
252 "PosX",
"PosY",
"Rot",
"Side" );
258 footprint_pos = list[ii].m_Footprint->GetPosition();
261 int layer = list[ii].m_Footprint->GetLayer();
265 footprint_pos.
x = - footprint_pos.
x;
267 wxString ref = list[ii].m_Reference;
268 wxString val = list[ii].m_Value;
269 wxString pkg = list[ii].m_Footprint->GetFPID().GetLibItemName();
270 ref.Replace( wxT(
" " ), wxT(
"_" ) );
271 val.Replace( wxT(
" " ), wxT(
"_" ) );
272 pkg.Replace( wxT(
" " ), wxT(
"_" ) );
273 snprintf( line,
sizeof(line),
"%-*s %-*s %-*s %9.4f %9.4f %8.4f %s\n",
277 footprint_pos.
x * conv_unit,
280 -footprint_pos.
y * conv_unit,
281 list[ii].m_Footprint->GetOrientation().AsDegrees(),
287 buffer +=
"## End\n";
311 buffer += fmt::format(
"## Printed by KiCad version {}\n",
TO_UTF8( Title ) );
315 buffer +=
"\n$BeginDESCRIPTION\n";
319 buffer +=
"\n$BOARD\n";
321 buffer += fmt::format(
"upper_left_corner {:9.6f} {:9.6f}\n",
322 bbbox.
GetX() * conv_unit,
323 bbbox.
GetY() * conv_unit );
325 buffer +=
"$EndBOARD\n\n";
327 std::vector<FOOTPRINT*> sortedFootprints;
330 sortedFootprints.push_back( footprint );
332 std::sort( sortedFootprints.begin(), sortedFootprints.end(),
335 return StrNumCmp( a->GetReference(), b->GetReference(), true ) < 0;
338 for(
FOOTPRINT* footprint : sortedFootprints )
340 wxString ref = footprint->Reference().GetShownText(
false );
341 wxString value = footprint->Value().GetShownText(
false );
343 buffer += fmt::format(
"$MODULE {}\n",
TO_UTF8( ref ) );
345 buffer += fmt::format(
"reference {}\n",
TO_UTF8( ref ) );
346 buffer += fmt::format(
"value {}\n",
TO_UTF8( value ) );
347 buffer += fmt::format(
"footprint {}\n", footprint->GetFPID().Format().c_str() );
349 buffer +=
"attribut";
352 buffer +=
" virtual";
354 if( footprint->GetAttributes() &
FP_SMD )
362 VECTOR2I footprint_pos = footprint->GetPosition();
365 buffer += fmt::format(
"position {:9.6f} {:9.6f} orientation {:.2f}\n",
366 footprint_pos.
x * conv_unit,
367 footprint_pos.
y * conv_unit,
368 footprint->GetOrientation().AsDegrees() );
370 if( footprint->GetLayer() ==
F_Cu )
371 buffer +=
"layer front\n";
372 else if( footprint->GetLayer() ==
B_Cu )
373 buffer +=
"layer back\n";
375 buffer +=
"layer other\n";
377 std::vector<PAD*> sortedPads;
379 for(
PAD*
pad : footprint->Pads() )
380 sortedPads.push_back(
pad );
382 std::sort( sortedPads.begin(), sortedPads.end(),
383 [](
PAD* a,
PAD* b ) ->
bool
385 return StrNumCmp( a->GetNumber(), b->GetNumber(), true ) < 0;
388 for(
PAD*
pad : sortedPads )
390 buffer += fmt::format(
"$PAD \"{}\"\n",
TO_UTF8(
pad->GetNumber() ) );
401 static const char* layer_name[4] = {
"nocopper",
"back",
"front",
"both" };
402 buffer += fmt::format(
"Shape {} Layer {}\n",
408 buffer += fmt::format(
"position {:9.6f} {:9.6f} size {:9.6f} {:9.6f} orientation {:.2f}\n",
409 padPos.
x * conv_unit,
410 padPos.
y * conv_unit,
413 pad->GetOrientation().AsDegrees() );
415 buffer += fmt::format(
"drill {:9.6f}\n",
pad->GetDrillSize().x * conv_unit );
417 buffer += fmt::format(
"shape_offset {:9.6f} {:9.6f}\n",
421 buffer +=
"$EndPAD\n";
424 buffer += fmt::format(
"$EndMODULE {}\n\n",
TO_UTF8( ref ) );
428 buffer +=
"$EndDESCRIPTION\n";
436 if( aFront && aBack )
437 return aBaseName + wxT(
"-" ) + wxT(
"all" );
constexpr EDA_IU_SCALE pcbIUScale
wxString GetBuildVersion()
Get the full KiCad version string.
Information pertinent to a Pcbnew printed circuit board.
constexpr coord_type GetY() const
constexpr coord_type GetX() const
const UTF8 & GetLibItemName() const
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
static constexpr PCB_LAYER_ID ALL_LAYERS
! Temporary layer identifier to identify code that is not padstack-aware
PLACE_FILE_EXPORTER(BOARD *aBoard, bool aUnitsMM, bool aOnlySMD, bool aExcludeAllTH, bool aExcludeDNP, bool aExcludeBOM, bool aTopSide, bool aBottomSide, bool aFormatCSV, bool aUseAuxOrigin, bool aNegateBottomX)
Create a PLACE_FILE_EXPORTER.
static std::string GetFrontSideName()
static wxString DecorateFilename(const wxString &aBaseName, bool aFront, bool aBack)
std::string GenPositionData()
build a string filled with the position data
static std::string GetBackSideName()
std::string GenReportData()
build a string filled with the pad report data This report does not used options aForceSmdItems,...
std::string::size_type length() const
bool IsExternalCopperLayer(int aLayerId)
Test whether a layer is an external (F_Cu or B_Cu) copper layer.
This file contains miscellaneous commonly used macros and functions.
static const double conv_unit_mm
static bool sortFPlist(const LIST_MOD &ref, const LIST_MOD &tst)
static const double conv_unit_inch
static const char unit_text_mm[]
static const char unit_text_inch[]
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase)
Compare two strings with alphanumerical content.
wxString GetISO8601CurrentDateTime()
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
VECTOR2< int32_t > VECTOR2I