KiCad PCB EDA Suite
base_units.h File Reference

Implementation of conversion functions that require both schematic and board internal units. More...

#include <common.h>
#include <convert_to_biu.h>

Go to the source code of this file.

Macros

#define _BASE_UNITS_H_
 
#define INDETERMINATE   wxString( "<...>" )
 
#define INDETERMINATE   wxString( "<...>" )
 Used for holding indeterminate values, such as with multiple selections holding different values or controls which do not wish to set a value. More...
 

Functions

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...
 
void FetchUnitsFromString (const wxString &aTextValue, EDA_UNITS_T &aUnits, bool &aUseMils)
 Function FetchUnitsFromString writes any unit info found in the string to aUnits and aUseMils. More...
 
wxString GetAbbreviatedUnitsLabel (EDA_UNITS_T aUnit, bool aUseMils=false)
 Get the units string for a given units type. More...
 

Detailed Description

Implementation of conversion functions that require both schematic and board internal units.

Author
Wayne Stambaugh stamb.nosp@m.augh.nosp@m.w@ver.nosp@m.izon.nosp@m..net

Definition in file base_units.h.

Macro Definition Documentation

#define _BASE_UNITS_H_

Definition at line 35 of file numeric_evaluator.cpp.

#define INDETERMINATE   wxString( "<...>" )

Used for holding indeterminate values, such as with multiple selections holding different values or controls which do not wish to set a value.

Definition at line 45 of file base_units.h.

Function Documentation

wxString AngleToStringDegrees ( double  aAngle)

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

Definition at line 421 of file base_units.cpp.

References StripTrailingZeros().

Referenced by Mils2mm(), and PANEL_PCBNEW_SETTINGS::TransferDataToWindow().

422 {
423  wxString text;
424 
425  text.Printf( wxT( "%.3f" ), aAngle/10.0 );
426  StripTrailingZeros( text, 1 );
427 
428  return text;
429 }
void StripTrailingZeros(wxString &aStringValue, unsigned aTrailingZeroAllowed)
Function StripTrailingZeros Remove trailing 0 from a string containing a converted float number...
Definition: base_units.cpp:178
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.

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.

Referenced by GBR_TO_PCB_EXPORTER::export_flashed_copper_item(), PCB_IO::format(), PCB_IO::formatSetup(), Mils2mm(), GBR_TO_PCB_EXPORTER::writeCopperLineItem(), GBR_TO_PCB_EXPORTER::writePcbLineItem(), and GBR_TO_PCB_EXPORTER::writePcbPolygonItem().

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 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

Definition at line 302 of file base_units.cpp.

References DEGREES, From_User_Unit(), INCHES, and MILLIMETRES.

Referenced by PROPERTIES_FRAME::CopyPrmsFromPanelToGeneral(), PROPERTIES_FRAME::CopyPrmsFromPanelToItem(), PANEL_PREV_3D::doIncrementOffset(), PANEL_PREV_3D::doIncrementRotation(), PANEL_PREV_3D::doIncrementScale(), DIALOG_DXF_IMPORT::getPCBdefaultLineWidthMM(), DIALOG_IMPORT_GFX::getPCBdefaultLineWidthMM(), DIALOG_DXF_IMPORT::getPcbImportOffsets(), DIALOG_EXPORT_STEP::GetXOrg(), DIALOG_EXPORT_IDF3::GetXRef(), DIALOG_EXPORT_3DFILE::GetXRef(), DIALOG_EXPORT_STEP::GetYOrg(), DIALOG_EXPORT_IDF3::GetYRef(), DIALOG_EXPORT_3DFILE::GetYRef(), Mils2mm(), PANEL_PREV_3D::onMouseWheelOffset(), PANEL_PREV_3D::onMouseWheelRot(), PANEL_PREV_3D::onMouseWheelScale(), DIALOG_IMPORT_GFX::onOKClick(), rotationFromString(), TEXT_MOD_GRID_TABLE::SetValue(), DIALOG_CREATE_ARRAY::TransferDataFromWindow(), DIALOG_PAD_PRIMITIVES_TRANSFORM::Transform(), PANEL_PREV_3D::updateOrientation(), DIALOG_IMPORT_GFX::updatePcbImportOffsets_mm(), and ValueFromString().

303 {
304  double value;
305  double dtmp = 0;
306 
307  // Acquire the 'right' decimal point separator
308  const struct lconv* lc = localeconv();
309 
310  wxChar decimal_point = lc->decimal_point[0];
311  wxString buf( aTextValue.Strip( wxString::both ) );
312 
313  // Convert the period in decimal point
314  buf.Replace( wxT( "." ), wxString( decimal_point, 1 ) );
315 
316  // Find the end of the numeric part
317  unsigned brk_point = 0;
318 
319  while( brk_point < buf.Len() )
320  {
321  wxChar ch = buf[brk_point];
322 
323  if( !( (ch >= '0' && ch <='9') || (ch == decimal_point) || (ch == '-') || (ch == '+') ) )
324  {
325  break;
326  }
327 
328  ++brk_point;
329  }
330 
331  // Extract the numeric part
332  buf.Left( brk_point );
333 
334  buf.ToDouble( &dtmp );
335 
336  // Check the optional unit designator (2 ch significant)
337  wxString unit( buf.Mid( brk_point ).Strip( wxString::leading ).Left( 2 ).Lower() );
338 
339  if( aUnits == INCHES || aUnits == MILLIMETRES )
340  {
341  if( unit == wxT( "in" ) || unit == wxT( "\"" ) )
342  {
343  aUnits = INCHES;
344  aUseMils = false;
345  }
346  else if( unit == wxT( "mm" ) )
347  {
348  aUnits = MILLIMETRES;
349  }
350  else if( unit == wxT( "mi" ) || unit == wxT( "th" ) ) // "mils" or "thou"
351  {
352  aUnits = INCHES;
353  aUseMils = true;
354  }
355  }
356  else if( aUnits == DEGREES )
357  {
358  if( unit == wxT( "ra" ) ) // Radians
359  {
360  dtmp *= 180.0f / M_PI;
361  }
362  }
363 
364  value = From_User_Unit( aUnits, dtmp, aUseMils );
365 
366  return value;
367 }
double From_User_Unit(EDA_UNITS_T aUnits, double aValue, bool aUseMils)
Return in internal units the value "val" given in a real unit such as "in", "mm" or "deg"...
Definition: base_units.cpp:278
Definition: common.h:160
void FetchUnitsFromString ( const wxString &  aTextValue,
EDA_UNITS_T aUnits,
bool &  aUseMils 
)

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

Definition at line 370 of file base_units.cpp.

References DEGREES, INCHES, and MILLIMETRES.

Referenced by Mils2mm(), DIALOG_TEXT_PROPERTIES::OnDimensionTextChange(), and PCB_PARSER::parseDIMENSION().

371 {
372  wxString buf( aTextValue.Strip( wxString::both ) );
373  unsigned brk_point = 0;
374 
375  while( brk_point < buf.Len() )
376  {
377  wxChar c = buf[brk_point];
378 
379  if( !( (c >= '0' && c <='9') || (c == '.') || (c == ',') || (c == '-') || (c == '+') ) )
380  break;
381 
382  ++brk_point;
383  }
384 
385  // Check the unit designator (2 ch significant)
386  wxString unit( buf.Mid( brk_point ).Strip( wxString::leading ).Left( 2 ).Lower() );
387 
388  if( unit == wxT( "in" ) || unit == wxT( "\"" ) )
389  {
390  aUnits = INCHES;
391  aUseMils = false;
392  }
393  else if( unit == wxT( "mm" ) )
394  {
395  aUnits = MILLIMETRES;
396  }
397  else if( unit == wxT( "mi" ) || unit == wxT( "th" ) ) // "mils" or "thou"
398  {
399  aUnits = INCHES;
400  aUseMils = true;
401  }
402  else if( unit == wxT( "de" ) || unit == wxT( "ra" ) ) // "deg" or "rad"
403  {
404  aUnits = DEGREES;
405  }
406 }
Definition: common.h:160
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".

Definition at line 278 of file base_units.cpp.

References DEGREES, INCHES, MILLIMETRES, and UNSCALED_UNITS.

Referenced by BASE_SCREEN::AddGrid(), DoubleValueFromString(), PCB_BASE_FRAME::LoadSettings(), and Mils2mm().

279 {
280  switch( aUnits )
281  {
282  case MILLIMETRES:
283  return MM_TO_IU( aValue );
284 
285  case INCHES:
286  if( aUseMils )
287  return MILS_TO_IU( aValue );
288  else
289  return IN_TO_IU( aValue );
290 
291  case DEGREES:
292  // Convert to "decidegrees"
293  return aValue * 10;
294 
295  default:
296  case UNSCALED_UNITS:
297  return aValue;
298  }
299 }
Definition: common.h:160
wxString GetAbbreviatedUnitsLabel ( EDA_UNITS_T  aUnit,
bool  aUseMils = false 
)

Get the units string for a given units type.

Parameters
aUnits- The units requested.
Returns
The human readable units string.

Definition at line 432 of file base_units.cpp.

References DEGREES, INCHES, MILLIMETRES, and UNSCALED_UNITS.

Referenced by DIALOG_PLOT::applyPlotSettings(), UNIT_BINDER::ChangeValue(), DIALOG_TRACK_VIA_PROPERTIES::DIALOG_TRACK_VIA_PROPERTIES(), PANEL_PREV_3D::formatOffsetValue(), PANEL_PREV_3D::formatRotationValue(), MessageTextFromValue(), Mils2mm(), UNIT_BINDER::SetUnits(), UNIT_BINDER::SetValue(), TEXT_MOD_GRID_TABLE::TEXT_MOD_GRID_TABLE(), and UNIT_BINDER::UNIT_BINDER().

433 {
434  switch( aUnit )
435  {
436  case INCHES:
437  if( aUseMils )
438  return _( "mils" );
439  else
440  return _( "in" );
441 
442  case MILLIMETRES:
443  return _( "mm" );
444 
445  case UNSCALED_UNITS:
446  return wxEmptyString;
447 
448  case DEGREES:
449  return _( "deg" );
450 
451  default:
452  return wxT( "??" );
453  }
454 }
Definition: common.h:160
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.

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.

Definition at line 132 of file base_units.cpp.

References GetAbbreviatedUnitsLabel(), INCHES, and To_User_Unit().

Referenced by Mils2mm().

133 {
134  wxString text;
135  const wxChar* format;
136  double value = To_User_Unit( aUnits, aValue, aUseMils );
137 
138  if( aUnits == INCHES )
139  {
140  if( aUseMils )
141  {
142 #if defined( EESCHEMA )
143  format = wxT( "%.0f" );
144 #else
145  format = wxT( "%.1f" );
146 #endif
147  }
148  else
149  {
150 #if defined( EESCHEMA )
151  format = wxT( "%.3f" );
152 #else
153  format = wxT( "%.4f" );
154 #endif
155  }
156  }
157  else
158  {
159 #if defined( EESCHEMA )
160  format = wxT( "%.2f" );
161 #else
162  format = wxT( "%.3f" );
163 #endif
164  }
165 
166  text.Printf( format, value );
167  text += " ";
168 
169  text += GetAbbreviatedUnitsLabel( aUnits, aUseMils );
170 
171  return text;
172 }
double To_User_Unit(EDA_UNITS_T aUnit, double aValue, bool aUseMils)
Function To_User_Unit convert aValue in internal units to the appropriate user units defined by aUnit...
Definition: base_units.cpp:93
Definition: common.h:160
wxString GetAbbreviatedUnitsLabel(EDA_UNITS_T aUnit, bool aUseMils)
Get the units string for a given units type.
Definition: base_units.cpp:432
wxString MessageTextFromValue ( EDA_UNITS_T  aUnits,
int  aValue,
bool  aUseMils = false 
)

Definition at line 125 of file base_units.cpp.

References MessageTextFromValue().

Referenced by DIMENSION::AdjustDimensionDetails(), DIALOG_PAD_PROPERTIES::displayPrimitivesList(), formatCoord(), LIB_CIRCLE::GetMsgPanelInfo(), LIB_RECTANGLE::GetMsgPanelInfo(), TEXTE_PCB::GetMsgPanelInfo(), LIB_POLYLINE::GetMsgPanelInfo(), LIB_TEXT::GetMsgPanelInfo(), LIB_ARC::GetMsgPanelInfo(), LIB_BEZIER::GetMsgPanelInfo(), LIB_PIN::GetMsgPanelInfo(), LIB_FIELD::GetMsgPanelInfo(), TEXTE_MODULE::GetMsgPanelInfo(), SCH_TEXT::GetMsgPanelInfo(), DRAWSEGMENT::GetMsgPanelInfo(), TRACK::GetMsgPanelInfo(), NETINFO_ITEM::GetMsgPanelInfo(), D_PAD::GetMsgPanelInfo(), TRACK::GetMsgPanelInfoBase(), SEGZONE::GetMsgPanelInfoBase(), LIB_PIN::getMsgPanelInfoBase(), VIA::GetMsgPanelInfoBase(), LIB_CIRCLE::GetSelectMenuText(), PCB_TARGET::GetSelectMenuText(), LIB_RECTANGLE::GetSelectMenuText(), MARKER_PCB::GetSelectMenuText(), LIB_POLYLINE::GetSelectMenuText(), LIB_ARC::GetSelectMenuText(), SCH_LINE::GetSelectMenuText(), DRAWSEGMENT::GetSelectMenuText(), TRACK::GetSelectMenuText(), VIA::GetSelectMenuText(), MessageTextFromValue(), SCH_EDIT_FRAME::OnFindDrcMarker(), DIALOG_NETLIST::OnTestFootprintsClick(), DRC_ITEM::ShowCoord(), PNS::MEANDER_SKEW_PLACER::TuningInfo(), PNS::MEANDER_PLACER::TuningInfo(), PNS::DP_MEANDER_PLACER::TuningInfo(), TRACK_WIDTH_MENU::update(), and DIFF_PAIR_MENU::update().

126 {
127  return MessageTextFromValue( aUnits, (double) aValue, aUseMils );
128 }
wxString MessageTextFromValue(EDA_UNITS_T aUnits, int aValue, bool aUseMils)
Definition: base_units.cpp:125
int Mils2mm ( double  x)
inline

Convert mils to mm.

Definition at line 52 of file base_units.h.

References AngleToStringDegrees(), Double2Str(), DoubleValueFromString(), FetchUnitsFromString(), From_User_Unit(), GetAbbreviatedUnitsLabel(), KiROUND(), MessageTextFromValue(), StringFromValue(), StripTrailingZeros(), To_User_Unit(), and ValueFromString().

Referenced by DIALOG_PRINT_GENERIC::initPrintData(), PL_EDITOR_FRAME::ToPrinter(), and DIALOG_PRINT_USING_PRINTER::TransferDataToWindow().

52 { return KiROUND( x * 25.4 / 1000. ); }
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:120
int Mm2mils ( double  x)
inline

Convert mm to mils.

Definition at line 49 of file base_units.h.

References KiROUND().

Referenced by WS_DRAW_ITEM_LIST::BuildWorkSheetGraphicList(), and PCB_PARSER::parsePAGE_INFO().

49 { return KiROUND( x * 1000./25.4 ); }
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:120
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.

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)

Definition at line 210 of file base_units.cpp.

References DEGREES, Format(), INCHES, MILLIMETRES, StripTrailingZeros(), To_User_Unit(), and UNSCALED_UNITS.

Referenced by Append_Track_Width_List(), PANEL_SETUP_TRACKS_AND_VIAS::AppendDiffPairs(), PANEL_SETUP_TRACKS_AND_VIAS::AppendTrackWidth(), PANEL_SETUP_TRACKS_AND_VIAS::AppendViaSize(), DIALOG_PLOT::applyPlotSettings(), UNIT_BINDER::ChangeValue(), ConvertOutlineToPolygon(), PCB_EDIT_FRAME::Create_MuWaveComponent(), MWAVE::CreateMicrowaveInductor(), DIALOG_TRACK_VIA_PROPERTIES::DIALOG_TRACK_VIA_PROPERTIES(), PCB_EDIT_FRAME::Edit_Gap(), LIB_PIN::getMsgPanelInfoBase(), TEXT_MOD_GRID_TABLE::GetValue(), FIELDS_GRID_TABLE< T >::GetValue(), PIN_TABLE_DATA_MODEL::GetValue(), DIALOG_PLOT::init_Dialog(), DIALOG_PAD_PROPERTIES::initValues(), Mils2mm(), DIALOG_TEXT_PROPERTIES::OnDimensionUnitsChange(), DIALOG_PAD_PROPERTIES::padValuesOK(), UNIT_BINDER::SetValue(), EDA_POSITION_CTRL::SetValue(), PANEL_LIBEDIT_SETTINGS::TransferDataToWindow(), PANEL_EESCHEMA_SETTINGS::TransferDataToWindow(), PANEL_EESCHEMA_DISPLAY_OPTIONS::TransferDataToWindow(), DIALOG_PAD_PRIMITIVE_POLY_PROPS::TransferDataToWindow(), UNIT_BINDER::Validate(), PANEL_SETUP_TRACKS_AND_VIAS::validateData(), and PANEL_SETUP_NETCLASSES::validateData().

211 {
212  double value_to_print = To_User_Unit( aUnits, aValue, aUseMils );
213 
214 #if defined( EESCHEMA )
215  wxString stringValue = wxString::Format( wxT( "%.3f" ), value_to_print );
216 
217  // Strip trailing zeros. However, keep at least 3 digits in mantissa
218  // For readability
219  StripTrailingZeros( stringValue, 3 );
220 
221 #else
222 
223  char buf[50];
224  int len;
225 
226  if( value_to_print != 0.0 && fabs( value_to_print ) <= 0.0001 )
227  {
228  len = sprintf( buf, "%.10f", value_to_print );
229 
230  while( --len > 0 && buf[len] == '0' )
231  buf[len] = '\0';
232 
233  if( buf[len]=='.' || buf[len]==',' )
234  buf[len] = '\0';
235  else
236  ++len;
237  }
238  else
239  {
240  if( aUnits == INCHES && aUseMils )
241  len = sprintf( buf, "%.7g", value_to_print );
242  else
243  len = sprintf( buf, "%.10g", value_to_print );
244  }
245 
246  wxString stringValue( buf, wxConvUTF8 );
247 
248 #endif
249 
250  if( aAddUnitSymbol )
251  {
252  switch( aUnits )
253  {
254  case INCHES:
255  if( aUseMils )
256  stringValue += wxT( " mils" );
257  else
258  stringValue += wxT( " in" );
259  break;
260 
261  case MILLIMETRES:
262  stringValue += wxT( " mm" );
263  break;
264 
265  case DEGREES:
266  stringValue += wxT( " deg" );
267  break;
268 
269  case UNSCALED_UNITS:
270  break;
271  }
272  }
273 
274  return stringValue;
275 }
void StripTrailingZeros(wxString &aStringValue, unsigned aTrailingZeroAllowed)
Function StripTrailingZeros Remove trailing 0 from a string containing a converted float number...
Definition: base_units.cpp:178
double To_User_Unit(EDA_UNITS_T aUnit, double aValue, bool aUseMils)
Function To_User_Unit convert aValue in internal units to the appropriate user units defined by aUnit...
Definition: base_units.cpp:93
Definition: common.h:160
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
void 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.

Referenced by AngleToStringDegrees(), Mils2mm(), and StringFromValue().

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 }
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.

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).

Definition at line 93 of file base_units.cpp.

References DEGREES, INCHES, and MILLIMETRES.

Referenced by BASE_SCREEN::BuildGridsChoiceList(), formatPreviewDimension(), MessageTextFromValue(), Mils2mm(), PCB_BASE_FRAME::SaveSettings(), StringFromValue(), PL_EDITOR_FRAME::UpdateStatusBar(), SCH_BASE_FRAME::UpdateStatusBar(), PCB_BASE_FRAME::UpdateStatusBar(), GERBVIEW_FRAME::UpdateStatusBar(), PCB_EDIT_FRAME::UpdateTrackWidthSelectBox(), and PCB_EDIT_FRAME::UpdateViaSizeSelectBox().

94 {
95  switch( aUnit )
96  {
97  case MILLIMETRES:
98  return IU_TO_MM( aValue );
99 
100  case INCHES:
101  if( aUseMils )
102  return IU_TO_MILS( aValue );
103  else
104  return IU_TO_IN( aValue );
105 
106  case DEGREES:
107  return aValue / 10.0f;
108 
109  default:
110  return aValue;
111  }
112 }
Definition: common.h:160
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.

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,

Definition at line 409 of file base_units.cpp.

References DoubleValueFromString(), and KiROUND().

Referenced by PIN_TABLE_DATA_MODEL::compare(), PCB_EDIT_FRAME::Create_MuWaveComponent(), MWAVE::CreateMicrowaveInductor(), PCB_EDIT_FRAME::Edit_Gap(), PANEL_MODEDIT_DEFAULTS::getGridValue(), PANEL_SETUP_TEXT_AND_GRAPHICS::getGridValue(), PANEL_SETUP_NETCLASSES::getNetclassValue(), DIALOG_ANNOTATE::GetStartNumber(), UNIT_BINDER::GetValue(), EDA_POSITION_CTRL::GetValue(), Mils2mm(), DIALOG_PAD_PRIMITIVE_POLY_PROPS::onCellChanging(), DIALOG_TEXT_PROPERTIES::OnDimensionUnitsChange(), TEXT_MOD_GRID_TABLE::SetValue(), FIELDS_GRID_TABLE< T >::SetValue(), PIN_TABLE_DATA_MODEL::SetValue(), PANEL_LIBEDIT_SETTINGS::TransferDataFromWindow(), PANEL_EESCHEMA_SETTINGS::TransferDataFromWindow(), PANEL_EESCHEMA_DISPLAY_OPTIONS::TransferDataFromWindow(), PANEL_SETUP_TRACKS_AND_VIAS::TransferDataFromWindow(), and PANEL_SETUP_TRACKS_AND_VIAS::validateData().

410 {
411  double value = DoubleValueFromString( aUnits, aTextValue, aUseMils );
412  return KiROUND( value );
413 }
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:120
double DoubleValueFromString(EDA_UNITS_T aUnits, const wxString &aTextValue, bool aUseMils)
Function DoubleValueFromString converts aTextValue to a double.
Definition: base_units.cpp:302