Store netclass visibility separately from nets
Fixes https://gitlab.com/kicad/code/kicad/-/issues/10290
This commit is contained in:
parent
1b38acd9c6
commit
7059ef9b89
|
@ -162,6 +162,9 @@ PROJECT_LOCAL_SETTINGS::PROJECT_LOCAL_SETTINGS( PROJECT* aProject, const wxStrin
|
|||
|
||||
m_params.emplace_back( new PARAM_LIST<wxString>( "board.hidden_nets", &m_HiddenNets, {} ) );
|
||||
|
||||
m_params.emplace_back( new PARAM_SET<wxString>( "board.hidden_netclasses",
|
||||
&m_HiddenNetclasses, {} ) );
|
||||
|
||||
m_params.emplace_back( new PARAM_ENUM<NET_COLOR_MODE>( "board.net_color_mode",
|
||||
&m_NetColorMode, NET_COLOR_MODE::RATSNEST, NET_COLOR_MODE::OFF,
|
||||
NET_COLOR_MODE::ALL ) );
|
||||
|
|
|
@ -138,6 +138,64 @@ template class PARAM_LIST<KIGFX::COLOR4D>;
|
|||
template class PARAM_LIST<FILE_INFO_PAIR>;
|
||||
|
||||
|
||||
template <typename ValueType>
|
||||
void PARAM_SET<ValueType>::Load( JSON_SETTINGS* aSettings, bool aResetIfMissing ) const
|
||||
{
|
||||
if( m_readOnly )
|
||||
return;
|
||||
|
||||
if( std::optional<nlohmann::json> js = aSettings->GetJson( m_path ) )
|
||||
{
|
||||
std::set<ValueType> val;
|
||||
|
||||
if( js->is_array() )
|
||||
{
|
||||
for( const auto& el : js->items() )
|
||||
val.insert( el.value().get<ValueType>() );
|
||||
}
|
||||
|
||||
*m_ptr = val;
|
||||
}
|
||||
else if( aResetIfMissing )
|
||||
*m_ptr = m_default;
|
||||
}
|
||||
|
||||
|
||||
template <typename ValueType>
|
||||
void PARAM_SET<ValueType>::Store( JSON_SETTINGS* aSettings ) const
|
||||
{
|
||||
nlohmann::json js = nlohmann::json::array();
|
||||
|
||||
for( const auto& el : *m_ptr )
|
||||
js.push_back( el );
|
||||
|
||||
aSettings->Set<nlohmann::json>( m_path, js );
|
||||
}
|
||||
|
||||
|
||||
template <typename ValueType>
|
||||
bool PARAM_SET<ValueType>::MatchesFile( JSON_SETTINGS* aSettings ) const
|
||||
{
|
||||
if( std::optional<nlohmann::json> js = aSettings->GetJson( m_path ) )
|
||||
{
|
||||
if( js->is_array() )
|
||||
{
|
||||
std::set<ValueType> val;
|
||||
|
||||
for( const auto& el : js->items() )
|
||||
val.insert( el.value().get<ValueType>() );
|
||||
|
||||
return val == *m_ptr;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
template class PARAM_SET<wxString>;
|
||||
|
||||
|
||||
void PARAM_PATH_LIST::Store( JSON_SETTINGS* aSettings ) const
|
||||
{
|
||||
nlohmann::json js = nlohmann::json::array();
|
||||
|
|
|
@ -130,6 +130,7 @@ public:
|
|||
* Currently, hiding nets means hiding the ratsnest for those nets.
|
||||
*/
|
||||
std::vector<wxString> m_HiddenNets;
|
||||
std::set<wxString> m_HiddenNetclasses;
|
||||
|
||||
/// State of the selection filter widget
|
||||
SELECTION_FILTER_OPTIONS m_SelectionFilter;
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#ifndef _PARAMETERS_H
|
||||
#define _PARAMETERS_H
|
||||
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <math/util.h>
|
||||
|
@ -445,6 +446,41 @@ protected:
|
|||
std::vector<Type> m_default;
|
||||
};
|
||||
|
||||
template<typename Type>
|
||||
class PARAM_SET : public PARAM_BASE
|
||||
{
|
||||
public:
|
||||
PARAM_SET( const std::string& aJsonPath, std::set<Type>* aPtr,
|
||||
std::initializer_list<Type> aDefault, bool aReadOnly = false ) :
|
||||
PARAM_BASE( aJsonPath, aReadOnly ),
|
||||
m_ptr( aPtr ),
|
||||
m_default( aDefault )
|
||||
{ }
|
||||
|
||||
PARAM_SET( const std::string& aJsonPath, std::set<Type>* aPtr,
|
||||
std::set<Type> aDefault, bool aReadOnly = false ) :
|
||||
PARAM_BASE( aJsonPath, aReadOnly ),
|
||||
m_ptr( aPtr ),
|
||||
m_default( aDefault )
|
||||
{ }
|
||||
|
||||
void Load( JSON_SETTINGS* aSettings, bool aResetIfMissing = true ) const override;
|
||||
|
||||
void Store( JSON_SETTINGS* aSettings) const override;
|
||||
|
||||
void SetDefault() override
|
||||
{
|
||||
*m_ptr = m_default;
|
||||
}
|
||||
|
||||
bool MatchesFile( JSON_SETTINGS* aSettings ) const override;
|
||||
|
||||
protected:
|
||||
std::set<Type>* m_ptr;
|
||||
|
||||
std::set<Type> m_default;
|
||||
};
|
||||
|
||||
/**
|
||||
* Represents a list of strings holding directory paths.
|
||||
* Normalizes paths to unix directory separator style in the file.
|
||||
|
|
|
@ -60,12 +60,20 @@ bool PCB_EDIT_FRAME::LoadProjectSettings()
|
|||
KIGFX::RENDER_SETTINGS* rs = GetCanvas()->GetView()->GetPainter()->GetSettings();
|
||||
KIGFX::PCB_RENDER_SETTINGS* renderSettings = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( rs );
|
||||
|
||||
NETINFO_LIST& nets = GetBoard()->GetNetInfo();
|
||||
|
||||
std::set<int>& hiddenNets = renderSettings->GetHiddenNets();
|
||||
hiddenNets.clear();
|
||||
|
||||
for( const wxString& hidden : localSettings.m_HiddenNets )
|
||||
{
|
||||
if( NETINFO_ITEM* net = GetBoard()->GetNetInfo().GetNetItem( hidden ) )
|
||||
if( NETINFO_ITEM* net = nets.GetNetItem( hidden ) )
|
||||
hiddenNets.insert( net->GetNetCode() );
|
||||
}
|
||||
|
||||
for( NETINFO_ITEM* net : nets )
|
||||
{
|
||||
if( localSettings.m_HiddenNetclasses.count( net->GetNetClass()->GetName() ) )
|
||||
hiddenNets.insert( net->GetNetCode() );
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,8 @@
|
|||
#include <pcb_edit_frame.h>
|
||||
#include <pcb_painter.h>
|
||||
#include <pcbnew_settings.h>
|
||||
#include <project.h>
|
||||
#include <project/project_local_settings.h>
|
||||
#include <settings/color_settings.h>
|
||||
#include <tool/tool_manager.h>
|
||||
#include <tools/pcb_actions.h>
|
||||
|
@ -2230,6 +2232,7 @@ void APPEARANCE_CONTROLS::rebuildNets()
|
|||
m_frame->GetCanvas()->GetView()->GetPainter()->GetSettings() );
|
||||
|
||||
std::map<wxString, KIGFX::COLOR4D>& netclassColors = rs->GetNetclassColorMap();
|
||||
const std::set<wxString>& hiddenClasses = m_frame->Prj().GetLocalSettings().m_HiddenNetclasses;
|
||||
|
||||
m_netclassOuterSizer->Clear( true );
|
||||
|
||||
|
@ -2263,7 +2266,7 @@ void APPEARANCE_CONTROLS::rebuildNets()
|
|||
setting->ctl_visibility = new BITMAP_TOGGLE( setting->ctl_panel, aId,
|
||||
KiBitmap( BITMAPS::visibility ),
|
||||
KiBitmap( BITMAPS::visibility_off ),
|
||||
true );
|
||||
!hiddenClasses.count( name ) );
|
||||
|
||||
wxString tip;
|
||||
tip.Printf( _( "Show or hide ratsnest for nets in %s" ), name );
|
||||
|
@ -2930,6 +2933,13 @@ void APPEARANCE_CONTROLS::showNetclass( const wxString& aClassName, bool aShow )
|
|||
}
|
||||
}
|
||||
|
||||
PROJECT_LOCAL_SETTINGS& localSettings = m_frame->Prj().GetLocalSettings();
|
||||
|
||||
if( !aShow )
|
||||
localSettings.m_HiddenNetclasses.insert( aClassName );
|
||||
else
|
||||
localSettings.m_HiddenNetclasses.erase( aClassName );
|
||||
|
||||
m_netsGrid->ForceRefresh();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue