/* * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2020 CERN * @author Jon Evans * * 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 . */ #include #include #include const int projectLocalSettingsVersion = 1; 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_params.emplace_back( new PARAM_LAMBDA( "board.visible_layers", [&]() -> std::string { return m_VisibleLayers.FmtHex(); }, [&]( const std::string& aString ) { m_VisibleLayers.ParseHex( aString.c_str(), aString.size() ); }, LSET::AllLayersMask().FmtHex() ) ); static GAL_SET defaultVisible; defaultVisible.set().reset( GAL_LAYER_INDEX( LAYER_MOD_TEXT_INVISIBLE ) ); m_params.emplace_back( new PARAM_LAMBDA( "board.visible_items", [&]() -> nlohmann::json { nlohmann::json ret = nlohmann::json::array(); for( size_t i = 0; i < m_VisibleItems.size(); i++ ) if( m_VisibleItems.test( i ) ) ret.push_back( i ); return ret; }, [&]( const nlohmann::json& aVal ) { if( !aVal.is_array() || aVal.empty() ) { m_VisibleItems = defaultVisible; return; } m_VisibleItems.reset(); for( const nlohmann::json& entry : aVal ) { try { int i = entry.get(); m_VisibleItems.set( i ); } catch( ... ) { // Non-integer or out of range entry in the array; ignore } } }, {} ) ); } bool PROJECT_LOCAL_SETTINGS::MigrateFromLegacy( wxConfigBase* aLegacyConfig ) { /** * The normal legacy migration code won't be used for this because the only legacy * information stored here was stored in board files, so we do that migration when loading * the board. */ return true; } bool PROJECT_LOCAL_SETTINGS::SaveToFile( const std::string& aDirectory, bool aForce ) { wxASSERT( m_project ); ( *this )[PointerFromString( "meta.filename" )] = m_project->GetProjectName() + "." + ProjectLocalSettingsFileExtension; return JSON_SETTINGS::SaveToFile( aDirectory, aForce ); }