More modern look & feel for tuning status popup.

(Also includes min and max info, and move string processing out
of router.)
This commit is contained in:
Jeff Young 2023-10-17 13:03:38 +01:00
parent 390bd44f18
commit 89011e888c
15 changed files with 153 additions and 135 deletions

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2014-2015 CERN
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2021-2023 KiCad Developers, see AUTHORS.txt for contributors.
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
*
* This program is free software; you can redistribute it and/or
@ -31,13 +31,14 @@
#include <math/vector2wx.h>
#include <status_popup.h>
#include <eda_draw_frame.h>
#include <bitmaps.h>
STATUS_POPUP::STATUS_POPUP( wxWindow* aParent ) :
wxPopupWindow( aParent ),
m_expireTimer( this )
{
m_panel = new wxPanel( this, wxID_ANY );
m_topSizer = new wxBoxSizer( wxVERTICAL );
m_topSizer = new wxBoxSizer( wxHORIZONTAL );
m_panel->SetSizer( m_topSizer );
m_panel->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) );
@ -116,7 +117,8 @@ void STATUS_POPUP::onExpire( wxTimerEvent& aEvent )
STATUS_TEXT_POPUP::STATUS_TEXT_POPUP( wxWindow* aParent ) :
STATUS_POPUP( aParent )
{
m_panel->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNSHADOW ) );
SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
m_panel->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
m_panel->SetForegroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT ) );
m_statusLine = new wxStaticText( m_panel, wxID_ANY, wxEmptyString ) ;
@ -137,8 +139,72 @@ void STATUS_TEXT_POPUP::SetTextColor( const wxColour& aColor )
}
void STATUS_TEXT_POPUP::SetBgColour( const wxColour& aColor )
STATUS_MIN_MAX_POPUP::STATUS_MIN_MAX_POPUP( EDA_DRAW_FRAME* aFrame ) :
STATUS_POPUP( aFrame ),
m_frame( aFrame )
{
m_panel->SetBackgroundColour( aColor );
SetBackgroundColour( aColor );
m_icon = new wxStaticBitmap( m_panel, wxID_ANY, KiBitmap( BITMAPS::checked_ok ),
wxDefaultPosition, wxSize( 12, 12 ) );
m_currentLabel = new wxStaticText( m_panel, wxID_ANY, _( "current" ) );
wxStaticText* minLabel = new wxStaticText( m_panel, wxID_ANY, _( "min" ) );
wxStaticText* maxLabel = new wxStaticText( m_panel, wxID_ANY, _( "max" ) );
wxFont infoFont = KIUI::GetStatusFont( this );
m_currentLabel->SetFont( infoFont );
minLabel->SetFont( infoFont );
maxLabel->SetFont( infoFont );
m_currentText = new wxStaticText( m_panel, wxID_ANY, wxEmptyString );
m_minText = new wxStaticText( m_panel, wxID_ANY, wxEmptyString );
m_maxText = new wxStaticText( m_panel, wxID_ANY, wxEmptyString );
wxBoxSizer* currentSizer = new wxBoxSizer( wxVERTICAL );
currentSizer->Add( m_currentLabel, 0, 0, 5 );
currentSizer->Add( m_currentText, 0, 0, 5 );
wxBoxSizer* minSizer = new wxBoxSizer( wxVERTICAL );
minSizer->Add( minLabel, 0, 0, 5 );
minSizer->Add( m_minText, 0, 0, 5 );
wxBoxSizer* maxSizer = new wxBoxSizer( wxVERTICAL );
maxSizer->Add( maxLabel, 0, 0, 5 );
maxSizer->Add( m_maxText, 0, 0, 5 );
m_topSizer->Add( currentSizer, 0, wxLEFT | wxRIGHT, 3 );
m_topSizer->Add( m_icon, 0, wxALL | wxALIGN_BOTTOM | wxRESERVE_SPACE_EVEN_IF_HIDDEN, 1 );
m_topSizer->Add( minSizer, 0, wxLEFT | wxRIGHT, 3 );
m_topSizer->Add( maxSizer, 0, wxLEFT | wxRIGHT, 3 );
}
void STATUS_MIN_MAX_POPUP::SetMinMax( double aMin, double aMax )
{
m_min = aMin;
m_minText->SetLabel( m_frame->MessageTextFromValue( m_min, false ) );
m_max = aMax;
m_maxText->SetLabel( m_frame->MessageTextFromValue( m_max, false ) );
}
void STATUS_MIN_MAX_POPUP::SetCurrent( double aCurrent, const wxString& aLabel )
{
m_currentLabel->SetLabel( aLabel );
m_currentText->SetLabel( m_frame->MessageTextFromValue( aCurrent ) );
m_icon->Show( aCurrent >= m_min && aCurrent <= m_max );
wxColour normal = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT );
// Determine the background color first and choose a contrasting value
COLOR4D bg = GetBackgroundColour();
COLOR4D red;
double bg_h, bg_s, bg_l;
bg.ToHSL( bg_h, bg_s, bg_l );
red.FromHSL( 0, 1.0, bg_l < 0.5 ? 0.7 : 0.3 );
m_minText->SetForegroundColour( aCurrent < m_min ? red.ToColour() : normal );
m_maxText->SetForegroundColour( aCurrent > m_max ? red.ToColour() : normal );
m_topSizer->Layout();
updateSize();
}

View File

@ -33,6 +33,7 @@
#include <wx/panel.h>
#include <wx/stattext.h>
#include <wx/sizer.h>
#include <wx/statbmp.h>
class EDA_DRAW_FRAME;
@ -99,15 +100,35 @@ public:
*/
void SetTextColor( const wxColour& aColor );
/**
* Change background color.
*
* @param aColor new background color.
*/
void SetBgColour( const wxColour& aColor );
protected:
wxStaticText* m_statusLine;
};
/**
* Extension of #STATUS_POPUP for displaying a value with min and max.
*/
class STATUS_MIN_MAX_POPUP : public STATUS_POPUP
{
public:
STATUS_MIN_MAX_POPUP( EDA_DRAW_FRAME* aFrame );
virtual ~STATUS_MIN_MAX_POPUP() {}
void SetMinMax( double aMin, double aMax );
void SetCurrent( double aCurrent, const wxString& aLabel );
protected:
EDA_DRAW_FRAME* m_frame;
double m_min;
double m_max;
private:
wxStaticText* m_currentLabel;
wxStaticText* m_currentText;
wxStaticText* m_minText;
wxStaticText* m_maxText;
wxStaticBitmap* m_icon;
};
#endif /* __STATUS_POPUP_H_*/

View File

@ -205,7 +205,7 @@ public:
void ShowPropertiesDialog( PCB_BASE_EDIT_FRAME* aEditFrame ) override;
void UpdateStatus( GENERATOR_TOOL* aTool, PCB_BASE_EDIT_FRAME* aFrame,
STATUS_TEXT_POPUP* aPopup ) override;
STATUS_MIN_MAX_POPUP* aPopup ) override;
void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
@ -987,9 +987,22 @@ bool PCB_GENERATOR_MEANDERS::Update( GENERATOR_TOOL* aTool, BOARD* aBoard,
m_diffPairGap = router->Sizes().DiffPairGap();
m_settings = placer->MeanderSettings();
m_lastNetName = iface->GetNetName( startItem->Net() );
m_tuningInfo = placer->TuningInfo( aFrame->GetUserUnits() );
m_tuningStatus = placer->TuningStatus();
wxString statusMessage;
switch ( m_tuningStatus )
{
case PNS::MEANDER_PLACER_BASE::TOO_LONG: statusMessage = _( "too long" ); break;
case PNS::MEANDER_PLACER_BASE::TOO_SHORT: statusMessage = _( "too short" ); break;
case PNS::MEANDER_PLACER_BASE::TUNED: statusMessage = _( "tuned" ); break;
default: statusMessage = _( "unknown" ); break;
}
m_tuningInfo.Printf( wxS( "%s (%s)" ),
aFrame->MessageTextFromValue( (double) placer->TuningResult() ),
statusMessage );
return true;
}
@ -1426,33 +1439,24 @@ void PCB_GENERATOR_MEANDERS::ShowPropertiesDialog( PCB_BASE_EDIT_FRAME* aEditFra
void PCB_GENERATOR_MEANDERS::UpdateStatus( GENERATOR_TOOL* aTool, PCB_BASE_EDIT_FRAME* aFrame,
STATUS_TEXT_POPUP* aPopup )
STATUS_MIN_MAX_POPUP* aPopup )
{
auto* placer = dynamic_cast<PNS::MEANDER_PLACER_BASE*>( aTool->Router()->Placer() );
if( !placer )
return;
aPopup->SetText( placer->TuningInfo( aFrame->GetUserUnits() ) );
// Determine the background color first and choose a contrasting value
COLOR4D bg( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) );
COLOR4D fg;
double h, s, l;
bg.ToHSL( h, s, l );
bg.FromHSL( h, s, l < 0.5 ? 0.1 : 0.9 );
aPopup->SetBgColour( bg.ToColour() );
switch( placer->TuningStatus() )
if( m_tuningMode == DIFF_PAIR_SKEW )
{
case PNS::MEANDER_PLACER_BASE::TUNED: h = 120.0; break; // Green
case PNS::MEANDER_PLACER_BASE::TOO_SHORT: h = 0; break; // Red
case PNS::MEANDER_PLACER_BASE::TOO_LONG: h = 240.0; break; // Blue
aPopup->SetMinMax( m_settings.m_targetSkew.Min(), m_settings.m_targetSkew.Max() );
aPopup->SetCurrent( (double) placer->TuningResult(), _( "current skew" ) );
}
else
{
aPopup->SetMinMax( (double) m_settings.m_targetLength.Min(),
(double) m_settings.m_targetLength.Max() );
aPopup->SetCurrent( (double) placer->TuningResult(), _( "current length" ) );
}
fg.FromHSL( h, 1.0, l < 0.5 ? 0.8 : 0.2 );
aPopup->SetTextColor( fg.ToColour() );
}

View File

@ -36,7 +36,7 @@ class BOARD;
class BOARD_ITEM;
class PCB_BASE_EDIT_FRAME;
class GENERATOR_TOOL;
class STATUS_TEXT_POPUP;
class STATUS_MIN_MAX_POPUP;
class PCB_GENERATOR : public PCB_GROUP
@ -96,7 +96,7 @@ public:
virtual void ShowPropertiesDialog( PCB_BASE_EDIT_FRAME* aEditFrame ) {};
virtual void UpdateStatus( GENERATOR_TOOL* aTool, PCB_BASE_EDIT_FRAME* aFrame,
STATUS_TEXT_POPUP* aPopup ) {};
STATUS_MIN_MAX_POPUP* aPopup ) {};
wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override;

View File

@ -21,8 +21,6 @@
#include <optional>
#include <base_units.h> // God forgive me doing this...
#include "pns_node.h"
#include "pns_itemset.h"
#include "pns_topology.h"
@ -456,33 +454,9 @@ int DP_MEANDER_PLACER::CurrentLayer() const
}
const wxString DP_MEANDER_PLACER::TuningInfo( EDA_UNITS aUnits ) const
long long int DP_MEANDER_PLACER::TuningResult() const
{
wxString status;
switch( m_lastStatus )
{
case TOO_LONG:
status = _( "Too long: " );
break;
case TOO_SHORT:
status = _("Too short: " );
break;
case TUNED:
status = _( "Tuned: " );
break;
default:
return _( "?" );
}
status += EDA_UNIT_UTILS::UI::MessageTextFromValue( pcbIUScale, aUnits, m_lastLength );
status += wxT( "/" );
status += EDA_UNIT_UTILS::UI::MessageTextFromValue( pcbIUScale, aUnits, m_settings.m_targetLength.Opt() );
status += wxT( " (gap: " );
status += EDA_UNIT_UTILS::UI::MessageTextFromValue( pcbIUScale, aUnits, m_originPair.Gap() );
status += wxT( ")" );
return status;
return m_lastLength;
}

View File

@ -104,7 +104,7 @@ public:
long long int totalLength();
const wxString TuningInfo( EDA_UNITS aUnits ) const override;
long long int TuningResult() const override;
TUNING_STATUS TuningStatus() const override;
bool CheckFit( MEANDER_SHAPE* aShape ) override;

View File

@ -19,8 +19,6 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <base_units.h> // God forgive me doing this...
#include "pns_debug_decorator.h"
#include "pns_itemset.h"
#include "pns_meander_placer.h"
@ -282,30 +280,9 @@ int MEANDER_PLACER::CurrentLayer() const
}
const wxString MEANDER_PLACER::TuningInfo( EDA_UNITS aUnits ) const
long long int MEANDER_PLACER::TuningResult() const
{
wxString status;
switch ( m_lastStatus )
{
case TOO_LONG:
status = _( "Too long: " );
break;
case TOO_SHORT:
status = _( "Too short: " );
break;
case TUNED:
status = _( "Tuned: " );
break;
default:
return _( "?" );
}
status += EDA_UNIT_UTILS::UI::MessageTextFromValue( pcbIUScale, aUnits, m_lastLength );
status += wxT( "/" );
status += EDA_UNIT_UTILS::UI::MessageTextFromValue( pcbIUScale, aUnits, m_settings.m_targetLength.Opt() );
return status;
return m_lastLength;
}

View File

@ -88,11 +88,11 @@ public:
/// @copydoc PLACEMENT_ALGO::CurrentLayer()
int CurrentLayer() const override;
/// @copydoc MEANDER_PLACER_BASE::TuningInfo()
virtual const wxString TuningInfo( EDA_UNITS aUnits ) const override;
/// @copydoc MEANDER_PLACER_BASE::TuningResult()
long long int TuningResult() const override;
/// @copydoc MEANDER_PLACER_BASE::TuningStatus()
virtual TUNING_STATUS TuningStatus() const override;
TUNING_STATUS TuningStatus() const override;
/// @copydoc MEANDER_PLACER_BASE::CheckFit()
bool CheckFit ( MEANDER_SHAPE* aShape ) override;

View File

@ -56,9 +56,9 @@ public:
virtual ~MEANDER_PLACER_BASE();
/**
* Return a string describing the status and length of the tuned traces.
* Return the resultant length or skew of the tuned traces.
*/
virtual const wxString TuningInfo( EDA_UNITS aUnits ) const = 0;
virtual long long int TuningResult() const = 0;
/**
* Return the tuning status (too short, too long, etc.) of the trace(s) being tuned.

View File

@ -19,8 +19,6 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <base_units.h> // God forgive me doing this...
#include "pns_node.h"
#include "pns_itemset.h"
#include "pns_topology.h"
@ -168,30 +166,9 @@ bool MEANDER_SKEW_PLACER::Move( const VECTOR2I& aP, ITEM* aEndItem )
}
const wxString MEANDER_SKEW_PLACER::TuningInfo( EDA_UNITS aUnits ) const
long long int MEANDER_SKEW_PLACER::TuningResult() const
{
wxString status;
switch( m_lastStatus )
{
case TOO_LONG:
status = _( "Too long: skew " );
break;
case TOO_SHORT:
status = _( "Too short: skew " );
break;
case TUNED:
status = _( "Tuned: skew " );
break;
default:
return _( "?" );
}
status += EDA_UNIT_UTILS::UI::MessageTextFromValue( pcbIUScale, aUnits, m_lastLength - m_coupledLength );
status += wxT( "/" );
status += EDA_UNIT_UTILS::UI::MessageTextFromValue( pcbIUScale, aUnits, m_settings.m_targetSkew.Opt() );
return status;
return m_lastLength - m_coupledLength;
}
}

View File

@ -48,8 +48,8 @@ public:
/// @copydoc PLACEMENT_ALGO::Move()
bool Move( const VECTOR2I& aP, ITEM* aEndItem ) override;
/// @copydoc MEANDER_PLACER_BASE::TuningInfo()
const wxString TuningInfo( EDA_UNITS aUnits ) const override;
/// @copydoc MEANDER_PLACER_BASE::TuningResult()
long long int TuningResult() const override;
long long int CurrentSkew() const;

View File

@ -301,7 +301,7 @@ void DRAWING_TOOL::Reset( RESET_REASON aReason )
m_textAttrs.m_Halign = GR_TEXT_H_ALIGN_LEFT;
m_textAttrs.m_Valign = GR_TEXT_V_ALIGN_TOP;
m_statusPopup = std::make_unique<STATUS_TEXT_POPUP>( m_frame );
m_statusPopup = std::make_unique<STATUS_MIN_MAX_POPUP>( m_frame );
UpdateStatusBar();
}

View File

@ -44,7 +44,7 @@ class PCB_BASE_EDIT_FRAME;
class PCB_SHAPE;
class POLYGON_GEOM_MANAGER;
class PCB_GENERATOR_MEANDERS;
class STATUS_TEXT_POPUP;
class STATUS_MIN_MAX_POPUP;
/**
@ -358,7 +358,7 @@ private:
BOARD_CONNECTED_ITEM* m_pickerItem;
PCB_GENERATOR_MEANDERS* m_tuningPattern;
std::unique_ptr<STATUS_TEXT_POPUP> m_statusPopup;
std::unique_ptr<STATUS_MIN_MAX_POPUP> m_statusPopup;
static const unsigned int WIDTH_STEP; // Amount of width change for one -/+ key press

View File

@ -125,7 +125,7 @@ void PCB_POINT_EDITOR::Reset( RESET_REASON aReason )
m_altConstraint.reset();
getViewControls()->SetAutoPan( false );
m_statusPopup = std::make_unique<STATUS_TEXT_POPUP>( getEditFrame<PCB_BASE_EDIT_FRAME>() );
m_statusPopup = std::make_unique<STATUS_MIN_MAX_POPUP>( getEditFrame<PCB_BASE_EDIT_FRAME>() );
}

View File

@ -174,24 +174,23 @@ private:
int changeArcEditMode( const TOOL_EVENT& aEvent );
private:
PCB_SELECTION_TOOL* m_selectionTool;
std::unique_ptr<STATUS_TEXT_POPUP> m_statusPopup;
std::shared_ptr<EDIT_POINTS> m_editPoints;
PCB_SELECTION_TOOL* m_selectionTool;
std::shared_ptr<EDIT_POINTS> m_editPoints;
EDIT_POINT* m_editedPoint;
EDIT_POINT* m_hoveredPoint;
EDIT_POINT* m_editedPoint;
EDIT_POINT* m_hoveredPoint;
EDIT_POINT m_original; ///< Original pos for the current drag point.
EDIT_POINT m_original; ///< Original pos for the current drag point.
bool m_refill;
ARC_EDIT_MODE m_arcEditMode;
ARC_EDIT_MODE m_arcEditMode;
std::unique_ptr<STATUS_MIN_MAX_POPUP> m_statusPopup;
// Alternative constraint, enabled while a modifier key is held
std::shared_ptr<EDIT_CONSTRAINT<EDIT_POINT>> m_altConstraint;
EDIT_POINT m_altConstrainer;
bool m_inPointEditorTool; // Re-entrancy guard
bool m_inPointEditorTool; // Re-entrancy guard
static const unsigned int COORDS_PADDING; // Padding from coordinates limits for this tool
};