2012-04-13 18:51:24 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 CERN
|
|
|
|
* Copyright (C) 1992-2011 KiCad Developers, see change_log.txt for contributors.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* @file base_units.h
|
|
|
|
* @brief Implementation of conversion functions that require both schematic and board
|
|
|
|
* internal units.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _BASE_UNITS_H_
|
|
|
|
#define _BASE_UNITS_H_
|
|
|
|
|
|
|
|
|
|
|
|
#include <common.h>
|
2012-04-25 19:33:24 +00:00
|
|
|
#include <convert_to_biu.h>
|
2012-04-16 01:25:26 +00:00
|
|
|
|
|
|
|
|
2012-04-13 18:51:24 +00:00
|
|
|
/**
|
|
|
|
* Function To_User_Unit
|
|
|
|
* convert \a aValue in internal units to the appropriate user units defined by \a aUnit.
|
|
|
|
*
|
|
|
|
* @return The converted value, in double
|
|
|
|
* @param aUnit The units to convert \a aValue to.
|
|
|
|
* @param aValue The value in internal units to convert.
|
|
|
|
*/
|
|
|
|
double To_User_Unit( EDA_UNITS_T aUnit, double aValue );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function CoordinateToString
|
2012-04-27 14:15:11 +00:00
|
|
|
* is a helper to convert the \a integer coordinate \a aValue to a string in inches,
|
2012-04-13 18:51:24 +00:00
|
|
|
* millimeters, or unscaled units according to the current user units setting.
|
|
|
|
*
|
2012-11-06 17:58:53 +00:00
|
|
|
* Should be used only to display a coordinate in status, but not in dialogs,
|
|
|
|
* because the mantissa of the number displayed has 4 digits max for readability.
|
|
|
|
* (i.e. the value shows the decimils or the microns )
|
|
|
|
* However the actual internal value could need up to 8 digits to be printed
|
|
|
|
*
|
2012-04-27 14:15:11 +00:00
|
|
|
* @param aValue The integer coordinate to convert.
|
2012-04-13 18:51:24 +00:00
|
|
|
* @param aConvertToMils Convert inch values to mils if true. This setting has no effect if
|
|
|
|
* the current user unit is millimeters.
|
|
|
|
* @return The converted string for display in user interface elements.
|
|
|
|
*/
|
|
|
|
wxString CoordinateToString( int aValue, bool aConvertToMils = false );
|
|
|
|
|
2012-04-27 14:15:11 +00:00
|
|
|
/**
|
|
|
|
* Function LenghtDoubleToString
|
|
|
|
* is a helper to convert the \a double length \a aValue to a string in inches,
|
|
|
|
* millimeters, or unscaled units according to the current user units setting.
|
|
|
|
*
|
2012-11-06 17:58:53 +00:00
|
|
|
* Should be used only to display a coordinate in status, but not in dialogs,
|
|
|
|
* because the mantissa of the number displayed has 4 digits max for readability.
|
|
|
|
* (i.e. the value shows the decimils or the microns )
|
|
|
|
* However the actual internal value could need up to 8 digits to be printed
|
|
|
|
*
|
2012-04-27 14:15:11 +00:00
|
|
|
* @param aValue The double value to convert.
|
|
|
|
* @param aConvertToMils Convert inch values to mils if true. This setting has no effect if
|
|
|
|
* the current user unit is millimeters.
|
|
|
|
* @return The converted string for display in user interface elements.
|
|
|
|
*/
|
|
|
|
wxString LengthDoubleToString( double aValue, bool aConvertToMils = false );
|
2012-04-13 18:51:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function ReturnStringFromValue
|
|
|
|
* returns the string from \a aValue according to units (inch, mm ...) for display,
|
|
|
|
* and the initial unit for value.
|
2012-11-06 17:58:53 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2012-04-13 18:51:24 +00:00
|
|
|
* @param aUnit = display units (INCHES, MILLIMETRE ..)
|
|
|
|
* @param aValue = value in Internal_Unit
|
|
|
|
* @param aAddUnitSymbol = true to add symbol unit to the string value
|
|
|
|
* @return A wxString object containing value and optionally the symbol unit (like 2.000 mm)
|
|
|
|
*/
|
|
|
|
wxString ReturnStringFromValue( EDA_UNITS_T aUnit, int aValue, bool aAddUnitSymbol = false );
|
|
|
|
|
2012-04-27 14:15:11 +00:00
|
|
|
/**
|
|
|
|
* Operator << overload
|
|
|
|
* outputs a point to the argument string in a format resembling
|
|
|
|
* "@ (x,y)
|
|
|
|
* @param aString Where to put the text describing the point value
|
|
|
|
* @param aPoint The point to output.
|
|
|
|
* @return wxString& - the input string
|
|
|
|
*/
|
|
|
|
wxString& operator <<( wxString& aString, const wxPoint& aPoint );
|
|
|
|
|
2012-04-13 18:51:24 +00:00
|
|
|
/**
|
|
|
|
* Function PutValueInLocalUnits
|
|
|
|
* converts \a aValue from internal units to user units and append the units notation
|
|
|
|
* (mm or ")then inserts the string an \a aTextCtrl.
|
|
|
|
*
|
|
|
|
* This function is used in dialog boxes for entering values depending on selected units.
|
|
|
|
*/
|
|
|
|
void PutValueInLocalUnits( wxTextCtrl& aTextCtr, int aValue );
|
|
|
|
|
2012-04-16 17:39:32 +00:00
|
|
|
/**
|
|
|
|
* Return in internal units the value "val" given in inch or mm
|
|
|
|
*/
|
2012-04-16 23:31:29 +00:00
|
|
|
double From_User_Unit( EDA_UNITS_T aUnit, double aValue );
|
2012-04-16 17:39:32 +00:00
|
|
|
|
|
|
|
/**
|
2012-07-22 22:23:17 +00:00
|
|
|
* Function ReturnValueFromString
|
2012-04-16 17:39:32 +00:00
|
|
|
* converts \a aTextValue in \a aUnits to internal units used by the application.
|
|
|
|
*
|
|
|
|
* @param aUnits The units of \a aTextValue.
|
|
|
|
* @param aTextValue A reference to a wxString object containing the string to convert.
|
|
|
|
* @return The string from Value, according to units (inch, mm ...) for display,
|
|
|
|
*/
|
|
|
|
int ReturnValueFromString( EDA_UNITS_T aUnits, const wxString& aTextValue );
|
|
|
|
|
2012-07-22 22:23:17 +00:00
|
|
|
/**
|
|
|
|
* Function ReturnValueFromString
|
|
|
|
|
2012-11-06 17:58:53 +00:00
|
|
|
* converts \a aTextValue in \a aUnits to internal units used by the application,
|
2012-07-22 22:23:17 +00:00
|
|
|
* unit type will be obtained from g_UserUnit.
|
|
|
|
*
|
|
|
|
* @param aTextValue A reference to a wxString object containing the string to convert.
|
|
|
|
* @return The string from Value, according to units (inch, mm ...) for display,
|
|
|
|
*/
|
|
|
|
|
|
|
|
int ReturnValueFromString( const wxString& aTextValue );
|
|
|
|
|
2012-04-16 17:39:32 +00:00
|
|
|
/**
|
|
|
|
* Convert the number Value in a string according to the internal units
|
|
|
|
* and the selected unit (g_UserUnit) and put it in the wxTextCtrl TextCtrl
|
|
|
|
*/
|
|
|
|
int ReturnValueFromTextCtrl( const wxTextCtrl& aTextCtr );
|
|
|
|
|
2012-04-13 18:51:24 +00:00
|
|
|
#endif // _BASE_UNITS_H_
|