38#include <fmt/format.h>
80 bool aExcludeAllTH,
bool aExcludeDNP,
bool aExcludeBOM,
81 bool aTopSide,
bool aBottomSide,
bool aFormatCSV,
82 bool aUseAuxOrigin,
bool aNegateBottomX )
93 if( aTopSide && aBottomSide )
97 else if( aBottomSide )
131 std::vector<LIST_MOD> list;
143 if( footprint->GetExcludedFromPosFilesForVariant(
m_variant ) )
162 item.
m_Reference = footprint->Reference().GetShownText(
false );
165 item.
m_Layer = footprint->GetLayer();
167 lenRefText = std::max( lenRefText, (
int) item.
m_Reference.length() );
168 lenValText = std::max( lenValText, (
int) item.
m_Value.length() );
171 list.push_back( std::move( item ) );
174 if( list.size() > 1 )
182 wxChar csv_sep =
',';
185 snprintf( line,
sizeof(line),
"Ref%cVal%cPackage%cPosX%cPosY%cRot%cSide\n",
186 csv_sep, csv_sep, csv_sep, csv_sep, csv_sep, csv_sep );
193 footprint_pos = list[ii].m_Footprint->GetPosition();
196 int layer = list[ii].m_Footprint->GetLayer();
200 footprint_pos.
x = - footprint_pos.
x;
202 wxLine = wxT(
"\"" ) + list[ii].m_Reference;
203 wxLine << wxT(
"\"" ) << csv_sep;
204 wxLine << wxT(
"\"" ) << list[ii].m_Value;
205 wxLine << wxT(
"\"" ) << csv_sep;
206 wxLine << wxT(
"\"" ) << list[ii].m_Footprint->GetFPID().GetLibItemName().wx_str();
207 wxLine << wxT(
"\"" ) << csv_sep;
209 wxLine << wxString::Format( wxT(
"%f%c%f%c%f" ),
210 footprint_pos.
x * conv_unit,
214 -footprint_pos.
y * conv_unit,
216 list[ii].m_Footprint->GetOrientation().AsDegrees() );
229 snprintf( line,
sizeof(line),
"### Footprint positions - created on %s ###\n",
235 snprintf( line,
sizeof(line),
"### Printed by KiCad version %s\n",
TO_UTF8( Title ) );
239 buffer +=
"## Side : ";
252 snprintf( line,
sizeof(line),
"%-*s %-*s %-*s %9.9s %9.9s %8.8s %s\n",
255 lenPkgText,
"Package",
256 "PosX",
"PosY",
"Rot",
"Side" );
262 footprint_pos = list[ii].m_Footprint->GetPosition();
265 int layer = list[ii].m_Footprint->GetLayer();
269 footprint_pos.
x = - footprint_pos.
x;
271 wxString ref = list[ii].m_Reference;
272 wxString val = list[ii].m_Value;
273 wxString pkg = list[ii].m_Footprint->GetFPID().GetLibItemName();
274 ref.Replace( wxT(
" " ), wxT(
"_" ) );
275 val.Replace( wxT(
" " ), wxT(
"_" ) );
276 pkg.Replace( wxT(
" " ), wxT(
"_" ) );
277 wxLine.Printf( wxT(
"%-*s %-*s %-*s %9.4f %9.4f %8.4f %s\n" ),
278 lenRefText, std::move( ref ),
279 lenValText, std::move( val ),
280 lenPkgText, std::move( pkg ),
281 footprint_pos.
x * conv_unit,
283 -footprint_pos.
y * conv_unit,
284 list[ii].m_Footprint->GetOrientation().AsDegrees(),
290 buffer +=
"## End\n";
314 buffer += fmt::format(
"## Printed by KiCad version {}\n",
TO_UTF8( Title ) );
318 buffer +=
"\n$BeginDESCRIPTION\n";
320 BOX2I bbbox =
m_board->ComputeBoundingBox(
false,
true );
322 buffer +=
"\n$BOARD\n";
324 buffer += fmt::format(
"upper_left_corner {:9.6f} {:9.6f}\n",
325 bbbox.
GetX() * conv_unit,
326 bbbox.
GetY() * conv_unit );
328 buffer +=
"$EndBOARD\n\n";
330 std::vector<FOOTPRINT*> sortedFootprints;
333 sortedFootprints.push_back( footprint );
335 std::sort( sortedFootprints.begin(), sortedFootprints.end(),
338 return StrNumCmp( a->GetReference(), b->GetReference(), true ) < 0;
341 for(
FOOTPRINT* footprint : sortedFootprints )
343 wxString ref = footprint->Reference().GetShownText(
false );
345 footprint->GetFieldValueForVariant(
m_variant,
348 buffer += fmt::format(
"$MODULE {}\n",
TO_UTF8( ref ) );
350 buffer += fmt::format(
"reference {}\n",
TO_UTF8( ref ) );
351 buffer += fmt::format(
"value {}\n",
TO_UTF8( value ) );
352 buffer += fmt::format(
"footprint {}\n", footprint->GetFPID().Format().c_str() );
354 buffer +=
"attribut";
357 buffer +=
" virtual";
359 if( footprint->GetAttributes() &
FP_SMD )
367 VECTOR2I footprint_pos = footprint->GetPosition();
370 buffer += fmt::format(
"position {:9.6f} {:9.6f} orientation {:.2f}\n",
371 footprint_pos.
x * conv_unit,
372 footprint_pos.
y * conv_unit,
373 footprint->GetOrientation().AsDegrees() );
375 if( footprint->GetLayer() ==
F_Cu )
376 buffer +=
"layer front\n";
377 else if( footprint->GetLayer() ==
B_Cu )
378 buffer +=
"layer back\n";
380 buffer +=
"layer other\n";
382 std::vector<PAD*> sortedPads;
384 for(
PAD*
pad : footprint->Pads() )
385 sortedPads.push_back(
pad );
387 std::sort( sortedPads.begin(), sortedPads.end(),
388 [](
PAD* a,
PAD* b ) ->
bool
390 return StrNumCmp( a->GetNumber(), b->GetNumber(), true ) < 0;
393 for(
PAD*
pad : sortedPads )
395 buffer += fmt::format(
"$PAD \"{}\"\n",
TO_UTF8(
pad->GetNumber() ) );
406 static const char* layer_name[4] = {
"nocopper",
"back",
"front",
"both" };
407 buffer += fmt::format(
"Shape {} Layer {}\n",
413 buffer += fmt::format(
"position {:9.6f} {:9.6f} size {:9.6f} {:9.6f} orientation {:.2f}\n",
414 padPos.
x * conv_unit,
415 padPos.
y * conv_unit,
418 pad->GetOrientation().AsDegrees() );
420 buffer += fmt::format(
"drill {:9.6f}\n",
pad->GetDrillSize().x * conv_unit );
422 buffer += fmt::format(
"shape_offset {:9.6f} {:9.6f}\n",
426 buffer +=
"$EndPAD\n";
429 buffer += fmt::format(
"$EndMODULE {}\n\n",
TO_UTF8( ref ) );
433 buffer +=
"$EndDESCRIPTION\n";
441 if( aFront && aBack )
442 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