7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-11 09:40:09 +00:00

Save layer job params using canonical name arrays instead of layer id ints

Fixes https://gitlab.com/kicad/code/kicad/-/issues/19532
This commit is contained in:
Marek Roszko 2025-01-10 22:20:34 -05:00
parent 4279672876
commit 6692f39d6f
3 changed files with 82 additions and 4 deletions

View File

@ -24,6 +24,8 @@
#include <map>
#include <wx/string.h>
#include <settings/json_settings.h>
#include <lseq.h>
#include <lset.h>
class KICOMMON_API JOB_PARAM_BASE
{
@ -109,6 +111,58 @@ protected:
std::vector<ListElementType> m_default;
};
class JOB_PARAM_LSEQ : public JOB_PARAM<LSEQ>
{
public:
JOB_PARAM_LSEQ( const std::string& aJsonPath, LSEQ* aPtr, LSEQ aDefault ) :
JOB_PARAM<LSEQ>( aJsonPath, aPtr, aDefault )
{
}
virtual void FromJson( const nlohmann::json& j ) const override
{
if( j.contains( m_jsonPath ) )
{
auto js = j.at( m_jsonPath );
LSEQ layers;
if( js.is_array() )
{
for( const nlohmann::json& layer : js )
{
if( layer.is_string() )
{
wxString name = layer.get<wxString>();
int layerId = LSET::NameToLayer( name );
if( layerId != UNDEFINED_LAYER )
layers.push_back( static_cast<PCB_LAYER_ID>( layerId ) );
}
else
{
int layerId = layer.get<int>();
if( layerId != UNDEFINED_LAYER )
layers.push_back( static_cast<PCB_LAYER_ID>( layerId ) );
}
}
}
*m_ptr = layers;
}
else
*m_ptr = m_default;
}
void ToJson( nlohmann::json& j ) override
{
nlohmann::json js = nlohmann::json::array();
for( PCB_LAYER_ID layer : ( *m_ptr ) )
js.push_back( LSET::Name( layer ) );
j[m_jsonPath] = js;
}
};
struct KICOMMON_API JOB_OUTPUT
{
JOB_OUTPUT(){};

View File

@ -43,8 +43,8 @@ JOB_EXPORT_PCB_PLOT::JOB_EXPORT_PCB_PLOT( PLOT_FORMAT aFormat, const std::string
m_drillShapeOption( DRILL_MARKS::FULL_DRILL_SHAPE ),
m_useDrillOrigin( false )
{
m_params.emplace_back( new JOB_PARAM<LSEQ>( "layers", &m_printMaskLayer, m_printMaskLayer ) );
m_params.emplace_back( new JOB_PARAM<LSEQ>( "layers_to_include_on_all_layers",
m_params.emplace_back( new JOB_PARAM_LSEQ( "layers", &m_printMaskLayer, m_printMaskLayer ) );
m_params.emplace_back( new JOB_PARAM_LSEQ( "layers_to_include_on_all_layers",
&m_printMaskLayersToIncludeOnAllLayers,
m_printMaskLayersToIncludeOnAllLayers ) );

View File

@ -24,11 +24,35 @@
void to_json( nlohmann::json& aJson, const LSET& aLset )
{
aJson = nlohmann::json( aLset.FmtHex() );
nlohmann::json layers = nlohmann::json::array();
for( PCB_LAYER_ID layer : aLset.Seq() )
layers.push_back( LSET::Name( layer ) );
aJson = layers;
}
void from_json( const nlohmann::json& aJson, LSET& aLset )
{
aLset.ParseHex( aJson.get<std::string>() );
if( aJson.is_array() )
{
aLset.clear();
for( const nlohmann::json& layer : aJson )
{
if( layer.is_string() )
{
wxString name = layer.get<wxString>();
int layerId = LSET::NameToLayer( name );
if( layerId != UNDEFINED_LAYER )
aLset.set( layerId );
}
}
}
else if( aJson.is_string() )
{
// Allow hex strings to be parsed into LSETs
aLset.ParseHex( aJson.get<std::string>() );
}
}