21 changed files with 362 additions and 31 deletions
-
1common/CMakeLists.txt
-
6common/project.cpp
-
41common/settings/json_settings.cpp
-
7common/settings/nested_settings.cpp
-
135common/settings/project_file.cpp
-
53common/settings/settings_manager.cpp
-
3common/wildcards_and_files_ext.cpp
-
2eeschema/dialogs/dialog_sch_import_settings.cpp
-
2eeschema/eeschema_config.cpp
-
4eeschema/files-io.cpp
-
11include/settings/json_settings.h
-
2include/settings/nested_settings.h
-
79include/settings/project_file.h
-
22include/settings/settings_manager.h
-
1include/wildcards_and_files_ext.h
-
4kicad/import_project.cpp
-
10kicad/tools/kicad_manager_control.cpp
-
2kicad/tree_project_frame.cpp
-
2pcbnew/dialogs/dialog_import_settings.cpp
-
4pcbnew/files.cpp
-
2qa/eeschema/test_netlists.cpp
@ -0,0 +1,135 @@ |
|||
/*
|
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2020 CERN |
|||
* @author Jon Evans <jon@craftyjon.com> |
|||
* |
|||
* 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 <config_params.h>
|
|||
#include <settings/common_settings.h>
|
|||
#include <settings/parameters.h>
|
|||
#include <settings/project_file.h>
|
|||
#include <wildcards_and_files_ext.h>
|
|||
#include <wx/config.h>
|
|||
#include <wx/log.h>
|
|||
|
|||
extern const char* traceSettings; |
|||
|
|||
///! Update the schema version whenever a migration is required
|
|||
const int projectFileSchemaVersion = 1; |
|||
|
|||
|
|||
PROJECT_FILE::PROJECT_FILE( const std::string& aFullPath ) : |
|||
JSON_SETTINGS( aFullPath, SETTINGS_LOC::NONE, projectFileSchemaVersion ), |
|||
m_sheets(), m_boards(), m_legacyVars() |
|||
{ |
|||
m_params.emplace_back( new PARAM_LIST<FILE_INFO_PAIR>( "sheets", &m_sheets, {} ) ); |
|||
|
|||
m_params.emplace_back( new PARAM_LIST<FILE_INFO_PAIR>( "boards", &m_boards, {} ) ); |
|||
|
|||
m_params.emplace_back( new PARAM_MAP<wxString>( "legacy", &m_legacyVars, {} ) ); |
|||
} |
|||
|
|||
|
|||
bool PROJECT_FILE::MigrateFromLegacy( wxConfigBase* aLegacyFile ) |
|||
{ |
|||
bool ret = true; |
|||
wxString str; |
|||
long dummy; |
|||
|
|||
// Legacy files don't store board info; they assume board matches project name
|
|||
// We will leave m_boards empty here so it can be populated with other code
|
|||
|
|||
auto loadSheetNames = |
|||
[&]() -> bool |
|||
{ |
|||
int index = 1; |
|||
wxString entry; |
|||
|
|||
aLegacyFile->SetPath( GROUP_SHEET_NAMES ); |
|||
|
|||
while( aLegacyFile->Read( wxString::Format( "%d", index++ ), &entry ) ) |
|||
{ |
|||
wxArrayString tokens = wxSplit( entry, ':' ); |
|||
|
|||
if( tokens.size() == 2 ) |
|||
m_sheets.emplace_back( std::make_pair( KIID( tokens[0] ), tokens[1] ) ); |
|||
} |
|||
|
|||
// TODO: any reason we want to fail on this?
|
|||
return true; |
|||
}; |
|||
|
|||
std::vector<wxString> groups; |
|||
|
|||
bool more = aLegacyFile->GetFirstGroup( str, dummy ); |
|||
|
|||
while( more ) |
|||
{ |
|||
if( str == GROUP_SHEET_NAMES ) |
|||
ret |= loadSheetNames(); |
|||
else |
|||
groups.emplace_back( str ); |
|||
|
|||
more = aLegacyFile->GetNextGroup( str, dummy ); |
|||
} |
|||
|
|||
auto loadLegacyPairs = |
|||
[&]( const wxString& aGroup = wxEmptyString ) -> bool |
|||
{ |
|||
aLegacyFile->SetPath( aGroup ); |
|||
|
|||
bool morePairs = aLegacyFile->GetFirstEntry( str, dummy ); |
|||
|
|||
while( morePairs ) |
|||
{ |
|||
wxString val = aLegacyFile->Read( str ); |
|||
std::string key( str.ToUTF8() ); |
|||
m_legacyVars[key] = val; |
|||
morePairs = aLegacyFile->GetNextEntry( str, dummy ); |
|||
} |
|||
|
|||
// TODO: any reason we want to fail on this?
|
|||
return true; |
|||
}; |
|||
|
|||
ret &= loadLegacyPairs(); |
|||
|
|||
for( const auto& groupName : groups ) |
|||
ret &= loadLegacyPairs( groupName ); |
|||
|
|||
return ret; |
|||
} |
|||
|
|||
|
|||
wxString PROJECT_FILE::getLegacyFileExt() const |
|||
{ |
|||
return LegacyProjectFileExtension; |
|||
} |
|||
|
|||
|
|||
void to_json( nlohmann::json& aJson, const FILE_INFO_PAIR& aPair ) |
|||
{ |
|||
aJson = nlohmann::json::array( { aPair.first.AsString().ToUTF8(), aPair.second.ToUTF8() } ); |
|||
} |
|||
|
|||
|
|||
void from_json( const nlohmann::json& aJson, FILE_INFO_PAIR& aPair ) |
|||
{ |
|||
wxASSERT( aJson.is_array() && aJson.size() == 2 ); |
|||
aPair.first = KIID( wxString( aJson[0].get<std::string>().c_str(), wxConvUTF8 ) ); |
|||
aPair.second = wxString( aJson[1].get<std::string>().c_str(), wxConvUTF8 ); |
|||
} |
|||
@ -0,0 +1,79 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2020 CERN |
|||
* @author Jon Evans <jon@craftyjon.com> |
|||
* |
|||
* 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_PROJECT_FILE_H |
|||
#define KICAD_PROJECT_FILE_H |
|||
|
|||
#include <common.h> |
|||
#include <settings/json_settings.h> |
|||
|
|||
|
|||
/** |
|||
* For files like sheets and boards, a pair of that object KIID and display name |
|||
* Display name is typically blank for the project root sheet |
|||
*/ |
|||
typedef std::pair<KIID, wxString> FILE_INFO_PAIR; |
|||
|
|||
|
|||
/** |
|||
* PROJECT_FILE is the backing store for a PROJECT, in JSON format. |
|||
* |
|||
* There is either zero or one PROJECT_FILE for every PROJECT |
|||
* (you can have a dummy PROJECT that has no file) |
|||
*/ |
|||
class PROJECT_FILE : public JSON_SETTINGS |
|||
{ |
|||
public: |
|||
/** |
|||
* Constructs the project file for a project |
|||
* @param aFullPath is the full disk path to the project |
|||
*/ |
|||
PROJECT_FILE( const std::string& aFullPath ); |
|||
|
|||
virtual ~PROJECT_FILE() {} |
|||
|
|||
virtual bool MigrateFromLegacy( wxConfigBase* aLegacyFile ) override; |
|||
|
|||
protected: |
|||
wxString getLegacyFileExt() const override; |
|||
|
|||
private: |
|||
|
|||
/// An list of schematic sheets in this project |
|||
std::vector<FILE_INFO_PAIR> m_sheets; |
|||
|
|||
/// A list of board files in this project |
|||
std::vector<FILE_INFO_PAIR> m_boards; |
|||
|
|||
/** |
|||
* Stores all K/V pairs migrated from a legacy (.pro) file so that the legacy file can be |
|||
* removed before these settings are migrated in by PROJECT_SETTINGS objects later. |
|||
*/ |
|||
std::map<std::string, wxString> m_legacyVars; |
|||
|
|||
}; |
|||
|
|||
// Specializations to allow directly reading/writing FILE_INFO_PAIRs from JSON |
|||
|
|||
void to_json( nlohmann::json& aJson, const FILE_INFO_PAIR& aPair ); |
|||
|
|||
void from_json( const nlohmann::json& aJson, FILE_INFO_PAIR& aPair ); |
|||
|
|||
#endif |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue