Save selection filter state in project local settings

This commit is contained in:
Jon Evans 2020-07-06 21:53:12 -04:00
parent d8be5f9ecf
commit a3655225cd
7 changed files with 178 additions and 28 deletions

View File

@ -29,7 +29,8 @@ PROJECT_LOCAL_SETTINGS::PROJECT_LOCAL_SETTINGS( const std::string& aFilename ) :
JSON_SETTINGS( aFilename, SETTINGS_LOC::PROJECT, projectLocalSettingsVersion,
/* aCreateIfMissing = */ true, /* aCreateIfDefault = */ false,
/* aWriteFile = */ true ),
m_project( nullptr )
m_project( nullptr ),
m_SelectionFilter()
{
m_params.emplace_back( new PARAM_LAMBDA<std::string>( "board.visible_layers",
[&]() -> std::string
@ -80,6 +81,63 @@ PROJECT_LOCAL_SETTINGS::PROJECT_LOCAL_SETTINGS( const std::string& aFilename ) :
}
},
{} ) );
m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "board.selection_filter",
[&]() -> nlohmann::json
{
nlohmann::json ret;
ret["lockedItems"] = m_SelectionFilter.lockedItems;
ret["footprints"] = m_SelectionFilter.footprints;
ret["text"] = m_SelectionFilter.text;
ret["tracks"] = m_SelectionFilter.tracks;
ret["vias"] = m_SelectionFilter.vias;
ret["pads"] = m_SelectionFilter.pads;
ret["graphics"] = m_SelectionFilter.graphics;
ret["zones"] = m_SelectionFilter.zones;
ret["keepouts"] = m_SelectionFilter.keepouts;
ret["dimensions"] = m_SelectionFilter.dimensions;
ret["otherItems"] = m_SelectionFilter.otherItems;
return ret;
},
[&]( const nlohmann::json& aVal )
{
if( aVal.empty() || !aVal.is_object() )
return;
auto setIfPresent =
[&aVal]( const std::string& aKey, bool& aTarget )
{
if( aVal.contains( aKey ) && aVal.at( aKey ).is_boolean() )
aTarget = aVal.at( aKey ).get<bool>();
};
setIfPresent( "lockedItems", m_SelectionFilter.lockedItems );
setIfPresent( "footprints", m_SelectionFilter.footprints );
setIfPresent( "text", m_SelectionFilter.text );
setIfPresent( "tracks", m_SelectionFilter.tracks );
setIfPresent( "vias", m_SelectionFilter.vias );
setIfPresent( "pads", m_SelectionFilter.pads );
setIfPresent( "graphics", m_SelectionFilter.graphics );
setIfPresent( "zones", m_SelectionFilter.zones );
setIfPresent( "keepouts", m_SelectionFilter.keepouts );
setIfPresent( "dimensions", m_SelectionFilter.dimensions );
setIfPresent( "otherItems", m_SelectionFilter.otherItems );
},
{
{ "lockedItems", true },
{ "footprints", true },
{ "text", true },
{ "tracks", true },
{ "vias", true },
{ "pads", true },
{ "graphics", true },
{ "zones", true },
{ "keepouts", true },
{ "dimensions", true },
{ "otherItems", true }
} ) );
}

View File

@ -0,0 +1,70 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2020 Jon Evans <jon@craftyjon.com>
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef KICAD_BOARD_LOCAL_SETTINGS_H
#define KICAD_BOARD_LOCAL_SETTINGS_H
/**
* Selection filtering that applies all the time (not the "filter selection" dialog that modifies
* the current selection)
*/
struct SELECTION_FILTER_OPTIONS
{
bool lockedItems; ///< Allow selecting locked items
bool footprints; ///< Allow selecting entire footprints
bool text; ///< Text (free or attached to a footprint)
bool tracks; ///< Copper tracks
bool vias; ///< Vias (all types>
bool pads; ///< Footprint pads
bool graphics; ///< Graphic lines, shapes, polygons
bool zones; ///< Copper zones
bool keepouts; ///< Keepout zones
bool dimensions; ///< Dimension items
bool otherItems; ///< Anything not fitting one of the above categories
SELECTION_FILTER_OPTIONS()
{
lockedItems = true;
footprints = true;
text = true;
tracks = true;
vias = true;
pads = true;
graphics = true;
zones = true;
keepouts = true;
dimensions = true;
otherItems = true;
}
bool Any()
{
return ( lockedItems || footprints || text || tracks || vias || pads || graphics || zones
|| keepouts || dimensions || otherItems );
}
bool All()
{
return ( lockedItems && footprints && text && tracks && vias && pads && graphics && zones
&& keepouts && dimensions && otherItems );
}
};
#endif // KICAD_BOARD_LOCAL_SETTINGS_H

View File

@ -22,6 +22,7 @@
#define KICAD_PROJECT_LOCAL_SETTINGS_H
#include <layers_id_colors_and_visibility.h>
#include <project/board_local_settings.h>
#include <settings/json_settings.h>
#include <wildcards_and_files_ext.h>
@ -83,6 +84,9 @@ public:
/// The GAL layers (aka items) that are turned on for viewing (@see GAL_LAYER_ID)
GAL_SET m_VisibleItems;
/// State of the selection filter widget
SELECTION_FILTER_OPTIONS m_SelectionFilter;
};
#endif

View File

@ -37,6 +37,8 @@
#include <panel_pcbnew_color_settings.h>
#include <panel_display_options.h>
#include <panel_pcbnew_action_plugins.h>
#include <tool/tool_manager.h>
#include <tools/selection_tool.h>
#include <fp_lib_table.h>
#include <ws_data_model.h>
#include <class_board.h>
@ -46,7 +48,9 @@
#include <invoke_pcb_dialog.h>
#include <wildcards_and_files_ext.h>
#include <widgets/paged_dialog.h>
#include <widgets/panel_selection_filter.h>
#include <project/project_file.h>
#include <project/project_local_settings.h>
void PCB_EDIT_FRAME::On3DShapeLibWizard( wxCommandEvent& event )
@ -91,6 +95,13 @@ bool PCB_EDIT_FRAME::LoadProjectSettings()
pglayout.SetPageLayout( filename );
PROJECT_LOCAL_SETTINGS& localSettings = Prj().GetLocalSettings();
SELECTION_FILTER_OPTIONS& filterOpts = GetToolManager()->GetTool<SELECTION_TOOL>()->GetFilter();
filterOpts = localSettings.m_SelectionFilter;
m_selectionFilterPanel->SetCheckboxesFromFilter( filterOpts );
return true;
}
@ -115,5 +126,11 @@ void PCB_EDIT_FRAME::SaveProjectSettings()
RecordDRCExclusions();
PROJECT_LOCAL_SETTINGS& localSettings = Prj().GetLocalSettings();
SELECTION_FILTER_OPTIONS& filterOpts = GetToolManager()->GetTool<SELECTION_TOOL>()->GetFilter();
localSettings.m_SelectionFilter = filterOpts;
GetSettingsManager()->SaveProject();
}

View File

@ -30,6 +30,7 @@
#include <memory>
#include <math/vector2d.h>
#include <project/board_local_settings.h>
#include <tools/pcb_tool_base.h>
#include <tool/action_menu.h>
#include <tools/pcbnew_selection.h>
@ -49,26 +50,6 @@ namespace KIGFX
typedef void (*CLIENT_SELECTION_FILTER)( const VECTOR2I&, GENERAL_COLLECTOR& );
/**
* Selection filtering that applies all the time (not the "filter selection" dialog that modifies
* the current selection)
*/
struct SELECTION_FILTER_OPTIONS
{
bool lockedItems; ///< Allow selecting locked items
bool footprints; ///< Allow selecting entire footprints
bool text; ///< Text (free or attached to a footprint)
bool tracks; ///< Copper tracks
bool vias; ///< Vias (all types>
bool pads; ///< Footprint pads
bool graphics; ///< Graphic lines, shapes, polygons
bool zones; ///< Copper zones
bool keepouts; ///< Keepout zones
bool dimensions; ///< Dimension items
bool otherItems; ///< Anything not fitting one of the above categories
};
/**
* SELECTION_TOOL
*

View File

@ -33,10 +33,8 @@ PANEL_SELECTION_FILTER::PANEL_SELECTION_FILTER( wxWindow* aParent ) :
m_tool = m_frame->GetToolManager()->GetTool<SELECTION_TOOL>();
wxASSERT( m_tool );
m_cbAllItems->SetValue( true );
wxCommandEvent dummy;
OnFilterChanged( dummy );
SELECTION_FILTER_OPTIONS& opts = m_tool->GetFilter();
SetCheckboxesFromFilter( opts );
m_cbFootprints->Bind( wxEVT_RIGHT_DOWN, &PANEL_SELECTION_FILTER::onRightClick, this );
m_cbText->Bind( wxEVT_RIGHT_DOWN, &PANEL_SELECTION_FILTER::onRightClick, this );
@ -51,6 +49,28 @@ PANEL_SELECTION_FILTER::PANEL_SELECTION_FILTER( wxWindow* aParent ) :
}
void PANEL_SELECTION_FILTER::SetCheckboxesFromFilter( SELECTION_FILTER_OPTIONS& aOptions )
{
Freeze();
m_cbLockedItems->SetValue( aOptions.lockedItems );
m_cbFootprints->SetValue( aOptions.footprints );
m_cbText->SetValue( aOptions.text );
m_cbTracks->SetValue( aOptions.tracks );
m_cbVias->SetValue( aOptions.vias );
m_cbPads->SetValue( aOptions.pads );
m_cbGraphics->SetValue( aOptions.graphics );
m_cbZones->SetValue( aOptions.zones );
m_cbKeepouts->SetValue( aOptions.keepouts );
m_cbDimensions->SetValue( aOptions.dimensions );
m_cbOtherItems->SetValue( aOptions.otherItems );
m_cbAllItems->SetValue( aOptions.All() );
Thaw();
}
void PANEL_SELECTION_FILTER::OnFilterChanged( wxCommandEvent& aEvent )
{
if( aEvent.GetEventObject() == m_cbAllItems )
@ -92,9 +112,7 @@ bool PANEL_SELECTION_FILTER::setFilterFromCheckboxes( SELECTION_FILTER_OPTIONS&
aOptions.dimensions = m_cbDimensions->GetValue();
aOptions.otherItems = m_cbOtherItems->GetValue();
return ( aOptions.lockedItems && aOptions.footprints && aOptions.text && aOptions.tracks
&& aOptions.vias && aOptions.pads && aOptions.graphics && aOptions.zones
&& aOptions.keepouts && aOptions.dimensions && aOptions.otherItems );
return aOptions.All();
}

View File

@ -35,6 +35,8 @@ public:
~PANEL_SELECTION_FILTER() = default;
void SetCheckboxesFromFilter( SELECTION_FILTER_OPTIONS& aOptions );
protected:
void OnFilterChanged( wxCommandEvent& aEvent ) override;