2013-05-26 04:36:44 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 CERN
|
2019-01-08 05:42:50 +00:00
|
|
|
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
|
2013-05-26 04:36:44 +00:00
|
|
|
*
|
|
|
|
* 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_
|
|
|
|
|
2019-01-08 05:42:50 +00:00
|
|
|
#include <string>
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2020-10-24 14:45:37 +00:00
|
|
|
#include <eda_units.h>
|
2013-05-26 04:36:44 +00:00
|
|
|
#include <convert_to_biu.h>
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <math/vector2d.h>
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2019-01-08 05:42:50 +00:00
|
|
|
//TODO: Abstract Base Units to a single class
|
2018-02-03 09:09:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Used for holding indeterminate values, such as with multiple selections
|
|
|
|
* holding different values or controls which do not wish to set a value.
|
|
|
|
*/
|
2020-05-05 15:40:18 +00:00
|
|
|
#define INDETERMINATE_STATE _( "-- mixed values --" )
|
|
|
|
#define INDETERMINATE_ACTION _( "-- leave unchanged --" )
|
2018-02-03 09:09:53 +00:00
|
|
|
|
|
|
|
|
2020-04-21 20:17:01 +00:00
|
|
|
// PCBNew doesn't support a bold style so we want to allow text thicknesses
|
|
|
|
// that achieve the same effect
|
|
|
|
#if defined( PCBNEW )
|
|
|
|
#define ALLOW_BOLD_THICKNESS true
|
|
|
|
#else
|
|
|
|
#define ALLOW_BOLD_THICKNESS IsBold()
|
|
|
|
#endif
|
|
|
|
|
2021-06-01 23:03:22 +00:00
|
|
|
/**
|
|
|
|
* Convert mm to mils.
|
|
|
|
*/
|
|
|
|
int Mm2mils( double x );
|
2020-04-21 20:17:01 +00:00
|
|
|
|
2021-06-01 23:03:22 +00:00
|
|
|
/**
|
|
|
|
* Convert mils to mm.
|
|
|
|
*/
|
|
|
|
int Mils2mm( double x );
|
2017-02-09 10:16:28 +00:00
|
|
|
|
2013-05-26 04:36:44 +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.
|
|
|
|
*/
|
2020-10-02 20:51:24 +00:00
|
|
|
double To_User_Unit( EDA_UNITS aUnit, double aValue );
|
2013-05-26 04:36:44 +00:00
|
|
|
|
|
|
|
/**
|
2018-03-06 12:06:46 +00:00
|
|
|
* Function MessageTextFromValue
|
2013-05-26 04:36:44 +00:00
|
|
|
* is a helper to convert the \a double length \a aValue to a string in inches,
|
2018-03-06 12:06:46 +00:00
|
|
|
* millimeters, or unscaled units.
|
2013-05-26 04:36:44 +00:00
|
|
|
*
|
|
|
|
* Should be used only to display a coordinate in status, but not in dialogs,
|
2018-03-06 12:06:46 +00:00
|
|
|
* 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.
|
2013-05-26 04:36:44 +00:00
|
|
|
*
|
2018-03-06 12:06:46 +00:00
|
|
|
* @param aUnits The units to show the value in. The unit string is added to the
|
|
|
|
* message text.
|
2013-05-26 04:36:44 +00:00
|
|
|
* @param aValue The double value to convert.
|
2020-10-04 15:29:18 +00:00
|
|
|
* @param aAddUnitLabel If true, adds the unit label to the end of the string
|
2020-02-05 09:43:52 +00:00
|
|
|
* @param aType Type of the unit being used (e.g. distance, area, etc.)
|
2013-05-26 04:36:44 +00:00
|
|
|
* @return The converted string for display in user interface elements.
|
|
|
|
*/
|
2020-10-04 15:29:18 +00:00
|
|
|
wxString MessageTextFromValue( EDA_UNITS aUnits, double aValue, bool aAddUnitLabel = true,
|
|
|
|
EDA_DATA_TYPE aType = EDA_DATA_TYPE::DISTANCE );
|
2018-03-06 12:06:46 +00:00
|
|
|
|
2020-10-04 15:29:18 +00:00
|
|
|
wxString MessageTextFromValue( EDA_UNITS aUnits, int aValue, bool aAddUnitLabel = true,
|
|
|
|
EDA_DATA_TYPE aType = EDA_DATA_TYPE::DISTANCE );
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2020-10-04 15:29:18 +00:00
|
|
|
wxString MessageTextFromValue( EDA_UNITS aUnits, long long int aValue, bool aAddUnitLabel = true,
|
|
|
|
EDA_DATA_TYPE aType = EDA_DATA_TYPE::DISTANCE );
|
2019-09-03 23:38:58 +00:00
|
|
|
|
2013-05-26 04:36:44 +00:00
|
|
|
/**
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
* Function StringFromValue
|
2013-05-26 04:36:44 +00:00
|
|
|
* returns the string from \a 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.
|
|
|
|
*
|
|
|
|
* @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)
|
|
|
|
*/
|
2020-04-21 20:17:01 +00:00
|
|
|
wxString StringFromValue( EDA_UNITS aUnit, double aValue, bool aAddUnitSymbol = false,
|
2020-10-02 20:51:24 +00:00
|
|
|
EDA_DATA_TYPE aType = EDA_DATA_TYPE::DISTANCE );
|
2013-05-26 04:36:44 +00:00
|
|
|
|
|
|
|
/**
|
2015-02-12 03:22:24 +00:00
|
|
|
* Return in internal units the value "val" given in a real unit
|
|
|
|
* such as "in", "mm" or "deg"
|
2013-05-26 04:36:44 +00:00
|
|
|
*/
|
2020-10-02 20:51:24 +00:00
|
|
|
double From_User_Unit( EDA_UNITS aUnit, double aValue );
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2015-02-12 03:22:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function DoubleValueFromString
|
|
|
|
* converts \a aTextValue to a double
|
2020-07-12 13:26:36 +00:00
|
|
|
* @warning This utilizes the current locale and will break if decimal formats differ
|
|
|
|
*
|
2015-02-12 03:22:24 +00:00
|
|
|
* @param aUnits The units of \a aTextValue.
|
|
|
|
* @param aTextValue A reference to a wxString object containing the string to convert.
|
|
|
|
* @return A double representing that value in internal units
|
|
|
|
*/
|
2020-10-04 15:29:18 +00:00
|
|
|
double DoubleValueFromString( EDA_UNITS aUnits, const wxString& aTextValue,
|
2020-06-29 16:16:37 +00:00
|
|
|
EDA_DATA_TYPE aType = EDA_DATA_TYPE::DISTANCE );
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2013-05-26 04:36:44 +00:00
|
|
|
/**
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
* Function ValueFromString
|
2013-05-26 04:36:44 +00:00
|
|
|
* converts \a aTextValue in \a aUnits to internal units used by the application.
|
2020-07-12 13:26:36 +00:00
|
|
|
* @warning This utilizes the current locale and will break if decimal formats differ
|
2013-05-26 04:36:44 +00:00
|
|
|
*
|
|
|
|
* @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,
|
|
|
|
*/
|
2020-10-02 20:51:24 +00:00
|
|
|
long long int ValueFromString( EDA_UNITS aUnits, const wxString& aTextValue,
|
2020-06-29 16:16:37 +00:00
|
|
|
EDA_DATA_TYPE aType = EDA_DATA_TYPE::DISTANCE );
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2017-02-09 10:16:28 +00:00
|
|
|
/**
|
2018-07-21 12:49:19 +00:00
|
|
|
* Function FetchUnitsFromString
|
2020-10-02 20:51:24 +00:00
|
|
|
* writes any unit info found in the string to aUnits.
|
2018-07-21 12:49:19 +00:00
|
|
|
*/
|
2020-10-02 20:51:24 +00:00
|
|
|
void FetchUnitsFromString( const wxString& aTextValue, EDA_UNITS& aUnits );
|
2018-07-21 12:49:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the units string for a given units type.
|
2017-02-09 10:16:28 +00:00
|
|
|
*
|
2018-06-13 16:05:43 +00:00
|
|
|
* @param aUnits - The units requested.
|
2020-02-05 09:43:52 +00:00
|
|
|
* @param aType - The data type of the unit (e.g. distance, area, etc.)
|
2017-02-09 10:16:28 +00:00
|
|
|
* @return The human readable units string.
|
|
|
|
*/
|
2020-10-02 20:51:24 +00:00
|
|
|
wxString GetAbbreviatedUnitsLabel( EDA_UNITS aUnit, EDA_DATA_TYPE aType = EDA_DATA_TYPE::DISTANCE );
|
2017-02-09 10:16:28 +00:00
|
|
|
|
2019-01-08 05:42:50 +00:00
|
|
|
/**
|
|
|
|
* Function FormatInternalUnits
|
|
|
|
* converts \a aValue from internal units to a string appropriate for writing
|
|
|
|
* to file.
|
|
|
|
*
|
|
|
|
* @note Internal units for board items can be either deci-mils or nanometers depending
|
|
|
|
* on how KiCad is built.
|
|
|
|
*
|
|
|
|
* @param aValue A coordinate value to convert.
|
|
|
|
* @return A std::string object containing the converted value.
|
|
|
|
*/
|
|
|
|
std::string FormatInternalUnits( int aValue );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function FormatAngle
|
|
|
|
* converts \a aAngle from board units to a string appropriate for writing to file.
|
|
|
|
*
|
|
|
|
* @note Internal angles for board items can be either degrees or tenths of degree
|
|
|
|
* on how KiCad is built.
|
|
|
|
* @param aAngle A angle value to convert.
|
|
|
|
* @return A std::string object containing the converted angle.
|
|
|
|
*/
|
|
|
|
std::string FormatAngle( double aAngle );
|
|
|
|
|
|
|
|
std::string FormatInternalUnits( const wxPoint& aPoint );
|
|
|
|
|
|
|
|
std::string FormatInternalUnits( const wxSize& aSize );
|
|
|
|
|
|
|
|
std::string FormatInternalUnits( const VECTOR2I& aPoint );
|
|
|
|
|
2017-02-09 10:16:28 +00:00
|
|
|
|
2013-05-26 04:36:44 +00:00
|
|
|
#endif // _BASE_UNITS_H_
|