KiCad PCB EDA Suite
Loading...
Searching...
No Matches
import_proj_properties.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#ifndef IMPORT_PROJ_PROPERTIES_H
21#define IMPORT_PROJ_PROPERTIES_H
22
23#include <map>
24#include <string>
25#include <vector>
26
27#include <core/utf8.h>
28#include <lib_id.h>
29#include <wx/arrstr.h>
30#include <wx/string.h>
31
40{
41inline constexpr char FP_CACHE_NICKNAME[] = "import_fp_cache_nickname";
42inline constexpr char SOURCE_FP_LIBS[] = "import_source_fp_libs";
43inline constexpr char SYM_CACHE_NICKNAME[] = "import_sym_cache_nickname";
44inline constexpr char SOURCE_SYM_LIBS[] = "import_source_sym_libs";
45
47inline constexpr char LIST_SEPARATOR = '\x1f';
48
50inline constexpr char MANAGED_CACHE_KEY[] = "kicad_import_cache";
51
53inline wxString ManagedCacheOption()
54{
55 return wxString( MANAGED_CACHE_KEY ) + wxS( "=1" );
56}
57
59inline wxString JoinList( const wxArrayString& aItems )
60{
61 return wxJoin( aItems, LIST_SEPARATOR, '\0' );
62}
63
65inline std::vector<wxString> SplitList( const wxString& aValue )
66{
67 std::vector<wxString> out;
68
69 for( const wxString& item : wxSplit( aValue, LIST_SEPARATOR, '\0' ) )
70 {
71 if( !item.IsEmpty() )
72 out.push_back( item );
73 }
74
75 return out;
76}
77
79inline void ReadFootprintProps( const std::map<std::string, UTF8>* aProps, wxString& aCacheNickname,
80 std::vector<wxString>& aSourceFpLibs )
81{
82 if( !aProps )
83 return;
84
85 if( auto it = aProps->find( FP_CACHE_NICKNAME ); it != aProps->end() )
86 aCacheNickname = it->second.wx_str();
87
88 if( auto it = aProps->find( SOURCE_FP_LIBS ); it != aProps->end() )
89 aSourceFpLibs = SplitList( it->second.wx_str() );
90}
91
93inline void ReadSymbolProps( const std::map<std::string, UTF8>* aProps, wxString& aCacheNickname,
94 std::vector<wxString>& aSourceSymLibs )
95{
96 if( !aProps )
97 return;
98
99 if( auto it = aProps->find( SYM_CACHE_NICKNAME ); it != aProps->end() )
100 aCacheNickname = it->second.wx_str();
101
102 if( auto it = aProps->find( SOURCE_SYM_LIBS ); it != aProps->end() )
103 aSourceSymLibs = SplitList( it->second.wx_str() );
104}
105
107inline wxString MakeCacheNickname( const wxString& aStem )
108{
109 return LIB_ID::FixIllegalChars( aStem + wxS( "-import-fps" ), true ).wx_str();
110}
111
113inline wxString MakeSymbolCacheNickname( const wxString& aStem )
114{
115 return LIB_ID::FixIllegalChars( aStem + wxS( "-import-syms" ), true ).wx_str();
116}
117}
118
119#endif // IMPORT_PROJ_PROPERTIES_H
static UTF8 FixIllegalChars(const UTF8 &aLibItemName, bool aLib)
Replace illegal LIB_ID item name characters with underscores '_'.
Definition lib_id.cpp:205
wxString wx_str() const
Definition utf8.cpp:41
Property keys and codec threaded through IMPORT_PROJ_HELPER::m_properties to coordinate a non-KiCad p...
void ReadSymbolProps(const std::map< std::string, UTF8 > *aProps, wxString &aCacheNickname, std::vector< wxString > &aSourceSymLibs)
Read the symbol-import coordination properties out of a properties map.
wxString ManagedCacheOption()
Options string identifying a library-table row as a generated import cache.
constexpr char SOURCE_FP_LIBS[]
constexpr char MANAGED_CACHE_KEY[]
Library-table row option key marking a row as a generated import cache.
constexpr char SYM_CACHE_NICKNAME[]
constexpr char FP_CACHE_NICKNAME[]
wxString JoinList(const wxArrayString &aItems)
Encode library nicknames into a single list-property value.
wxString MakeCacheNickname(const wxString &aStem)
Derive the generated footprint-cache nickname from a project or file stem.
wxString MakeSymbolCacheNickname(const wxString &aStem)
Derive the generated symbol-cache nickname from a project or file stem.
constexpr char LIST_SEPARATOR
Separator joining a list value within a single property.
std::vector< wxString > SplitList(const wxString &aValue)
Decode a list-property value back into nicknames, dropping empties.
constexpr char SOURCE_SYM_LIBS[]
void ReadFootprintProps(const std::map< std::string, UTF8 > *aProps, wxString &aCacheNickname, std::vector< wxString > &aSourceFpLibs)
Read the footprint-import coordination properties out of a properties map.