|
KiCad PCB EDA Suite
|
Converts PADS file format units to KiCad internal units (nanometers). More...
#include <pads_unit_converter.h>
Public Member Functions | |
| PADS_UNIT_CONVERTER () | |
| void | SetBaseUnits (PADS_UNIT_TYPE aUnitType) |
| Set the base units for conversion. | |
| PADS_UNIT_TYPE | GetUnitType () const |
| Get the current unit type. | |
| void | SetBasicUnitsMode (bool aEnabled) |
| Enable or disable BASIC units mode. | |
| bool | IsBasicUnitsMode () const |
| Check if BASIC units mode is enabled. | |
| void | SetBasicUnitsScale (double aScale) |
| Set a custom scale for BASIC units. | |
| double | GetBasicUnitsScale () const |
| Get the current BASIC units scale. | |
| bool | ParseFileHeader (const std::string &aHeader) |
| Parse a PADS file header string and configure units accordingly. | |
| bool | PushUnitOverride (const std::string &aUnitCode) |
| Push a unit override onto the stack. | |
| void | PopUnitOverride () |
| Pop the most recent unit override from the stack. | |
| bool | HasUnitOverride () const |
| Check if any unit overrides are currently active. | |
| size_t | GetOverrideDepth () const |
| Get the current override depth. | |
| int64_t | ToNanometers (double aValue) const |
| Convert a coordinate value to nanometers. | |
| int64_t | ToNanometersSize (double aValue) const |
| Convert a size value to nanometers. | |
Static Public Member Functions | |
| static std::optional< PADS_UNIT_TYPE > | ParseUnitCode (const std::string &aUnitCode) |
| Parse a PADS unit code and return the corresponding unit type. | |
Static Public Attributes | |
| static constexpr double | MILS_TO_NM = 25400.0 |
| static constexpr double | MM_TO_NM = 1000000.0 |
| static constexpr double | INCHES_TO_NM = 25400000.0 |
| static constexpr double | BASIC_TO_NM = MILS_TO_NM / 38100.0 |
Private Member Functions | |
| void | updateScaleFactor () |
Private Attributes | |
| PADS_UNIT_TYPE | m_unitType |
| double | m_scaleFactor |
| bool | m_basicUnitsMode |
| double | m_basicUnitsScale |
| std::vector< PADS_UNIT_TYPE > | m_unitOverrideStack |
Converts PADS file format units to KiCad internal units (nanometers).
PADS files can use different unit systems: MILS, METRIC (mm), or INCHES. Additionally, files can use BASIC units which are internal database units. This class handles conversion from any of these to KiCad's internal nanometer representation.
Definition at line 46 of file pads_unit_converter.h.
| PADS_UNIT_CONVERTER::PADS_UNIT_CONVERTER | ( | ) |
Definition at line 24 of file pads_unit_converter.cpp.
References BASIC_TO_NM, m_basicUnitsMode, m_basicUnitsScale, m_scaleFactor, m_unitType, MILS, and MILS_TO_NM.
|
inline |
Get the current BASIC units scale.
Definition at line 98 of file pads_unit_converter.h.
References m_basicUnitsScale.
Referenced by BOOST_AUTO_TEST_CASE().
|
inline |
Get the current override depth.
Definition at line 160 of file pads_unit_converter.h.
References m_unitOverrideStack.
Referenced by BOOST_AUTO_TEST_CASE().
|
inline |
Get the current unit type.
Definition at line 63 of file pads_unit_converter.h.
References m_unitType.
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().
|
inline |
Check if any unit overrides are currently active.
Definition at line 153 of file pads_unit_converter.h.
References m_unitOverrideStack.
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().
|
inline |
Check if BASIC units mode is enabled.
Definition at line 81 of file pads_unit_converter.h.
References m_basicUnitsMode.
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().
| bool PADS_UNIT_CONVERTER::ParseFileHeader | ( | const std::string & | aHeader | ) |
Parse a PADS file header string and configure units accordingly.
Detects BASIC mode from header strings like "!PADS-POWERPCB-V9.0-BASIC!" and unit types from strings like "!PADS-POWERPCB-V9.5-MILS!".
| aHeader | The file header string to parse. |
Definition at line 56 of file pads_unit_converter.cpp.
References INCHES, METRIC, MILS, SetBaseUnits(), and SetBasicUnitsMode().
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().
|
static |
Parse a PADS unit code and return the corresponding unit type.
PADS uses short codes in parts and decals to specify local unit overrides:
| aUnitCode | The unit code string to parse. |
Definition at line 95 of file pads_unit_converter.cpp.
References INCHES, METRIC, and MILS.
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and PushUnitOverride().
| void PADS_UNIT_CONVERTER::PopUnitOverride | ( | ) |
Pop the most recent unit override from the stack.
Removes the most recent override, reverting to the previous unit setting (either another override or the base units).
Definition at line 142 of file pads_unit_converter.cpp.
References m_unitOverrideStack, and updateScaleFactor().
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().
| bool PADS_UNIT_CONVERTER::PushUnitOverride | ( | const std::string & | aUnitCode | ) |
Push a unit override onto the stack.
PADS parts and decals can specify their own units that temporarily override the file's base units. This pushes an override onto the stack, affecting all subsequent conversions until popped.
| aUnitCode | The unit code string (e.g., "M", "MM", "I"). |
Definition at line 129 of file pads_unit_converter.cpp.
References m_unitOverrideStack, ParseUnitCode(), and updateScaleFactor().
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().
| void PADS_UNIT_CONVERTER::SetBaseUnits | ( | PADS_UNIT_TYPE | aUnitType | ) |
Set the base units for conversion.
| aUnitType | The unit type used in the PADS file. |
Definition at line 33 of file pads_unit_converter.cpp.
References m_unitType, and updateScaleFactor().
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and ParseFileHeader().
| void PADS_UNIT_CONVERTER::SetBasicUnitsMode | ( | bool | aEnabled | ) |
Enable or disable BASIC units mode.
BASIC units are PADS internal database units at 1/38100 mil resolution. When enabled, coordinate values are interpreted as BASIC units regardless of the base unit type.
| aEnabled | True to enable BASIC units mode. |
Definition at line 40 of file pads_unit_converter.cpp.
References m_basicUnitsMode, and updateScaleFactor().
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and ParseFileHeader().
| void PADS_UNIT_CONVERTER::SetBasicUnitsScale | ( | double | aScale | ) |
Set a custom scale for BASIC units.
Some PADS files may use non-standard BASIC unit scales. The default scale is MILS_TO_NM / 38100.0 (1/38100 mil per unit).
| aScale | The scale factor in nanometers per BASIC unit. |
Definition at line 47 of file pads_unit_converter.cpp.
References m_basicUnitsMode, m_basicUnitsScale, and updateScaleFactor().
Referenced by BOOST_AUTO_TEST_CASE().
| int64_t PADS_UNIT_CONVERTER::ToNanometers | ( | double | aValue | ) | const |
Convert a coordinate value to nanometers.
This is the primary conversion function for positional values.
| aValue | The value in PADS file units. |
Definition at line 182 of file pads_unit_converter.cpp.
References m_scaleFactor.
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().
| int64_t PADS_UNIT_CONVERTER::ToNanometersSize | ( | double | aValue | ) | const |
Convert a size value to nanometers.
Size values (widths, heights, radii) use the same conversion as coordinates but may have different rounding behavior in the future.
| aValue | The size value in PADS file units. |
Definition at line 188 of file pads_unit_converter.cpp.
References m_scaleFactor.
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().
|
private |
Definition at line 152 of file pads_unit_converter.cpp.
References INCHES, INCHES_TO_NM, m_basicUnitsMode, m_basicUnitsScale, m_scaleFactor, m_unitOverrideStack, m_unitType, METRIC, MILS, MILS_TO_NM, and MM_TO_NM.
Referenced by PopUnitOverride(), PushUnitOverride(), SetBaseUnits(), SetBasicUnitsMode(), and SetBasicUnitsScale().
|
staticconstexpr |
Definition at line 187 of file pads_unit_converter.h.
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), PCB_IO_PADS::loadBoardSetup(), PCB_IO_PADS_BINARY::loadBoardSetup(), and PADS_UNIT_CONVERTER().
|
staticconstexpr |
Definition at line 186 of file pads_unit_converter.h.
Referenced by BOOST_AUTO_TEST_CASE(), PCB_IO_PADS::loadBoardSetup(), PCB_IO_PADS::loadFootprints(), and updateScaleFactor().
|
private |
Definition at line 194 of file pads_unit_converter.h.
Referenced by IsBasicUnitsMode(), PADS_UNIT_CONVERTER(), SetBasicUnitsMode(), SetBasicUnitsScale(), and updateScaleFactor().
|
private |
Definition at line 195 of file pads_unit_converter.h.
Referenced by GetBasicUnitsScale(), PADS_UNIT_CONVERTER(), SetBasicUnitsScale(), and updateScaleFactor().
|
private |
Definition at line 193 of file pads_unit_converter.h.
Referenced by PADS_UNIT_CONVERTER(), ToNanometers(), ToNanometersSize(), and updateScaleFactor().
|
private |
Definition at line 196 of file pads_unit_converter.h.
Referenced by GetOverrideDepth(), HasUnitOverride(), PopUnitOverride(), PushUnitOverride(), and updateScaleFactor().
|
private |
Definition at line 192 of file pads_unit_converter.h.
Referenced by GetUnitType(), PADS_UNIT_CONVERTER(), SetBaseUnits(), and updateScaleFactor().
|
staticconstexpr |
Definition at line 184 of file pads_unit_converter.h.
Referenced by BOOST_AUTO_TEST_CASE(), PCB_IO_PADS::loadBoardSetup(), PCB_IO_PADS::loadFootprints(), PADS_UNIT_CONVERTER(), and updateScaleFactor().
|
staticconstexpr |
Definition at line 185 of file pads_unit_converter.h.
Referenced by BOOST_AUTO_TEST_CASE(), PCB_IO_PADS::generateDrcRules(), PCB_IO_PADS::loadBoardSetup(), PCB_IO_PADS::loadFootprints(), and updateScaleFactor().