![]() |
KiCad PCB EDA Suite
|
Code to handle objects that require both schematic and board internal units. More...
#include <base_units.h>
#include <common.h>
#include <kicad_string.h>
#include <math/util.h>
#include <macros.h>
#include <title_block.h>
Go to the source code of this file.
Functions | |
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... | |
double | To_User_Unit (EDA_UNITS aUnit, double aValue) |
Function To_User_Unit convert aValue in internal units to the appropriate user units defined by aUnit. More... | |
wxString | MessageTextFromValue (EDA_UNITS aUnits, int aValue, bool aAddUnitLabel, EDA_DATA_TYPE aType) |
Convert a value to a string using double notation. More... | |
wxString | MessageTextFromValue (EDA_UNITS aUnits, long long int aValue, bool aAddUnitLabel, EDA_DATA_TYPE aType) |
wxString | MessageTextFromValue (EDA_UNITS aUnits, double aValue, bool aAddUnitLabel, EDA_DATA_TYPE aType) |
Function MessageTextFromValue is a helper to convert the double length aValue to a string in inches, millimeters, or unscaled units. More... | |
wxString | StringFromValue (EDA_UNITS aUnits, double aValue, bool aAddUnitSymbol, EDA_DATA_TYPE aType) |
Convert a value to a string using double notation. More... | |
double | From_User_Unit (EDA_UNITS aUnits, double aValue) |
Return in internal units the value "val" given in a real unit such as "in", "mm" or "deg". More... | |
double | DoubleValueFromString (EDA_UNITS aUnits, const wxString &aTextValue, EDA_DATA_TYPE aType) |
Function DoubleValueFromString converts aTextValue to a double. More... | |
void | FetchUnitsFromString (const wxString &aTextValue, EDA_UNITS &aUnits) |
Function FetchUnitsFromString writes any unit info found in the string to aUnits. More... | |
long long int | ValueFromString (EDA_UNITS aUnits, const wxString &aTextValue, EDA_DATA_TYPE aType) |
Function ValueFromString converts aTextValue in aUnits to internal units used by the application. More... | |
wxString | AngleToStringDegrees (double aAngle) |
A helper to convert aAngle in deci-degrees to a string in degrees. More... | |
wxString | GetAbbreviatedUnitsLabel (EDA_UNITS aUnit, EDA_DATA_TYPE aType) |
Get the units string for a given units type. More... | |
std::string | FormatInternalUnits (int aValue) |
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing to file. More... | |
std::string | FormatAngle (double aAngle) |
Function FormatAngle converts aAngle from board units to a string appropriate for writing to file. More... | |
std::string | FormatInternalUnits (const wxPoint &aPoint) |
std::string | FormatInternalUnits (const VECTOR2I &aPoint) |
std::string | FormatInternalUnits (const wxSize &aSize) |
Code to handle objects that require both schematic and board internal units.
Definition in file base_units.cpp.
wxString AngleToStringDegrees | ( | double | aAngle | ) |
A helper to convert aAngle in deci-degrees to a string in degrees.
Function AngleToStringDegrees is a helper to convert the double aAngle (in internal unit) to a string in degrees.
Definition at line 461 of file base_units.cpp.
References StripTrailingZeros().
Referenced by PANEL_EDIT_OPTIONS::TransferDataToWindow().
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 61 of file base_units.cpp.
Referenced by GBR_TO_PCB_EXPORTER::export_non_copper_item(), GBR_TO_PCB_EXPORTER::export_via(), PCB_IO::format(), BOARD_STACKUP::FormatBoardStackup(), PCB_IO::formatSetup(), formatStroke(), SCH_SEXPR_PLUGIN::saveJunction(), GBR_TO_PCB_EXPORTER::writeCopperLineItem(), GBR_TO_PCB_EXPORTER::writePcbPolygon(), and GBR_TO_PCB_EXPORTER::writePcbZoneItem().
double DoubleValueFromString | ( | EDA_UNITS | aUnits, |
const wxString & | aTextValue, | ||
EDA_DATA_TYPE | aType = EDA_DATA_TYPE::DISTANCE |
||
) |
Function DoubleValueFromString converts aTextValue to a double.
aUnits | The units of aTextValue. |
aTextValue | A reference to a wxString object containing the string to convert. |
Definition at line 338 of file base_units.cpp.
References AREA, DEGREES, DISTANCE, From_User_Unit(), INCHES, KI_FALLTHROUGH, MILLIMETRES, MILS, and VOLUME.
Referenced by PCB_UNIT_RESOLVER::Convert(), PROPERTIES_FRAME::CopyPrmsFromPanelToItem(), PANEL_PREV_3D::doIncrementOffset(), PANEL_PREV_3D::doIncrementRotation(), PANEL_PREV_3D::doIncrementScale(), LIBEVAL::COMPILER::generateUCode(), UNIT_BINDER::GetDoubleValue(), DIALOG_BOARD_REANNOTATE::GetParameters(), DIALOG_IMPORT_GFX::getPCBdefaultLineWidthMM(), DIALOG_EXPORT_STEP::GetXOrg(), DIALOG_EXPORT_IDF3::GetXRef(), DIALOG_EXPORT_3DFILE::GetXRef(), DIALOG_EXPORT_STEP::GetYOrg(), DIALOG_EXPORT_IDF3::GetYRef(), DIALOG_EXPORT_3DFILE::GetYRef(), PANEL_PREV_3D::onMouseWheelOffset(), PANEL_PREV_3D::onMouseWheelRot(), PANEL_PREV_3D::onMouseWheelScale(), rotationFromString(), FP_TEXT_GRID_TABLE::SetValue(), DIALOG_CREATE_ARRAY::TransferDataFromWindow(), DIALOG_IMPORT_GFX::TransferDataFromWindow(), DIALOG_PAD_PRIMITIVES_TRANSFORM::Transform(), PANEL_PREV_3D::updateOrientation(), DIALOG_IMPORT_GFX::updatePcbImportOffsets_mm(), and ValueFromString().
void FetchUnitsFromString | ( | const wxString & | aTextValue, |
EDA_UNITS & | aUnits | ||
) |
Function FetchUnitsFromString writes any unit info found in the string to aUnits.
Definition at line 422 of file base_units.cpp.
References DEGREES, INCHES, MILLIMETRES, and MILS.
Referenced by PCB_PARSER::parseDIMENSION().
std::string FormatAngle | ( | double | aAngle | ) |
Function FormatAngle converts aAngle from board units to a string appropriate for writing to file.
aAngle | A angle value to convert. |
Definition at line 568 of file base_units.cpp.
Referenced by DIALOG_PAD_PROPERTIES::displayPrimitivesList(), PCB_IO::format(), SCH_SEXPR_PLUGIN::saveField(), SCH_SEXPR_PLUGIN_CACHE::savePin(), SCH_SEXPR_PLUGIN::saveSheet(), SCH_SEXPR_PLUGIN::saveSymbol(), and SCH_SEXPR_PLUGIN::saveText().
std::string FormatInternalUnits | ( | int | aValue | ) |
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing to file.
aValue | A coordinate value to convert. |
Definition at line 533 of file base_units.cpp.
References IU_PER_MM, and NULL.
Referenced by BOOST_AUTO_TEST_CASE(), PCB_IO::format(), EDA_TEXT::Format(), BOARD_STACKUP::FormatBoardStackup(), PCB_IO::formatGeneral(), FormatInternalUnits(), PCB_IO::formatSetup(), formatStroke(), SCH_SEXPR_PLUGIN_CACHE::saveArc(), SCH_SEXPR_PLUGIN_CACHE::saveBezier(), SCH_SEXPR_PLUGIN::saveBitmap(), SCH_SEXPR_PLUGIN::saveBusEntry(), SCH_SEXPR_PLUGIN_CACHE::saveCircle(), SCH_SEXPR_PLUGIN::saveField(), SCH_SEXPR_PLUGIN_CACHE::saveField(), SCH_SEXPR_PLUGIN::saveJunction(), SCH_SEXPR_PLUGIN::saveLine(), SCH_SEXPR_PLUGIN::saveNoConnect(), SCH_SEXPR_PLUGIN_CACHE::savePin(), SCH_SEXPR_PLUGIN_CACHE::savePolyLine(), SCH_SEXPR_PLUGIN_CACHE::saveRectangle(), SCH_SEXPR_PLUGIN::saveSheet(), SCH_SEXPR_PLUGIN::saveSymbol(), SCH_SEXPR_PLUGIN_CACHE::SaveSymbol(), SCH_SEXPR_PLUGIN::saveText(), and SCH_SEXPR_PLUGIN_CACHE::saveText().
std::string FormatInternalUnits | ( | const wxPoint & | aPoint | ) |
Definition at line 579 of file base_units.cpp.
References FormatInternalUnits().
std::string FormatInternalUnits | ( | const VECTOR2I & | aPoint | ) |
Definition at line 585 of file base_units.cpp.
References FormatInternalUnits(), VECTOR2< T >::x, and VECTOR2< T >::y.
std::string FormatInternalUnits | ( | const wxSize & | aSize | ) |
Definition at line 591 of file base_units.cpp.
References FormatInternalUnits().
double From_User_Unit | ( | EDA_UNITS | aUnits, |
double | aValue | ||
) |
Return in internal units the value "val" given in a real unit such as "in", "mm" or "deg".
Definition at line 313 of file base_units.cpp.
References DEGREES, INCHES, MILLIMETRES, MILS, PERCENT, and UNSCALED.
Referenced by PROPERTIES_FRAME::CopyPrmsFromGeneralToPanel(), PROPERTIES_FRAME::CopyPrmsFromItemToPanel(), DoubleValueFromString(), FOOTPRINT_EDITOR_SETTINGS::MigrateFromLegacy(), PCBNEW_SETTINGS::MigrateFromLegacy(), UNIT_BINDER::setPrecision(), and UNIT_BINDER::Validate().
wxString GetAbbreviatedUnitsLabel | ( | EDA_UNITS | aUnit, |
EDA_DATA_TYPE | aType = EDA_DATA_TYPE::DISTANCE |
||
) |
Get the units string for a given units type.
aUnits | - The units requested. |
aType | - The data type of the unit (e.g. distance, area, etc.) |
Definition at line 472 of file base_units.cpp.
References _, AREA, DEGREES, DISTANCE, INCHES, KI_FALLTHROUGH, MILLIMETRES, MILS, PERCENT, UNSCALED, and VOLUME.
Referenced by DIALOG_PLOT::applyPlotSettings(), UNIT_BINDER::ChangeValue(), ComboBoxUnits(), DIALOG_TRACK_VIA_PROPERTIES::DIALOG_TRACK_VIA_PROPERTIES(), KIGFX::PREVIEW::DimensionLabel(), PANEL_PREV_3D::formatOffsetValue(), PANEL_PREV_3D::formatRotationValue(), FP_TEXT_GRID_TABLE::FP_TEXT_GRID_TABLE(), DIMENSION_BASE::GetMsgPanelInfo(), MessageTextFromValue(), UNIT_BINDER::SetDataType(), UNIT_BINDER::SetUnits(), UNIT_BINDER::SetValue(), UNIT_BINDER::UNIT_BINDER(), and DIMENSION_BASE::updateText().
wxString MessageTextFromValue | ( | EDA_UNITS | aUnits, |
int | aValue, | ||
bool | aAddUnitLabel, | ||
EDA_DATA_TYPE | aType | ||
) |
Convert a value to a string using double notation.
For readability, the mantissa has 0, 1, 3 or 4 digits, depending on units for unit = inch the mantissa has 3 digits (Eeschema) or 4 digits for unit = mil the mantissa has 0 digits (Eeschema) or 1 digits for unit = mm the mantissa has 3 digits (Eeschema) or 4 digits Should be used only to display info in status, but not in dialogs, because 4 digits only could truncate the actual value
Definition at line 125 of file base_units.cpp.
References MessageTextFromValue().
Referenced by GRID_MENU::BuildChoiceList(), DRC_TEST_PROVIDER_MATCHED_LENGTH::checkLengthViolations(), DRC_TEST_PROVIDER_HOLE_SIZE::checkPad(), DRC_TEST_PROVIDER_MATCHED_LENGTH::checkSkewViolations(), DRC_TEST_PROVIDER_HOLE_SIZE::checkVia(), DIALOG_BOARD_REANNOTATE::CoordTowxString(), GERBVIEW_FRAME::DisplayGridMsg(), EDA_DRAW_FRAME::DisplayGridMsg(), PCB_BASE_FRAME::DisplayGridMsg(), DIALOG_PAD_PROPERTIES::displayPrimitivesList(), DRC_ENGINE::EvalRules(), formatCoord(), DIALOG_NET_INSPECTOR::formatLength(), LIB_CIRCLE::GetMsgPanelInfo(), LIB_RECTANGLE::GetMsgPanelInfo(), SCH_PIN::GetMsgPanelInfo(), LIB_ARC::GetMsgPanelInfo(), LIB_POLYLINE::GetMsgPanelInfo(), LIB_TEXT::GetMsgPanelInfo(), PL_EDITOR_LAYOUT::GetMsgPanelInfo(), LIB_BEZIER::GetMsgPanelInfo(), PCB_TEXT::GetMsgPanelInfo(), DS_DRAW_ITEM_BASE::GetMsgPanelInfo(), PCB_TARGET::GetMsgPanelInfo(), ZONE::GetMsgPanelInfo(), SCH_BITMAP::GetMsgPanelInfo(), NETINFO_ITEM::GetMsgPanelInfo(), LIB_FIELD::GetMsgPanelInfo(), TRACK::GetMsgPanelInfo(), FP_TEXT::GetMsgPanelInfo(), LIB_PIN::GetMsgPanelInfo(), DIMENSION_BASE::GetMsgPanelInfo(), PCB_SHAPE::GetMsgPanelInfo(), SCH_TEXT::GetMsgPanelInfo(), ALIGNED_DIMENSION::GetMsgPanelInfo(), VIA::GetMsgPanelInfo(), LEADER::GetMsgPanelInfo(), PAD::GetMsgPanelInfo(), LIB_CIRCLE::GetSelectMenuText(), LIB_RECTANGLE::GetSelectMenuText(), LIB_ARC::GetSelectMenuText(), DS_DRAW_ITEM_LINE::GetSelectMenuText(), TRACK::GetSelectMenuText(), SCH_LINE::GetSelectMenuText(), DS_DRAW_ITEM_RECT::GetSelectMenuText(), DIALOG_BOARD_REANNOTATE::MakeSampleText(), MessageTextFromValue(), DRC_TEST_PROVIDER_VIA_DIAMETER::Run(), DRC_TEST_PROVIDER_TRACK_WIDTH::Run(), DRC_TEST_PROVIDER_ANNULUS::Run(), DRC_TEST_PROVIDER_SILK_TO_MASK::Run(), DRC_TEST_PROVIDER_SILK_CLEARANCE::Run(), test::DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING::Run(), DRC_TEST_PROVIDER_MATCHED_LENGTH::runInternal(), DIALOG_BOARD_STATISTICS::saveReportClicked(), RC_ITEM::ShowCoord(), DRC_TEST_PROVIDER_EDGE_CLEARANCE::testAgainstEdge(), DRC_TEST_PROVIDER_COURTYARD_CLEARANCE::testCourtyardClearances(), DRC_TEST_PROVIDER_HOLE_CLEARANCE::testHoleAgainstHole(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::testItemAgainstZones(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::testPadAgainstItem(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::testTrackAgainstItem(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::testZones(), PNS::MEANDER_SKEW_PLACER::TuningInfo(), PNS::MEANDER_PLACER::TuningInfo(), PNS::DP_MEANDER_PLACER::TuningInfo(), VIA_SIZE_MENU::update(), TRACK_WIDTH_MENU::update(), DIFF_PAIR_MENU::update(), DIALOG_BOARD_STATISTICS::updateDrillGrid(), GERBVIEW_FRAME::UpdateStatusBar(), SCH_BASE_FRAME::UpdateStatusBar(), PCB_BASE_FRAME::UpdateStatusBar(), and DIALOG_BOARD_STATISTICS::updateWidets().
wxString MessageTextFromValue | ( | EDA_UNITS | aUnits, |
long long int | aValue, | ||
bool | aAddUnitLabel, | ||
EDA_DATA_TYPE | aType | ||
) |
Definition at line 133 of file base_units.cpp.
References MessageTextFromValue().
wxString MessageTextFromValue | ( | EDA_UNITS | aUnits, |
double | aValue, | ||
bool | aAddUnitLabel = true , |
||
EDA_DATA_TYPE | aType = EDA_DATA_TYPE::DISTANCE |
||
) |
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.
aUnits | The units to show the value in. The unit string is added to the message text. |
aValue | The double value to convert. |
aAddUnitLabel | If true, adds the unit label to the end of the string |
aType | Type of the unit being used (e.g. distance, area, etc.) |
Definition at line 141 of file base_units.cpp.
References AREA, DEGREES, DISTANCE, GetAbbreviatedUnitsLabel(), INCHES, KI_FALLTHROUGH, MILLIMETRES, MILS, To_User_Unit(), UNSCALED, and VOLUME.
wxString StringFromValue | ( | EDA_UNITS | aUnits, |
double | aValue, | ||
bool | aAddUnitSymbol, | ||
EDA_DATA_TYPE | aType | ||
) |
Convert a value to a string using double notation.
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, 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.
Definition at line 225 of file base_units.cpp.
References AREA, DEGREES, DISTANCE, Format(), INCHES, KI_FALLTHROUGH, MILLIMETRES, MILS, PERCENT, StripTrailingZeros(), To_User_Unit(), UNSCALED, and VOLUME.
Referenced by PANEL_SETUP_TRACKS_AND_VIAS::AppendDiffPairs(), PANEL_SETUP_TRACKS_AND_VIAS::AppendTrackWidth(), PANEL_SETUP_TRACKS_AND_VIAS::AppendViaSize(), DIALOG_PLOT::applyPlotSettings(), BuildStackupReport(), UNIT_BINDER::ChangeValue(), MICROWAVE_TOOL::createFootprint(), MICROWAVE_TOOL::createMicrowaveInductor(), PANEL_SETUP_BOARD_STACKUP::createRowData(), DIALOG_TRACK_VIA_PROPERTIES::DIALOG_TRACK_VIA_PROPERTIES(), SCH_PIN::GetMsgPanelInfo(), LIB_PIN::GetMsgPanelInfo(), FP_TEXT_GRID_TABLE::GetValue(), PIN_TABLE_DATA_MODEL::GetValue(), FIELDS_GRID_TABLE< SCH_FIELD >::GetValue(), DIALOG_PLOT::init_Dialog(), DIALOG_PAD_PROPERTIES::initValues(), BOARD_INSPECTION_TOOL::InspectConstraints(), FOOTPRINT_EDITOR_SETTINGS::MigrateFromLegacy(), PCBNEW_SETTINGS::MigrateFromLegacy(), PANEL_SETUP_BOARD_STACKUP::onUpdateThicknessValue(), BOARD_INSPECTION_TOOL::reportClearance(), BOARD_INSPECTION_TOOL::reportZoneConnection(), UNIT_BINDER::SetDoubleValue(), UNIT_BINDER::SetValue(), EDA_POSITION_CTRL::SetValue(), PANEL_SETUP_BOARD_STACKUP::synchronizeWithBoard(), DIALOG_GRID_SETTINGS::TransferDataFromWindow(), PANEL_SETUP_CONSTRAINTS::TransferDataToWindow(), DIALOG_PAD_PRIMITIVE_POLY_PROPS::TransferDataToWindow(), PANEL_SETUP_TRACKS_AND_VIAS::Validate(), and UNIT_BINDER::Validate().
double To_User_Unit | ( | EDA_UNITS | aUnit, |
double | aValue | ||
) |
Function To_User_Unit convert aValue in internal units to the appropriate user units defined by aUnit.
aUnit | The units to convert aValue to. |
aValue | The value in internal units to convert. |
Definition at line 91 of file base_units.cpp.
References DEGREES, INCHES, MILLIMETRES, and MILS.
Referenced by ComboBoxUnits(), PROPERTIES_FRAME::CopyPrmsFromPanelToGeneral(), PROPERTIES_FRAME::CopyPrmsFromPanelToItem(), KIGFX::PREVIEW::DimensionLabel(), PL_EDITOR_FRAME::DisplayGridMsg(), DIMENSION_BASE::GetValueText(), MessageTextFromValue(), UNIT_BINDER::setPrecision(), StringFromValue(), and PL_EDITOR_FRAME::UpdateStatusBar().
long long int ValueFromString | ( | EDA_UNITS | aUnits, |
const wxString & | aTextValue, | ||
EDA_DATA_TYPE | aType = EDA_DATA_TYPE::DISTANCE |
||
) |
Function ValueFromString converts aTextValue in aUnits to internal units used by the application.
aUnits | The units of aTextValue. |
aTextValue | A reference to a wxString object containing the string to convert. |
Definition at line 451 of file base_units.cpp.
References DoubleValueFromString().
Referenced by GRID_MENU::BuildChoiceList(), PIN_TABLE_DATA_MODEL::compare(), MICROWAVE_TOOL::createFootprint(), MICROWAVE_TOOL::createMicrowaveInductor(), PANEL_FP_EDITOR_DEFAULTS::getGridValue(), PANEL_SETUP_TEXT_AND_GRAPHICS::getGridValue(), DIALOG_ANNOTATE::GetStartNumber(), EDA_POSITION_CTRL::GetValue(), UNIT_BINDER::GetValue(), FOOTPRINT_PREVIEW_PANEL::New(), DIALOG_PAD_PRIMITIVE_POLY_PROPS::onCellChanging(), PANEL_SETUP_BOARD_STACKUP::onThicknessChange(), PANEL_SETUP_BOARD_STACKUP::onUpdateThicknessValue(), COMMON_TOOLS::Reset(), FP_TEXT_GRID_TABLE::SetValue(), FIELDS_GRID_TABLE< SCH_FIELD >::SetValue(), PIN_TABLE_DATA_MODEL::SetValue(), PANEL_SETUP_BOARD_STACKUP::transferDataFromUIToStackup(), PANEL_SETUP_TRACKS_AND_VIAS::TransferDataFromWindow(), DIALOG_GRID_SETTINGS::TransferDataToWindow(), and PANEL_SETUP_TRACKS_AND_VIAS::Validate().