KiCad PCB EDA Suite
macros.h File Reference

This file contains miscellaneous commonly used macros and functions. More...

#include <wx/string.h>

Go to the source code of this file.

Macros

#define KI_HAS_ATTRIBUTE(x)   0
 
#define KI_HAS_CPP_ATTRIBUTE(x)   0
 
#define KI_FALLTHROUGH   ( ( void ) 0 )
 The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from one to the next. More...
 
#define TO_UTF8(wxstring)   ( (const char*) (wxstring).utf8_str() )
 Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes. More...
 
#define TO_STR2(x)   #x
 Stringifies the given parameter by placing in quotes. More...
 
#define TO_STR(x)   TO_STR2(x)
 

Functions

static wxString FROM_UTF8 (const char *cstring)
 function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes. More...
 
template<typename T , std::size_t N>
constexpr std::size_t arrayDim (T const (&)[N]) noexcept
 
template<typename T >
MIRRORVAL (T aPoint, T aMirrorRef)
 Function MIRROR Mirror aPoint in aMirrorRef. More...
 
template<typename T >
void MIRROR (T &aPoint, const T &aMirrorRef)
 

Detailed Description

This file contains miscellaneous commonly used macros and functions.

Definition in file macros.h.

Macro Definition Documentation

◆ KI_FALLTHROUGH

#define KI_FALLTHROUGH   ( ( void ) 0 )

The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from one to the next.

It must be followed by a ";".

Sample code: switch( a ) { case 1: // Some code KI_FALLTHROUGH;

case 2: // More code break; }

Definition at line 83 of file macros.h.

◆ KI_HAS_ATTRIBUTE

#define KI_HAS_ATTRIBUTE (   x)    0

Definition at line 39 of file macros.h.

◆ KI_HAS_CPP_ATTRIBUTE

#define KI_HAS_CPP_ATTRIBUTE (   x)    0

Definition at line 46 of file macros.h.

◆ TO_STR

#define TO_STR (   x)    TO_STR2(x)

Definition at line 103 of file macros.h.

◆ TO_STR2

#define TO_STR2 (   x)    #x

Stringifies the given parameter by placing in quotes.

Parameters
cstringSTRING (no spaces)
Returns
"STRING"

Definition at line 102 of file macros.h.

◆ TO_UTF8

#define TO_UTF8 (   wxstring)    ( (const char*) (wxstring).utf8_str() )

Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.

wxstring is a wxString, not a wxT() or _(). The scope of the return value is very limited and volatile, but can be used with printf() style functions well. NOTE: Trying to convert it to a function is tricky because of the type of the parameter!

Definition at line 95 of file macros.h.

Function Documentation

◆ arrayDim()

template<typename T , std::size_t N>
constexpr std::size_t arrayDim ( T   const(&)[N])
noexcept

of elements in an array. This implements type-safe compile time checking

Definition at line 121 of file macros.h.

122 {
123  return N;
124 }

Referenced by PROJECT_ARCHIVER::Archive(), AskLoadBoardFileName(), LSET::BackAssembly(), EAGLE_PLUGIN::clear_cu_map(), BOARD_ADAPTER::createLayers(), CreatePadsShapesSection(), LSET::CuStack(), GAL_SET::DefaultVisible(), DIELECTRIC_SUBSTRATE_LIST::DIELECTRIC_SUBSTRATE_LIST(), dlg_layers(), EDA_DRAW_FRAME::EDA_DRAW_FRAME(), PROJECT::ElemsClear(), DIALOG_PRINT_PCBNEW::enableLayer(), EVT_TOOL_RANGE(), FindKicadFile(), LSET::FmtHex(), PCB_IO::formatBoardLayers(), LSET::FrontAssembly(), DIALOG_GENDRILL::GenDrillAndMapFiles(), GERBER_FILE_IMAGE::GERBER_FILE_IMAGE(), AUTOPLACER::get_colliding_sides(), AUTOPLACER::get_preferred_sides(), DIALOG_EXPORT_SVG::getCheckBoxSelectedLayers(), GetColorStandardListCount(), GetCopperFinishStandardList(), GERBER_FILE_IMAGE::GetDCODE(), GERBER_FILE_IMAGE::GetDCODEOrCreate(), GERBER_FILE_IMAGE::GetDcodesCount(), PROJECT::GetElem(), MODEL_VRML::GetLayerZ(), DIALOG_PAGES_SETTINGS::GetPageLayoutInfoFromDialog(), PROJECT::GetRString(), LSET::InternalCuMask(), isKeyModifierOnly(), isKeySpecialCode(), DIALOG_PRINT_PCBNEW::isLayerEnabled(), EAGLE_PLUGIN::kicad_layer(), KIWAY::KiFACE(), MODEL_VRML::MODEL_VRML(), DIALOG_PAD_PROPERTIES::onAddPrimitive(), PANEL_SETUP_LAYERS::OnPresetsChoice(), DIALOG_PAD_PROPERTIES::OnUpdateUI(), DIALOG_PAD_PROPERTIES::PadTypeSelected(), KIGFX::PCB_RENDER_SETTINGS::PCB_RENDER_SETTINGS(), PL_EDITOR_FRAME::PL_EDITOR_FRAME(), PlotLayerOutlines(), GERBER_LAYER_WIDGET::ReFillRender(), EDA_DRAW_FRAME::saveCanvasTypeSetting(), LSET::SeqStackupBottom2Top(), PROJECT::SetElem(), PGM_BASE::SetLanguageIdentifier(), BOARD::SetLayerDescr(), DIALOG_PRINT_PCBNEW::setLayerSetFromList(), PROJECT::SetRString(), PANEL_SETUP_LAYERS::showPresets(), LSET::TechAndUserUIOrder(), LSET::Technicals(), PANEL_GERBVIEW_SETTINGS::TransferDataToWindow(), LSET::Users(), DIALOG_EXPORT_SVG::~DIALOG_EXPORT_SVG(), and GERBER_FILE_IMAGE::~GERBER_FILE_IMAGE().

◆ FROM_UTF8()

static wxString FROM_UTF8 ( const char *  cstring)
inlinestatic

function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes.

Definition at line 109 of file macros.h.

110 {
111  wxString line = wxString::FromUTF8( cstring );
112 
113  if( line.IsEmpty() ) // happens when cstring is not a valid UTF8 sequence
114  line = wxConvCurrent->cMB2WC( cstring ); // try to use locale conversion
115 
116  return line;
117 }

Referenced by SCH_REFERENCE::Annotate(), SCH_EDITOR_CONTROL::AssignFootprints(), CVPCB_MAINFRAME::buildEquivalenceList(), PLACEFILE_GERBER_WRITER::CreatePlaceFile(), detect_file_type(), DIALOG_CHANGE_SYMBOLS::DIALOG_CHANGE_SYMBOLS(), DIALOG_EXCHANGE_FOOTPRINTS::DIALOG_EXCHANGE_FOOTPRINTS(), DIALOG_FP_PLUGIN_OPTIONS::DIALOG_FP_PLUGIN_OPTIONS(), EXCELLON_IMAGE::Execute_EXCELLON_G_Command(), SCH_EDIT_FRAME::ExecuteRemoteCommand(), PCB_EDIT_FRAME::ExecuteRemoteCommand(), PCB_EDIT_FRAME::Export_IDF3(), PCB_EDIT_FRAME::ExportVRML_File(), GPCB_PLUGIN::FootprintEnumerate(), LEGACY_PLUGIN::FootprintEnumerate(), EAGLE_PLUGIN::FootprintEnumerate(), GERBER_JOBFILE_READER::formatStringFromJSON(), DSN::SPECCTRA_DB::FromSESSION(), GENDRILL_WRITER_BASE::genDrillMapFile(), SEXPR::PARSER::GetFileContents(), GetIllegalFileNameWxChars(), DISPLAY_FOOTPRINTS_FRAME::GetModule(), BACK_ANNOTATE::getPcbModulesFromString(), NETLIST_READER::GuessNetlistFileType(), EDA_3D_CANVAS::initializeOpenGL(), CMP_READER::Load(), LEGACY_NETLIST_READER::loadComponent(), LEGACY_PLUGIN::loadDIMENSION(), SCH_LEGACY_PLUGIN_CACHE::loadDocs(), EAGLE_PLUGIN::loadElements(), LEGACY_NETLIST_READER::loadFootprintFilters(), EAGLE_PLUGIN::loadLayerDefs(), LEGACY_PLUGIN::loadMODULE(), LEGACY_NETLIST_READER::loadNet(), LEGACY_PLUGIN::loadNETCLASS(), LEGACY_PLUGIN::loadNETINFO_ITEM(), LEGACY_PLUGIN::loadPAD(), LEGACY_PLUGIN::loadPCB_TEXT(), EAGLE_PLUGIN::loadPlain(), LEGACY_PLUGIN::loadSETUP(), LEGACY_PLUGIN::loadSHEET(), SCH_LEGACY_PLUGIN::loadText(), main(), EAGLE_PLUGIN::makeModule(), DSN::SPECCTRA_DB::makeTRACK(), DSN::SPECCTRA_DB::makeVIA(), APP_SINGLE_TOP::OnInit(), APP_TEST::OnInit(), APP_SINGLE_TOP::OnRun(), APP_TEST::OnRun(), APP_KICAD::OnRun(), EAGLE_PLUGIN::orientModuleText(), EAGLE_PLUGIN::packageText(), PCB_PLOT_PARAMS_PARSER::Parse(), TEMPLATE_FIELDNAME::Parse(), X2_ATTRIBUTE::ParseAttribCmd(), KICAD_NETLIST_PARSER::parseComponent(), PCB_PARSER::parseLayer(), KICAD_NETLIST_PARSER::parseLibPartList(), KICAD_NETLIST_PARSER::parseNet(), parseQuotedString(), PCB_CALCULATOR_DATAFILE_PARSER::ParseRegulatorDescr(), parseUnquotedString(), pcbnewRunPythonMethodWithReturnedString(), SCH_EDITOR_CONTROL::processCmpToFootprintLinkFile(), PyArrayStringToWx(), PyStringToWx(), GERBER_FILE_IMAGE::ReadApertureMacro(), ReadDelimitedText(), CVPCB_MAINFRAME::ReadNetListAndFpFiles(), PCB_EDIT_FRAME::RecreateBOMFileFromBoard(), CVPCB_MAINFRAME::refreshAfterComponentSearch(), REPORTER::Report(), PARAM_CFG_FIELDNAMES::SaveParam(), SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS(), DIALOG_FP_PLUGIN_OPTIONS::TransferDataToWindow(), EAGLE_PLUGIN::transferPad(), FOOTPRINT_EDIT_FRAME::updateTitle(), DIALOG_BOM::~DIALOG_BOM(), and WS_DATA_MODEL_STRINGIO::~WS_DATA_MODEL_STRINGIO().

◆ MIRROR()

◆ MIRRORVAL()

template<typename T >
T MIRRORVAL ( aPoint,
aMirrorRef 
)

Function MIRROR Mirror aPoint in aMirrorRef.

Definition at line 131 of file macros.h.

132 {
133  return -( aPoint - aMirrorRef ) + aMirrorRef;
134 }

Referenced by FP_TEXT::Flip(), FP_TEXT::Mirror(), MIRROR(), SCH_TEXT::MirrorX(), and SCH_TEXT::MirrorY().