KiCad PCB EDA Suite
base_units.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2012 CERN
5  * Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
33 #ifndef _BASE_UNITS_H_
34 #define _BASE_UNITS_H_
35 
36 
37 #include <common.h>
38 #include <convert_to_biu.h>
39 
41 inline int Mm2mils( double x ) { return KiROUND( x * 1000./25.4 ); }
42 
44 inline int Mils2mm( double x ) { return KiROUND( x * 25.4 / 1000. ); }
45 
54 std::string Double2Str( double aValue );
55 
62 void StripTrailingZeros( wxString& aStringValue, unsigned aTrailingZeroAllowed = 1 );
63 
64 
73 double To_User_Unit( EDA_UNITS_T aUnit, double aValue );
74 
90 wxString CoordinateToString( int aValue, bool aConvertToMils = false );
91 
97 wxString AngleToStringDegrees( double aAngle );
98 
114 wxString LengthDoubleToString( double aValue, bool aConvertToMils = false );
115 
135 wxString StringFromValue( EDA_UNITS_T aUnit, int aValue, bool aAddUnitSymbol = false );
136 
145 wxString& operator <<( wxString& aString, const wxPoint& aPoint );
146 
154 void PutValueInLocalUnits( wxTextCtrl& aTextCtr, int aValue );
155 
160 double From_User_Unit( EDA_UNITS_T aUnit, double aValue );
161 
162 
170 double DoubleValueFromString( EDA_UNITS_T aUnits, const wxString& aTextValue );
171 
180 int ValueFromString( EDA_UNITS_T aUnits, const wxString& aTextValue );
181 
192 int ValueFromString( const wxString& aTextValue );
193 
198 int ValueFromTextCtrl( const wxTextCtrl& aTextCtr );
199 
208 wxString ReturnUnitSymbol( EDA_UNITS_T aUnits = g_UserUnit,
209  const wxString& aFormatString = " (%s):" );
210 
220 wxString GetUnitsLabel( EDA_UNITS_T aUnits );
222 
223 void AddUnitSymbol( wxStaticText& Stext, EDA_UNITS_T aUnit = g_UserUnit );
224 
225 #endif // _BASE_UNITS_H_
double DoubleValueFromString(EDA_UNITS_T aUnits, const wxString &aTextValue)
Function DoubleValueFromString converts aTextValue to a double.
Definition: base_units.cpp:301
int Mm2mils(double x)
Convert mm to mils.
Definition: base_units.h:41
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:106
wxString CoordinateToString(int aValue, bool aConvertToMils=false)
Function CoordinateToString is a helper to convert the integer coordinate aValue to a string in inche...
Definition: base_units.cpp:117
void PutValueInLocalUnits(wxTextCtrl &aTextCtr, int aValue)
Function PutValueInLocalUnits converts aValue from internal units to user units and append the units ...
Definition: base_units.cpp:265
double To_User_Unit(EDA_UNITS_T aUnit, double aValue)
Function To_User_Unit convert aValue in internal units to the appropriate user units defined by aUnit...
Definition: base_units.cpp:90
int ValueFromString(EDA_UNITS_T aUnits, const wxString &aTextValue)
Function ValueFromString converts aTextValue in aUnits to internal units used by the application...
Definition: base_units.cpp:368
double From_User_Unit(EDA_UNITS_T aUnit, double aValue)
Return in internal units the value "val" given in a real unit such as "in", "mm" or "deg"...
Definition: base_units.cpp:273
std::string Double2Str(double aValue)
Helper function Double2Str to print a float number without using scientific notation and no trailing ...
Definition: base_units.cpp:60
int Mils2mm(double x)
Convert mils to mm.
Definition: base_units.h:44
wxString AngleToStringDegrees(double aAngle)
Function AngleToStringDegrees is a helper to convert the double aAngle (in internal unit) to a string...
Definition: base_units.cpp:409
wxString GetAbbreviatedUnitsLabel(EDA_UNITS_T aUnit=g_UserUnit)
Definition: base_units.cpp:479
wxString & operator<<(wxString &aString, const wxPoint &aPoint)
Operator << overload outputs a point to the argument string in a format resembling "@ (x...
Definition: base_units.cpp:395
EDA_UNITS_T g_UserUnit
Global variables definitions.
Definition: common.cpp:56
wxString GetUnitsLabel(EDA_UNITS_T aUnits)
Get a human readable units string.
Definition: base_units.cpp:452
void StripTrailingZeros(wxString &aStringValue, unsigned aTrailingZeroAllowed=1)
Function StripTrailingZeros Remove trailing 0 from a string containing a converted float number...
Definition: base_units.cpp:171
wxString LengthDoubleToString(double aValue, bool aConvertToMils=false)
Function LengthDoubleToString is a helper to convert the double length aValue to a string in inches...
Definition: base_units.cpp:122
wxString ReturnUnitSymbol(EDA_UNITS_T aUnits=g_UserUnit, const wxString &aFormatString=" (%s):")
Returns the units symbol.
Definition: base_units.cpp:420
The common library.
int ValueFromTextCtrl(const wxTextCtrl &aTextCtr)
Convert the number Value in a string according to the internal units and the selected unit (g_UserUni...
Definition: base_units.cpp:384
EDA_UNITS_T
Definition: common.h:143
void AddUnitSymbol(wxStaticText &Stext, EDA_UNITS_T aUnit=g_UserUnit)
Definition: base_units.cpp:509
wxString StringFromValue(EDA_UNITS_T aUnit, int aValue, bool aAddUnitSymbol=false)
Function StringFromValue returns the string from aValue according to units (inch, mm ...
Definition: base_units.cpp:203