Centralize min/opt/max printing.

This commit is contained in:
Jeff Young 2023-10-15 22:08:27 +01:00
parent 55caa9c1e8
commit 2c02c26af4
5 changed files with 57 additions and 49 deletions

View File

@ -26,6 +26,7 @@
#include <math/util.h> // for KiROUND
#include <macros.h>
#include <charconv>
#include <wx/translation.h>
bool EDA_UNIT_UTILS::IsImperialUnit( EDA_UNITS aUnit )
{
@ -425,6 +426,37 @@ wxString EDA_UNIT_UTILS::UI::MessageTextFromValue( const EDA_IU_SCALE& aIuScale,
}
wxString EDA_UNIT_UTILS::UI::MessageTextFromMinOptMax( const EDA_IU_SCALE& aIuScale,
EDA_UNITS aUnits,
const MINOPTMAX<int>& aValue )
{
wxString msg;
if( aValue.HasMin() && aValue.Min() > 0 )
{
msg += _( "min" ) + wxS( " " ) + MessageTextFromValue( aIuScale, aUnits, aValue.Min() );
}
if( aValue.HasOpt() )
{
if( !msg.IsEmpty() )
msg += wxS( "; " );
msg += _( "opt" ) + wxS( " " ) + MessageTextFromValue( aIuScale, aUnits, aValue.Opt() );
}
if( aValue.HasMax() )
{
if( !msg.IsEmpty() )
msg += wxS( "; " );
msg += _( "max" ) + wxS( " " ) + MessageTextFromValue( aIuScale, aUnits, aValue.Max() );
}
return msg;
};
double EDA_UNIT_UTILS::UI::FromUserUnit( const EDA_IU_SCALE& aIuScale, EDA_UNITS aUnits,
double aValue )
{

View File

@ -29,6 +29,7 @@
#include <wx/string.h>
#include <geometry/eda_angle.h>
#include <base_units.h>
#include <core/minoptmax.h>
/**
* The type of unit.
@ -216,10 +217,15 @@ namespace EDA_UNIT_UTILS
KICOMMON_API wxString MessageTextFromValue( EDA_ANGLE aValue, bool aAddUnitLabel = true );
KICOMMON_API wxString MessageTextFromMinOptMax( const EDA_IU_SCALE& aIuScale,
EDA_UNITS aUnits,
const MINOPTMAX<int>& aValue );
/**
* Return in internal units the value "val" given in a real unit such as "in", "mm" or "deg"
* Return in internal units the value \a aValue given in a real unit such as "in", "mm",
* or "deg"
*/
KICOMMON_API double FromUserUnit( const EDA_IU_SCALE& aIuScale, EDA_UNITS aUnit, double aValue );
KICOMMON_API double FromUserUnit( const EDA_IU_SCALE& aIuScale, EDA_UNITS aUnit,
double aValue );
/**

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2022-2023 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -26,6 +26,7 @@
#include <eda_units.h>
#include <origin_transforms.h>
#include <core/minoptmax.h>
class UNITS_PROVIDER
@ -111,6 +112,11 @@ public:
EDA_DATA_TYPE::DISTANCE );
}
wxString MessageTextFromMinOptMax( const MINOPTMAX<int>& aValue ) const
{
return EDA_UNIT_UTILS::UI::MessageTextFromMinOptMax( GetIuScale(), GetUserUnits(), aValue );
};
/**
* Converts \a aTextValue in \a aUnits to internal units used by the frame.
* @warning This utilizes the current locale and will break if decimal formats differ

View File

@ -1572,35 +1572,6 @@ void PCB_GENERATOR_MEANDERS::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame,
}
}
auto getMinOptMax =
[&]( const MINOPTMAX<int>& v )
{
wxString msg;
if( v.HasMin() )
{
msg += wxString::Format( _( "min %s" ), aFrame->MessageTextFromValue( v.Min() ) );
}
if( v.HasOpt() )
{
if( !msg.IsEmpty() )
msg += wxS( "; " );
msg += wxString::Format( _( "opt %s" ), aFrame->MessageTextFromValue( v.Opt() ) );
}
if( v.HasMax() )
{
if( !msg.IsEmpty() )
msg += wxS( "; " );
msg += wxString::Format( _( "max %s" ), aFrame->MessageTextFromValue( v.Max() ) );
}
return msg;
};
if( m_tuningMode == DIFF_PAIR_SKEW )
{
constraint = drcEngine->EvalRules( SKEW_CONSTRAINT, primaryItem, coupledItem, m_layer );
@ -1614,11 +1585,11 @@ void PCB_GENERATOR_MEANDERS::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame,
}
else
{
msg = getMinOptMax( constraint.GetValue() );
msg = aFrame->MessageTextFromMinOptMax( constraint.GetValue() );
if( !msg.IsEmpty() )
{
aList.emplace_back( wxString::Format( _( "Skew Constraints: %s." ), msg ),
aList.emplace_back( wxString::Format( _( "Skew Constraints: %s" ), msg ),
wxString::Format( _( "(from %s)" ), constraint.GetName() ) );
}
}
@ -1636,11 +1607,11 @@ void PCB_GENERATOR_MEANDERS::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame,
}
else
{
msg = getMinOptMax( constraint.GetValue() );
msg = aFrame->MessageTextFromMinOptMax( constraint.GetValue() );
if( !msg.IsEmpty() )
{
aList.emplace_back( wxString::Format( _( "Length Constraints: %s." ), msg ),
aList.emplace_back( wxString::Format( _( "Length Constraints: %s" ), msg ),
wxString::Format( _( "(from %s)" ), constraint.GetName() ) );
}
}
@ -1877,8 +1848,8 @@ static struct PCB_GENERATOR_MEANDERS_DESC
{
ENUM_MAP<LENGTH_TUNING_MODE>::Instance()
.Map( LENGTH_TUNING_MODE::SINGLE, _HKI( "Single track" ) )
.Map( LENGTH_TUNING_MODE::DIFF_PAIR, _HKI( "Diff. pair" ) )
.Map( LENGTH_TUNING_MODE::DIFF_PAIR_SKEW, _HKI( "Diff. pair Skew" ) );
.Map( LENGTH_TUNING_MODE::DIFF_PAIR, _HKI( "Differential pair" ) )
.Map( LENGTH_TUNING_MODE::DIFF_PAIR_SKEW, _HKI( "Diff pair skew" ) );
ENUM_MAP<PNS::MEANDER_SIDE>::Instance()
.Map( PNS::MEANDER_SIDE_LEFT, _HKI( "Left" ) )

View File

@ -904,19 +904,12 @@ void PCB_TRACK::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_I
aFrame->MessageTextFromValue( clearance ) ),
wxString::Format( _( "(from %s)" ), source ) );
MINOPTMAX<int> c = GetWidthConstraint( &source );
MINOPTMAX<int> constraintValue = GetWidthConstraint( &source );
msg = aFrame->MessageTextFromMinOptMax( constraintValue );
if( c.HasMax() )
if( !msg.IsEmpty() )
{
aList.emplace_back( wxString::Format( _( "Width Constraints: min %s, max %s" ),
aFrame->MessageTextFromValue( c.Min() ),
aFrame->MessageTextFromValue( c.Max() ) ),
wxString::Format( _( "(from %s)" ), source ) );
}
else
{
aList.emplace_back( wxString::Format( _( "Width Constraints: min %s" ),
aFrame->MessageTextFromValue( c.Min() ) ),
aList.emplace_back( wxString::Format( _( "Width Constraints: %s" ), msg ),
wxString::Format( _( "(from %s)" ), source ) );
}
}