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
 Class FILE_LINE_READER is a LINE_READER that reads from an open file. More...
 
class  FILE_OUTPUTFORMATTER
 Class 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
 Class 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
 class 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  LINE_READER
 Class 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
 Class 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
 Class STREAM_OUTPUTFORMATTER implements OUTPUTFORMATTER to a wxWidgets wxOutputStream. More...
 
class  STRING_FORMATTER
 Class STRING_FORMATTER implements OUTPUTFORMATTER to a memory buffer. More...
 
class  STRING_LINE_READER
 Class STRING_LINE_READER is a LINE_READER that reads from a multiline 8 bit wide std::string. More...
 
struct  StructColors
 
struct  TokenType
 
class  UTF8
 Class 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...
 
union  YYMINORTYPE
 
struct  yyParser
 
struct  yyStackEntry
 

Typedefs

typedef long 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 uint32_t EDA_KEY
 
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
}
 The color enumeration. More...
 
enum  pseudokeys {
  EDA_PANNING_UP_KEY = 1, EDA_PANNING_DOWN_KEY, EDA_PANNING_LEFT_KEY, EDA_PANNING_RIGHT_KEY,
  EDA_ZOOM_IN_FROM_MOUSE, EDA_ZOOM_OUT_FROM_MOUSE, EDA_ZOOM_CENTER_FROM_MOUSE
}
 Pseudo key codes for command panning. More...
 
enum  EDA_UNITS_T { INCHES = 0, MILLIMETRES = 1, UNSCALED_UNITS = 2, DEGREES = 3 }
 

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...
 
EDA_COLOR_T ColorFromInt (int aColor)
 Checked cast. Use only when necessary (usually I/O) More...
 
EDA_COLOR_T NextColor (EDA_COLOR_T &aColor)
 
EDA_COLOR_T ColorGetBase (EDA_COLOR_T aColor)
 Return only the plain color part. More...
 
EDA_COLOR_T ColorMix (EDA_COLOR_T aColor1, EDA_COLOR_T aColor2)
 Mix two colors in some way (hopefully like a logical OR) More...
 
void ColorTurnToDarkDarkGray (EDA_COLOR_T *aColor)
 Force the color part of a color to darkdarkgray. More...
 
void ColorChangeHighlightFlag (EDA_COLOR_T *aColor, bool flag)
 
void SetAlpha (EDA_COLOR_T *aColor, unsigned char aBlend)
 Function SetAlpha ORs in the alpha blend parameter in to a color index. More...
 
unsigned char GetAlpha (EDA_COLOR_T aColor)
 Function GetAlpha returns the alpha blend parameter from a color index. More...
 
void ColorApplyHighlightFlag (EDA_COLOR_T *aColor)
 Step a color to the highlighted version if the highlight flag is set. More...
 
EDA_COLOR_T ColorByName (const wxString &aName)
 Find a color by name. More...
 
EDA_COLOR_T ColorFindNearest (const wxColour &aColor)
 Find the nearest color match. More...
 
EDA_COLOR_T ColorFindNearest (int aR, int aG, int aB)
 Find the nearest color match. More...
 
bool ColorIsLight (EDA_COLOR_T aColor)
 Check if a color is light i.e. More...
 
const wxChar * ColorGetName (EDA_COLOR_T aColor)
 
void ColorSetBrush (wxBrush *aBrush, EDA_COLOR_T aColor)
 
wxColour MakeColour (EDA_COLOR_T aColor)
 Function MakeColour returns a wxWidgets wxColor from a KiCad color index with alpha value. More...
 
static int KiROUND (double v)
 Round a floating point number to an integer using "round halfway cases away from zero". More...
 
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...
 
int ProcessExecute (const wxString &aCommandLine, int aFlags=wxEXEC_ASYNC, wxProcess *callback=NULL)
 Run a command in a child process. More...
 
timestamp_t GetNewTimeStamp ()
 
int GetCommandOptions (const int argc, const char **argv, const char *stringtst, const char **optarg, int *optind)
 
double RoundTo0 (double x, double precision)
 Round to the nearest precision. 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...
 
wxConfigBase * GetNewConfig (const wxString &aProgName)
 Create a new wxConfig so we can put configuration files in a more proper place for each platform. More...
 
wxString GetKicadConfigPath ()
 Return the user configuration path used to store KiCad's configuration files. More...
 
const wxString ExpandEnvVarSubstitutions (const wxString &aString)
 Replace any environment variable references with their values. More...
 
const wxString ResolveUriByEnvVars (const wxString &aUri)
 Replace any environment variables in file-path uris (leaving network-path URIs alone). More...
 
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_T 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_T aUnits, double aValue, bool aUseMils=false)
 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_T aUnits, int aValue, bool aUseMils=false)
 
wxString StringFromValue (EDA_UNITS_T aUnit, int aValue, bool aAddUnitSymbol=false, bool aUseMils=false)
 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_T 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_T aUnits, const wxString &aTextValue, bool aUseMils=false)
 Function DoubleValueFromString converts aTextValue to a double. More...
 
int ValueFromString (EDA_UNITS_T aUnits, const wxString &aTextValue, bool aUseMils=false)
 Function ValueFromString converts aTextValue in aUnits to internal units used by the application. More...
 
wxString GetUnitsLabel (EDA_UNITS_T aUnits, bool aUseMils=false)
 Get a human readable units string. More...
 
wxString GetAbbreviatedUnitsLabel (EDA_UNITS_T aUnit, bool aUseMils=false)
 
void ParseTrace (FILE *TraceFILE, char *zTracePrompt)
 
void * ParseAlloc (void *(*mallocProc)(YYMALLOCARGTYPE))
 
static void yy_destructor (yyParser *yypParser, YYCODETYPE yymajor, YYMINORTYPE *yypminor)
 
static void yy_pop_parser_stack (yyParser *pParser)
 
void ParseFree (void *p, void(*freeProc)(void *))
 
static int yy_find_shift_action (yyParser *pParser, YYCODETYPE iLookAhead)
 
static int yy_find_reduce_action (int stateno, YYCODETYPE iLookAhead)
 
static void yyStackOverflow (yyParser *yypParser, YYMINORTYPE *yypMinor)
 
static void yyTraceShift (yyParser *yypParser, int yyNewState)
 
static void yy_shift (yyParser *yypParser, int yyNewState, int yyMajor, YYMINORTYPE *yypMinor)
 
static void yy_accept (yyParser *)
 
static void yy_reduce (yyParser *yypParser, int yyruleno)
 
static void yy_parse_failed (yyParser *yypParser)
 
static void yy_syntax_error (yyParser *yypParser, int yymajor, YYMINORTYPE yyminor)
 
void Parse (void *yyp, int yymajor, ParseTOKENTYPE yyminorParseARG_PDECL)
 

Variables

const StructColors g_ColorRefs [NBCOLORS]
 list of existing Colors More...
 
KIGFX::COLOR4D g_GhostColor
 Draw color for moving objects. More...
 
static const YYMINORTYPE yyzerominor = { 0 }
 
static const YYACTIONTYPE yy_action []
 
static const YYCODETYPE yy_lookahead []
 
static const signed 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 []
 
struct {
   YYCODETYPE   numEval::lhs
 
   unsigned char   numEval::nrhs
 
yyRuleInfo []
 

Typedef Documentation

typedef uint32_t numEval::EDA_KEY

Definition at line 72 of file numeric_evaluator.cpp.

typedef long 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()) ?

The type should be at least 32 bit and simple to map via swig; swig does have issues with types such as 'int32_t', so we choose 'long'.

Definition at line 51 of file numeric_evaluator.cpp.

typedef struct yyParser numEval::yyParser

Definition at line 284 of file numeric_evaluator.cpp.

Definition at line 266 of file numeric_evaluator.cpp.

Enumeration Type Documentation

The 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 g_ColorRefs[]

Definition at line 43 of file numeric_evaluator.cpp.

60 {
61  struct lconv* lc = localeconv();
62  m_localeDecimalSeparator = *lc->decimal_point;
63 
64  m_parseError = false;
65  m_parseFinished = false;
66 
67  m_parser = numEval::ParseAlloc( malloc );
68 
69  switch( aUnits )
70  {
71  case INCHES:
72  if( aUseMils )
73  m_defaultUnits = Unit::Mil;
74  else
75  m_defaultUnits = Unit::Inch;
76  break;
77  case MILLIMETRES:m_defaultUnits = Unit::Metric;
78  break;
79  default:m_defaultUnits = Unit::Metric;
Definition: common.h:159
void * ParseAlloc(void *(*mallocProc)(YYMALLOCARGTYPE))
Enumerator
INCHES 
MILLIMETRES 
UNSCALED_UNITS 
DEGREES 

Definition at line 158 of file numeric_evaluator.cpp.

159 {
160  Clear();
161  auto len = aString.length();
162  m_token.token = reinterpret_cast<decltype( m_token.token )>( malloc( TokenStat::OutLen + 1 ));
163  strcpy( m_token.token, "0" );

Pseudo key codes for command panning.

Enumerator
EDA_PANNING_UP_KEY 
EDA_PANNING_DOWN_KEY 
EDA_PANNING_LEFT_KEY 
EDA_PANNING_RIGHT_KEY 
EDA_ZOOM_IN_FROM_MOUSE 
EDA_ZOOM_OUT_FROM_MOUSE 
EDA_ZOOM_CENTER_FROM_MOUSE 

Definition at line 90 of file numeric_evaluator.cpp.

97 {
98  free( m_token.token );

Function Documentation

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 382 of file base_units.cpp.

383 {
384  wxString text;
385 
386  text.Printf( wxT( "%.3f" ), aAngle/10.0 );
387  StripTrailingZeros( text, 1 );
388 
389  return text;
390 }
void StripTrailingZeros(wxString &aStringValue, unsigned aTrailingZeroAllowed)
Function StripTrailingZeros Remove trailing 0 from a string containing a converted float number...
Definition: base_units.cpp:178
void numEval::ColorApplyHighlightFlag ( EDA_COLOR_T aColor)
inline

Step a color to the highlighted version if the highlight flag is set.

Definition at line 158 of file numeric_evaluator.cpp.

159 {
160  Clear();
161  auto len = aString.length();
162  m_token.token = reinterpret_cast<decltype( m_token.token )>( malloc( TokenStat::OutLen + 1 ));
163  strcpy( m_token.token, "0" );
164  m_token.inputLen = len;
EDA_COLOR_T numEval::ColorByName ( const wxString &  aName)

Find a color by name.

Definition at line 72 of file colors.cpp.

73 {
74  // look for a match in the palette itself
75  for( EDA_COLOR_T trying = BLACK; trying < NBCOLORS; trying = NextColor(trying) )
76  {
77  if( 0 == aName.CmpNoCase( ColorGetName( trying ) ) )
78  return trying;
79  }
80 
81  // Not found, no idea...
82  return UNSPECIFIED_COLOR;
83 }
EDA_COLOR_T
NOTE: EDA_COLOR_T is deprecated and is kept around for compatibility with legacy canvas.
Definition: colors.h:42
const wxChar * ColorGetName(EDA_COLOR_T aColor)
Definition: colors.h:185
Definition: colors.h:45
Number of colors.
Definition: colors.h:75
EDA_COLOR_T NextColor(EDA_COLOR_T &aColor)
Definition: colors.h:87
void numEval::ColorChangeHighlightFlag ( EDA_COLOR_T aColor,
bool  flag 
)
inline

Definition at line 112 of file numeric_evaluator.cpp.

113 {
114  m_parseFinished = true;
115 }
116 
117 
118 void NUMERIC_EVALUATOR::parseSetResult( double val )
void parseSetResult(double)
EDA_COLOR_T numEval::ColorFindNearest ( const wxColour &  aColor)

Find the nearest color match.

Definition at line 96 of file colors.cpp.

97 {
98  return ColorFindNearest( aColor.Red(), aColor.Green(), aColor.Blue() );
99 }
EDA_COLOR_T ColorFindNearest(const wxColour &aColor)
Find the nearest color match.
Definition: colors.cpp:96
EDA_COLOR_T numEval::ColorFindNearest ( int  aR,
int  aG,
int  aB 
)

Find the nearest color match.

Parameters
aRis the red component of the color to be matched (in range 0-255)
aGis the green component of the color to be matched (in range 0-255)
aBis the blue component of the color to be matched (in range 0-255)

Definition at line 102 of file colors.cpp.

103 {
104  EDA_COLOR_T candidate = BLACK;
105 
106  /* Find the 'nearest' color in the palette. This is fun. There is
107  a gazilion of metrics for the color space and no one of the
108  useful one is in the RGB color space. Who cares, this is a CAD,
109  not a photosomething...
110 
111  I hereby declare that the distance is the sum of the square of the
112  component difference. Think about the RGB color cube. Now get the
113  euclidean distance, but without the square root... for ordering
114  purposes it's the same, obviously. Also each component can't be
115  less of the target one, since I found this currently work better...
116  */
117  int nearest_distance = 255 * 255 * 3 + 1; // Can't beat this
118 
119  for( EDA_COLOR_T trying = BLACK; trying < NBCOLORS; trying = NextColor(trying) )
120  {
121  const StructColors &c = g_ColorRefs[trying];
122  int distance = (aR - c.m_Red) * (aR - c.m_Red) +
123  (aG - c.m_Green) * (aG - c.m_Green) +
124  (aB - c.m_Blue) * (aB - c.m_Blue);
125 
126  if( distance < nearest_distance && c.m_Red >= aR &&
127  c.m_Green >= aG && c.m_Blue >= aB )
128  {
129  nearest_distance = distance;
130  candidate = trying;
131  }
132  }
133 
134  return candidate;
135 }
EDA_COLOR_T
NOTE: EDA_COLOR_T is deprecated and is kept around for compatibility with legacy canvas.
Definition: colors.h:42
unsigned char m_Red
Definition: colors.h:146
unsigned char m_Green
Definition: colors.h:145
unsigned char m_Blue
Definition: colors.h:144
const StructColors g_ColorRefs[NBCOLORS]
The predefined colors used in KiCad.
Definition: colors.cpp:37
Definition: colors.h:45
Number of colors.
Definition: colors.h:75
EDA_COLOR_T NextColor(EDA_COLOR_T &aColor)
Definition: colors.h:87
EDA_COLOR_T numEval::ColorFromInt ( int  aColor)
inline

Checked cast. Use only when necessary (usually I/O)

Definition at line 82 of file numeric_evaluator.cpp.

86 {
EDA_COLOR_T numEval::ColorGetBase ( EDA_COLOR_T  aColor)
inline

Return only the plain color part.

Definition at line 97 of file numeric_evaluator.cpp.

97 {
98  free( m_token.token );
99  m_token.token = nullptr;
100  m_token.input = nullptr;
101  m_parseError = true;
const wxChar* numEval::ColorGetName ( EDA_COLOR_T  aColor)
inline

Definition at line 186 of file numeric_evaluator.cpp.

188  {
189  return ( ch == m_localeDecimalSeparator || ch == '.' || ch == ',' );
190  };
191 
bool numEval::ColorIsLight ( EDA_COLOR_T  aColor)

Check if a color is light i.e.

if black would be more readable than white on it

EDA_COLOR_T numEval::ColorMix ( EDA_COLOR_T  aColor1,
EDA_COLOR_T  aColor2 
)

Mix two colors in some way (hopefully like a logical OR)

void numEval::ColorSetBrush ( wxBrush *  aBrush,
EDA_COLOR_T  aColor 
)
inline

Definition at line 193 of file numeric_evaluator.cpp.

193  {
194  bool haveSeparator = false;
195  idx = 0;
196  auto ch = m_token.input[ m_token.pos ];
197 
198  do
199  {
void numEval::ColorTurnToDarkDarkGray ( EDA_COLOR_T aColor)
inline

Force the color part of a color to darkdarkgray.

Definition at line 107 of file numeric_evaluator.cpp.

107 {
108  m_parseError = true;
109 }
110 
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 63 of file base_units.cpp.

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

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
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 281 of file common.cpp.

284 {
285  wxString msg;
286  wxString baseFilePath = wxFileName( aBaseFilename ).GetPath();
287 
288  // make aTargetFullFileName path, which is relative to aBaseFilename path (if it is not
289  // already an absolute path) absolute:
290  if( !aTargetFullFileName->MakeAbsolute( baseFilePath ) )
291  {
292  if( aReporter )
293  {
294  msg.Printf( _( "Cannot make path \"%s\" absolute with respect to \"%s\"." ),
295  GetChars( aTargetFullFileName->GetPath() ),
296  GetChars( baseFilePath ) );
297  aReporter->Report( msg, REPORTER::RPT_ERROR );
298  }
299 
300  return false;
301  }
302 
303  // Ensure the path of aTargetFullFileName exists, and create it if needed:
304  wxString outputPath( aTargetFullFileName->GetPath() );
305 
306  if( !wxFileName::DirExists( outputPath ) )
307  {
308  if( wxMkdir( outputPath ) )
309  {
310  if( aReporter )
311  {
312  msg.Printf( _( "Output directory \"%s\" created.\n" ), GetChars( outputPath ) );
313  aReporter->Report( msg, REPORTER::RPT_INFO );
314  return true;
315  }
316  }
317  else
318  {
319  if( aReporter )
320  {
321  msg.Printf( _( "Cannot create output directory \"%s\".\n" ),
322  GetChars( outputPath ) );
323  aReporter->Report( msg, REPORTER::RPT_ERROR );
324  }
325 
326  return false;
327  }
328  }
329 
330  return true;
331 }
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
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 101 of file common.cpp.

102 {
103  wxWindow* window = aCtrl->GetParent();
104 
105  if( !window )
106  window = aCtrl;
107 
108  wxString ctrlText;
109 
110  if( !aString )
111  {
112  ctrlText = aCtrl->GetValue();
113  aString = &ctrlText;
114  }
115 
116  wxSize textz = GetTextSize( *aString, window );
117  wxSize ctrlz = aCtrl->GetSize();
118 
119  if( ctrlz.GetWidth() < textz.GetWidth() + 10 )
120  {
121  ctrlz.SetWidth( textz.GetWidth() + 10 );
122  aCtrl->SetSizeHints( ctrlz );
123  return true;
124  }
125 
126  return false;
127 }
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:86
const wxString numEval::ExpandEnvVarSubstitutions ( const wxString &  aString)

Replace any environment 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 254 of file common.cpp.

255 {
256  // wxGetenv( wchar_t* ) is not re-entrant on linux.
257  // Put a lock on multithreaded use of wxGetenv( wchar_t* ), called from wxEpandEnvVars(),
258  static MUTEX getenv_mutex;
259 
260  MUTLOCK lock( getenv_mutex );
261 
262  // We reserve the right to do this another way, by providing our own member
263  // function.
264  return wxExpandEnvVars( aString );
265 }
boost::interprocess::interprocess_mutex MUTEX
Establish KiCad MUTEX choices here in this file: typedef MUTEX and typedef MUTLOCK.
Definition: ki_mutex.h:42
boost::interprocess::scoped_lock< MUTEX > MUTLOCK
Definition: ki_mutex.h:43
double numEval::From_User_Unit ( EDA_UNITS_T  aUnit,
double  aValue,
bool  aUseMils = false 
)

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

wxString numEval::GetAbbreviatedUnitsLabel ( EDA_UNITS_T  aUnit,
bool  aUseMils = false 
)
unsigned char numEval::GetAlpha ( EDA_COLOR_T  aColor)
inline

Function GetAlpha returns the alpha blend parameter from a color index.

Definition at line 136 of file numeric_evaluator.cpp.

142  {
int numEval::GetCommandOptions ( const int  argc,
const char **  argv,
const char *  stringtst,
const char **  optarg,
int *  optind 
)
wxString numEval::GetKicadConfigPath ( )

Return the user configuration path used to store KiCad's configuration files.

The configuration path order of precedence is determined by the following criteria:

  • The value of the KICAD_CONFIG_HOME environment variable
  • The value of the XDG_CONFIG_HOME environment variable.
  • The result of the call to wxStandardPaths::GetUserConfigDir() with ".config" appended as required on Linux builds.
Returns
A wxString containing the config path for Kicad

Definition at line 210 of file common.cpp.

211 {
212  wxFileName cfgpath;
213 
214  // http://docs.wxwidgets.org/3.0/classwx_standard_paths.html#a7c7cf595d94d29147360d031647476b0
215  cfgpath.AssignDir( wxStandardPaths::Get().GetUserConfigDir() );
216 
217  // GetUserConfigDir() does not default to ~/.config which is the current standard
218  // configuration file location on Linux. This has been fixed in later versions of wxWidgets.
219 #if !defined( __WXMSW__ ) && !defined( __WXMAC__ )
220  wxArrayString dirs = cfgpath.GetDirs();
221 
222  if( dirs.Last() != ".config" )
223  cfgpath.AppendDir( ".config" );
224 #endif
225 
226  wxString envstr;
227 
228  // This shouldn't cause any issues on Windows or MacOS.
229  if( wxGetEnv( wxT( "XDG_CONFIG_HOME" ), &envstr ) && !envstr.IsEmpty() )
230  {
231  // Override the assignment above with XDG_CONFIG_HOME
232  cfgpath.AssignDir( envstr );
233  }
234 
235  cfgpath.AppendDir( wxT( "kicad" ) );
236 
237  // Use KICAD_CONFIG_HOME to allow the user to force a specific configuration path.
238  if( wxGetEnv( wxT( "KICAD_CONFIG_HOME" ), &envstr ) && !envstr.IsEmpty() )
239  {
240  // Override the assignment above with KICAD_CONFIG_HOME
241  cfgpath.AssignDir( envstr );
242  }
243 
244  if( !cfgpath.DirExists() )
245  {
246  cfgpath.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
247  }
248 
249  return cfgpath.GetPath();
250 }
wxConfigBase* numEval::GetNewConfig ( const wxString &  aProgName)

Create a new wxConfig so we can put configuration files in a more proper place for each platform.

This is generally $HOME/.config/kicad/ in Linux according to the FreeDesktop specification at http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html The config object created here should be destroyed by the caller.

Parameters
aProgNameis the name of the program calling this function - can be obtained by calling Pgm().App().GetAppName(). This will be the actual file name of the config file.
Returns
A pointer to a new wxConfigBase derived object is returned. The caller is in charge of deleting it.

Definition at line 198 of file common.cpp.

199 {
200  wxConfigBase* cfg = 0;
201  wxFileName configname;
202  configname.AssignDir( GetKicadConfigPath() );
203  configname.SetFullName( aProgName );
204 
205  cfg = new wxFileConfig( wxT( "" ), wxT( "" ), configname.GetFullPath() );
206  return cfg;
207 }
wxString GetKicadConfigPath()
Return the user configuration path used to store KiCad&#39;s configuration files.
Definition: common.cpp:210
timestamp_t numEval::GetNewTimeStamp ( )
Returns
an unique time stamp that changes after each call

Definition at line 159 of file common.cpp.

160 {
161  static timestamp_t oldTimeStamp;
162  timestamp_t newTimeStamp;
163 
164  newTimeStamp = time( NULL );
165 
166  if( newTimeStamp <= oldTimeStamp )
167  newTimeStamp = oldTimeStamp + 1;
168 
169  oldTimeStamp = newTimeStamp;
170 
171  return newTimeStamp;
172 }
long timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...
Definition: common.h:51
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 86 of file common.cpp.

87 {
88  wxCoord width;
89  wxCoord height;
90 
91  {
92  wxClientDC dc( aWindow );
93  dc.SetFont( aWindow->GetFont() );
94  dc.GetTextExtent( aSingleLine, &width, &height );
95  }
96 
97  return wxSize( width, height );
98 }
wxString numEval::GetUnitsLabel ( EDA_UNITS_T  aUnits,
bool  aUseMils = false 
)

Get a human readable units string.

The strings returned are full text name and not abbreviations or symbolic representations of the units. Use ReturnUnitSymbol() for that.

Parameters
aUnits- The units requested.
Returns
The human readable units string.
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 170 of file utf8.cpp.

171 {
172  int len = strlen( aString );
173 
174  if( len )
175  {
176  const unsigned char* next = (unsigned char*) aString;
177  const unsigned char* end = next + len;
178 
179  try
180  {
181  while( next < end )
182  {
183  next += UTF8::uni_forward( next, NULL );
184  }
185 
186  // uni_forward() should find the exact end if it is truly UTF8
187  if( next > end )
188  return false;
189  }
190  catch( const IO_ERROR& )
191  {
192  return false;
193  }
194  }
195 
196  return true;
197 }
CITER next(CITER it)
Definition: ptree.cpp:130
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:70
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76
static int numEval::KiROUND ( double  v)
inlinestatic

Round a floating point number to an integer using "round halfway cases away from zero".

In Debug build an assert fires if will not fit into an int.KiROUND: a function so v is not evaluated twice. Unfortunately, compiler is unable to pre-compute constants using this.

Definition at line 119 of file numeric_evaluator.cpp.

119 {
120  snprintf( m_token.token, m_token.OutLen, "%.10g", val );
121 }
122 
wxColour numEval::MakeColour ( EDA_COLOR_T  aColor)
inline

Function MakeColour returns a wxWidgets wxColor from a KiCad color index with alpha value.

Note that alpha support is not available on every wxWidgets platform. On such platform the behavior is the same as for wxALPHA_OPAQUE and that means the alpha value has no effect and will be ignored.

Returns
wxColour - given a KiCad color index with alpha value

Definition at line 209 of file numeric_evaluator.cpp.

221  {
wxString numEval::MessageTextFromValue ( EDA_UNITS_T  aUnits,
double  aValue,
bool  aUseMils = false 
)

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.
Returns
The converted string for display in user interface elements.
wxString numEval::MessageTextFromValue ( EDA_UNITS_T  aUnits,
int  aValue,
bool  aUseMils = false 
)
int numEval::Mils2mm ( double  x)
inline

Convert mils to mm.

Definition at line 52 of file numeric_evaluator.cpp.

int numEval::Mm2mils ( double  x)
inline

Convert mm to mils.

Definition at line 49 of file numeric_evaluator.cpp.

EDA_COLOR_T numEval::NextColor ( EDA_COLOR_T aColor)
inline

Definition at line 88 of file numeric_evaluator.cpp.

void numEval::Parse ( void *  yyp,
int  yymajor,
ParseTOKENTYPE yyminor  ParseARG_PDECL 
)
void* numEval::ParseAlloc ( void *(*)(YYMALLOCARGTYPE mallocProc)

Definition at line 398 of file numeric_evaluator.cpp.

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

Definition at line 473 of file numeric_evaluator.cpp.

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

Definition at line 310 of file numeric_evaluator.cpp.

310  :retval.value.dValue = 1.0; break;
311  case Unit::Mil :retval.value.dValue = 1.0 / 1000.0; break;
312  case Unit::Metric :retval.value.dValue = 1.0 / 25.4; break;
313  case Unit::Invalid :break;
314  }
315  }
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 }
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 153 of file common.cpp.

154 {
155  return wxExecute( aCommandLine, aFlags, callback );
156 }
const wxString numEval::ResolveUriByEnvVars ( const wxString &  aUri)

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

Definition at line 268 of file common.cpp.

269 {
270  // URL-like URI: return as is.
271  wxURL url( aUri );
272  if( url.GetError() == wxURL_NOERR )
273  return aUri;
274 
275  // Otherwise, the path points to a local file. Resolve environment
276  // variables if any.
277  return ExpandEnvVarSubstitutions( aUri );
278 }
const wxString ExpandEnvVarSubstitutions(const wxString &aString)
Replace any environment variable references with their values.
Definition: common.cpp:254
double numEval::RoundTo0 ( double  x,
double  precision 
)

Round to the nearest precision.

Try to approximate a coordinate using a given precision to prevent rounding errors when converting from inches to mm.

ie round the unit value to 0 if unit is 1 or 2, or 8 or 9

Definition at line 175 of file common.cpp.

176 {
177  assert( precision != 0 );
178 
179  long long ix = KiROUND( x * precision );
180 
181  if ( x < 0.0 )
182  ix = -ix;
183 
184  int remainder = ix % 10; // remainder is in precision mm
185 
186  if( remainder <= 2 )
187  ix -= remainder; // truncate to the near number
188  else if( remainder >= 8 )
189  ix += 10 - remainder; // round to near number
190 
191  if ( x < 0 )
192  ix = -ix;
193 
194  return (double) ix / precision;
195 }
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:119
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 66 of file searchhelpfilefullpath.cpp.

Referenced by EDA_BASE_FRAME::GetKicadHelp().

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

Function SetAlpha ORs in the alpha blend parameter in to a color index.

Definition at line 124 of file numeric_evaluator.cpp.

125 {
126  return m_originalText;
127 }
128 
129 
130 bool NUMERIC_EVALUATOR::Process( const wxString& aString )
bool Process(const wxString &aString)
wxString numEval::StringFromValue ( EDA_UNITS_T  aUnit,
int  aValue,
bool  aAddUnitSymbol = false,
bool  aUseMils = false 
)

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)
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 178 of file base_units.cpp.

179 {
180  struct lconv * lc = localeconv();
181  char sep = lc->decimal_point[0];
182  unsigned sep_pos = aStringValue.Find( sep );
183 
184  if( sep_pos > 0 )
185  {
186  // We want to keep at least aTrailingZeroAllowed digits after the separator
187  unsigned min_len = sep_pos + aTrailingZeroAllowed + 1;
188 
189  while( aStringValue.Len() > min_len )
190  {
191  if( aStringValue.Last() == '0' )
192  aStringValue.RemoveLast();
193  else
194  break;
195  }
196  }
197 }
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.

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

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
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
double numEval::To_User_Unit ( EDA_UNITS_T  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).
int numEval::ValueFromString ( EDA_UNITS_T  aUnits,
const wxString &  aTextValue,
bool  aUseMils = false 
)

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,
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 130 of file common.cpp.

131 {
132  wxString tmp;
133 
134  for( unsigned ii = 0; ii < aText.Length(); ii++ )
135  {
136  if( aText[ii] == aSplitter )
137  {
138  aStrings.Add( tmp );
139  tmp.Clear();
140  }
141 
142  else
143  tmp << aText[ii];
144  }
145 
146  if( !tmp.IsEmpty() )
147  {
148  aStrings.Add( tmp );
149  }
150 }
static void numEval::yy_accept ( yyParser yypParser)
static

Definition at line 878 of file numeric_evaluator.cpp.

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

Definition at line 422 of file numeric_evaluator.cpp.

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

Definition at line 568 of file numeric_evaluator.cpp.

static int numEval::yy_find_shift_action ( yyParser pParser,
YYCODETYPE  iLookAhead 
)
static

Definition at line 502 of file numeric_evaluator.cpp.

static void numEval::yy_parse_failed ( yyParser yypParser)
static

Definition at line 838 of file numeric_evaluator.cpp.

static void numEval::yy_pop_parser_stack ( yyParser pParser)
static

Definition at line 451 of file numeric_evaluator.cpp.

static void numEval::yy_reduce ( yyParser yypParser,
int  yyruleno 
)
static

Definition at line 702 of file numeric_evaluator.cpp.

static void numEval::yy_shift ( yyParser yypParser,
int  yyNewState,
int  yyMajor,
YYMINORTYPE yypMinor 
)
static

Definition at line 637 of file numeric_evaluator.cpp.

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

Definition at line 859 of file numeric_evaluator.cpp.

static void numEval::yyStackOverflow ( yyParser yypParser,
YYMINORTYPE yypMinor 
)
static

Definition at line 598 of file numeric_evaluator.cpp.

static void numEval::yyTraceShift ( yyParser yypParser,
int  yyNewState 
)
static

Definition at line 618 of file numeric_evaluator.cpp.

Variable Documentation

const StructColors numEval::g_ColorRefs[NBCOLORS]

list of existing Colors

list of existing Colors

Please: if you change a value, remember these values are carefully chosen to have good results in Pcbnew, that uses the ORed value of basic colors when displaying superimposed objects This list must have exactly NBCOLORS items

Definition at line 37 of file colors.cpp.

KIGFX::COLOR4D numEval::g_GhostColor

Draw color for moving objects.

Draw color for moving objects.

TODO: All of these variables should be moved into the class were they are defined and used. Most of them probably belong in the application class.

Definition at line 57 of file common.cpp.

unsigned char numEval::nrhs

Definition at line 676 of file numeric_evaluator.cpp.

const YYACTIONTYPE numEval::yy_action[]
static
Initial value:
= {
31, 8, 7, 33, 5, 6, 30, 42, 15, 10,
15, 11, 4, 12, 4, 40, 29, 32, 2, 32,
2, 8, 7, 33, 5, 6, 15, 28, 9, 41,
4, 39, 13, 14, 29, 32, 2, 44, 3, 8,
7, 33, 5, 6, 59, 1, 27, 9, 33, 5,
6,
}

Definition at line 187 of file numeric_evaluator.cpp.

const YYACTIONTYPE numEval::yy_default[]
static
Initial value:
= {
58, 58, 58, 58, 58, 58, 58, 58, 58, 58,
58, 52, 50, 54, 53, 51,
}

Definition at line 218 of file numeric_evaluator.cpp.

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

Definition at line 195 of file numeric_evaluator.cpp.

const signed char numEval::yy_reduce_ofst[]
static
Initial value:
= {
30, 11, -8, -6, -4, -2, 14, 15, 16,
}

Definition at line 215 of file numeric_evaluator.cpp.

const signed char numEval::yy_shift_ofst[]
static
Initial value:
= {
25, 7, 9, 9, 9, 9, 9, 9, 9, -3,
17, 35, 42, 42, 42, 36,
}

Definition at line 207 of file numeric_evaluator.cpp.

const { ... } numEval::yyRuleInfo[]
Initial value:
= {
{ 14, 1 },
{ 15, 1 },
{ 15, 2 },
{ 16, 1 },
{ 16, 2 },
{ 16, 2 },
{ 17, 1 },
{ 17, 2 },
{ 17, 2 },
{ 17, 1 },
{ 17, 3 },
{ 17, 3 },
{ 17, 3 },
{ 17, 3 },
{ 17, 3 },
{ 17, 3 },
}
const char* const numEval::yyRuleName[]
static
Initial value:
= {
"main ::= in",
"in ::= stmt",
"in ::= in stmt",
"stmt ::= ENDS",
"stmt ::= expr ENDS",
"stmt ::= expr SEMCOL",
"expr ::= VALUE",
"expr ::= expr UNIT",
"expr ::= MINUS 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",
}

Definition at line 333 of file numeric_evaluator.cpp.

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

Definition at line 321 of file numeric_evaluator.cpp.

FILE* numEval::yyTraceFILE = 0
static

Definition at line 288 of file numeric_evaluator.cpp.

char* numEval::yyTracePrompt = 0
static

Definition at line 289 of file numeric_evaluator.cpp.

const YYMINORTYPE numEval::yyzerominor = { 0 }
static

Definition at line 119 of file numeric_evaluator.cpp.