ADDED: Hide ratsnest for specific nets
List of hidden nets stored in project local settings Hide/Show actions in context menu only for now, will add them to some more GUI places soon. Ref https://gitlab.com/kicad/code/kicad/-/issues/1951
This commit is contained in:
parent
95bfb64d48
commit
72b08f2b18
|
@ -177,8 +177,6 @@ NET_SETTINGS::NET_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) :
|
|||
}
|
||||
},
|
||||
{} ) );
|
||||
|
||||
m_params.emplace_back( new PARAM_LIST<wxString>( "hidden_nets", &m_HiddenNets, {} ) );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -138,6 +138,11 @@ PROJECT_LOCAL_SETTINGS::PROJECT_LOCAL_SETTINGS( const std::string& aFilename ) :
|
|||
{ "dimensions", true },
|
||||
{ "otherItems", true }
|
||||
} ) );
|
||||
|
||||
m_params.emplace_back( new PARAM_ENUM<PCB_LAYER_ID>(
|
||||
"active_layer", &m_ActiveLayer, F_Cu, PCBNEW_LAYER_ID_START, F_Fab ) );
|
||||
|
||||
m_params.emplace_back( new PARAM_LIST<wxString>( "hidden_nets", &m_HiddenNets, {} ) );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -50,12 +50,6 @@ public:
|
|||
*/
|
||||
std::map<wxString, KIGFX::COLOR4D> m_PcbNetColors;
|
||||
|
||||
/**
|
||||
* A list of netnames that have been manually hidden in the board editor.
|
||||
* Currently, hiding nets means hiding the ratsnest for those nets.
|
||||
*/
|
||||
std::vector<wxString> m_HiddenNets;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Parses a bus vector (e.g. A[7..0]) into name, begin, and end.
|
||||
|
|
|
@ -85,6 +85,15 @@ public:
|
|||
/// The GAL layers (aka items) that are turned on for viewing (@see GAL_LAYER_ID)
|
||||
GAL_SET m_VisibleItems;
|
||||
|
||||
/// The current (active) board layer for editing
|
||||
PCB_LAYER_ID m_ActiveLayer;
|
||||
|
||||
/**
|
||||
* A list of netnames that have been manually hidden in the board editor.
|
||||
* Currently, hiding nets means hiding the ratsnest for those nets.
|
||||
*/
|
||||
std::vector<wxString> m_HiddenNets;
|
||||
|
||||
/// State of the selection filter widget
|
||||
SELECTION_FILTER_OPTIONS m_SelectionFilter;
|
||||
};
|
||||
|
|
|
@ -219,6 +219,75 @@ private:
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Stores an enum as an integer
|
||||
*/
|
||||
template<typename EnumType>
|
||||
class PARAM_ENUM : public PARAM_BASE
|
||||
{
|
||||
public:
|
||||
PARAM_ENUM( const std::string& aJsonPath, EnumType* aPtr, EnumType aDefault,
|
||||
EnumType aMin, EnumType aMax, bool aReadOnly = false ) :
|
||||
PARAM_BASE( aJsonPath, aReadOnly ),
|
||||
m_ptr( aPtr ),
|
||||
m_min( aMin ),
|
||||
m_max( aMax ),
|
||||
m_default( aDefault )
|
||||
{
|
||||
}
|
||||
|
||||
void Load( JSON_SETTINGS* aSettings, bool aResetIfMissing = true ) const override
|
||||
{
|
||||
if( m_readOnly )
|
||||
return;
|
||||
|
||||
if( OPT<int> val = aSettings->Get<int>( m_path ) )
|
||||
{
|
||||
if( *val >= static_cast<int>( m_min ) && *val <= static_cast<int>( m_max ) )
|
||||
*m_ptr = static_cast<EnumType>( *val );
|
||||
else if( aResetIfMissing )
|
||||
*m_ptr = m_default;
|
||||
|
||||
}
|
||||
else if( aResetIfMissing )
|
||||
*m_ptr = m_default;
|
||||
}
|
||||
|
||||
void Store( JSON_SETTINGS* aSettings ) const override
|
||||
{
|
||||
aSettings->Set<int>( m_path, static_cast<int>( *m_ptr ) );
|
||||
}
|
||||
|
||||
EnumType GetDefault() const
|
||||
{
|
||||
return m_default;
|
||||
}
|
||||
|
||||
void SetDefault() override
|
||||
{
|
||||
*m_ptr = m_default;
|
||||
}
|
||||
|
||||
bool IsDefault() const override
|
||||
{
|
||||
return *m_ptr == m_default;
|
||||
}
|
||||
|
||||
bool MatchesFile( JSON_SETTINGS* aSettings ) const override
|
||||
{
|
||||
if( OPT<int> val = aSettings->Get<int>( m_path ) )
|
||||
return *val == static_cast<int>( *m_ptr );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
EnumType* m_ptr;
|
||||
EnumType m_min;
|
||||
EnumType m_max;
|
||||
EnumType m_default;
|
||||
};
|
||||
|
||||
/**
|
||||
* Like a normal param, but with custom getter and setter functions
|
||||
* @tparam ValueType is the value to store
|
||||
|
|
|
@ -605,6 +605,9 @@ void PCB_EDIT_FRAME::OnCloseWindow( wxCloseEvent& aEvent )
|
|||
wxMessageBox( msg, Pgm().App().GetAppName(), wxOK | wxICON_ERROR, this );
|
||||
}
|
||||
|
||||
// Make sure local settings are persisted
|
||||
SaveProjectSettings();
|
||||
|
||||
// Do not show the layer manager during closing to avoid flicker
|
||||
// on some platforms (Windows) that generate useless redraw of items in
|
||||
// the Layer Manger
|
||||
|
|
|
@ -218,8 +218,8 @@ void PCB_RENDER_SETTINGS::LoadDisplayOptions( const PCB_DISPLAY_OPTIONS& aOption
|
|||
}
|
||||
|
||||
|
||||
void PCB_RENDER_SETTINGS::LoadNetSettings( const NET_SETTINGS& aSettings,
|
||||
const NETINFO_LIST& aList )
|
||||
void PCB_RENDER_SETTINGS::LoadNetSettings( const NET_SETTINGS& aSettings, const NETINFO_LIST& aList,
|
||||
const std::set<int>& aHiddenNets )
|
||||
{
|
||||
m_netColors.clear();
|
||||
|
||||
|
@ -237,13 +237,9 @@ void PCB_RENDER_SETTINGS::LoadNetSettings( const NET_SETTINGS& aSettings,
|
|||
m_netclassColors[pair.first] = pair.second->GetPcbColor();
|
||||
}
|
||||
|
||||
m_hiddenNets.clear();
|
||||
m_hiddenNets = aHiddenNets;
|
||||
|
||||
|
||||
for( const wxString& hidden : aSettings.m_HiddenNets )
|
||||
{
|
||||
if( NETINFO_ITEM* net = aList.GetNetItem( hidden ) )
|
||||
m_hiddenNets.insert( net->GetNet() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -108,9 +108,11 @@ public:
|
|||
/**
|
||||
* Loads net-specific render settings
|
||||
* @param aSettings is the NET_SETTINGS for the current proejct
|
||||
* @param aList is the list of nets in the board
|
||||
* @param aList is the list of nets on the board
|
||||
* @param aHiddenNets is a list of nets to hide from the ratsnest
|
||||
*/
|
||||
void LoadNetSettings( const NET_SETTINGS& aSettings, const NETINFO_LIST& aList );
|
||||
void LoadNetSettings( const NET_SETTINGS& aSettings, const NETINFO_LIST& aList,
|
||||
const std::set<int>& aHiddenNets );
|
||||
|
||||
virtual void LoadColors( const COLOR_SETTINGS* aSettings ) override;
|
||||
|
||||
|
|
|
@ -84,7 +84,8 @@ bool PCB_EDIT_FRAME::LoadProjectSettings()
|
|||
{
|
||||
wxLogDebug( wxT( "Loading project '%s' settings." ), GetChars( Prj().GetProjectFullName() ) );
|
||||
|
||||
PROJECT_FILE& project = Prj().GetProjectFile();
|
||||
PROJECT_FILE& project = Prj().GetProjectFile();
|
||||
PROJECT_LOCAL_SETTINGS& localSettings = Prj().GetLocalSettings();
|
||||
|
||||
BASE_SCREEN::m_PageLayoutDescrFileName = project.m_BoardPageLayoutDescrFile;
|
||||
|
||||
|
@ -100,9 +101,16 @@ bool PCB_EDIT_FRAME::LoadProjectSettings()
|
|||
KIGFX::PCB_RENDER_SETTINGS* rs = static_cast<KIGFX::PCB_RENDER_SETTINGS*>(
|
||||
GetCanvas()->GetView()->GetPainter()->GetSettings() );
|
||||
|
||||
rs->LoadNetSettings( project.NetSettings(), GetBoard()->GetNetInfo() );
|
||||
NETINFO_LIST& nets = GetBoard()->GetNetInfo();
|
||||
std::set<int> hiddenNets;
|
||||
|
||||
PROJECT_LOCAL_SETTINGS& localSettings = Prj().GetLocalSettings();
|
||||
for( const wxString& hidden : localSettings.m_HiddenNets )
|
||||
{
|
||||
if( NETINFO_ITEM* net = nets.GetNetItem( hidden ) )
|
||||
hiddenNets.insert( net->GetNet() );
|
||||
}
|
||||
|
||||
rs->LoadNetSettings( project.NetSettings(), nets, hiddenNets );
|
||||
|
||||
SELECTION_FILTER_OPTIONS& filterOpts = GetToolManager()->GetTool<SELECTION_TOOL>()->GetFilter();
|
||||
|
||||
|
@ -126,18 +134,29 @@ void PCB_EDIT_FRAME::SaveProjectSettings()
|
|||
if( !IsWritable( fn ) )
|
||||
return;
|
||||
|
||||
PROJECT_FILE& project = Prj().GetProjectFile();
|
||||
PROJECT_FILE& project = Prj().GetProjectFile();
|
||||
PROJECT_LOCAL_SETTINGS& localSettings = Prj().GetLocalSettings();
|
||||
|
||||
// TODO: Can this be pulled out of BASE_SCREEN?
|
||||
project.m_BoardPageLayoutDescrFile = BASE_SCREEN::m_PageLayoutDescrFileName;
|
||||
|
||||
RecordDRCExclusions();
|
||||
|
||||
PROJECT_LOCAL_SETTINGS& localSettings = Prj().GetLocalSettings();
|
||||
KIGFX::PCB_RENDER_SETTINGS* rs = static_cast<KIGFX::PCB_RENDER_SETTINGS*>(
|
||||
GetCanvas()->GetView()->GetPainter()->GetSettings() );
|
||||
|
||||
NETINFO_LIST& nets = GetBoard()->GetNetInfo();
|
||||
|
||||
localSettings.m_HiddenNets.clear();
|
||||
|
||||
for( int netcode : rs->GetHiddenNets() )
|
||||
{
|
||||
if( NETINFO_ITEM* net = nets.GetNetItem( netcode ) )
|
||||
localSettings.m_HiddenNets.emplace_back( net->GetNetname() );
|
||||
}
|
||||
|
||||
SELECTION_FILTER_OPTIONS& filterOpts = GetToolManager()->GetTool<SELECTION_TOOL>()->GetFilter();
|
||||
|
||||
localSettings.m_SelectionFilter = filterOpts;
|
||||
localSettings.m_SelectionFilter = filterOpts;
|
||||
|
||||
GetSettingsManager()->SaveProject();
|
||||
}
|
||||
|
|
|
@ -604,7 +604,8 @@ TOOL_ACTION PCB_ACTIONS::appendBoard( "pcbnew.EditorControl.appendBoard",
|
|||
add_board_xpm );
|
||||
|
||||
TOOL_ACTION PCB_ACTIONS::highlightNet( "pcbnew.EditorControl.highlightNet",
|
||||
AS_GLOBAL );
|
||||
AS_GLOBAL, 0, "", _( "Highlight Net" ), _( "Highlight the selected net" ),
|
||||
net_highlight_xpm );
|
||||
|
||||
TOOL_ACTION PCB_ACTIONS::toggleLastNetHighlight( "pcbnew.EditorControl.toggleLastNetHighlight",
|
||||
AS_GLOBAL, 0, "",
|
||||
|
@ -629,6 +630,12 @@ TOOL_ACTION PCB_ACTIONS::highlightNetSelection( "pcbnew.EditorControl.highlightN
|
|||
TOOL_ACTION PCB_ACTIONS::highlightItem( "pcbnew.EditorControl.highlightItem",
|
||||
AS_GLOBAL );
|
||||
|
||||
TOOL_ACTION PCB_ACTIONS::hideNet( "pcbnew.EditorControl.hideNet", AS_GLOBAL, 0, "",
|
||||
_( "Hide Net" ), _( "Hide the ratsnest for the selected net" ), ratsnest_xpm );
|
||||
|
||||
TOOL_ACTION PCB_ACTIONS::showNet( "pcbnew.EditorControl.showNet", AS_GLOBAL, 0, "",
|
||||
_( "Show Net" ), _( "Show the ratsnest for the selected net" ), ratsnest_xpm );
|
||||
|
||||
TOOL_ACTION PCB_ACTIONS::showEeschema( "pcbnew.EditorControl.showEeschema",
|
||||
AS_GLOBAL, 0, "",
|
||||
_( "Switch to Schematic Editor" ), _( "Open schematic in Eeschema" ),
|
||||
|
|
|
@ -404,17 +404,21 @@ public:
|
|||
static TOOL_ACTION pickerTool;
|
||||
static TOOL_ACTION measureTool;
|
||||
static TOOL_ACTION updateUnits;
|
||||
static TOOL_ACTION drillOrigin;
|
||||
static TOOL_ACTION placeFileOrigin;
|
||||
static TOOL_ACTION appendBoard;
|
||||
static TOOL_ACTION showEeschema;
|
||||
static TOOL_ACTION boardStatistics;
|
||||
|
||||
// Appearance controls
|
||||
static TOOL_ACTION clearHighlight;
|
||||
static TOOL_ACTION highlightNet;
|
||||
static TOOL_ACTION toggleLastNetHighlight;
|
||||
static TOOL_ACTION highlightNetTool;
|
||||
static TOOL_ACTION highlightNetSelection;
|
||||
static TOOL_ACTION highlightItem;
|
||||
static TOOL_ACTION drillOrigin;
|
||||
static TOOL_ACTION placeFileOrigin;
|
||||
static TOOL_ACTION appendBoard;
|
||||
static TOOL_ACTION showEeschema;
|
||||
static TOOL_ACTION boardStatistics;
|
||||
static TOOL_ACTION hideNet;
|
||||
static TOOL_ACTION showNet;
|
||||
|
||||
// Ratsnest
|
||||
static TOOL_ACTION localRatsnestTool;
|
||||
|
|
|
@ -21,12 +21,12 @@
|
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
|
||||
#include <bitmaps.h>
|
||||
#include <tool/tool_manager.h>
|
||||
#include <tools/selection_tool.h>
|
||||
#include <tools/pcbnew_picker_tool.h>
|
||||
#include <tools/edit_tool.h>
|
||||
#include <painter.h>
|
||||
#include <pcb_painter.h>
|
||||
#include <connectivity/connectivity_data.h>
|
||||
#include <profile.h>
|
||||
#include "pcb_inspection_tool.h"
|
||||
|
@ -43,10 +43,69 @@ PCB_INSPECTION_TOOL::PCB_INSPECTION_TOOL() :
|
|||
}
|
||||
|
||||
|
||||
class NET_CONTEXT_MENU : public ACTION_MENU
|
||||
{
|
||||
public:
|
||||
NET_CONTEXT_MENU() : ACTION_MENU( true )
|
||||
{
|
||||
SetIcon( ratsnest_xpm );
|
||||
SetTitle( _( "Net Tools" ) );
|
||||
|
||||
Add( PCB_ACTIONS::showNet );
|
||||
Add( PCB_ACTIONS::hideNet );
|
||||
// Add( PCB_ACTIONS::highlightNet );
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void update() override
|
||||
{
|
||||
const auto& selection = getToolManager()->GetTool<SELECTION_TOOL>()->GetSelection();
|
||||
|
||||
bool haveNetCode = false;
|
||||
|
||||
for( EDA_ITEM* item : selection )
|
||||
{
|
||||
if( BOARD_CONNECTED_ITEM* bci = dynamic_cast<BOARD_CONNECTED_ITEM*>( item ) )
|
||||
{
|
||||
if( bci->GetNetCode() > 0 )
|
||||
{
|
||||
haveNetCode = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Enable( getMenuId( PCB_ACTIONS::showNet ), haveNetCode );
|
||||
Enable( getMenuId( PCB_ACTIONS::hideNet ), haveNetCode );
|
||||
// Enable( getMenuId( PCB_ACTIONS::highlightNet ), haveNetCode );
|
||||
}
|
||||
|
||||
ACTION_MENU* create() const override
|
||||
{
|
||||
return new NET_CONTEXT_MENU();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
bool PCB_INSPECTION_TOOL::Init()
|
||||
{
|
||||
SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<SELECTION_TOOL>();
|
||||
|
||||
auto netSubMenu = std::make_shared<NET_CONTEXT_MENU>();
|
||||
netSubMenu->SetTool( this );
|
||||
|
||||
static KICAD_T connectedTypes[] = { PCB_TRACE_T, PCB_VIA_T, PCB_ARC_T, PCB_PAD_T,
|
||||
PCB_ZONE_AREA_T, EOT };
|
||||
|
||||
CONDITIONAL_MENU& menu = selectionTool->GetToolMenu().GetMenu();
|
||||
|
||||
selectionTool->GetToolMenu().AddSubMenu( netSubMenu );
|
||||
menu.AddMenu( netSubMenu.get(), SELECTION_CONDITIONS::OnlyTypes( connectedTypes ) );
|
||||
|
||||
m_ratsnestTimer.SetOwner( this );
|
||||
Connect( m_ratsnestTimer.GetId(), wxEVT_TIMER, wxTimerEventHandler( PCB_INSPECTION_TOOL::ratsnestTimer ), NULL, this );
|
||||
Connect( m_ratsnestTimer.GetId(), wxEVT_TIMER,
|
||||
wxTimerEventHandler( PCB_INSPECTION_TOOL::ratsnestTimer ), NULL, this );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -462,6 +521,7 @@ void PCB_INSPECTION_TOOL::calculateSelectionRatsnest()
|
|||
connectivity->ComputeDynamicRatsnest( items );
|
||||
}
|
||||
|
||||
|
||||
int PCB_INSPECTION_TOOL::ListNets( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
if( m_listNetsDialog == nullptr )
|
||||
|
@ -482,6 +542,7 @@ int PCB_INSPECTION_TOOL::ListNets( const TOOL_EVENT& aEvent )
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void PCB_INSPECTION_TOOL::onListNetsDialogClosed( wxCommandEvent& event )
|
||||
{
|
||||
m_listNetsDialogSettings = m_listNetsDialog->Settings();
|
||||
|
@ -496,6 +557,53 @@ void PCB_INSPECTION_TOOL::onListNetsDialogClosed( wxCommandEvent& event )
|
|||
m_listNetsDialog.release();
|
||||
}
|
||||
|
||||
|
||||
int PCB_INSPECTION_TOOL::HideNet( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
doHideNet( aEvent.Parameter<intptr_t>(), true );
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int PCB_INSPECTION_TOOL::ShowNet( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
doHideNet( aEvent.Parameter<intptr_t>(), false );
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void PCB_INSPECTION_TOOL::doHideNet( int aNetCode, bool aHide )
|
||||
{
|
||||
KIGFX::PCB_RENDER_SETTINGS* rs = static_cast<KIGFX::PCB_RENDER_SETTINGS*>(
|
||||
m_toolMgr->GetView()->GetPainter()->GetSettings() );
|
||||
|
||||
SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<SELECTION_TOOL>();
|
||||
SELECTION& selection = selectionTool->GetSelection();
|
||||
|
||||
if( aNetCode <= 0 && !selection.Empty() )
|
||||
{
|
||||
for( EDA_ITEM* item : selection )
|
||||
{
|
||||
if( BOARD_CONNECTED_ITEM* bci = dynamic_cast<BOARD_CONNECTED_ITEM*>( item ) )
|
||||
{
|
||||
if( bci->GetNetCode() > 0 )
|
||||
doHideNet( bci->GetNetCode(), aHide );
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if( aHide )
|
||||
rs->GetHiddenNets().insert( aNetCode );
|
||||
else
|
||||
rs->GetHiddenNets().erase( aNetCode );
|
||||
|
||||
m_frame->GetCanvas()->RedrawRatsnest();
|
||||
m_frame->GetCanvas()->Refresh();
|
||||
}
|
||||
|
||||
|
||||
void PCB_INSPECTION_TOOL::setTransitions()
|
||||
{
|
||||
Go( &PCB_INSPECTION_TOOL::CrossProbePcbToSch, EVENTS::SelectedEvent );
|
||||
|
@ -516,4 +624,7 @@ void PCB_INSPECTION_TOOL::setTransitions()
|
|||
Go( &PCB_INSPECTION_TOOL::HighlightNetTool, PCB_ACTIONS::highlightNetTool.MakeEvent() );
|
||||
Go( &PCB_INSPECTION_TOOL::ClearHighlight, ACTIONS::cancelInteractive.MakeEvent() );
|
||||
Go( &PCB_INSPECTION_TOOL::HighlightItem, PCB_ACTIONS::highlightItem.MakeEvent() );
|
||||
|
||||
Go( &PCB_INSPECTION_TOOL::HideNet, PCB_ACTIONS::hideNet.MakeEvent() );
|
||||
Go( &PCB_INSPECTION_TOOL::ShowNet, PCB_ACTIONS::showNet.MakeEvent() );
|
||||
}
|
||||
|
|
|
@ -82,6 +82,12 @@ public:
|
|||
|
||||
int ListNets( const TOOL_EVENT& aEvent );
|
||||
|
||||
///> Hide the ratsnest for a given net
|
||||
int HideNet( const TOOL_EVENT& aEvent );
|
||||
|
||||
///> Show the ratsnest for a given net
|
||||
int ShowNet( const TOOL_EVENT& aEvent );
|
||||
|
||||
private:
|
||||
///> Event handler to recalculate dynamic ratsnest
|
||||
void ratsnestTimer( wxTimerEvent& aEvent );
|
||||
|
@ -91,6 +97,8 @@ private:
|
|||
|
||||
bool highlightNet( const VECTOR2D& aPosition, bool aUseSelection );
|
||||
|
||||
void doHideNet( int aNetCode, bool aHide );
|
||||
|
||||
///> Bind handlers to corresponding TOOL_ACTIONs
|
||||
void setTransitions() override;
|
||||
|
||||
|
|
Loading…
Reference in New Issue