34#include <fmt/format.h>
76 bool aExcludeAllTH,
bool aExcludeDNP,
bool aExcludeBOM,
77 bool aTopSide,
bool aBottomSide,
bool aFormatCSV,
78 bool aUseAuxOrigin,
bool aNegateBottomX )
89 if( aTopSide && aBottomSide )
93 else if( aBottomSide )
127 std::vector<LIST_MOD> list;
139 if( footprint->GetExcludedFromPosFilesForVariant(
m_variant ) )
158 item.
m_Reference = footprint->Reference().GetShownText(
false );
161 item.
m_Layer = footprint->GetLayer();
163 lenRefText = std::max( lenRefText, (
int) item.
m_Reference.length() );
164 lenValText = std::max( lenValText, (
int) item.
m_Value.length() );
167 list.push_back( std::move( item ) );
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 wxLine = wxT(
"\"" ) + list[ii].m_Reference;
199 wxLine << wxT(
"\"" ) << csv_sep;
200 wxLine << wxT(
"\"" ) << list[ii].m_Value;
201 wxLine << wxT(
"\"" ) << csv_sep;
202 wxLine << wxT(
"\"" ) << list[ii].m_Footprint->GetFPID().GetLibItemName().wx_str();
203 wxLine << wxT(
"\"" ) << csv_sep;
205 wxLine << 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",
251 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 wxLine.Printf( wxT(
"%-*s %-*s %-*s %9.4f %9.4f %8.4f %s\n" ),
274 lenRefText, std::move( ref ),
275 lenValText, std::move( val ),
276 lenPkgText, std::move( pkg ),
277 footprint_pos.
x * conv_unit,
279 -footprint_pos.
y * conv_unit,
280 list[ii].m_Footprint->GetOrientation().AsDegrees(),
286 buffer +=
"## End\n";
310 buffer += fmt::format(
"## Printed by KiCad version {}\n",
TO_UTF8( Title ) );
314 buffer +=
"\n$BeginDESCRIPTION\n";
316 BOX2I bbbox =
m_board->ComputeBoundingBox(
false,
true );
318 buffer +=
"\n$BOARD\n";
320 buffer += fmt::format(
"upper_left_corner {:9.6f} {:9.6f}\n",
321 bbbox.
GetX() * conv_unit,
322 bbbox.
GetY() * conv_unit );
324 buffer +=
"$EndBOARD\n\n";
326 std::vector<FOOTPRINT*> sortedFootprints;
329 sortedFootprints.push_back( footprint );
331 std::sort( sortedFootprints.begin(), sortedFootprints.end(),
334 return StrNumCmp( a->GetReference(), b->GetReference(), true ) < 0;
337 for(
FOOTPRINT* footprint : sortedFootprints )
339 wxString ref = footprint->Reference().GetShownText(
false );
341 footprint->GetFieldValueForVariant(
m_variant,
344 buffer += fmt::format(
"$MODULE {}\n",
TO_UTF8( ref ) );
346 buffer += fmt::format(
"reference {}\n",
TO_UTF8( ref ) );
347 buffer += fmt::format(
"value {}\n",
TO_UTF8( value ) );
348 buffer += fmt::format(
"footprint {}\n", footprint->GetFPID().Format().c_str() );
350 buffer +=
"attribut";
353 buffer +=
" virtual";
355 if( footprint->GetAttributes() &
FP_SMD )
363 VECTOR2I footprint_pos = footprint->GetPosition();
366 buffer += fmt::format(
"position {:9.6f} {:9.6f} orientation {:.2f}\n",
367 footprint_pos.
x * conv_unit,
368 footprint_pos.
y * conv_unit,
369 footprint->GetOrientation().AsDegrees() );
371 if( footprint->GetLayer() ==
F_Cu )
372 buffer +=
"layer front\n";
373 else if( footprint->GetLayer() ==
B_Cu )
374 buffer +=
"layer back\n";
376 buffer +=
"layer other\n";
378 std::vector<PAD*> sortedPads;
380 for(
PAD*
pad : footprint->Pads() )
381 sortedPads.push_back(
pad );
383 std::sort( sortedPads.begin(), sortedPads.end(),
384 [](
PAD* a,
PAD* b ) ->
bool
386 return StrNumCmp( a->GetNumber(), b->GetNumber(), true ) < 0;
389 for(
PAD*
pad : sortedPads )
391 buffer += fmt::format(
"$PAD \"{}\"\n",
TO_UTF8(
pad->GetNumber() ) );
402 static const char* layer_name[4] = {
"nocopper",
"back",
"front",
"both" };
403 buffer += fmt::format(
"Shape {} Layer {}\n",
409 buffer += fmt::format(
"position {:9.6f} {:9.6f} size {:9.6f} {:9.6f} orientation {:.2f}\n",
410 padPos.
x * conv_unit,
411 padPos.
y * conv_unit,
414 pad->GetOrientation().AsDegrees() );
416 buffer += fmt::format(
"drill {:9.6f}\n",
pad->GetDrillSize().x * conv_unit );
418 buffer += fmt::format(
"shape_offset {:9.6f} {:9.6f}\n",
422 buffer +=
"$EndPAD\n";
425 buffer += fmt::format(
"$EndMODULE {}\n\n",
TO_UTF8( ref ) );
429 buffer +=
"$EndDESCRIPTION\n";
437 if( aFront && aBack )
438 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 UnescapeString(const wxString &aSource)
wxString GetISO8601CurrentDateTime()
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
@ VALUE
Field Value of part, i.e. "3.3K".
wxString GetCanonicalFieldName(FIELD_T aFieldType)
VECTOR2< int32_t > VECTOR2I