Update target length/skew to std::optional.

Also fixes a bug in the router where the target length would
get trashed if set to maxLongLongInt.  (We'd add the default
tolerance to it sending it negative.)
This commit is contained in:
Jeff Young 2024-02-08 18:14:20 +00:00
parent e62b4f8ff4
commit ecbe1df7c1
2 changed files with 66 additions and 10 deletions

View File

@ -391,11 +391,49 @@ public:
int GetSpacing() const { return m_settings.m_spacing; }
void SetSpacing( int aValue ) { m_settings.m_spacing = aValue; }
long long int GetTargetLength() const { return m_settings.m_targetLength.Opt(); }
void SetTargetLength( long long int aValue ) { m_settings.SetTargetLength( aValue ); }
std::optional<int> GetTargetLength() const
{
if( m_unconstrained )
return std::optional<int>();
else
return m_settings.m_targetLength.Opt();
}
int GetTargetSkew() const { return m_settings.m_targetSkew.Opt(); }
void SetTargetSkew( int aValue ) { m_settings.SetTargetSkew( aValue ); }
void SetTargetLength( std::optional<int> aValue )
{
if( aValue.has_value() )
{
m_unconstrained = false;
m_settings.SetTargetLength( aValue.value() );
}
else
{
m_unconstrained = true;
m_settings.SetTargetLength( std::numeric_limits<long long int>::max() );
}
}
std::optional<int> GetTargetSkew() const
{
if( m_unconstrained )
return std::optional<int>();
else
return m_settings.m_targetSkew.Opt();
}
void SetTargetSkew( std::optional<int> aValue )
{
if( aValue.has_value() )
{
m_unconstrained = false;
m_settings.SetTargetSkew( aValue.value() );
}
else
{
m_unconstrained = true;
m_settings.SetTargetSkew( std::numeric_limits<int>::max() );
}
}
bool GetOverrideCustomRules() const { return m_settings.m_overrideCustomRules; }
void SetOverrideCustomRules( bool aOverride ) { m_settings.m_overrideCustomRules = aOverride; }
@ -2371,7 +2409,7 @@ static struct PCB_TUNING_PATTERN_DESC
return !isSkew( aItem );
};
propMgr.AddProperty( new PROPERTY<PCB_TUNING_PATTERN, long long int>(
propMgr.AddProperty( new PROPERTY<PCB_TUNING_PATTERN, std::optional<int>>(
_HKI( "Target Length" ),
&PCB_TUNING_PATTERN::SetTargetLength,
&PCB_TUNING_PATTERN::GetTargetLength,
@ -2380,7 +2418,7 @@ static struct PCB_TUNING_PATTERN_DESC
.SetAvailableFunc( notIsSkew );
propMgr.AddProperty( new PROPERTY<PCB_TUNING_PATTERN, int>(
propMgr.AddProperty( new PROPERTY<PCB_TUNING_PATTERN, std::optional<int>>(
_HKI( "Target Skew" ), &PCB_TUNING_PATTERN::SetTargetSkew,
&PCB_TUNING_PATTERN::GetTargetSkew,
PROPERTY_DISPLAY::PT_SIZE, ORIGIN_TRANSFORMS::ABS_X_COORD ),

View File

@ -91,8 +91,17 @@ public:
void SetTargetLength( long long int aOpt )
{
m_targetLength.SetOpt( aOpt );
m_targetLength.SetMin( aOpt - DEFAULT_TOLERANCE );
m_targetLength.SetMax( aOpt + DEFAULT_TOLERANCE );
if( aOpt == std::numeric_limits<long long int>::max() )
{
m_targetLength.SetMin( 0 );
m_targetLength.SetMax( aOpt );
}
else
{
m_targetLength.SetMin( aOpt - DEFAULT_TOLERANCE );
m_targetLength.SetMax( aOpt + DEFAULT_TOLERANCE );
}
}
void SetTargetLength( const MINOPTMAX<int>& aConstraint )
@ -109,8 +118,17 @@ public:
void SetTargetSkew( int aOpt )
{
m_targetSkew.SetOpt( aOpt );
m_targetSkew.SetMin( aOpt - DEFAULT_TOLERANCE );
m_targetSkew.SetMax( aOpt + DEFAULT_TOLERANCE );
if( aOpt == std::numeric_limits<int>::max() )
{
m_targetSkew.SetMin( 0 );
m_targetSkew.SetMax( aOpt );
}
else
{
m_targetSkew.SetMin( aOpt - DEFAULT_TOLERANCE );
m_targetSkew.SetMax( aOpt + DEFAULT_TOLERANCE );
}
}
void SetTargetSkew( const MINOPTMAX<int>& aConstraint )