22#include <boost/uuid/name_generator_sha1.hpp>
23#include <boost/uuid/string_generator.hpp>
24#include <boost/uuid/uuid_io.hpp>
28#include <wx/fileconf.h>
29#include <wx/filename.h>
40 wxFileName fn( aPrjPcbPath );
43 return fn.GetFullPath();
51 static const boost::uuids::uuid s_namespace =
52 boost::uuids::string_generator()(
"6f9619ff-8b86-d011-b42d-00cf4fc964ff" );
54 boost::uuids::name_generator_sha1 generator( s_namespace );
55 boost::uuids::uuid uuid = generator( aUniqueId.utf8_string() );
57 return KIID( wxString::FromUTF8( boost::uuids::to_string( uuid ) ) );
67 bool inAlternatePart =
false;
71 for(
const wxString& token : wxSplit( aValue,
'|',
'\0' ) )
73 int eqPos = token.Find(
'=' );
75 if( eqPos == wxNOT_FOUND )
78 wxString key = token.Left( eqPos ).Trim().Trim(
false );
79 wxString val = token.Mid( eqPos + 1 ).Trim().Trim(
false );
81 if( key.CmpNoCase( wxS(
"AlternatePart" ) ) == 0 )
83 inAlternatePart =
true;
89 else if( inAlternatePart )
94 else if( key.CmpNoCase( wxS(
"Designator" ) ) == 0 )
98 else if( key.CmpNoCase( wxS(
"UniqueId" ) ) == 0 )
102 int sep = val.Find(
'\\',
true );
104 if( sep != wxNOT_FOUND )
105 entry.
uniqueId = val.Mid( sep + 1 );
109 else if( key.CmpNoCase( wxS(
"Kind" ) ) == 0 )
113 entry.
kind =
static_cast<int>( k );
123 std::map<wxString, wxString> parameters;
126 wxCONFIG_USE_NO_ESCAPE_CHARACTERS );
131 for(
bool more =
config.GetFirstGroup( groupname, groupid ); more;
132 more =
config.GetNextGroup( groupname, groupid ) )
134 if( !groupname.StartsWith( wxS(
"Parameter" ) ) )
139 wxString numStr = groupname.Mid( 9 );
142 if( !numStr.ToLong( &num ) )
145 wxString
name =
config.Read( groupname + wxS(
"/Name" ), wxEmptyString );
150 wxString value =
config.Read( groupname + wxS(
"/Value" ), wxEmptyString );
157 parameters[
name] = value;
167 wxCONFIG_USE_NO_ESCAPE_CHARACTERS );
169 return config.ReadLong( wxS(
"Design/PowerPortNamesTakePriority" ), 0 ) != 0;
174 const std::map<wxString, wxString>& aParameters )
182 static const std::set<wxString> reserved = {
183 wxS(
"LAYER" ), wxS(
"FILENAME" ), wxS(
"FILEPATH" ),
184 wxS(
"PROJECTNAME" ), wxS(
"VARIANT" ), wxS(
"VARIANT_DESC" ),
185 wxS(
"ISSUE_DATE" ), wxS(
"CURRENT_DATE" ), wxS(
"CURRENT_TIME_LOCALE" ),
186 wxS(
"CURRENT_TIME_HH_MM_SS" ), wxS(
"REVISION" ), wxS(
"TITLE" ),
187 wxS(
"COMPANY" ), wxS(
"COMMENT1" ), wxS(
"COMMENT2" ),
188 wxS(
"COMMENT3" ), wxS(
"COMMENT4" ), wxS(
"COMMENT5" ),
189 wxS(
"COMMENT6" ), wxS(
"COMMENT7" ), wxS(
"COMMENT8" ),
190 wxS(
"COMMENT9" ), wxS(
"VCSHASH" ), wxS(
"VCSSHORTHASH" ),
191 wxS(
"KICAD_VERSION" ), wxS(
"PAPER" ), wxS(
"SHEETNAME" ),
192 wxS(
"SHEETPATH" ), wxS(
"DRC_WARNING" ), wxS(
"DRC_ERROR" ),
193 wxS(
"ERC_WARNING" ), wxS(
"ERC_ERROR" )
196 std::map<wxString, wxString>& textVars = aProject->
GetTextVars();
199 for(
const auto& [
name, value] : aParameters )
201 if( reserved.count(
name ) )
205 if( textVars.count(
name ) )
208 textVars[
name] = value;
219 std::vector<ALTIUM_PROJECT_VARIANT> variants;
222 wxCONFIG_USE_NO_ESCAPE_CHARACTERS );
227 for(
bool more =
config.GetFirstGroup( groupname, groupid ); more;
228 more =
config.GetNextGroup( groupname, groupid ) )
230 if( !groupname.StartsWith( wxS(
"ProjectVariant" ) ) )
233 wxString numStr = groupname.Mid( 14 );
236 if( !numStr.ToLong( &num ) )
241 pv.
description =
config.Read( groupname + wxS(
"/Description" ), wxEmptyString );
244 if( pv.
name.empty() )
247 long variationCount = 0;
248 config.Read( groupname + wxS(
"/VariationCount" ), &variationCount, 0 );
250 for(
long vi = 1; vi <= variationCount; ++vi )
252 wxString key = wxString::Format( wxS(
"%s/Variation%ld" ), groupname, vi );
253 wxString value =
config.Read( key, wxEmptyString );
261 pv.
variations.push_back( std::move( entry ) );
265 variants.push_back( std::move( pv ) );
std::vector< ALTIUM_PROJECT_VARIANT > ParseAltiumProjectVariants(const wxString &aPrjPcbPath)
Parse all [ProjectVariantN] sections from an Altium .PrjPcb project file.
static wxString absoluteProjectPath(const wxString &aPrjPcbPath)
wxFileConfig resolves a relative local filename against the user's home directory rather than the wor...
std::map< wxString, wxString > ParseAltiumProjectParameters(const wxString &aPrjPcbPath)
Parse all [ParameterN] sections from an Altium .PrjPcb project file.
ALTIUM_VARIANT_ENTRY ParseVariationString(const wxString &aValue)
Parse a single pipe-delimited Altium "Variation" string into its component entry.
bool AltiumPowerPortNamesTakePriority(const wxString &aPrjPcbPath)
Read the project's Power Port Names Take Priority netlist option.
KIID AltiumUniqueIdToKiid(const wxString &aUniqueId)
Derive a stable KIID from an Altium component unique id.
void ApplyAltiumProjectParametersToProject(PROJECT *aProject, const std::map< wxString, wxString > &aParameters)
Register Altium project parameters as KiCad project text variables so that imported board text refere...
Container for project specific data.
void IncrementTextVarsTicker()
virtual std::map< wxString, wxString > & GetTextVars() const
A project-level assembly variant parsed from an Altium .PrjPcb file.
std::vector< ALTIUM_VARIANT_ENTRY > variations
A single component variation within an Altium project variant.
std::map< wxString, wxString > alternateFields