KiCad PCB EDA Suite
numEval Namespace Reference

Namespaces

 KIGFX
 
 numEval
 
 std
 

Template specialization to enable wxStrings for certain containers (e.g. unordered_map)


 

Classes

class  FILE_LINE_READER
 FILE_LINE_READER is a LINE_READER that reads from an open file. More...
 
class  FILE_OUTPUTFORMATTER
 FILE_OUTPUTFORMATTER may be used for text file output. More...
 
struct  FUTURE_FORMAT_ERROR
 Struct FUTURE_FORMAT_ERROR variant of PARSE_ERROR indicating that a syntax or related error was likely caused by a file generated by a newer version of KiCad than this. More...
 
class  INPUTSTREAM_LINE_READER
 INPUTSTREAM_LINE_READER is a LINE_READER that reads from a wxInputStream object. More...
 
class  IO_ERROR
 Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions containing meaningful error messages. More...
 
class  KI_PARAM_ERROR
 KI_PARAM_ERROR is a class used to hold a translatable error message and may be used when throwing exceptions containing a translated error message. More...
 
class  KIID
 
class  KIID_PATH
 
class  LINE_READER
 LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived to read single lines of text and manage a line number counter. More...
 
class  LOCALE_IO
 Instantiate the current locale within a scope in which you are expecting exceptions to be thrown. More...
 
class  NUMERIC_EVALUATOR
 
class  OUTPUTFORMATTER
 OUTPUTFORMATTER is an important interface (abstract class) used to output 8 bit text in a convenient way. More...
 
struct  PARSE_ERROR
 Struct PARSE_ERROR contains a filename or source description, a problem input line, a line number, a byte offset, and an error message which contains the the caller's report and his call site information: CPP source file, function, and line number. More...
 
class  STREAM_OUTPUTFORMATTER
 STREAM_OUTPUTFORMATTER implements OUTPUTFORMATTER to a wxWidgets wxOutputStream. More...
 
class  STRING_FORMATTER
 STRING_FORMATTER implements OUTPUTFORMATTER to a memory buffer. More...
 
class  STRING_LINE_READER
 STRING_LINE_READER is a LINE_READER that reads from a multiline 8 bit wide std::string. More...
 
struct  StructColors
 
struct  TokenType
 
class  UTF8
 UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and from wxString, to and from std::string, and has non-mutating iteration over unicode characters. More...
 
class  WX_FILENAME
 A wrapper around a wxFileName which is much more performant with a subset of the API. More...
 
union  YYMINORTYPE
 
struct  yyParser
 
struct  yyStackEntry
 

Typedefs

typedef uint32_t timestamp_t
 timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the timestamp when they were created. More...
 
typedef struct yyStackEntry yyStackEntry
 
typedef struct yyParser yyParser
 

Enumerations

enum  EDA_COLOR_T {
  UNSPECIFIED_COLOR = -1, BLACK = 0, DARKDARKGRAY, DARKGRAY,
  LIGHTGRAY, WHITE, LIGHTYELLOW, DARKBLUE,
  DARKGREEN, DARKCYAN, DARKRED, DARKMAGENTA,
  DARKBROWN, BLUE, GREEN, CYAN,
  RED, MAGENTA, BROWN, LIGHTBLUE,
  LIGHTGREEN, LIGHTCYAN, LIGHTRED, LIGHTMAGENTA,
  YELLOW, PUREBLUE, PUREGREEN, PURECYAN,
  PURERED, PUREMAGENTA, PUREYELLOW, NBCOLORS,
  HIGHLIGHT_FLAG = ( 1<<19 ), MASKCOLOR = 31
}
 Legacy color enumeration. More...
 
enum  EDA_DATA_TYPE { EDA_DATA_TYPE::DISTANCE = 0, EDA_DATA_TYPE::AREA = 1, EDA_DATA_TYPE::VOLUME = 2 }
 The type of unit. More...
 
enum  EDA_UNITS {
  EDA_UNITS::INCHES = 0, EDA_UNITS::MILLIMETRES = 1, EDA_UNITS::UNSCALED = 2, EDA_UNITS::DEGREES = 3,
  EDA_UNITS::PERCENT = 4
}
 

Functions

bool IsUTF8 (const char *aString)
 Function IsUTF8 tests a c-string to see if it is UTF8 encoded. More...
 
int StrPrintf (std::string *aResult, const char *aFormat,...)
 Function StrPrintf is like sprintf() but the output is appended to a std::string instead of to a character array. More...
 
std::string StrPrintf (const char *format,...)
 Function StrPrintf is like sprintf() but the output is returned in a std::string instead of to a character array. More...
 
const StructColorscolorRefs ()
 Global list of legacy color names, still used all over the place for constructing COLOR4D's. More...
 
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...
 
void AccumulateDescription (wxString &aDesc, const wxString &aItem)
 Utility to build comma separated lists in messages. More...
 
static const wxChar * GetChars (const wxString &s)
 Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for passing strings to wxString::Printf() and wxString::Format(). More...
 
template<typename T , std::size_t N>
constexpr std::size_t arrayDim (T const (&)[N]) noexcept
 
template<typename T >
Mirror (T aPoint, T aMirrorRef)
 Function MIRROR Mirror aPoint in aMirrorRef. More...
 
template<typename T >
void MIRROR (T &aPoint, const T &aMirrorRef)
 
KIIDNilUuid ()
 
wxSize GetTextSize (const wxString &aSingleLine, wxWindow *aWindow)
 Return the size of aSingleLine of text when it is rendered in aWindow using whatever font is currently set in that window. More...
 
bool EnsureTextCtrlWidth (wxTextCtrl *aCtrl, const wxString *aString=NULL)
 Set the minimum pixel width on a text control in order to make a text string be fully visible within it. More...
 
void SelectReferenceNumber (wxTextEntry *aTextEntry)
 Select the number (or "?") in a reference for ease of editing. More...
 
int ProcessExecute (const wxString &aCommandLine, int aFlags=wxEXEC_ASYNC, wxProcess *callback=NULL)
 Run a command in a child process. More...
 
void wxStringSplit (const wxString &aText, wxArrayString &aStrings, wxChar aSplitter)
 Split aString to a string list separated at aSplitter. More...
 
wxString SearchHelpFileFullPath (const SEARCH_STACK &aSearchStack, const wxString &aBaseName)
 Return the help file's full path. More...
 
bool EnsureFileDirectoryExists (wxFileName *aTargetFullFileName, const wxString &aBaseFilename, REPORTER *aReporter=NULL)
 Make aTargetFullFileName absolute and create the path of this file if it doesn't yet exist. More...
 
const wxString PrePendPath (const wxString &aEnvVar, const wxString &aPriorityPath)
 Put aPriorityPath in front of all paths in the value of aEnvVar. More...
 
const wxString ExpandEnvVarSubstitutions (const wxString &aString, PROJECT *aProject)
 Replace any environment variable & text variable references with their values. More...
 
wxString ExpandTextVars (const wxString &aSource, const std::function< bool(wxString *)> *aLocalResolver, const PROJECT *aProject)
 Expand '${var-name}' templates in text. More...
 
const wxString ResolveUriByEnvVars (const wxString &aUri, PROJECT *aProject)
 Replace any environment and/or text variables in file-path uris (leaving network-path URIs alone). More...
 
std::ostream & operator<< (std::ostream &out, const wxSize &size)
 Helper function to print the given wxSize to a stream. More...
 
std::ostream & operator<< (std::ostream &out, const wxPoint &pt)
 Helper function to print the given wxPoint to a stream. More...
 
long long TimestampDir (const wxString &aDirPath, const wxString &aFilespec)
 A copy of ConvertFileTimeToWx() because wxWidgets left it as a static function private to src/common/filename.cpp. More...
 
constexpr int PcbMils2iu (int mils)
 
constexpr int SchMils2iu (int mils)
 
constexpr int PcbMillimeter2iu (double mm)
 
constexpr int SchMillimeter2iu (double mm)
 
constexpr double PcbIu2Millimeter (int iu)
 
constexpr double SchIu2Millimeter (int iu)
 
int Mm2mils (double x)
 Convert mm to mils. More...
 
int Mils2mm (double x)
 Convert mils to mm. More...
 
std::string Double2Str (double aValue)
 Helper function Double2Str to print a float number without using scientific notation and no trailing 0 We want to avoid scientific notation in S-expr files (not easy to read) for floating numbers. More...
 
void StripTrailingZeros (wxString &aStringValue, unsigned aTrailingZeroAllowed=1)
 Function StripTrailingZeros Remove trailing 0 from a string containing a converted float number. More...
 
double To_User_Unit (EDA_UNITS aUnit, double aValue, bool aUseMils=false)
 Function To_User_Unit convert aValue in internal units to the appropriate user units defined by aUnit. More...
 
wxString AngleToStringDegrees (double aAngle)
 Function AngleToStringDegrees is a helper to convert the double aAngle (in internal unit) to a string in degrees. More...
 
wxString MessageTextFromValue (EDA_UNITS aUnits, double aValue, bool aUseMils=false, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
 Function MessageTextFromValue is a helper to convert the double length aValue to a string in inches, millimeters, or unscaled units. More...
 
wxString MessageTextFromValue (EDA_UNITS aUnits, int aValue, bool aUseMils=false, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
 
wxString MessageTextFromValue (EDA_UNITS aUnits, long long int aValue, bool aUseMils=false, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
 
wxString StringFromValue (EDA_UNITS aUnit, double aValue, bool aAddUnitSymbol=false, bool aUseMils=false, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
 Function StringFromValue returns the string from aValue according to units (inch, mm ...) for display, and the initial unit for value. More...
 
double From_User_Unit (EDA_UNITS aUnit, double aValue, bool aUseMils=false)
 Return in internal units the value "val" given in a real unit such as "in", "mm" or "deg". More...
 
double DoubleValueFromString (EDA_UNITS aUnits, const wxString &aTextValue, bool aUseMils=false, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
 Function DoubleValueFromString converts aTextValue to a double. More...
 
long long int ValueFromString (EDA_UNITS aUnits, const wxString &aTextValue, bool aUseMils=false, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
 Function ValueFromString converts aTextValue in aUnits to internal units used by the application. More...
 
void FetchUnitsFromString (const wxString &aTextValue, EDA_UNITS &aUnits, bool &aUseMils)
 Function FetchUnitsFromString writes any unit info found in the string to aUnits and aUseMils. More...
 
wxString GetAbbreviatedUnitsLabel (EDA_UNITS aUnit, bool aUseMils=false, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
 Get the units string for a given units type. More...
 
std::string FormatInternalUnits (int aValue)
 Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing to file. More...
 
std::string FormatAngle (double aAngle)
 Function FormatAngle converts aAngle from board units to a string appropriate for writing to file. More...
 
std::string FormatInternalUnits (const wxPoint &aPoint)
 
std::string FormatInternalUnits (const wxSize &aSize)
 
std::string FormatInternalUnits (const VECTOR2I &aPoint)
 
void ParseTrace (FILE *TraceFILE, char *zTracePrompt)
 
void ParseInit (void *yypRawParser ParseCTX_PDECL)
 
void * ParseAlloc (void *(*mallocProc)(YYMALLOCARGTYPE) ParseCTX_PDECL)
 
static void yy_destructor (yyParser *yypParser, YYCODETYPE yymajor, YYMINORTYPE *yypminor)
 
static void yy_pop_parser_stack (yyParser *pParser)
 
void ParseFinalize (void *p)
 
void ParseFree (void *p, void(*freeProc)(void *))
 
static YYACTIONTYPE yy_find_shift_action (YYCODETYPE iLookAhead, YYACTIONTYPE stateno)
 
static YYACTIONTYPE yy_find_reduce_action (YYACTIONTYPE stateno, YYCODETYPE iLookAhead)
 
static void yyStackOverflow (yyParser *yypParser)
 
static void yyTraceShift (yyParser *yypParser, int yyNewState, const char *zTag)
 
static void yy_shift (yyParser *yypParser, YYACTIONTYPE yyNewState, YYCODETYPE yyMajor, ParseTOKENTYPE yyMinor)
 
static void yy_accept (yyParser *)
 
static YYACTIONTYPE yy_reduce (yyParser *yypParser, unsigned int yyruleno, int yyLookahead, ParseTOKENTYPE yyLookaheadToken ParseCTX_PDECL)
 
static void yy_parse_failed (yyParser *yypParser)
 
static void yy_syntax_error (yyParser *yypParser, int yymajor, ParseTOKENTYPE yyminor)
 
void Parse (void *yyp, int yymajor, ParseTOKENTYPE yyminor ParseARG_PDECL)
 
int ParseFallback (int iToken)
 

Variables

KIID niluuid
 
constexpr double GERB_IU_PER_MM = 1e5
 some define and functions to convert a value in mils, decimils or mm to the internal unit used in pcbnew, cvpcb or gerbview (nanometer or deci-mil) depending on compile time option More...
 
constexpr double PCB_IU_PER_MM = 1e6
 
constexpr double PL_IU_PER_MM = 1e3
 
constexpr double SCH_IU_PER_MM = 1e4
 
constexpr double PCB_IU_PER_MILS = (PCB_IU_PER_MM * 0.0254)
 
constexpr double SCH_IU_PER_MILS = (SCH_IU_PER_MM * 0.0254)
 
static const YYACTIONTYPE yy_action []
 
static const YYCODETYPE yy_lookahead []
 
static const unsigned char yy_shift_ofst []
 
static const signed char yy_reduce_ofst []
 
static const YYACTIONTYPE yy_default []
 
static FILE * yyTraceFILE = 0
 
static char * yyTracePrompt = 0
 
static const char *const yyTokenName []
 
static const char *const yyRuleName []
 
static const YYCODETYPE yyRuleInfoLhs []
 
static const signed char yyRuleInfoNRhs []
 

Typedef Documentation

◆ timestamp_t

typedef uint32_t numEval::timestamp_t

timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the timestamp when they were created.

Long term, this type might be renamed to something like unique_id_t (and then rename all the methods from {Get,Set}TimeStamp() to {Get,Set}Id()) ?

Definition at line 56 of file numeric_evaluator.cpp.

◆ yyParser

typedef struct yyParser numEval::yyParser

Definition at line 295 of file numeric_evaluator.cpp.

◆ yyStackEntry

Definition at line 272 of file numeric_evaluator.cpp.

Enumeration Type Documentation

◆ EDA_COLOR_T

Legacy color enumeration.

Also contains a flag and the alpha value in the upper bits

Enumerator
UNSPECIFIED_COLOR 
BLACK 
DARKDARKGRAY 
DARKGRAY 
LIGHTGRAY 
WHITE 
LIGHTYELLOW 
DARKBLUE 
DARKGREEN 
DARKCYAN 
DARKRED 
DARKMAGENTA 
DARKBROWN 
BLUE 
GREEN 
CYAN 
RED 
MAGENTA 
BROWN 
LIGHTBLUE 
LIGHTGREEN 
LIGHTCYAN 
LIGHTRED 
LIGHTMAGENTA 
YELLOW 
PUREBLUE 
PUREGREEN 
PURECYAN 
PURERED 
PUREMAGENTA 
PUREYELLOW 
NBCOLORS 

Number of colors.

HIGHLIGHT_FLAG 
MASKCOLOR 

mask for color index into colorRefs()[]

Definition at line 42 of file numeric_evaluator.cpp.

47 {
48  struct lconv* lc = localeconv();
49  m_localeDecimalSeparator = *lc->decimal_point;
50 
51  m_parseError = false;
52  m_parseFinished = false;
53 
54  m_parser = numEval::ParseAlloc( malloc );
55 
56  switch( aUnits )
57  {
58  case EDA_UNITS::INCHES:
59  if( aUseMils )
60  m_defaultUnits = Unit::Mil;
61  else
62  m_defaultUnits = Unit::Inch;
63  break;
65  m_defaultUnits = Unit::MM;
66  break;
67  default:m_defaultUnits = Unit::MM;
68  break;
69  }
70 }
71 
72 
74 {
76 
77  // Allow explicit call to destructor
78  m_parser = nullptr;
void * ParseAlloc(void *(*mallocProc)(YYMALLOCARGTYPE) ParseCTX_PDECL)
void ParseFree(void *p, void(*freeProc)(void *))

◆ EDA_DATA_TYPE

The type of unit.

Enumerator
DISTANCE 
AREA 
VOLUME 

Definition at line 191 of file numeric_evaluator.cpp.

193  {
194  return ( ch == m_localeDecimalSeparator || ch == '.' || ch == ',' );
195  };
196 

◆ EDA_UNITS

enum numEval::EDA_UNITS
strong
Enumerator
INCHES 
MILLIMETRES 
UNSCALED 
DEGREES 
PERCENT 

Definition at line 198 of file numeric_evaluator.cpp.

198  {
199  bool haveSeparator = false;
200  idx = 0;
201  auto ch = m_token.input[ m_token.pos ];
202 
203  do
204  {
205  if( isDecimalSeparator( ch ) && haveSeparator )

Function Documentation

◆ AccumulateDescription()

void numEval::AccumulateDescription ( wxString &  aDesc,
const wxString &  aItem 
)
inline

Utility to build comma separated lists in messages.

Definition at line 127 of file numeric_evaluator.cpp.

129 {
130  // Feed parser token after token until end of input.
131 
132  newString( aString );
133  m_parseError = false;

◆ AngleToStringDegrees()

wxString numEval::AngleToStringDegrees ( double  aAngle)

Function AngleToStringDegrees is a helper to convert the double aAngle (in internal unit) to a string in degrees.

Definition at line 484 of file base_units.cpp.

485 {
486  wxString text;
487 
488  text.Printf( wxT( "%.3f" ), aAngle/10.0 );
489  StripTrailingZeros( text, 1 );
490 
491  return text;
492 }
void StripTrailingZeros(wxString &aStringValue, unsigned aTrailingZeroAllowed)
Function StripTrailingZeros Remove trailing 0 from a string containing a converted float number.
Definition: base_units.cpp:201

◆ arrayDim()

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

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

Definition at line 161 of file numeric_evaluator.cpp.

161 {
162  Clear();
163 
164  m_originalText = aString;

◆ colorRefs()

const StructColors* numEval::colorRefs ( )

Global list of legacy color names, still used all over the place for constructing COLOR4D's.

Definition at line 37 of file color4d.cpp.

38 {
39  static StructColors s_ColorRefs[NBCOLORS] =
40  {
41  { 0, 0, 0, BLACK, TS( "Black" ), DARKDARKGRAY },
42  { 72, 72, 72, DARKDARKGRAY, TS( "Gray 1" ), DARKGRAY },
43  { 132, 132, 132, DARKGRAY, TS( "Gray 2" ), LIGHTGRAY },
44  { 194, 194, 194, LIGHTGRAY, TS( "Gray 3" ), WHITE },
45  { 255, 255, 255, WHITE, TS( "White" ), WHITE },
46  { 194, 255, 255, LIGHTYELLOW, TS( "L.Yellow" ), WHITE },
47  { 72, 0, 0, DARKBLUE, TS( "Blue 1" ), BLUE },
48  { 0, 72, 0, DARKGREEN, TS( "Green 1" ), GREEN },
49  { 72, 72, 0, DARKCYAN, TS( "Cyan 1" ), CYAN },
50  { 0, 0, 72, DARKRED, TS( "Red 1" ), RED },
51  { 72, 0, 72, DARKMAGENTA, TS( "Magenta 1" ), MAGENTA },
52  { 0, 72, 72, DARKBROWN, TS( "Brown 1" ), BROWN },
53  { 132, 0, 0, BLUE, TS( "Blue 2" ), LIGHTBLUE },
54  { 0, 132, 0, GREEN, TS( "Green 2" ), LIGHTGREEN },
55  { 132, 132, 0, CYAN, TS( "Cyan 2" ), LIGHTCYAN },
56  { 0, 0, 132, RED, TS( "Red 2" ), LIGHTRED },
57  { 132, 0, 132, MAGENTA, TS( "Magenta 2" ), LIGHTMAGENTA },
58  { 0, 132, 132, BROWN, TS( "Brown 2" ), YELLOW },
59  { 194, 0, 0, LIGHTBLUE, TS( "Blue 3" ), PUREBLUE, },
60  { 0, 194, 0, LIGHTGREEN, TS( "Green 3" ), PUREGREEN },
61  { 194, 194, 0, LIGHTCYAN, TS( "Cyan 3" ), PURECYAN },
62  { 0, 0, 194, LIGHTRED, TS( "Red 3" ), PURERED },
63  { 194, 0, 194, LIGHTMAGENTA, TS( "Magenta 3" ), PUREMAGENTA },
64  { 0, 194, 194, YELLOW, TS( "Yellow 3" ), PUREYELLOW },
65  { 255, 0, 0, PUREBLUE, TS( "Blue 4" ), WHITE },
66  { 0, 255, 0, PUREGREEN, TS( "Green 4" ), WHITE },
67  { 255, 255, 0, PURECYAN, TS( "Cyan 4" ), WHITE },
68  { 0, 0, 255, PURERED, TS( "Red 4" ), WHITE },
69  { 255, 0, 255, PUREMAGENTA, TS( "Magenta 4" ), WHITE },
70  { 0, 255, 255, PUREYELLOW, TS( "Yellow 4" ), WHITE },
71  };
72  return s_ColorRefs;
73 }
Definition: color4d.h:61
Definition: color4d.h:44
Number of colors.
Definition: color4d.h:74
Definition: color4d.h:67
Definition: color4d.h:57
Definition: color4d.h:58
Definition: color4d.h:59
Definition: color4d.h:48
Definition: color4d.h:56
#define TS(string)
Definition: color4d.cpp:33

◆ Double2Str()

std::string numEval::Double2Str ( double  aValue)

Helper function Double2Str to print a float number without using scientific notation and no trailing 0 We want to avoid scientific notation in S-expr files (not easy to read) for floating numbers.

So we cannot always just use the g or the f format to print a fp number this helper function uses the f format when needed, or g when f is not well working and then removes trailing 0

Definition at line 62 of file base_units.cpp.

63 {
64  char buf[50];
65  int len;
66 
67  if( aValue != 0.0 && fabs( aValue ) <= 0.0001 )
68  {
69  // For these small values, %f works fine,
70  // and %g gives an exponent
71  len = sprintf( buf, "%.16f", aValue );
72 
73  while( --len > 0 && buf[len] == '0' )
74  buf[len] = '\0';
75 
76  if( buf[len] == '.' )
77  buf[len] = '\0';
78  else
79  ++len;
80  }
81  else
82  {
83  // For these values, %g works fine, and sometimes %f
84  // gives a bad value (try aValue = 1.222222222222, with %.16f format!)
85  len = sprintf( buf, "%.16g", aValue );
86  }
87 
88  return std::string( buf, len );
89 }

◆ DoubleValueFromString()

double numEval::DoubleValueFromString ( EDA_UNITS  aUnits,
const wxString &  aTextValue,
bool  aUseMils = false,
EDA_DATA_TYPE  aType = EDA_DATA_TYPE::DISTANCE 
)

Function DoubleValueFromString converts aTextValue to a double.

Parameters
aUnitsThe units of aTextValue.
aTextValueA reference to a wxString object containing the string to convert.
aUseMilsIndicates mils should be used for imperial units (inches).
Returns
A double representing that value in internal units

◆ EnsureFileDirectoryExists()

bool numEval::EnsureFileDirectoryExists ( wxFileName *  aTargetFullFileName,
const wxString &  aBaseFilename,
REPORTER aReporter = NULL 
)

Make aTargetFullFileName absolute and create the path of this file if it doesn't yet exist.

Parameters
aTargetFullFileNamethe wxFileName containing the full path and file name to modify. The path may be absolute or relative to aBaseFilename .
aBaseFilenamea full filename. Only its path is used to set the aTargetFullFileName path.
aReportera point to a REPORTER object use to show messages (can be NULL)
Returns
true if aOutputDir already exists or was successfully created.

Definition at line 602 of file common.cpp.

605 {
606  wxString msg;
607  wxString baseFilePath = wxFileName( aBaseFilename ).GetPath();
608 
609  // make aTargetFullFileName path, which is relative to aBaseFilename path (if it is not
610  // already an absolute path) absolute:
611  if( !aTargetFullFileName->MakeAbsolute( baseFilePath ) )
612  {
613  if( aReporter )
614  {
615  msg.Printf( _( "Cannot make path \"%s\" absolute with respect to \"%s\"." ),
616  aTargetFullFileName->GetPath(),
617  baseFilePath );
618  aReporter->Report( msg, RPT_SEVERITY_ERROR );
619  }
620 
621  return false;
622  }
623 
624  // Ensure the path of aTargetFullFileName exists, and create it if needed:
625  wxString outputPath( aTargetFullFileName->GetPath() );
626 
627  if( !wxFileName::DirExists( outputPath ) )
628  {
629  if( wxMkdir( outputPath ) )
630  {
631  if( aReporter )
632  {
633  msg.Printf( _( "Output directory \"%s\" created.\n" ), outputPath );
634  aReporter->Report( msg, RPT_SEVERITY_INFO );
635  return true;
636  }
637  }
638  else
639  {
640  if( aReporter )
641  {
642  msg.Printf( _( "Cannot create output directory \"%s\".\n" ), outputPath );
643  aReporter->Report( msg, RPT_SEVERITY_ERROR );
644  }
645 
646  return false;
647  }
648  }
649 
650  return true;
651 }
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
#define _(s)
Definition: 3d_actions.cpp:33

◆ EnsureTextCtrlWidth()

bool numEval::EnsureTextCtrlWidth ( wxTextCtrl *  aCtrl,
const wxString *  aString = NULL 
)

Set the minimum pixel width on a text control in order to make a text string be fully visible within it.

The current font within the text control is considered. The text can come either from the control or be given as an argument. If the text control is larger than needed, then nothing is done.

Parameters
aCtrlthe text control to potentially make wider.
aStringthe text that is used in sizing the control's pixel width. If NULL, then the text already within the control is used.
Returns
bool - true if the aCtrl had its size changed, else false.

Definition at line 283 of file common.cpp.

284 {
285  wxWindow* window = aCtrl->GetParent();
286 
287  if( !window )
288  window = aCtrl;
289 
290  wxString ctrlText;
291 
292  if( !aString )
293  {
294  ctrlText = aCtrl->GetValue();
295  aString = &ctrlText;
296  }
297 
298  wxSize textz = GetTextSize( *aString, window );
299  wxSize ctrlz = aCtrl->GetSize();
300 
301  if( ctrlz.GetWidth() < textz.GetWidth() + 10 )
302  {
303  ctrlz.SetWidth( textz.GetWidth() + 10 );
304  aCtrl->SetSizeHints( ctrlz );
305  return true;
306  }
307 
308  return false;
309 }
wxSize GetTextSize(const wxString &aSingleLine, wxWindow *aWindow)
Return the size of aSingleLine of text when it is rendered in aWindow using whatever font is currentl...
Definition: common.cpp:268

◆ ExpandEnvVarSubstitutions()

const wxString numEval::ExpandEnvVarSubstitutions ( const wxString &  aString,
PROJECT aProject 
)

Replace any environment variable & text variable references with their values.

Parameters
aString= a string containing (perhaps) references to env var
Returns
a string where env var are replaced by their value

Definition at line 574 of file common.cpp.

575 {
576  // wxGetenv( wchar_t* ) is not re-entrant on linux.
577  // Put a lock on multithreaded use of wxGetenv( wchar_t* ), called from wxEpandEnvVars(),
578  static std::mutex getenv_mutex;
579 
580  std::lock_guard<std::mutex> lock( getenv_mutex );
581 
582  // We reserve the right to do this another way, by providing our own member function.
583  return KIwxExpandEnvVars( aString, aProject );
584 }
wxString KIwxExpandEnvVars(const wxString &str, const PROJECT *aProject)
Definition: common.cpp:435

◆ ExpandTextVars()

wxString numEval::ExpandTextVars ( const wxString &  aSource,
const std::function< bool(wxString *)> *  aLocalResolver,
const PROJECT aProject 
)

Expand '${var-name}' templates in text.

The LocalResolver is given first crack at it, after which the PROJECT's resolver is called.

Definition at line 382 of file common.cpp.

385 {
386  wxString newbuf;
387  size_t sourceLen = aSource.length();
388 
389  newbuf.Alloc( sourceLen ); // best guess (improves performance)
390 
391  for( size_t i = 0; i < sourceLen; ++i )
392  {
393  if( aSource[i] == '$' && i + 1 < sourceLen && aSource[i+1] == '{' )
394  {
395  wxString token;
396 
397  for( i = i + 2; i < sourceLen; ++i )
398  {
399  if( aSource[i] == '}' )
400  break;
401  else
402  token.append( aSource[i] );
403  }
404 
405  if( token.IsEmpty() )
406  continue;
407 
408  if( aLocalResolver && (*aLocalResolver)( &token ) )
409  {
410  newbuf.append( token );
411  }
412  else if( aProject && aProject->TextVarResolver( &token ) )
413  {
414  newbuf.append( token );
415  }
416  else
417  {
418  // Token not resolved: leave the reference unchanged
419  newbuf.append( "${" + token + "}" );
420  }
421  }
422  else
423  {
424  newbuf.append( aSource[i] );
425  }
426  }
427 
428  return newbuf;
429 }
VTBL_ENTRY bool TextVarResolver(wxString *aToken) const
Definition: project.cpp:66

◆ FetchUnitsFromString()

void numEval::FetchUnitsFromString ( const wxString &  aTextValue,
EDA_UNITS aUnits,
bool &  aUseMils 
)

Function FetchUnitsFromString writes any unit info found in the string to aUnits and aUseMils.

◆ FormatAngle()

std::string numEval::FormatAngle ( double  aAngle)

Function FormatAngle converts aAngle from board units to a string appropriate for writing to file.

Note
Internal angles for board items can be either degrees or tenths of degree on how KiCad is built.
Parameters
aAngleA angle value to convert.
Returns
A std::string object containing the converted angle.

Definition at line 589 of file base_units.cpp.

590 {
591  char temp[50];
592  int len;
593 
594  len = snprintf( temp, sizeof(temp), "%.10g", aAngle / 10.0 );
595 
596  return std::string( temp, len );
597 }

◆ FormatInternalUnits() [1/4]

std::string numEval::FormatInternalUnits ( int  aValue)

Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing to file.

Note
Internal units for board items can be either deci-mils or nanometers depending on how KiCad is built.
Parameters
aValueA coordinate value to convert.
Returns
A std::string object containing the converted value.

Definition at line 560 of file base_units.cpp.

561 {
562  char buf[50];
563  double engUnits = aValue;
564  int len;
565 
566  engUnits /= IU_PER_MM;
567 
568  if( engUnits != 0.0 && fabs( engUnits ) <= 0.0001 )
569  {
570  len = snprintf( buf, sizeof(buf), "%.10f", engUnits );
571 
572  while( --len > 0 && buf[len] == '0' )
573  buf[len] = '\0';
574 
575  if( buf[len] == '.' )
576  buf[len] = '\0';
577  else
578  ++len;
579  }
580  else
581  {
582  len = snprintf( buf, sizeof(buf), "%.10g", engUnits );
583  }
584 
585  return std::string( buf, len );
586 }

◆ FormatInternalUnits() [2/4]

std::string numEval::FormatInternalUnits ( const wxPoint aPoint)

Definition at line 600 of file base_units.cpp.

601 {
602  return FormatInternalUnits( aPoint.x ) + " " + FormatInternalUnits( aPoint.y );
603 }
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:560

◆ FormatInternalUnits() [3/4]

std::string numEval::FormatInternalUnits ( const wxSize &  aSize)

Definition at line 612 of file base_units.cpp.

613 {
614  return FormatInternalUnits( aSize.GetWidth() ) + " " + FormatInternalUnits( aSize.GetHeight() );
615 }
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:560

◆ FormatInternalUnits() [4/4]

std::string numEval::FormatInternalUnits ( const VECTOR2I aPoint)

Definition at line 606 of file base_units.cpp.

607 {
608  return FormatInternalUnits( aPoint.x ) + " " + FormatInternalUnits( aPoint.y );
609 }
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:560

◆ From_User_Unit()

double numEval::From_User_Unit ( EDA_UNITS  aUnit,
double  aValue,
bool  aUseMils = false 
)

Return in internal units the value "val" given in a real unit such as "in", "mm" or "deg".

◆ FROM_UTF8()

static wxString numEval::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 115 of file numeric_evaluator.cpp.

115  {
116  // Can be printed as a floating point
117  snprintf( m_token.token, m_token.OutLen, "%.10g", val );
118  }
119 }
120 
121 
122 wxString NUMERIC_EVALUATOR::OriginalText() const
123 {
wxString OriginalText() const

◆ GetAbbreviatedUnitsLabel()

wxString numEval::GetAbbreviatedUnitsLabel ( EDA_UNITS  aUnit,
bool  aUseMils = false,
EDA_DATA_TYPE  aType = EDA_DATA_TYPE::DISTANCE 
)

Get the units string for a given units type.

Parameters
aUnits- The units requested.
aUseMils- Use mils for the unit
aType- The data type of the unit (e.g. distance, area, etc.)
Returns
The human readable units string.

◆ GetChars()

static const wxChar* numEval::GetChars ( const wxString &  s)
inlinestatic

Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for passing strings to wxString::Printf() and wxString::Format().

It can also be passed a UTF8 parameter which will be converted to wxString by the compiler.

Example: wxString::Format( wxT( "%s" ), GetChars( UTF( "some text" ) ) );

When wxWidgets is properly built for KiCad, a const wxChar* points to either:

  • 32 bit unicode characters on linux/OSX or
  • 16 bit UTF16 characters on windows.

Note that you cannot pass 8 bit strings to wxString::Format() or Printf() so this is a useful conversion function to wxChar*, which is needed by wxString::Format().

Returns
const wxChar* - a pointer to the UNICODE or UTF16 (on windows) text.

Definition at line 154 of file numeric_evaluator.cpp.

◆ GetTextSize()

wxSize numEval::GetTextSize ( const wxString &  aSingleLine,
wxWindow *  aWindow 
)

Return the size of aSingleLine of text when it is rendered in aWindow using whatever font is currently set in that window.

Definition at line 268 of file common.cpp.

269 {
270  wxCoord width;
271  wxCoord height;
272 
273  {
274  wxClientDC dc( aWindow );
275  dc.SetFont( aWindow->GetFont() );
276  dc.GetTextExtent( aSingleLine, &width, &height );
277  }
278 
279  return wxSize( width, height );
280 }

◆ IsUTF8()

bool numEval::IsUTF8 ( const char *  aString)

Function IsUTF8 tests a c-string to see if it is UTF8 encoded.

BTW an ASCII string is a valid UTF8 string.

Definition at line 185 of file utf8.cpp.

186 {
187  int len = strlen( aString );
188 
189  if( len )
190  {
191  const unsigned char* next = (unsigned char*) aString;
192  const unsigned char* end = next + len;
193 
194  while( next < end )
195  {
196  int charLen = UTF8::uni_forward( next, NULL );
197 
198  if( charLen == 0 )
199  return false;
200 
201  next += charLen;
202  }
203 
204  // uni_forward() should find the exact end if it is truly UTF8
205  if( next > end )
206  return false;
207  }
208 
209  return true;
210 }
CITER next(CITER it)
Definition: ptree.cpp:130
#define NULL
static int uni_forward(const unsigned char *aSequence, unsigned *aResult=NULL)
Function uni_forward advances over a single UTF8 encoded multibyte character, capturing the unicode c...
Definition: utf8.cpp:73

◆ MessageTextFromValue() [1/3]

wxString numEval::MessageTextFromValue ( EDA_UNITS  aUnits,
double  aValue,
bool  aUseMils = false,
EDA_DATA_TYPE  aType = EDA_DATA_TYPE::DISTANCE 
)

Function MessageTextFromValue is a helper to convert the double length aValue to a string in inches, millimeters, or unscaled units.

Should be used only to display a coordinate in status, but not in dialogs, files, etc., because the mantissa of the number displayed has 4 digits max for readability. The actual internal value could need up to 8 digits to be printed.

Use StringFromValue() instead where precision matters.

Parameters
aUnitsThe units to show the value in. The unit string is added to the message text.
aValueThe double value to convert.
aUseMilsConvert inch values to mils if true.
aTypeType of the unit being used (e.g. distance, area, etc.)
Returns
The converted string for display in user interface elements.

◆ MessageTextFromValue() [2/3]

wxString numEval::MessageTextFromValue ( EDA_UNITS  aUnits,
int  aValue,
bool  aUseMils = false,
EDA_DATA_TYPE  aType = EDA_DATA_TYPE::DISTANCE 
)

◆ MessageTextFromValue() [3/3]

wxString numEval::MessageTextFromValue ( EDA_UNITS  aUnits,
long long int  aValue,
bool  aUseMils = false,
EDA_DATA_TYPE  aType = EDA_DATA_TYPE::DISTANCE 
)

◆ Mils2mm()

int numEval::Mils2mm ( double  x)
inline

Convert mils to mm.

Definition at line 65 of file numeric_evaluator.cpp.

67 :m_defaultUnits = Unit::MM;

◆ Mirror()

template<typename T >
T numEval::Mirror ( aPoint,
aMirrorRef 
)

Function MIRROR Mirror aPoint in aMirrorRef.

Definition at line 171 of file numeric_evaluator.cpp.

◆ MIRROR()

template<typename T >
void numEval::MIRROR ( T &  aPoint,
const T &  aMirrorRef 
)

Definition at line 176 of file numeric_evaluator.cpp.

177 {
178  Token retval;
179  size_t idx;

◆ Mm2mils()

int numEval::Mm2mils ( double  x)
inline

Convert mm to mils.

Definition at line 62 of file numeric_evaluator.cpp.

◆ NilUuid()

KIID& numEval::NilUuid ( )

Definition at line 57 of file common.cpp.

58 {
59  static KIID nil( 0 );
60  return nil;
61 }
Definition: common.h:68

◆ operator<<() [1/2]

std::ostream& numEval::operator<< ( std::ostream &  out,
const wxSize &  size 
)

Helper function to print the given wxSize to a stream.

Used for debugging functions like EDA_ITEM::Show and also in unit testing fixtures.

Definition at line 731 of file common.cpp.

732 {
733  out << " width=\"" << size.GetWidth() << "\" height=\"" << size.GetHeight() << "\"";
734  return out;
735 }

◆ operator<<() [2/2]

std::ostream& numEval::operator<< ( std::ostream &  out,
const wxPoint pt 
)

Helper function to print the given wxPoint to a stream.

Used for debugging functions like EDA_ITEM::Show and also in unit testing fixtures.

Definition at line 738 of file common.cpp.

739 {
740  out << " x=\"" << pt.x << "\" y=\"" << pt.y << "\"";
741  return out;
742 }

◆ Parse()

◆ ParseAlloc()

void* numEval::ParseAlloc ( void *(*)(YYMALLOCARGTYPE) ParseCTX_PDECL  mallocProc)

Definition at line 461 of file numeric_evaluator.cpp.

◆ ParseFallback()

int numEval::ParseFallback ( int  iToken)

Definition at line 1288 of file numeric_evaluator.cpp.

◆ ParseFinalize()

void numEval::ParseFinalize ( void *  p)

Definition at line 528 of file numeric_evaluator.cpp.

◆ ParseFree()

void numEval::ParseFree ( void *  p,
void(*)(void *)  freeProc 
)

Definition at line 545 of file numeric_evaluator.cpp.

◆ ParseInit()

void numEval::ParseInit ( void *yypRawParser  ParseCTX_PDECL)

Definition at line 422 of file numeric_evaluator.cpp.

◆ ParseTrace()

void numEval::ParseTrace ( FILE *  TraceFILE,
char *  zTracePrompt 
)

Definition at line 321 of file numeric_evaluator.cpp.

321  {
322  case Unit::Inch :retval.value.dValue = 1.0; break;
323  case Unit::Mil :retval.value.dValue = 1.0 / 1000.0; break;
324  case Unit::MM :retval.value.dValue = 1.0 / 25.4; break;
325  case Unit::CM :retval.value.dValue = 1.0 / 2.54; break;
326  case Unit::Invalid :break;

References NUMERIC_EVALUATOR::CM, NUMERIC_EVALUATOR::Inch, NUMERIC_EVALUATOR::Invalid, NUMERIC_EVALUATOR::Mil, and NUMERIC_EVALUATOR::MM.

◆ PcbIu2Millimeter()

constexpr double numEval::PcbIu2Millimeter ( int  iu)
inline

Definition at line 131 of file numeric_evaluator.cpp.

138  {

◆ PcbMillimeter2iu()

constexpr int numEval::PcbMillimeter2iu ( double  mm)
inline

Definition at line 122 of file numeric_evaluator.cpp.

123 {
124  return m_originalText;
125 }

◆ PcbMils2iu()

constexpr int numEval::PcbMils2iu ( int  mils)
inline

Definition at line 111 of file numeric_evaluator.cpp.

115  {

◆ PrePendPath()

const wxString numEval::PrePendPath ( const wxString &  aEnvVar,
const wxString &  aPriorityPath 
)

Put aPriorityPath in front of all paths in the value of aEnvVar.

Definition at line 32 of file prependpath.cpp.

33 {
34  wxPathList paths;
35 
36  paths.AddEnvList( aEnvVar );
37  paths.Insert( aPriorityPath, 0 );
38 
39  return wxJoin( paths, wxPATH_SEP[0] );
40 }

◆ ProcessExecute()

int numEval::ProcessExecute ( const wxString &  aCommandLine,
int  aFlags = wxEXEC_ASYNC,
wxProcess *  callback = NULL 
)

Run a command in a child process.

Parameters
aCommandLineThe process and any arguments to it all in a single string.
aFlagsThe same args as allowed for wxExecute()
callbackwxProcess implementing OnTerminate to be run when the child process finishes
Returns
int - pid of process, 0 in case of error (like return values of wxExecute())

Definition at line 364 of file common.cpp.

365 {
366  return (int) wxExecute( aCommandLine, aFlags, callback );
367 }

◆ ResolveUriByEnvVars()

const wxString numEval::ResolveUriByEnvVars ( const wxString &  aUri,
PROJECT aProject 
)

Replace any environment and/or text variables in file-path uris (leaving network-path URIs alone).

Definition at line 587 of file common.cpp.

588 {
589  wxString uri = ExpandTextVars( aUri, nullptr, aProject );
590 
591  // URL-like URI: return as is.
592  wxURL url( uri );
593 
594  if( url.GetError() == wxURL_NOERR )
595  return uri;
596 
597  // Otherwise, the path points to a local file. Resolve environment variables if any.
598  return ExpandEnvVarSubstitutions( aUri, aProject );
599 }
const wxString ExpandEnvVarSubstitutions(const wxString &aString, PROJECT *aProject)
Replace any environment variable & text variable references with their values.
Definition: common.cpp:574
wxString ExpandTextVars(const wxString &aSource, const std::function< bool(wxString *)> *aLocalResolver, const PROJECT *aProject)
Expand '${var-name}' templates in text.
Definition: common.cpp:382

◆ SchIu2Millimeter()

constexpr double numEval::SchIu2Millimeter ( int  iu)
inline

Definition at line 135 of file numeric_evaluator.cpp.

138  {

◆ SchMillimeter2iu()

constexpr int numEval::SchMillimeter2iu ( double  mm)
inline

Definition at line 126 of file numeric_evaluator.cpp.

129 {

◆ SchMils2iu()

constexpr int numEval::SchMils2iu ( int  mils)
inline

Definition at line 116 of file numeric_evaluator.cpp.

◆ SearchHelpFileFullPath()

wxString numEval::SearchHelpFileFullPath ( const SEARCH_STACK aSearchStack,
const wxString &  aBaseName 
)

Return the help file's full path.

Return the KiCad help file with path and extension. Help files can be html (.html ext) or pdf (.pdf ext) files. A <BaseName>.html file is searched and if not found, <BaseName>.pdf file is searched in the same path. If the help file for the current locale is not found, an attempt to find the English version of the help file is made. Help file is searched in directories in this order: help/<canonical name> like help/en_GB help/<short name> like help/en help/en

Parameters
aSearchStackcontains some possible base dirs that may be above the the one actually holding aBaseName. These are starting points for nested searches.
aBaseNameis the name of the help file to search for,

without extension

.

Returns
wxEmptyString is returned if aBaseName is not found, else the full path & filename.

Definition at line 67 of file searchhelpfilefullpath.cpp.

68 {
69  wxArrayString subdirs;
70  wxArrayString altsubdirs;
71  SEARCH_STACK ss = aSStack;
72 
73  // It might already be in aSStack, but why depend on other code
74  // far away when it's so easy to add it again (to our copy) as the first place to look.
75 
76  // This is CMAKE_INSTALL_PREFIX unless DEFAULT_INSTALL_PATH was defined during
77  // build configuration:
78  ss.AddPaths( wxT( DEFAULT_INSTALL_PATH ), 0 );
79 
80 #if defined(__WXMAC__)
81  ss.AddPaths( GetOSXKicadMachineDataDir() );
82  ss.AddPaths( Pgm().GetExecutablePath(), 0 );
83 
84  // OS X packages can have the help files in
85  // /Library/Application\ Support/kicad/help,
86  // and in Contents/SharedSupport/help inside the
87  // bundle.
88  // Below we account for an international subdirectory.
89  subdirs.Add( "help" );
90  altsubdirs.Add( "Contents" );
91  altsubdirs.Add( "SharedSupport" );
92  altsubdirs.Add( "help" );
93 #endif
94 
95 #if ! defined(__WXMAC__) // && defined(__linux__)
96  // This is the executable path minus the trailing bin directory used on Windows and Linux.
97  wxFileName tmp( Pgm().GetExecutablePath(), wxEmptyString );
98  wxArrayString binDirs = tmp.GetDirs();
99 
100  if( !binDirs.IsEmpty() && binDirs[ binDirs.GetCount() - 1 ].CmpNoCase( wxT( "bin" ) ) == 0 )
101  tmp.RemoveLastDir();
102 
103  ss.AddPaths( tmp.GetPath(), 0 );
104 
105  // Based on kicad-doc.bzr/CMakeLists.txt, line 20, the help files are
106  // installed into "<CMAKE_INSTALL_PREFIX>/share/doc/kicad/help" for linux.
107  // This is ${KICAD_HELP} var in that CMakeLists.txt file.
108  // Below we account for an international subdirectory.
109  subdirs.Add( "share" );
110  subdirs.Add( "doc" );
111  subdirs.Add( "kicad" );
112  subdirs.Add( "help" );
113 
114  // Based on kicad-doc.bzr/CMakeLists.txt, line 35, the help files are
115  // installed into "<CMAKE_INSTALL_PREFIX>/doc/help" for Windows.
116  // This is ${KICAD_HELP} var in that CMakeLists.txt file.
117  // Below we account for an international subdirectory.
118  altsubdirs.Add( "doc" );
119  altsubdirs.Add( "help" );
120 #endif
121 
122  // If there's a KICAD environment variable set, always use that guy's path first.
123  if( !Pgm().GetKicadEnvVariable().IsEmpty() )
124  ss.AddPaths( Pgm().GetKicadEnvVariable(), 0 );
125 
126  /* Search for a help file.
127  * we *must* find a help file.
128  * so help is searched in directories in this order:
129  * help/<canonical name> like help/en_GB
130  * help/<short name> like help/en
131  * help/en
132  */
133 
134  wxLocale* i18n = Pgm().GetLocale();
135 
136  // We try to find help file in help/<canonical name>
137  // If fails, try to find help file in help/<short canonical name>
138  // If fails, try to find help file in help/en
139  wxArrayString locale_name_dirs;
140  locale_name_dirs.Add( i18n->GetCanonicalName() ); // canonical name like fr_FR
141 
142  // wxLocale::GetName() does not return always the short name
143  locale_name_dirs.Add( i18n->GetName().BeforeLast( '_' ) ); // short canonical name like fr
144  locale_name_dirs.Add( "en" ); // default (en)
145 
146 #if defined(DEBUG) && 1
147  ss.Show( wxString( __func__ ) );
148  wxLogTrace( tracePathsAndFiles, "%s: m_help_file:'%s'", __func__, aBaseName );
149 #endif
150 
151  wxLogTrace( tracePathsAndFiles, "Checking SEARCH_STACK for file %s", aBaseName );
152 
153  // Help files can be html (.html ext) or pdf (.pdf ext) files.
154  // Therefore, <BaseName>.html file is searched and if not found,
155  // <BaseName>.pdf file is searched in the same paths
156  wxString fn;
157 
158  for( unsigned ii = 0; ii < locale_name_dirs.GetCount(); ii++ )
159  {
160  subdirs.Add( locale_name_dirs[ii] );
161  altsubdirs.Add( locale_name_dirs[ii] );
162 
163  fn = FindFileInSearchPaths( ss, aBaseName + wxT( ".html" ), &altsubdirs );
164 
165  if( !fn.IsEmpty() )
166  {
167  // Prepend URI protocol since we will open in a browser
168  fn = wxT( "file://" ) + fn;
169  break;
170  }
171 
172  fn = FindFileInSearchPaths( ss, aBaseName + wxT( ".pdf" ), &altsubdirs );
173 
174  if( !fn.IsEmpty() )
175  break;
176 
177  fn = FindFileInSearchPaths( ss, aBaseName + wxT( ".html" ), &subdirs );
178 
179  if( !fn.IsEmpty() )
180  {
181  // Prepend URI protocol since we will open in a browser
182  fn = wxT( "file://" ) + fn;
183  break;
184  }
185 
186  fn = FindFileInSearchPaths( ss, aBaseName + wxT( ".pdf" ), &subdirs );
187 
188  if( !fn.IsEmpty() )
189  break;
190 
191  subdirs.RemoveAt( subdirs.GetCount() - 1 );
192  altsubdirs.RemoveAt( altsubdirs.GetCount() - 1 );
193  }
194 
195  return fn;
196 }
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:104
const wxChar *const tracePathsAndFiles
Flag to enable path and file name debug output.
SEARCH_STACK looks for files in a number of places.
Definition: search_stack.h:41
wxString FindFileInSearchPaths(const SEARCH_STACK &aStack, const wxString &aFilename, const wxArrayString *aSubdirs)
Function FindFileInSearchPaths looks in "this" for aFilename, but first modifies every search path by...
void AddPaths(const wxString &aPaths, int aIndex=-1)
Function AddPaths insert or append path(s)

Referenced by COMMON_CONTROL::ShowHelp().

◆ SelectReferenceNumber()

void numEval::SelectReferenceNumber ( wxTextEntry *  aTextEntry)

Select the number (or "?") in a reference for ease of editing.

Definition at line 312 of file common.cpp.

313 {
314  wxString ref = aTextEntry->GetValue();
315 
316  if( ref.find_first_of( '?' ) != ref.npos )
317  {
318  aTextEntry->SetSelection( ref.find_first_of( '?' ), ref.find_last_of( '?' ) + 1 );
319  }
320  else
321  {
322  wxString num = ref;
323 
324  while( !num.IsEmpty() && ( !isdigit( num.Last() ) || !isdigit( num.GetChar( 0 ) ) ) )
325  {
326  if( !isdigit( num.Last() ) )
327  num.RemoveLast();
328 
329  if( !isdigit( num.GetChar ( 0 ) ) )
330  num = num.Right( num.Length() - 1);
331  }
332 
333  aTextEntry->SetSelection( ref.Find( num ), ref.Find( num ) + num.Length() );
334 
335  if( num.IsEmpty() )
336  aTextEntry->SetSelection( -1, -1 );
337  }
338 }

◆ StringFromValue()

wxString numEval::StringFromValue ( EDA_UNITS  aUnit,
double  aValue,
bool  aAddUnitSymbol = false,
bool  aUseMils = false,
EDA_DATA_TYPE  aType = EDA_DATA_TYPE::DISTANCE 
)

Function StringFromValue returns the string from aValue according to units (inch, mm ...) for display, and the initial unit for value.

For readability, the mantissa has 3 or more digits (max 8 digits), the trailing 0 are removed if the mantissa has more than 3 digits and some trailing 0 This function should be used to display values in dialogs because a value entered in mm (for instance 2.0 mm) could need up to 8 digits mantissa if displayed in inch to avoid truncation or rounding made just by the printf function. otherwise the actual value is rounded when read from dialog and converted in internal units, and therefore modified.

Parameters
aUnit= display units (INCHES, MILLIMETRE ..)
aValue= value in Internal_Unit
aAddUnitSymbol= true to add symbol unit to the string value
aUseMilsIndicates mils should be used for imperial units (inches).
Returns
A wxString object containing value and optionally the symbol unit (like 2.000 mm)

◆ StripTrailingZeros()

void numEval::StripTrailingZeros ( wxString &  aStringValue,
unsigned  aTrailingZeroAllowed = 1 
)

Function StripTrailingZeros Remove trailing 0 from a string containing a converted float number.

The trailing 0 are removed if the mantissa has more than aTrailingZeroAllowed digits and some trailing 0

Definition at line 201 of file base_units.cpp.

202 {
203  struct lconv * lc = localeconv();
204  char sep = lc->decimal_point[0];
205  unsigned sep_pos = aStringValue.Find( sep );
206 
207  if( sep_pos > 0 )
208  {
209  // We want to keep at least aTrailingZeroAllowed digits after the separator
210  unsigned min_len = sep_pos + aTrailingZeroAllowed + 1;
211 
212  while( aStringValue.Len() > min_len )
213  {
214  if( aStringValue.Last() == '0' )
215  aStringValue.RemoveLast();
216  else
217  break;
218  }
219  }
220 }

◆ StrPrintf() [1/2]

int numEval::StrPrintf ( std::string *  aResult,
const char *  aFormat,
  ... 
)

Function StrPrintf is like sprintf() but the output is appended to a std::string instead of to a character array.

Parameters
aResultis the string to append to, previous text is not clear()ed.
aFormatis a printf() style format string.
Returns
int - the count of bytes appended to the result string, no terminating nul is included.

Definition at line 74 of file richio.cpp.

75 {
76  va_list args;
77 
78  va_start( args, format );
79  int ret = vprint( result, format, args );
80  va_end( args );
81 
82  return ret;
83 }
static int vprint(std::string *result, const char *format, va_list ap)
Definition: richio.cpp:38

Referenced by fmt_mask(), GITHUB_PLUGIN::FootprintDelete(), GITHUB_PLUGIN::FootprintSave(), PCB_IO::format(), FormatProbeItem(), GenCADLayerName(), GenCADLayerNameFlipped(), PCB_PARSER::init(), GENDRILL_WRITER_BASE::layerName(), KICAD_MANAGER_FRAME::OnImportEagleFiles(), PCB_EDIT_FRAME::OpenProjectFiles(), GITHUB_GETLIBLIST::remoteGetJSON(), GITHUB_PLUGIN::remoteGetZip(), ReplaceIllegalFileNameChars(), SCH_EDIT_FRAME::SendCrossProbeNetName(), PCB_EDIT_FRAME::SendCrossProbeNetName(), CVPCB_MAINFRAME::SendMessageToEESCHEMA(), and SCH_EDIT_FRAME::SetCrossProbeConnection().

◆ StrPrintf() [2/2]

std::string numEval::StrPrintf ( const char *  format,
  ... 
)

Function StrPrintf is like sprintf() but the output is returned in a std::string instead of to a character array.

Parameters
formatis a printf() style format string.
Returns
std::string - the result of the sprintf().

Definition at line 86 of file richio.cpp.

87 {
88  std::string ret;
89  va_list args;
90 
91  va_start( args, format );
92  int ignore = vprint( &ret, format, args );
93  (void) ignore;
94  va_end( args );
95 
96  return ret;
97 }
static int vprint(std::string *result, const char *format, va_list ap)
Definition: richio.cpp:38

◆ TimestampDir()

long long numEval::TimestampDir ( const wxString &  aDirPath,
const wxString &  aFilespec 
)

A copy of ConvertFileTimeToWx() because wxWidgets left it as a static function private to src/common/filename.cpp.

TimestampDir

This routine offers SIGNIFICANT performance benefits over using wxWidgets to gather timestamps from matching files in a directory.

Parameters
aDirPaththe directory to search
aFilespeca (wildcarded) file spec to match against
Returns
a hash of the last-mod-dates of all matching files in the directory

Definition at line 966 of file common.cpp.

967 {
968  long long timestamp = 0;
969 
970 #if defined( __WIN32__ )
971  // Win32 version.
972  // Save time by not searching for each path twice: once in wxDir.GetNext() and once in
973  // wxFileName.GetModificationTime(). Also cuts out wxWidgets' string-matching and case
974  // conversion by staying on the MSW side of things.
975  std::wstring filespec( aDirPath.t_str() );
976  filespec += '\\';
977  filespec += aFilespec.t_str();
978 
979  WIN32_FIND_DATA findData;
980  wxDateTime lastModDate;
981 
982  HANDLE fileHandle = ::FindFirstFile( filespec.data(), &findData );
983 
984  if( fileHandle != INVALID_HANDLE_VALUE )
985  {
986  do
987  {
988  ConvertFileTimeToWx( &lastModDate, findData.ftLastWriteTime );
989  timestamp += lastModDate.GetValue().GetValue();
990  }
991  while ( FindNextFile( fileHandle, &findData ) != 0 );
992  }
993 
994  FindClose( fileHandle );
995 #else
996  // POSIX version.
997  // Save time by not converting between encodings -- do everything on the file-system side.
998  std::string filespec( aFilespec.fn_str() );
999  std::string dir_path( aDirPath.fn_str() );
1000 
1001  DIR* dir = opendir( dir_path.c_str() );
1002 
1003  if( dir )
1004  {
1005  for( dirent* dir_entry = readdir( dir ); dir_entry; dir_entry = readdir( dir ) )
1006  {
1007  if( !matchWild( filespec.c_str(), dir_entry->d_name, true ) )
1008  continue;
1009 
1010  std::string entry_path = dir_path + '/' + dir_entry->d_name;
1011  struct stat entry_stat;
1012 
1013  if( wxCRT_Lstat( entry_path.c_str(), &entry_stat ) == 0 )
1014  {
1015  // Timestamp the source file, not the symlink
1016  if( S_ISLNK( entry_stat.st_mode ) ) // wxFILE_EXISTS_SYMLINK
1017  {
1018  char buffer[ PATH_MAX + 1 ];
1019  ssize_t pathLen = readlink( entry_path.c_str(), buffer, PATH_MAX );
1020 
1021  if( pathLen > 0 )
1022  {
1023  struct stat linked_stat;
1024  buffer[ pathLen ] = '\0';
1025  entry_path = dir_path + buffer;
1026 
1027  if( wxCRT_Lstat( entry_path.c_str(), &linked_stat ) == 0 )
1028  {
1029  entry_stat = linked_stat;
1030  }
1031  else
1032  {
1033  // if we couldn't lstat the linked file we'll have to just use
1034  // the symbolic link info
1035  }
1036  }
1037  }
1038 
1039  if( S_ISREG( entry_stat.st_mode ) ) // wxFileExists()
1040  timestamp += entry_stat.st_mtime * 1000;
1041  }
1042  else
1043  {
1044  // if we couldn't lstat the file itself all we can do is use the name
1045  timestamp += (signed) std::hash<std::string>{}( std::string( dir_entry->d_name ) );
1046  }
1047  }
1048 
1049  closedir( dir );
1050  }
1051 #endif
1052 
1053  return timestamp;
1054 }
bool matchWild(const char *pat, const char *text, bool dot_special)
A copy of wxMatchWild(), which wxWidgets attributes to Douglas A.
Definition: common.cpp:824

◆ To_User_Unit()

double numEval::To_User_Unit ( EDA_UNITS  aUnit,
double  aValue,
bool  aUseMils = false 
)

Function To_User_Unit convert aValue in internal units to the appropriate user units defined by aUnit.

Returns
The converted value, in double
Parameters
aUnitThe units to convert aValue to.
aValueThe value in internal units to convert.
aUseMilsIndicates mils should be used for imperial units (inches).

◆ ValueFromString()

long long int numEval::ValueFromString ( EDA_UNITS  aUnits,
const wxString &  aTextValue,
bool  aUseMils = false,
EDA_DATA_TYPE  aType = EDA_DATA_TYPE::DISTANCE 
)

Function ValueFromString converts aTextValue in aUnits to internal units used by the application.

Parameters
aUnitsThe units of aTextValue.
aTextValueA reference to a wxString object containing the string to convert.
aUseMilsIndicates mils should be used for imperial units (inches).
Returns
The string from Value, according to units (inch, mm ...) for display,

◆ wxStringSplit()

void numEval::wxStringSplit ( const wxString &  aText,
wxArrayString &  aStrings,
wxChar  aSplitter 
)

Split aString to a string list separated at aSplitter.

Parameters
aTextis the text to split
aStringswill contain the splitted lines
aSplitteris the 'split' character

Definition at line 341 of file common.cpp.

342 {
343  wxString tmp;
344 
345  for( unsigned ii = 0; ii < aText.Length(); ii++ )
346  {
347  if( aText[ii] == aSplitter )
348  {
349  aStrings.Add( tmp );
350  tmp.Clear();
351  }
352 
353  else
354  tmp << aText[ii];
355  }
356 
357  if( !tmp.IsEmpty() )
358  {
359  aStrings.Add( tmp );
360  }
361 }

◆ yy_accept()

static void numEval::yy_accept ( yyParser yypParser)
static

Definition at line 1069 of file numeric_evaluator.cpp.

◆ yy_destructor()

static void numEval::yy_destructor ( yyParser yypParser,
YYCODETYPE  yymajor,
YYMINORTYPE yypminor 
)
static

Definition at line 480 of file numeric_evaluator.cpp.

◆ yy_find_reduce_action()

static YYACTIONTYPE numEval::yy_find_reduce_action ( YYACTIONTYPE  stateno,
YYCODETYPE  iLookAhead 
)
static

Definition at line 677 of file numeric_evaluator.cpp.

◆ yy_find_shift_action()

static YYACTIONTYPE numEval::yy_find_shift_action ( YYCODETYPE  iLookAhead,
YYACTIONTYPE  stateno 
)
static

Definition at line 608 of file numeric_evaluator.cpp.

◆ yy_parse_failed()

static void numEval::yy_parse_failed ( yyParser yypParser)
static

Definition at line 1025 of file numeric_evaluator.cpp.

◆ yy_pop_parser_stack()

static void numEval::yy_pop_parser_stack ( yyParser pParser)
static

Definition at line 510 of file numeric_evaluator.cpp.

◆ yy_reduce()

static YYACTIONTYPE numEval::yy_reduce ( yyParser yypParser,
unsigned int  yyruleno,
int  yyLookahead,
ParseTOKENTYPE yyLookaheadToken  ParseCTX_PDECL 
)
static

Definition at line 842 of file numeric_evaluator.cpp.

◆ yy_shift()

static void numEval::yy_shift ( yyParser yypParser,
YYACTIONTYPE  yyNewState,
YYCODETYPE  yyMajor,
ParseTOKENTYPE  yyMinor 
)
static

Definition at line 747 of file numeric_evaluator.cpp.

◆ yy_syntax_error()

static void numEval::yy_syntax_error ( yyParser yypParser,
int  yymajor,
ParseTOKENTYPE  yyminor 
)
static

Definition at line 1048 of file numeric_evaluator.cpp.

◆ yyStackOverflow()

static void numEval::yyStackOverflow ( yyParser yypParser)
static

Definition at line 706 of file numeric_evaluator.cpp.

◆ yyTraceShift()

static void numEval::yyTraceShift ( yyParser yypParser,
int  yyNewState,
const char *  zTag 
)
static

Definition at line 727 of file numeric_evaluator.cpp.

Variable Documentation

◆ GERB_IU_PER_MM

constexpr double numEval::GERB_IU_PER_MM = 1e5

some define and functions to convert a value in mils, decimils or mm to the internal unit used in pcbnew, cvpcb or gerbview (nanometer or deci-mil) depending on compile time option

Definition at line 35 of file numeric_evaluator.cpp.

◆ niluuid

KIID numEval::niluuid

◆ PCB_IU_PER_MILS

constexpr double numEval::PCB_IU_PER_MILS = (PCB_IU_PER_MM * 0.0254)

Definition at line 108 of file numeric_evaluator.cpp.

◆ PCB_IU_PER_MM

constexpr double numEval::PCB_IU_PER_MM = 1e6

Definition at line 36 of file numeric_evaluator.cpp.

◆ PL_IU_PER_MM

constexpr double numEval::PL_IU_PER_MM = 1e3

Definition at line 37 of file numeric_evaluator.cpp.

◆ SCH_IU_PER_MILS

constexpr double numEval::SCH_IU_PER_MILS = (SCH_IU_PER_MM * 0.0254)

Definition at line 109 of file numeric_evaluator.cpp.

◆ SCH_IU_PER_MM

constexpr double numEval::SCH_IU_PER_MM = 1e4

Definition at line 38 of file numeric_evaluator.cpp.

◆ yy_action

const YYACTIONTYPE numEval::yy_action[]
static
Initial value:
= {
61, 17, 63, 10, 4, 5, 11, 12, 13, 44,
30, 2, 14, 29, 9, 8, 31, 6, 7, 28,
17, 59, 17, 4, 5, 4, 5, 58, 44, 30,
2, 30, 2, 9, 8, 31, 6, 7, 31, 6,
7, 40, 9, 8, 31, 6, 7, 46, 1, 1,
10, 15, 16, 3,
}

Definition at line 194 of file numeric_evaluator.cpp.

◆ yy_default

const YYACTIONTYPE numEval::yy_default[]
static
Initial value:
= {
45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
45, 45, 55, 53, 52, 57, 56, 54,
}

Definition at line 224 of file numeric_evaluator.cpp.

◆ yy_lookahead

const YYCODETYPE numEval::yy_lookahead[]
static
Initial value:
= {
0, 1, 15, 16, 4, 5, 16, 16, 16, 9,
10, 11, 16, 3, 4, 5, 6, 7, 8, 9,
1, 16, 1, 4, 5, 4, 5, 16, 9, 10,
11, 10, 11, 4, 5, 6, 7, 8, 6, 7,
8, 12, 4, 5, 6, 7, 8, 13, 14, 15,
16, 16, 16, 2, 17, 17, 17, 17, 17, 17,
17, 17, 17, 17, 17, 17, 17,
}

Definition at line 202 of file numeric_evaluator.cpp.

◆ yy_reduce_ofst

const signed char numEval::yy_reduce_ofst[]
static
Initial value:
= {
34, -13, -10, -9, -8, -4, 5, 11, 35, 36,
}

Definition at line 221 of file numeric_evaluator.cpp.

◆ yy_shift_ofst

const unsigned char numEval::yy_shift_ofst[]
static
Initial value:
= {
19, 0, 21, 21, 21, 21, 21, 21, 21, 21,
10, 29, 38, 32, 32, 32, 32, 51,
}

Definition at line 214 of file numeric_evaluator.cpp.

◆ yyRuleInfoLhs

const YYCODETYPE numEval::yyRuleInfoLhs[]
static
Initial value:
= {
15,
15,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
13,
14,
14,
15,
}

Definition at line 788 of file numeric_evaluator.cpp.

◆ yyRuleInfoNRhs

const signed char numEval::yyRuleInfoNRhs[]
static
Initial value:
= {
-2,
-2,
-1,
-2,
-2,
-2,
-1,
-3,
-3,
-3,
-3,
-3,
-3,
-1,
-1,
-2,
-1,
}

Definition at line 810 of file numeric_evaluator.cpp.

◆ yyRuleName

const char* const numEval::yyRuleName[]
static
Initial value:
= {
"stmt ::= expr ENDS",
"stmt ::= expr SEMCOL",
"expr ::= VALUE",
"expr ::= expr UNIT",
"expr ::= MINUS expr",
"expr ::= PLUS expr",
"expr ::= VAR",
"expr ::= VAR ASSIGN expr",
"expr ::= expr PLUS expr",
"expr ::= expr MINUS expr",
"expr ::= expr MULT expr",
"expr ::= expr DIVIDE expr",
"expr ::= PARENL expr PARENR",
"main ::= in",
"in ::= stmt",
"in ::= in stmt",
"stmt ::= ENDS",
}

Definition at line 356 of file numeric_evaluator.cpp.

◆ yyTokenName

const char* const numEval::yyTokenName[]
static
Initial value:
= {
"$",
"VAR",
"ASSIGN",
"SEMCOL",
"PLUS",
"MINUS",
"UNIT",
"DIVIDE",
"MULT",
"ENDS",
"VALUE",
"PARENL",
"PARENR",
"main",
"in",
"stmt",
"expr",
}

Definition at line 332 of file numeric_evaluator.cpp.

◆ yyTraceFILE

FILE* numEval::yyTraceFILE = 0
static

Definition at line 299 of file numeric_evaluator.cpp.

◆ yyTracePrompt

char* numEval::yyTracePrompt = 0
static

Definition at line 300 of file numeric_evaluator.cpp.