37#include <fmt/format.h>
79 bool aExcludeAllTH,
bool aExcludeDNP,
bool aTopSide,
80 bool aBottomSide,
bool aFormatCSV,
bool aUseAuxOrigin,
91 if( aTopSide && aBottomSide )
95 else if( aBottomSide )
128 std::vector<LIST_MOD> list;
156 item.
m_Reference = footprint->Reference().GetShownText(
false );
157 item.
m_Value = footprint->Value().GetShownText(
false );
158 item.
m_Layer = footprint->GetLayer();
159 list.push_back( item );
161 lenRefText = std::max( lenRefText, (
int) item.
m_Reference.length() );
162 lenValText = std::max( lenValText, (
int) item.
m_Value.length() );
166 if( list.size() > 1 )
174 wxChar csv_sep =
',';
177 snprintf( line,
sizeof(line),
"Ref%cVal%cPackage%cPosX%cPosY%cRot%cSide\n",
178 csv_sep, csv_sep, csv_sep, csv_sep, csv_sep, csv_sep );
185 footprint_pos = list[ii].m_Footprint->GetPosition();
188 int layer = list[ii].m_Footprint->GetLayer();
192 footprint_pos.
x = - footprint_pos.
x;
194 wxString tmp = wxT(
"\"" ) + list[ii].m_Reference;
195 tmp << wxT(
"\"" ) << csv_sep;
196 tmp << wxT(
"\"" ) << list[ii].m_Value;
197 tmp << wxT(
"\"" ) << csv_sep;
198 tmp << wxT(
"\"" ) << list[ii].m_Footprint->GetFPID().GetLibItemName().wx_str();
199 tmp << wxT(
"\"" ) << csv_sep;
201 tmp << wxString::Format( wxT(
"%f%c%f%c%f" ),
202 footprint_pos.
x * conv_unit,
206 -footprint_pos.
y * conv_unit,
208 list[ii].m_Footprint->GetOrientation().AsDegrees() );
221 snprintf( line,
sizeof(line),
"### Footprint positions - created on %s ###\n",
227 snprintf( line,
sizeof(line),
"### Printed by KiCad version %s\n",
TO_UTF8( Title ) );
231 buffer +=
"## Side : ";
244 snprintf( line,
sizeof(line),
"%-*s %-*s %-*s %9.9s %9.9s %8.8s %s\n",
245 int(lenRefText),
"# Ref",
246 int(lenValText),
"Val",
247 int(lenPkgText),
"Package",
248 "PosX",
"PosY",
"Rot",
"Side" );
254 footprint_pos = list[ii].m_Footprint->GetPosition();
257 int layer = list[ii].m_Footprint->GetLayer();
261 footprint_pos.
x = - footprint_pos.
x;
263 wxString ref = list[ii].m_Reference;
264 wxString val = list[ii].m_Value;
265 wxString pkg = list[ii].m_Footprint->GetFPID().GetLibItemName();
266 ref.Replace( wxT(
" " ), wxT(
"_" ) );
267 val.Replace( wxT(
" " ), wxT(
"_" ) );
268 pkg.Replace( wxT(
" " ), wxT(
"_" ) );
269 snprintf( line,
sizeof(line),
"%-*s %-*s %-*s %9.4f %9.4f %8.4f %s\n",
273 footprint_pos.
x * conv_unit,
276 -footprint_pos.
y * conv_unit,
277 list[ii].m_Footprint->GetOrientation().AsDegrees(),
283 buffer +=
"## End\n";
307 buffer += fmt::format(
"## Printed by KiCad version {}\n",
TO_UTF8( Title ) );
311 buffer +=
"\n$BeginDESCRIPTION\n";
315 buffer +=
"\n$BOARD\n";
317 buffer += fmt::format(
"upper_left_corner {:9.6f} {:9.6f}\n",
318 bbbox.
GetX() * conv_unit,
319 bbbox.
GetY() * conv_unit );
321 buffer +=
"$EndBOARD\n\n";
323 std::vector<FOOTPRINT*> sortedFootprints;
326 sortedFootprints.push_back( footprint );
328 std::sort( sortedFootprints.begin(), sortedFootprints.end(),
331 return StrNumCmp( a->GetReference(), b->GetReference(), true ) < 0;
334 for(
FOOTPRINT* footprint : sortedFootprints )
336 wxString ref = footprint->Reference().GetShownText(
false );
337 wxString value = footprint->Value().GetShownText(
false );
339 buffer += fmt::format(
"$MODULE {}\n",
TO_UTF8( ref ) );
341 buffer += fmt::format(
"reference {}\n",
TO_UTF8( ref ) );
342 buffer += fmt::format(
"value {}\n",
TO_UTF8( value ) );
343 buffer += fmt::format(
"footprint {}\n", footprint->GetFPID().Format().c_str() );
345 buffer +=
"attribut";
348 buffer +=
" virtual";
350 if( footprint->GetAttributes() &
FP_SMD )
358 VECTOR2I footprint_pos = footprint->GetPosition();
361 buffer += fmt::format(
"position {:9.6f} {:9.6f} orientation {:.2f}\n",
362 footprint_pos.
x * conv_unit,
363 footprint_pos.
y * conv_unit,
364 footprint->GetOrientation().AsDegrees() );
366 if( footprint->GetLayer() ==
F_Cu )
367 buffer +=
"layer front\n";
368 else if( footprint->GetLayer() ==
B_Cu )
369 buffer +=
"layer back\n";
371 buffer +=
"layer other\n";
373 std::vector<PAD*> sortedPads;
375 for(
PAD*
pad : footprint->Pads() )
376 sortedPads.push_back(
pad );
378 std::sort( sortedPads.begin(), sortedPads.end(),
379 [](
PAD* a,
PAD* b ) ->
bool
381 return StrNumCmp( a->GetNumber(), b->GetNumber(), true ) < 0;
384 for(
PAD*
pad : sortedPads )
386 buffer += fmt::format(
"$PAD \"{}\"\n",
TO_UTF8(
pad->GetNumber() ) );
397 static const char* layer_name[4] = {
"nocopper",
"back",
"front",
"both" };
398 buffer += fmt::format(
"Shape {} Layer {}\n",
404 buffer += fmt::format(
"position {:9.6f} {:9.6f} size {:9.6f} {:9.6f} orientation {:.2f}\n",
405 padPos.
x * conv_unit,
406 padPos.
y * conv_unit,
409 pad->GetOrientation().AsDegrees() );
411 buffer += fmt::format(
"drill {:9.6f}\n",
pad->GetDrillSize().x * conv_unit );
413 buffer += fmt::format(
"shape_offset {:9.6f} {:9.6f}\n",
417 buffer +=
"$EndPAD\n";
420 buffer += fmt::format(
"$EndMODULE {}\n\n",
TO_UTF8( ref ) );
424 buffer +=
"$EndDESCRIPTION\n";
432 if( aFront && aBack )
433 return aBaseName + wxT(
"-" ) + wxT(
"all" );
constexpr EDA_IU_SCALE pcbIUScale
wxString GetBuildVersion()
Get the full KiCad version string.
const VECTOR2I & GetAuxOrigin() const
Information pertinent to a Pcbnew printed circuit board.
BOX2I ComputeBoundingBox(bool aBoardEdgesOnly=false) const
Calculate the bounding box containing all board items (or board edge segments).
const FOOTPRINTS & Footprints() const
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
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
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
PLACE_FILE_EXPORTER(BOARD *aBoard, bool aUnitsMM, bool aOnlySMD, bool aExcludeAllTH, bool aExcludeDNP, bool aTopSide, bool aBottomSide, bool aFormatCSV, bool aUseAuxOrigin, bool aNegateBottomX)
Create a PLACE_FILE_EXPORTER.
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