Correctly format pad-to-die delays in sexpr format
This commit is contained in:
+15
-2
@@ -191,12 +191,13 @@ std::string EDA_UNIT_UTILS::FormatAngle( const EDA_ANGLE& aAngle )
|
||||
}
|
||||
|
||||
|
||||
std::string EDA_UNIT_UTILS::FormatInternalUnits( const EDA_IU_SCALE& aIuScale, int aValue )
|
||||
std::string EDA_UNIT_UTILS::FormatInternalUnits( const EDA_IU_SCALE& aIuScale, const int aValue,
|
||||
const EDA_DATA_TYPE aDataType )
|
||||
{
|
||||
std::string buf;
|
||||
double engUnits = aValue;
|
||||
|
||||
engUnits /= aIuScale.IU_PER_MM;
|
||||
engUnits /= GetScaleForInternalUnitType( aIuScale, aDataType );
|
||||
|
||||
if( engUnits != 0.0 && fabs( engUnits ) <= 0.0001 )
|
||||
{
|
||||
@@ -232,6 +233,18 @@ std::string EDA_UNIT_UTILS::FormatInternalUnits( const EDA_IU_SCALE& aIuScale,
|
||||
}
|
||||
|
||||
|
||||
double EDA_UNIT_UTILS::GetScaleForInternalUnitType( const EDA_IU_SCALE& aIuScale, const EDA_DATA_TYPE aDataType )
|
||||
{
|
||||
switch( aDataType )
|
||||
{
|
||||
case EDA_DATA_TYPE::TIME: return aIuScale.IU_PER_PS;
|
||||
case EDA_DATA_TYPE::LENGTH_DELAY: return aIuScale.IU_PER_PS_PER_MM;
|
||||
case EDA_DATA_TYPE::UNITLESS: return 1.0;
|
||||
default: return aIuScale.IU_PER_MM;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if 0 // No support for std::from_chars on MacOS yet
|
||||
|
||||
bool EDA_UNIT_UTILS::ParseInternalUnits( const std::string& aInput, const EDA_IU_SCALE& aIuScale,
|
||||
|
||||
+11
-2
@@ -129,13 +129,22 @@ namespace EDA_UNIT_UTILS
|
||||
* on how KiCad is built.
|
||||
*
|
||||
* @param aValue A coordinate value to convert.
|
||||
* @param aDataType The EDA_UNITS data type for @param aValue
|
||||
* @return A std::string object containing the converted value.
|
||||
*/
|
||||
KICOMMON_API std::string FormatInternalUnits( const EDA_IU_SCALE& aIuScale, int aValue );
|
||||
KICOMMON_API std::string FormatInternalUnits( const EDA_IU_SCALE& aIuScale, int aValue,
|
||||
EDA_DATA_TYPE aDataType = EDA_DATA_TYPE::DISTANCE );
|
||||
KICOMMON_API std::string FormatInternalUnits( const EDA_IU_SCALE& aIuScale,
|
||||
const VECTOR2I& aPoint );
|
||||
|
||||
#if 0 // No support for std::from_chars on MacOS yet
|
||||
/**
|
||||
* Returns the scaling parameter for the given units data type
|
||||
*
|
||||
* This should only be used when scaling for writing to files as it assumes metric distances are being used
|
||||
*/
|
||||
KICOMMON_API double GetScaleForInternalUnitType( const EDA_IU_SCALE& aIuScale, EDA_DATA_TYPE aDataType );
|
||||
|
||||
#if 0 // No support for std::from_chars on MacOS yet
|
||||
/**
|
||||
* Convert \a aInput string to internal units when reading from a file.
|
||||
*
|
||||
|
||||
@@ -435,9 +435,9 @@ void PCB_IO_KICAD_SEXPR::Format( const BOARD_ITEM* aItem ) const
|
||||
}
|
||||
|
||||
|
||||
std::string formatInternalUnits( int aValue )
|
||||
std::string formatInternalUnits( const int aValue, const EDA_DATA_TYPE aDataType = EDA_DATA_TYPE::DISTANCE )
|
||||
{
|
||||
return EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aValue );
|
||||
return EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aValue, aDataType );
|
||||
}
|
||||
|
||||
|
||||
@@ -1756,7 +1756,7 @@ void PCB_IO_KICAD_SEXPR::format( const PAD* aPad ) const
|
||||
|
||||
if( aPad->GetPadToDieDelay() != 0 )
|
||||
{
|
||||
m_out->Print( "(die_delay %s)", formatInternalUnits( aPad->GetPadToDieDelay() ).c_str() );
|
||||
m_out->Print( "(die_delay %s)", formatInternalUnits( aPad->GetPadToDieDelay(), EDA_DATA_TYPE::TIME ).c_str() );
|
||||
}
|
||||
|
||||
if( aPad->GetLocalSolderMaskMargin().has_value() )
|
||||
|
||||
@@ -195,7 +195,8 @@ class PCB_IO_KICAD_SEXPR; // forward decl
|
||||
//#define SEXPR_BOARD_FILE_VERSION 20250907 // uuids for tables
|
||||
//#define SEXPR_BOARD_FILE_VERSION 20250909 // footprint unit metadata (units/pins)
|
||||
//#define SEXPR_BOARD_FILE_VERSION 20250914 // Add support for PCB_BARCODE objects
|
||||
#define SEXPR_BOARD_FILE_VERSION 20250926 // Split via types into blind/buried/through
|
||||
//#define SEXPR_BOARD_FILE_VERSION 20250926 // Split via types into blind/buried/through
|
||||
#define SEXPR_BOARD_FILE_VERSION 20251027 // Store pad-to-die delays with correct scaling
|
||||
|
||||
#define BOARD_FILE_HOST_VERSION 20200825 ///< Earlier files than this include the host tag
|
||||
#define LEGACY_ARC_FORMATTING 20210925 ///< These were the last to use old arc formatting
|
||||
|
||||
@@ -211,9 +211,11 @@ int PCB_IO_KICAD_SEXPR_PARSER::parseBoardUnits()
|
||||
}
|
||||
|
||||
|
||||
int PCB_IO_KICAD_SEXPR_PARSER::parseBoardUnits( const char* aExpected )
|
||||
int PCB_IO_KICAD_SEXPR_PARSER::parseBoardUnits( const char* aExpected,
|
||||
const EDA_DATA_TYPE aDataType = EDA_DATA_TYPE::DISTANCE )
|
||||
{
|
||||
auto retval = parseDouble( aExpected ) * pcbIUScale.IU_PER_MM;
|
||||
const double scale = EDA_UNIT_UTILS::GetScaleForInternalUnitType( pcbIUScale, aDataType );
|
||||
auto retval = parseDouble( aExpected ) * scale;
|
||||
|
||||
// N.B. we currently represent board units as integers. Any values that are
|
||||
// larger or smaller than those board units represent undefined behavior for
|
||||
@@ -5671,9 +5673,15 @@ PAD* PCB_IO_KICAD_SEXPR_PARSER::parsePAD( FOOTPRINT* aParent )
|
||||
break;
|
||||
|
||||
case T_die_delay:
|
||||
pad->SetPadToDieDelay( parseBoardUnits( T_die_delay ) );
|
||||
{
|
||||
if( m_requiredVersion <= 20250926 )
|
||||
pad->SetPadToDieDelay( parseBoardUnits( T_die_delay ) );
|
||||
else
|
||||
pad->SetPadToDieDelay( parseBoardUnits( T_die_delay, EDA_DATA_TYPE::TIME ) );
|
||||
|
||||
NeedRIGHT();
|
||||
break;
|
||||
}
|
||||
|
||||
case T_solder_mask_margin:
|
||||
pad->SetLocalSolderMaskMargin( parseBoardUnits( "local solder mask margin value" ) );
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#ifndef _PCBNEW_PARSER_H_
|
||||
#define _PCBNEW_PARSER_H_
|
||||
|
||||
#include <eda_units.h>
|
||||
#include <core/wx_stl_compat.h>
|
||||
#include <hashtables.h>
|
||||
#include <lib_id.h>
|
||||
@@ -353,11 +354,11 @@ private:
|
||||
|
||||
int parseBoardUnits();
|
||||
|
||||
int parseBoardUnits( const char* aExpected );
|
||||
int parseBoardUnits( const char* aExpected, EDA_DATA_TYPE aDataType );
|
||||
|
||||
inline int parseBoardUnits( PCB_KEYS_T::T aToken )
|
||||
inline int parseBoardUnits( const PCB_KEYS_T::T aToken, const EDA_DATA_TYPE aDataType = EDA_DATA_TYPE::DISTANCE )
|
||||
{
|
||||
return parseBoardUnits( GetTokenText( aToken ) );
|
||||
return parseBoardUnits( GetTokenText( aToken ), aDataType );
|
||||
}
|
||||
|
||||
inline int parseInt()
|
||||
|
||||
Reference in New Issue
Block a user