KiCad PCB EDA Suite
Loading...
Searching...
No Matches
PADS_UNIT_CONVERTER Class Reference

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_TYPEParseUnitCode (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_TYPEm_unitOverrideStack
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ PADS_UNIT_CONVERTER()

PADS_UNIT_CONVERTER::PADS_UNIT_CONVERTER ( )

Member Function Documentation

◆ GetBasicUnitsScale()

double PADS_UNIT_CONVERTER::GetBasicUnitsScale ( ) const
inline

Get the current BASIC units scale.

Returns
The scale factor in nanometers per BASIC unit.

Definition at line 98 of file pads_unit_converter.h.

References m_basicUnitsScale.

Referenced by BOOST_AUTO_TEST_CASE().

◆ GetOverrideDepth()

size_t PADS_UNIT_CONVERTER::GetOverrideDepth ( ) const
inline

Get the current override depth.

Returns
The number of overrides currently on the stack.

Definition at line 160 of file pads_unit_converter.h.

References m_unitOverrideStack.

Referenced by BOOST_AUTO_TEST_CASE().

◆ GetUnitType()

PADS_UNIT_TYPE PADS_UNIT_CONVERTER::GetUnitType ( ) const
inline

Get the current unit type.

Returns
The currently configured 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().

◆ HasUnitOverride()

bool PADS_UNIT_CONVERTER::HasUnitOverride ( ) const
inline

Check if any unit overrides are currently active.

Returns
True if one or more overrides are on the stack.

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().

◆ IsBasicUnitsMode()

bool PADS_UNIT_CONVERTER::IsBasicUnitsMode ( ) const
inline

Check if BASIC units mode is enabled.

Returns
True 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().

◆ ParseFileHeader()

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!".

Parameters
aHeaderThe file header string to parse.
Returns
True if the header was successfully parsed and units configured.

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().

◆ ParseUnitCode()

std::optional< PADS_UNIT_TYPE > PADS_UNIT_CONVERTER::ParseUnitCode ( const std::string & aUnitCode)
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:

  • "M" = MILS
  • "MM" = METRIC (millimeters)
  • "I" = INCHES
  • "D" = MILS (default)
  • "N" = No override (returns empty optional)
Parameters
aUnitCodeThe unit code string to parse.
Returns
The corresponding unit type, or empty optional if code is invalid or indicates no override.

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().

◆ PopUnitOverride()

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().

◆ PushUnitOverride()

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.

Parameters
aUnitCodeThe unit code string (e.g., "M", "MM", "I").
Returns
True if a valid override was pushed, false if code was invalid or indicated no override.

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().

◆ SetBaseUnits()

void PADS_UNIT_CONVERTER::SetBaseUnits ( PADS_UNIT_TYPE aUnitType)

Set the base units for conversion.

Parameters
aUnitTypeThe 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().

◆ SetBasicUnitsMode()

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.

Parameters
aEnabledTrue 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().

◆ SetBasicUnitsScale()

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).

Parameters
aScaleThe 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().

◆ ToNanometers()

int64_t PADS_UNIT_CONVERTER::ToNanometers ( double aValue) const

Convert a coordinate value to nanometers.

This is the primary conversion function for positional values.

Parameters
aValueThe value in PADS file units.
Returns
The value in nanometers (KiCad internal 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().

◆ ToNanometersSize()

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.

Parameters
aValueThe size value in PADS file units.
Returns
The size in nanometers (KiCad internal 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().

◆ updateScaleFactor()

Member Data Documentation

◆ BASIC_TO_NM

double PADS_UNIT_CONVERTER::BASIC_TO_NM = MILS_TO_NM / 38100.0
staticconstexpr

◆ INCHES_TO_NM

double PADS_UNIT_CONVERTER::INCHES_TO_NM = 25400000.0
staticconstexpr

◆ m_basicUnitsMode

bool PADS_UNIT_CONVERTER::m_basicUnitsMode
private

◆ m_basicUnitsScale

double PADS_UNIT_CONVERTER::m_basicUnitsScale
private

◆ m_scaleFactor

double PADS_UNIT_CONVERTER::m_scaleFactor
private

◆ m_unitOverrideStack

std::vector<PADS_UNIT_TYPE> PADS_UNIT_CONVERTER::m_unitOverrideStack
private

◆ m_unitType

PADS_UNIT_TYPE PADS_UNIT_CONVERTER::m_unitType
private

◆ MILS_TO_NM

double PADS_UNIT_CONVERTER::MILS_TO_NM = 25400.0
staticconstexpr

◆ MM_TO_NM

double PADS_UNIT_CONVERTER::MM_TO_NM = 1000000.0
staticconstexpr

The documentation for this class was generated from the following files: