From 89011e888cc017dfcf9fae79207ed29b390df0a5 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 17 Oct 2023 13:03:38 +0100 Subject: [PATCH] More modern look & feel for tuning status popup. (Also includes min and max info, and move string processing out of router.) --- common/status_popup.cpp | 78 ++++++++++++++++++-- include/status_popup.h | 35 +++++++-- pcbnew/generators/pcb_generator_meanders.cpp | 46 ++++++------ pcbnew/pcb_generator.h | 4 +- pcbnew/router/pns_dp_meander_placer.cpp | 30 +------- pcbnew/router/pns_dp_meander_placer.h | 2 +- pcbnew/router/pns_meander_placer.cpp | 27 +------ pcbnew/router/pns_meander_placer.h | 6 +- pcbnew/router/pns_meander_placer_base.h | 4 +- pcbnew/router/pns_meander_skew_placer.cpp | 27 +------ pcbnew/router/pns_meander_skew_placer.h | 4 +- pcbnew/tools/drawing_tool.cpp | 2 +- pcbnew/tools/drawing_tool.h | 4 +- pcbnew/tools/pcb_point_editor.cpp | 2 +- pcbnew/tools/pcb_point_editor.h | 17 ++--- 15 files changed, 153 insertions(+), 135 deletions(-) diff --git a/common/status_popup.cpp b/common/status_popup.cpp index 091bbd952f..a070fb4803 100644 --- a/common/status_popup.cpp +++ b/common/status_popup.cpp @@ -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 * * This program is free software; you can redistribute it and/or @@ -31,13 +31,14 @@ #include #include #include +#include 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(); +} \ No newline at end of file diff --git a/include/status_popup.h b/include/status_popup.h index b7c49185d6..57ecf78fb9 100644 --- a/include/status_popup.h +++ b/include/status_popup.h @@ -33,6 +33,7 @@ #include #include #include +#include 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_*/ diff --git a/pcbnew/generators/pcb_generator_meanders.cpp b/pcbnew/generators/pcb_generator_meanders.cpp index 6001981466..6d1096023a 100644 --- a/pcbnew/generators/pcb_generator_meanders.cpp +++ b/pcbnew/generators/pcb_generator_meanders.cpp @@ -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& 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( 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() ); } diff --git a/pcbnew/pcb_generator.h b/pcbnew/pcb_generator.h index 83fc30cd0b..a5fb6c6151 100644 --- a/pcbnew/pcb_generator.h +++ b/pcbnew/pcb_generator.h @@ -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; diff --git a/pcbnew/router/pns_dp_meander_placer.cpp b/pcbnew/router/pns_dp_meander_placer.cpp index 642d826503..cf61e5e32b 100644 --- a/pcbnew/router/pns_dp_meander_placer.cpp +++ b/pcbnew/router/pns_dp_meander_placer.cpp @@ -21,8 +21,6 @@ #include -#include // 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; } diff --git a/pcbnew/router/pns_dp_meander_placer.h b/pcbnew/router/pns_dp_meander_placer.h index 2d209847e8..9a2ae4c4c4 100644 --- a/pcbnew/router/pns_dp_meander_placer.h +++ b/pcbnew/router/pns_dp_meander_placer.h @@ -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; diff --git a/pcbnew/router/pns_meander_placer.cpp b/pcbnew/router/pns_meander_placer.cpp index 3dbbb88cf4..f7c8cda2ec 100644 --- a/pcbnew/router/pns_meander_placer.cpp +++ b/pcbnew/router/pns_meander_placer.cpp @@ -19,8 +19,6 @@ * with this program. If not, see . */ -#include // 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; } diff --git a/pcbnew/router/pns_meander_placer.h b/pcbnew/router/pns_meander_placer.h index 05cd13040c..3edeeb1ad2 100644 --- a/pcbnew/router/pns_meander_placer.h +++ b/pcbnew/router/pns_meander_placer.h @@ -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; diff --git a/pcbnew/router/pns_meander_placer_base.h b/pcbnew/router/pns_meander_placer_base.h index 872bff29bc..77cb45d144 100644 --- a/pcbnew/router/pns_meander_placer_base.h +++ b/pcbnew/router/pns_meander_placer_base.h @@ -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. diff --git a/pcbnew/router/pns_meander_skew_placer.cpp b/pcbnew/router/pns_meander_skew_placer.cpp index f54272a90f..82b03bc856 100644 --- a/pcbnew/router/pns_meander_skew_placer.cpp +++ b/pcbnew/router/pns_meander_skew_placer.cpp @@ -19,8 +19,6 @@ * with this program. If not, see . */ -#include // 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; } } diff --git a/pcbnew/router/pns_meander_skew_placer.h b/pcbnew/router/pns_meander_skew_placer.h index 0962976bc9..a9b67c19df 100644 --- a/pcbnew/router/pns_meander_skew_placer.h +++ b/pcbnew/router/pns_meander_skew_placer.h @@ -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; diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index c8eebbfffd..eb182da5db 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -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( m_frame ); + m_statusPopup = std::make_unique( m_frame ); UpdateStatusBar(); } diff --git a/pcbnew/tools/drawing_tool.h b/pcbnew/tools/drawing_tool.h index 7cad3d1011..730462528d 100644 --- a/pcbnew/tools/drawing_tool.h +++ b/pcbnew/tools/drawing_tool.h @@ -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 m_statusPopup; + std::unique_ptr m_statusPopup; static const unsigned int WIDTH_STEP; // Amount of width change for one -/+ key press diff --git a/pcbnew/tools/pcb_point_editor.cpp b/pcbnew/tools/pcb_point_editor.cpp index 0e8ace5b82..97dacf46cc 100644 --- a/pcbnew/tools/pcb_point_editor.cpp +++ b/pcbnew/tools/pcb_point_editor.cpp @@ -125,7 +125,7 @@ void PCB_POINT_EDITOR::Reset( RESET_REASON aReason ) m_altConstraint.reset(); getViewControls()->SetAutoPan( false ); - m_statusPopup = std::make_unique( getEditFrame() ); + m_statusPopup = std::make_unique( getEditFrame() ); } diff --git a/pcbnew/tools/pcb_point_editor.h b/pcbnew/tools/pcb_point_editor.h index a6a958c487..efcd3265b5 100644 --- a/pcbnew/tools/pcb_point_editor.h +++ b/pcbnew/tools/pcb_point_editor.h @@ -174,24 +174,23 @@ private: int changeArcEditMode( const TOOL_EVENT& aEvent ); private: - PCB_SELECTION_TOOL* m_selectionTool; - std::unique_ptr m_statusPopup; - std::shared_ptr m_editPoints; + PCB_SELECTION_TOOL* m_selectionTool; + std::shared_ptr 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 m_statusPopup; // Alternative constraint, enabled while a modifier key is held std::shared_ptr> 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 };