Implement changed notifiers for textvar, netclasses and severities.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/15440
This commit is contained in:
Jeff Young 2023-09-17 15:49:46 +01:00
parent be4c89011c
commit ef92429ac2
11 changed files with 175 additions and 44 deletions

View File

@ -78,6 +78,7 @@ PANEL_SETUP_NETCLASSES::PANEL_SETUP_NETCLASSES( wxWindow* aParentWindow, EDA_DRA
m_isEEschema( aIsEEschema ),
m_netSettings( aNetSettings ),
m_netNames( aNetNames ),
m_lastCheckedTicker( 0 ),
m_hoveredCol( -1 ),
m_lastNetclassGridWidth( -1 )
{
@ -219,6 +220,21 @@ PANEL_SETUP_NETCLASSES::PANEL_SETUP_NETCLASSES( wxWindow* aParentWindow, EDA_DRA
m_assignmentGrid->EndBatch();
Thaw();
Bind( wxEVT_IDLE,
[this]( wxIdleEvent& aEvent )
{
// Careful of consuming CPU in an idle event handler. Check the ticker first to
// see if there's even a possibility of the netclasses having changed.
if( m_frame->Prj().GetNetclassesTicker() > m_lastCheckedTicker )
{
wxWindow* dialog = wxGetTopLevelParent( this );
wxWindow* topLevelFocus = wxGetTopLevelParent( wxWindow::FindFocus() );
if( topLevelFocus == dialog && m_lastLoaded != m_netSettings->m_NetClasses )
checkReload();
}
} );
m_matchingNets->SetFont( KIUI::GetInfoFont( this ) );
}
@ -242,27 +258,7 @@ PANEL_SETUP_NETCLASSES::~PANEL_SETUP_NETCLASSES()
}
void PANEL_SETUP_NETCLASSES::onUnitsChanged( wxCommandEvent& aEvent )
{
std::shared_ptr<NET_SETTINGS> tempNetSettings = std::make_shared<NET_SETTINGS>( nullptr, "" );
std::shared_ptr<NET_SETTINGS> saveNetSettings = m_netSettings;
m_netSettings = tempNetSettings;
TransferDataFromWindow();
m_schUnitsProvider->SetUserUnits( m_frame->GetUserUnits() );
m_pcbUnitsProvider->SetUserUnits( m_frame->GetUserUnits() );
TransferDataToWindow();
m_netSettings = saveNetSettings;
aEvent.Skip();
}
bool PANEL_SETUP_NETCLASSES::TransferDataToWindow()
void PANEL_SETUP_NETCLASSES::loadNetclasses()
{
int row = 0;
@ -321,7 +317,50 @@ bool PANEL_SETUP_NETCLASSES::TransferDataToWindow()
m_assignmentGrid->SetCellValue( row, 1, netclassName );
row++;
}
}
void PANEL_SETUP_NETCLASSES::checkReload()
{
// MUST update the ticker before calling IsOK (or we'll end up re-entering through the idle
// event until we crash the stack).
m_lastCheckedTicker = m_frame->Prj().GetTextVarsTicker();
if( IsOK( m_parent, _( "The netclasses have been changed outside the Setup dialog.\n"
"Do you wish to reload them?" ) ) )
{
m_lastLoaded = m_netSettings->m_NetClasses;
loadNetclasses();
}
}
void PANEL_SETUP_NETCLASSES::onUnitsChanged( wxCommandEvent& aEvent )
{
std::shared_ptr<NET_SETTINGS> tempNetSettings = std::make_shared<NET_SETTINGS>( nullptr, "" );
std::shared_ptr<NET_SETTINGS> saveNetSettings = m_netSettings;
m_netSettings = tempNetSettings;
TransferDataFromWindow();
m_schUnitsProvider->SetUserUnits( m_frame->GetUserUnits() );
m_pcbUnitsProvider->SetUserUnits( m_frame->GetUserUnits() );
TransferDataToWindow();
m_netSettings = saveNetSettings;
aEvent.Skip();
}
bool PANEL_SETUP_NETCLASSES::TransferDataToWindow()
{
m_lastLoaded = m_netSettings->m_NetClasses;
m_lastCheckedTicker = m_frame->Prj().GetNetclassesTicker();
loadNetclasses();
AdjustAssignmentGridColumns( GetSize().x * 3 / 5 );
return true;

View File

@ -28,6 +28,7 @@
#include <wx/radiobut.h>
#include <wx/scrolwin.h>
#include <wx/stattext.h>
#include "confirm.h"
PANEL_SETUP_SEVERITIES::PANEL_SETUP_SEVERITIES( wxWindow* aParentWindow,
@ -149,12 +150,39 @@ PANEL_SETUP_SEVERITIES::PANEL_SETUP_SEVERITIES( wxWindow* aParentWindow,
scrollWinSizer->Add( gridSizer, 1, wxEXPAND | wxALL, 5 );
panelSizer->Add( scrollWin, 1, wxEXPAND, 0 );
Bind( wxEVT_IDLE,
[this]( wxIdleEvent& aEvent )
{
if( m_lastLoaded != m_severities )
{
wxWindow* dialog = wxGetTopLevelParent( this );
wxWindow* topLevelFocus = wxGetTopLevelParent( wxWindow::FindFocus() );
if( topLevelFocus == dialog )
checkReload();
}
} );
SetSizer( panelSizer );
Layout();
panelSizer->Fit( this );
}
void PANEL_SETUP_SEVERITIES::checkReload()
{
// MUST update lastLoaded before calling IsOK (or we'll end up re-entering through the idle
// event until we crash the stack).
m_lastLoaded = m_severities;
if( IsOK( m_parent, _( "The violation severities have been changed outside the Setup dialog.\n"
"Do you wish to reload them?" ) ) )
{
TransferDataToWindow();
}
}
void PANEL_SETUP_SEVERITIES::ImportSettingsFrom( std::map<int, SEVERITY>& aSettings )
{
for( const RC_ITEM& item : m_items )
@ -188,6 +216,8 @@ void PANEL_SETUP_SEVERITIES::ImportSettingsFrom( std::map<int, SEVERITY>& aSetti
bool PANEL_SETUP_SEVERITIES::TransferDataToWindow()
{
m_lastLoaded = m_severities;
for( const RC_ITEM& item : m_items )
{
int errorCode = item.GetErrorCode();

View File

@ -64,6 +64,21 @@ PANEL_TEXT_VARIABLES::PANEL_TEXT_VARIABLES( wxWindow* aParent, PROJECT* aProject
m_TextVars->Connect( wxEVT_GRID_CELL_CHANGING,
wxGridEventHandler( PANEL_TEXT_VARIABLES::OnGridCellChanging ),
nullptr, this );
Bind( wxEVT_IDLE,
[this]( wxIdleEvent& aEvent )
{
// Careful of consuming CPU in an idle event handler. Check the ticker first to
// see if there's even a possibility of the text variables having changed.
if( m_project->GetTextVarsTicker() > m_lastCheckedTicker )
{
wxWindow* dialog = wxGetTopLevelParent( this );
wxWindow* topLevelFocus = wxGetTopLevelParent( wxWindow::FindFocus() );
if( topLevelFocus == dialog && m_lastLoaded != m_project->GetTextVars() )
checkReload();
}
} );
}
@ -78,11 +93,31 @@ PANEL_TEXT_VARIABLES::~PANEL_TEXT_VARIABLES()
}
void PANEL_TEXT_VARIABLES::checkReload()
{
// MUST update the ticker before calling IsOK (or we'll end up re-entering through the idle
// event until we crash the stack).
m_lastCheckedTicker = m_project->GetTextVarsTicker();
if( IsOK( m_parent, _( "The text variables have been changed outside the Setup dialog.\n"
"Do you wish to reload them?" ) ) )
{
m_TextVars->ClearRows();
m_lastLoaded = m_project->GetTextVars();
for( const auto& var : m_lastLoaded )
AppendTextVar( var.first, var.second );
}
}
bool PANEL_TEXT_VARIABLES::TransferDataToWindow()
{
std::map<wxString, wxString>& variables = m_project->GetTextVars();
m_lastLoaded = m_project->GetTextVars();
m_lastCheckedTicker = m_project->GetTextVarsTicker();
for( const auto& var : variables )
for( const auto& var : m_lastLoaded )
AppendTextVar( var.first, var.second );
return true;

View File

@ -22,6 +22,7 @@
#define JOB_EXPORT_SCH_BOM_H
#include <kicommon.h>
#include <vector>
#include <wx/string.h>
#include "job.h"

View File

@ -43,6 +43,8 @@
PROJECT::PROJECT() :
m_readOnly( false ),
m_textVarsTicker( 0 ),
m_netclassesTicker( 0 ),
m_projectFile( nullptr ),
m_localSettings( nullptr )
{

View File

@ -96,6 +96,9 @@ void SCH_EDIT_FRAME::ShowSchematicSetupDialog( const wxString& aInitialPage )
Kiway().CommonSettingsChanged( false, true );
Prj().IncrementTextVarsTicker();
Prj().IncrementNetclassesTicker();
GetRenderSettings()->SetDefaultPenWidth( Schematic().Settings().m_DefaultLineWidth );
GetRenderSettings()->m_LabelSizeRatio = Schematic().Settings().m_LabelSizeRatio;
GetRenderSettings()->m_TextOffsetRatio = Schematic().Settings().m_TextOffsetRatio;

View File

@ -30,6 +30,7 @@
#include <panel_setup_netclasses_base.h>
class NET_SETTINGS;
class NETCLASS;
class PANEL_SETUP_NETCLASSES : public PANEL_SETUP_NETCLASSES_BASE
@ -67,6 +68,9 @@ private:
void AdjustNetclassGridColumns( int aWidth );
void AdjustAssignmentGridColumns( int aWidth );
void loadNetclasses();
void checkReload();
private:
EDA_DRAW_FRAME* m_frame;
bool m_isEEschema;
@ -76,6 +80,9 @@ private:
std::unique_ptr<UNITS_PROVIDER> m_schUnitsProvider;
std::unique_ptr<UNITS_PROVIDER> m_pcbUnitsProvider;
std::map<wxString, std::shared_ptr<NETCLASS>> m_lastLoaded;
int m_lastCheckedTicker;
int* m_originalColWidths;
bool m_netclassesDirty; // The netclass drop-down menus need rebuilding
int m_hoveredCol; // Column being hovered over, for tooltips

View File

@ -64,6 +64,11 @@ public:
private:
bool TransferDataToWindow() override;
bool TransferDataFromWindow() override;
void checkReload();
private:
std::map<int, SEVERITY> m_lastLoaded;
};
#endif //KICAD_PANEL_SETUP_SEVERITIES_H

View File

@ -26,6 +26,7 @@
#include <../common/dialogs/panel_text_variables_base.h>
#include <wx/valtext.h>
#include <map>
class PROJECT;
@ -50,16 +51,21 @@ protected:
void AppendTextVar( const wxString& aName, const wxString& aValue );
void checkReload();
private:
PROJECT* m_project;
PROJECT* m_project;
wxString m_errorMsg;
int m_errorRow;
int m_errorCol;
std::map<wxString, wxString> m_lastLoaded;
int m_lastCheckedTicker;
wxTextValidator m_nameValidator;
wxString m_errorMsg;
int m_errorRow;
int m_errorCol;
bool m_gridWidthsDirty;
wxTextValidator m_nameValidator;
bool m_gridWidthsDirty;
};
#endif // _PANEL_TEXT_VARIABLES_H_

View File

@ -91,6 +91,12 @@ public:
*/
virtual void ApplyTextVars( const std::map<wxString, wxString>& aVarsMap );
bool GetTextVarsTicker() const { return m_textVarsTicker; }
void IncrementTextVarsTicker() { m_textVarsTicker++; }
bool GetNetclassesTicker() const { return m_netclassesTicker; }
void IncrementNetclassesTicker() { m_netclassesTicker++; }
/**
* Return the full path and name of the project.
*
@ -348,25 +354,27 @@ private:
*/
const wxString libTableName( const wxString& aLibTableName ) const;
private:
wxFileName m_project_name; ///< \<fullpath\>/\<basename\>.pro
wxString m_pro_date_and_time;
///< True if the project is read-only: no project files will be written
bool m_readOnly;
bool m_readOnly; ///< No project files will be written to disk
int m_textVarsTicker; ///< Update counter on text vars
int m_netclassesTicker; ///< Update counter on netclasses
/// Backing store for project data -- owned by SETTINGS_MANAGER
PROJECT_FILE* m_projectFile;
PROJECT_FILE* m_projectFile;
/// Backing store for project local settings -- owned by SETTINGS_MANAGER
PROJECT_LOCAL_SETTINGS* m_localSettings;
PROJECT_LOCAL_SETTINGS* m_localSettings;
std::map<KIID, wxString> m_sheetNames;
std::map<KIID, wxString> m_sheetNames;
/// @see this::SetRString(), GetRString(), and enum RSTRING_T.
wxString m_rstrings[RSTRING_COUNT];
wxString m_rstrings[RSTRING_COUNT];
/// @see this::Elem() and enum ELEM_T.
_ELEM* m_elems[ELEM_COUNT];
_ELEM* m_elems[ELEM_COUNT];
};

View File

@ -761,13 +761,6 @@ void PCB_EDIT_FRAME::setupUIConditions()
return GetPcbNewSettings()->m_Use45DegreeLimit;
};
auto enableBoardSetupCondition =
[this] ( const SELECTION& )
{
DRC_TOOL* tool = m_toolManager->GetTool<DRC_TOOL>();
return !( tool && tool->IsDRCDialogShown() );
};
auto boardFlippedCond =
[this]( const SELECTION& )
{
@ -832,7 +825,6 @@ void PCB_EDIT_FRAME::setupUIConditions()
mgr->SetConditions( PCB_ACTIONS::ratsnestLineMode, CHECK( curvedRatsnestCond ) );
mgr->SetConditions( PCB_ACTIONS::toggleNetHighlight, CHECK( netHighlightCond )
.Enable( enableNetHighlightCond ) );
mgr->SetConditions( PCB_ACTIONS::boardSetup, ENABLE( enableBoardSetupCondition ) );
mgr->SetConditions( PCB_ACTIONS::showProperties, CHECK( propertiesCond ) );
mgr->SetConditions( PCB_ACTIONS::showSearch, CHECK( searchPaneCond ) );
@ -1234,6 +1226,9 @@ void PCB_EDIT_FRAME::ShowBoardSetupDialog( const wxString& aInitialPage )
Kiway().CommonSettingsChanged( false, true );
Prj().IncrementTextVarsTicker();
Prj().IncrementNetclassesTicker();
PCBNEW_SETTINGS* settings = GetPcbNewSettings();
static LSET maskAndPasteLayers = LSET( 4, F_Mask, F_Paste, B_Mask, B_Paste );