mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-04-20 21:01:22 +00:00
Move layer presets to use named render layers
Add a migration to account for KiCad 8 render layer id numbers Fixes https://gitlab.com/kicad/code/kicad/-/issues/18718
This commit is contained in:
parent
fdfeda7b72
commit
96f87b5b83
@ -105,6 +105,7 @@ set( KICOMMON_SRCS
|
||||
settings/grid_settings.cpp
|
||||
settings/json_settings.cpp
|
||||
settings/kicad_settings.cpp
|
||||
settings/layer_settings_utils.cpp
|
||||
settings/nested_settings.cpp
|
||||
settings/parameters.cpp
|
||||
settings/settings_manager.cpp
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include <lset.h>
|
||||
#include <lseq.h>
|
||||
#include <project/board_project_settings.h>
|
||||
#include <settings/layer_settings_utils.h>
|
||||
|
||||
using namespace std::placeholders;
|
||||
|
||||
@ -59,7 +60,10 @@ nlohmann::json PARAM_LAYER_PRESET::presetsToJson()
|
||||
nlohmann::json renderLayers = nlohmann::json::array();
|
||||
|
||||
for( GAL_LAYER_ID layer : preset.renderLayers.Seq() )
|
||||
renderLayers.push_back( static_cast<int>( layer ) );
|
||||
{
|
||||
if( std::optional<VISIBILITY_LAYER> vl = VisibilityLayerFromRenderLayer( layer ) )
|
||||
renderLayers.push_back( VisibilityLayerToString( *vl ) );
|
||||
}
|
||||
|
||||
js["renderLayers"] = renderLayers;
|
||||
|
||||
@ -115,13 +119,12 @@ void PARAM_LAYER_PRESET::jsonToPresets( const nlohmann::json& aJson )
|
||||
|
||||
for( const nlohmann::json& layer : preset.at( "renderLayers" ) )
|
||||
{
|
||||
if( layer.is_number_integer() )
|
||||
if( layer.is_string() )
|
||||
{
|
||||
int layerNum = layer.get<int>();
|
||||
std::string vs = layer.get<std::string>();
|
||||
|
||||
if( layerNum >= GAL_LAYER_ID_START
|
||||
&& layerNum < GAL_LAYER_ID_END )
|
||||
p.renderLayers.set( static_cast<GAL_LAYER_ID>( layerNum ) );
|
||||
if( std::optional<GAL_LAYER_ID> rl = RenderLayerFromVisbilityString( vs ) )
|
||||
p.renderLayers.set( *rl );
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -146,6 +149,31 @@ void PARAM_LAYER_PRESET::MigrateToV9Layers( nlohmann::json& aJson )
|
||||
}
|
||||
|
||||
aJson["layers"] = newLayers;
|
||||
|
||||
if( aJson.contains( "activeLayer" ) )
|
||||
aJson["activeLayer"] = BoardLayerFromLegacyId( aJson.at( "activeLayer" ).get<int>() );
|
||||
}
|
||||
|
||||
|
||||
void PARAM_LAYER_PRESET::MigrateToNamedRenderLayers( nlohmann::json& aJson )
|
||||
{
|
||||
static constexpr int V8_GAL_LAYER_ID_START = 125;
|
||||
|
||||
if( !aJson.is_object() || !aJson.contains( "renderLayers" ) )
|
||||
return;
|
||||
|
||||
std::vector<std::string> newLayers;
|
||||
|
||||
for( const nlohmann::json& layer : aJson.at( "renderLayers" ) )
|
||||
{
|
||||
wxCHECK2( layer.is_number_integer(), continue );
|
||||
GAL_LAYER_ID layerId = GAL_LAYER_ID_START + ( layer.get<int>() - V8_GAL_LAYER_ID_START );
|
||||
|
||||
if( std::optional<VISIBILITY_LAYER> vl = VisibilityLayerFromRenderLayer( layerId ) )
|
||||
newLayers.emplace_back( VisibilityLayerToString( *vl ) );
|
||||
}
|
||||
|
||||
aJson["renderLayers"] = newLayers;
|
||||
}
|
||||
|
||||
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
|
||||
///! Update the schema version whenever a migration is required
|
||||
const int projectFileSchemaVersion = 2;
|
||||
const int projectFileSchemaVersion = 3;
|
||||
|
||||
|
||||
PROJECT_FILE::PROJECT_FILE( const wxString& aFullPath ) :
|
||||
@ -142,6 +142,7 @@ PROJECT_FILE::PROJECT_FILE( const wxString& aFullPath ) :
|
||||
&m_IP2581Bom.dist, wxEmptyString ) );
|
||||
|
||||
registerMigration( 1, 2, std::bind( &PROJECT_FILE::migrateSchema1To2, this ) );
|
||||
registerMigration( 2, 3, std::bind( &PROJECT_FILE::migrateSchema2To3, this ) );
|
||||
}
|
||||
|
||||
|
||||
@ -165,6 +166,25 @@ bool PROJECT_FILE::migrateSchema1To2()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Schema version 3: move layer presets to use named render layers
|
||||
*/
|
||||
bool PROJECT_FILE::migrateSchema2To3()
|
||||
{
|
||||
auto p( "/board/layer_presets"_json_pointer );
|
||||
|
||||
if( !m_internals->contains( p ) || !m_internals->at( p ).is_array() )
|
||||
return true;
|
||||
|
||||
nlohmann::json& presets = m_internals->at( p );
|
||||
|
||||
for( nlohmann::json& entry : presets )
|
||||
PARAM_LAYER_PRESET::MigrateToNamedRenderLayers( entry );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool PROJECT_FILE::MigrateFromLegacy( wxConfigBase* aCfg )
|
||||
{
|
||||
bool ret = true;
|
||||
|
104
common/settings/layer_settings_utils.cpp
Normal file
104
common/settings/layer_settings_utils.cpp
Normal file
@ -0,0 +1,104 @@
|
||||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright The 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/>.
|
||||
*/
|
||||
|
||||
#include <boost/algorithm/string/case_conv.hpp>
|
||||
#include <magic_enum.hpp>
|
||||
#include <settings/layer_settings_utils.h>
|
||||
|
||||
|
||||
GAL_LAYER_ID RenderLayerFromVisibilityLayer( VISIBILITY_LAYER aLayer )
|
||||
{
|
||||
switch( aLayer )
|
||||
{
|
||||
case VISIBILITY_LAYER::TRACKS: return LAYER_TRACKS;
|
||||
case VISIBILITY_LAYER::VIAS: return LAYER_VIAS;
|
||||
case VISIBILITY_LAYER::PADS: return LAYER_PADS;
|
||||
case VISIBILITY_LAYER::ZONES: return LAYER_ZONES;
|
||||
case VISIBILITY_LAYER::SHAPES: return LAYER_SHAPES;
|
||||
case VISIBILITY_LAYER::BITMAPS: return LAYER_DRAW_BITMAPS;
|
||||
case VISIBILITY_LAYER::FOOTPRINTS_FRONT: return LAYER_FOOTPRINTS_FR;
|
||||
case VISIBILITY_LAYER::FOOTPRINTS_BACK: return LAYER_FOOTPRINTS_BK;
|
||||
case VISIBILITY_LAYER::FOOTPRINT_VALUES: return LAYER_FP_VALUES;
|
||||
case VISIBILITY_LAYER::FOOTPRINT_REFERENCES: return LAYER_FP_REFERENCES;
|
||||
case VISIBILITY_LAYER::FOOTPRINT_TEXT: return LAYER_FP_TEXT;
|
||||
case VISIBILITY_LAYER::FOOTPRINT_ANCHORS: return LAYER_ANCHOR;
|
||||
case VISIBILITY_LAYER::RATSNEST: return LAYER_RATSNEST;
|
||||
case VISIBILITY_LAYER::DRC_WARNINGS: return LAYER_DRC_WARNING;
|
||||
case VISIBILITY_LAYER::DRC_ERRORS: return LAYER_DRC_ERROR;
|
||||
case VISIBILITY_LAYER::DRC_EXCLUSIONS: return LAYER_DRC_EXCLUSION;
|
||||
case VISIBILITY_LAYER::LOCKED_ITEM_SHADOWS: return LAYER_LOCKED_ITEM_SHADOW;
|
||||
case VISIBILITY_LAYER::CONFLICT_SHADOWS: return LAYER_CONFLICTS_SHADOW;
|
||||
case VISIBILITY_LAYER::DRAWING_SHEET: return LAYER_DRAWINGSHEET;
|
||||
case VISIBILITY_LAYER::GRID: return LAYER_GRID;
|
||||
}
|
||||
|
||||
wxCHECK_MSG( false, GAL_LAYER_ID_END, "Unhandled layer in RenderLayerFromVisibilityLayer" );
|
||||
}
|
||||
|
||||
|
||||
std::optional<VISIBILITY_LAYER> VisibilityLayerFromRenderLayer( GAL_LAYER_ID aLayerId )
|
||||
{
|
||||
switch( aLayerId )
|
||||
{
|
||||
case LAYER_TRACKS: return VISIBILITY_LAYER::TRACKS;
|
||||
case LAYER_VIAS: return VISIBILITY_LAYER::VIAS;
|
||||
case LAYER_PADS: return VISIBILITY_LAYER::PADS;
|
||||
case LAYER_ZONES: return VISIBILITY_LAYER::ZONES;
|
||||
case LAYER_SHAPES: return VISIBILITY_LAYER::SHAPES;
|
||||
case LAYER_DRAW_BITMAPS: return VISIBILITY_LAYER::BITMAPS;
|
||||
case LAYER_FOOTPRINTS_FR: return VISIBILITY_LAYER::FOOTPRINTS_FRONT;
|
||||
case LAYER_FOOTPRINTS_BK: return VISIBILITY_LAYER::FOOTPRINTS_BACK;
|
||||
case LAYER_FP_VALUES: return VISIBILITY_LAYER::FOOTPRINT_VALUES;
|
||||
case LAYER_FP_REFERENCES: return VISIBILITY_LAYER::FOOTPRINT_REFERENCES;
|
||||
case LAYER_FP_TEXT: return VISIBILITY_LAYER::FOOTPRINT_TEXT;
|
||||
case LAYER_ANCHOR: return VISIBILITY_LAYER::FOOTPRINT_ANCHORS;
|
||||
case LAYER_RATSNEST: return VISIBILITY_LAYER::RATSNEST;
|
||||
case LAYER_DRC_WARNING: return VISIBILITY_LAYER::DRC_WARNINGS;
|
||||
case LAYER_DRC_ERROR: return VISIBILITY_LAYER::DRC_ERRORS;
|
||||
case LAYER_DRC_EXCLUSION: return VISIBILITY_LAYER::DRC_EXCLUSIONS;
|
||||
case LAYER_LOCKED_ITEM_SHADOW: return VISIBILITY_LAYER::LOCKED_ITEM_SHADOWS;
|
||||
case LAYER_CONFLICTS_SHADOW: return VISIBILITY_LAYER::CONFLICT_SHADOWS;
|
||||
case LAYER_DRAWINGSHEET: return VISIBILITY_LAYER::DRAWING_SHEET;
|
||||
case LAYER_GRID: return VISIBILITY_LAYER::GRID;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
|
||||
std::optional<GAL_LAYER_ID> RenderLayerFromVisbilityString( const std::string& aLayer )
|
||||
{
|
||||
if( std::optional<VISIBILITY_LAYER> val =
|
||||
magic_enum::enum_cast<VISIBILITY_LAYER>( aLayer, magic_enum::case_insensitive ) )
|
||||
{
|
||||
return RenderLayerFromVisibilityLayer( *val );
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
|
||||
std::string VisibilityLayerToString( VISIBILITY_LAYER aLayerId )
|
||||
{
|
||||
std::string ret( magic_enum::enum_name<VISIBILITY_LAYER>( aLayerId ) );
|
||||
boost::algorithm::to_lower( ret );
|
||||
return ret;
|
||||
}
|
@ -99,6 +99,8 @@ private:
|
||||
bool migrateSchema0to1();
|
||||
|
||||
bool migrateSchema2To3();
|
||||
|
||||
bool migrateSchema3To4();
|
||||
};
|
||||
|
||||
|
||||
|
@ -192,6 +192,8 @@ public:
|
||||
|
||||
static void MigrateToV9Layers( nlohmann::json& aJson );
|
||||
|
||||
static void MigrateToNamedRenderLayers( nlohmann::json& aJson );
|
||||
|
||||
private:
|
||||
nlohmann::json presetsToJson();
|
||||
|
||||
|
@ -187,6 +187,7 @@ public:
|
||||
|
||||
private:
|
||||
bool migrateSchema1To2();
|
||||
bool migrateSchema2To3();
|
||||
|
||||
/// An list of schematic sheets in this project
|
||||
std::vector<FILE_INFO_PAIR> m_sheets;
|
||||
|
63
include/settings/layer_settings_utils.h
Normal file
63
include/settings/layer_settings_utils.h
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright The 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 LAYER_SETTINGS_UTILS_H
|
||||
#define LAYER_SETTINGS_UTILS_H
|
||||
|
||||
#include <optional>
|
||||
#include <layer_ids.h>
|
||||
|
||||
/**
|
||||
* The set of things that can have visibility settings stored in a project file
|
||||
* (for example in a view preset). This is maintained separately from the enums in
|
||||
* layer_ids.h because not all GAL layers get visibility controls, and these are
|
||||
* turned into strings for storing in JSON settings files.
|
||||
*/
|
||||
enum class VISIBILITY_LAYER
|
||||
{
|
||||
TRACKS,
|
||||
VIAS,
|
||||
PADS,
|
||||
ZONES,
|
||||
SHAPES,
|
||||
BITMAPS,
|
||||
FOOTPRINTS_FRONT,
|
||||
FOOTPRINTS_BACK,
|
||||
FOOTPRINT_VALUES,
|
||||
FOOTPRINT_REFERENCES,
|
||||
FOOTPRINT_TEXT,
|
||||
FOOTPRINT_ANCHORS,
|
||||
RATSNEST,
|
||||
DRC_WARNINGS,
|
||||
DRC_ERRORS,
|
||||
DRC_EXCLUSIONS,
|
||||
LOCKED_ITEM_SHADOWS,
|
||||
CONFLICT_SHADOWS,
|
||||
DRAWING_SHEET,
|
||||
GRID
|
||||
};
|
||||
|
||||
GAL_LAYER_ID RenderLayerFromVisibilityLayer( VISIBILITY_LAYER aLayer );
|
||||
std::optional<VISIBILITY_LAYER> VisibilityLayerFromRenderLayer( GAL_LAYER_ID aLayerId );
|
||||
|
||||
std::optional<GAL_LAYER_ID> RenderLayerFromVisbilityString( const std::string& aLayer );
|
||||
std::string VisibilityLayerToString( VISIBILITY_LAYER aLayerId );
|
||||
|
||||
|
||||
#endif //LAYER_SETTINGS_UTILS_H
|
@ -37,7 +37,7 @@
|
||||
|
||||
|
||||
///! Update the schema version whenever a migration is required
|
||||
const int fpEditSchemaVersion = 3;
|
||||
const int fpEditSchemaVersion = 4;
|
||||
|
||||
|
||||
FOOTPRINT_EDITOR_SETTINGS::FOOTPRINT_EDITOR_SETTINGS() :
|
||||
@ -373,6 +373,7 @@ FOOTPRINT_EDITOR_SETTINGS::FOOTPRINT_EDITOR_SETTINGS() :
|
||||
} );
|
||||
|
||||
registerMigration( 2, 3, std::bind( &FOOTPRINT_EDITOR_SETTINGS::migrateSchema2To3, this ) );
|
||||
registerMigration( 3, 4, std::bind( &FOOTPRINT_EDITOR_SETTINGS::migrateSchema3To4, this ) );
|
||||
}
|
||||
|
||||
|
||||
@ -546,3 +547,22 @@ bool FOOTPRINT_EDITOR_SETTINGS::migrateSchema2To3()
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Schema version 4: move layer presets to use named render layers
|
||||
*/
|
||||
bool FOOTPRINT_EDITOR_SETTINGS::migrateSchema3To4()
|
||||
{
|
||||
auto p( "/pcb_display/layer_presets"_json_pointer );
|
||||
|
||||
if( !m_internals->contains( p ) || !m_internals->at( p ).is_array() )
|
||||
return true;
|
||||
|
||||
nlohmann::json& presets = m_internals->at( p );
|
||||
|
||||
for( nlohmann::json& entry : presets )
|
||||
PARAM_LAYER_PRESET::MigrateToNamedRenderLayers( entry );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user