52 const std::unordered_set<wxString>& classNames )
55 if( classNames.size() == 0 )
59 if( classNames.size() == 1 )
61 const wxString& className = *classNames.begin();
67 const std::vector<wxString> sortedClassNames =
sortClassNames( classNames );
76 return effectiveClass;
103 std::unordered_set<const COMPONENT_CLASS*> classesToDelete;
111 classesToDelete.insert( staticClass );
115 if( combinedCompClass->ContainsClassName( className ) )
116 classesToDelete.insert( combinedCompClass.get() );
122 if( !classesToDelete.empty() )
126 if( classesToDelete.count( footprint->GetStaticComponentClass() ) )
127 footprint->SetStaticComponentClass(
nullptr );
139 std::unordered_set<wxString> effectiveClassesToDelete;
143 if( combinedCompClass->ContainsClassName( className ) )
144 effectiveClassesToDelete.insert( combinedFullName );
147 for(
const wxString& classNameToDelete : effectiveClassesToDelete )
167 const std::unordered_set<wxString>& classNames )
169 const std::vector<wxString> sortedClassNames =
sortClassNames( classNames );
178 if( classNames.size() == 0 )
179 return wxEmptyString;
181 wxString fullName = classNames[0];
183 for( std::size_t i = 1; i < classNames.size(); ++i )
186 fullName += classNames[i];
194 const std::vector<COMPONENT_CLASS_ASSIGNMENT_DATA>& aAssignments,
195 bool aGenerateSheetClasses,
const std::unordered_set<wxString>& aNewSheetPaths )
203 std::unordered_set<wxString> prevClassNames;
206 prevClassNames.insert( rule->GetComponentClass() );
211 std::vector<std::shared_ptr<COMPONENT_CLASS_ASSIGNMENT_RULE>> rules;
218 rules.emplace_back( std::move( rule ) );
224 if( aGenerateSheetClasses )
226 std::unordered_set<wxString> sheetNames = aNewSheetPaths;
229 sheetNames.insert( footprint->GetSheetname() );
231 for( wxString sheetName : sheetNames )
235 if( sheetName.empty() || sheetName == wxT(
"/" ) )
238 sheetName.Replace( wxT(
"\"" ), wxT(
"" ) );
239 sheetName.Replace( wxT(
"'" ), wxT(
"" ) );
244 sheetName, wxEmptyString );
246 std::shared_ptr<COMPONENT_CLASS_ASSIGNMENT_RULE> rule =
250 rules.emplace_back( std::move( rule ) );
263 wxString className = rule->GetComponentClass();
264 prevClassNames.erase( className );
270 for(
const wxString& className : prevClassNames )
277 std::unordered_set<wxString> classesToDelete;
281 if( combinedCompClass->ContainsClassName( className ) )
282 classesToDelete.insert( combinedFullName );
285 for(
const wxString& classNameToDelete : classesToDelete )
303std::shared_ptr<COMPONENT_CLASS_ASSIGNMENT_RULE>
309 if( ruleSource.empty() )
312 DRC_RULES_PARSER parser( ruleSource, wxT(
"Component class assignment rule" ) );
316 std::vector<std::shared_ptr<COMPONENT_CLASS_ASSIGNMENT_RULE>> parsed;
324 if( parsed.size() != 1 )
340 std::unordered_set<wxString> classNames;
345 classNames.insert( compClass->GetName() );
351 classNames.insert( compClass->GetName() );
354 if( classNames.empty() )
357 if( classNames.size() == 1 )
363 const std::vector<wxString> sortedClassNames =
sortClassNames( classNames );
369 std::unique_ptr<COMPONENT_CLASS> combinedClass = std::make_unique<COMPONENT_CLASS>(
372 for(
const wxString& className : sortedClassNames )
393 for(
const auto& footprint :
m_board->Footprints() )
395 footprint->RecomputeComponentClass();
403 std::unordered_set<wxString> classNames;
408 if( rule->Matches( footprint ) )
409 classNames.insert( rule->GetComponentClass() );
413 const std::vector<wxString> sortedClassNames =
sortClassNames( classNames );
417 if( classNames.empty() )
421 if( classNames.size() == 1 )
432 std::vector<wxString> sortedClassNames( classNames.begin(), classNames.end() );
434 std::ranges::sort( sortedClassNames,
435 [](
const wxString& str1,
const wxString& str2 )
437 return str1.Cmp( str2 ) < 0;
440 return sortedClassNames;
451 wxFAIL_MSG(
"Can't create a STATIC_AND_DYNAMIC or EFFECTIVE constituent component class" );
465 std::unique_ptr<COMPONENT_CLASS> newClass =
466 std::make_unique<COMPONENT_CLASS>( aClassName, aContext );
467 newClass->AddConstituentClass( newClass.get() );
487 if( constituentClass->GetUsageContext() != aContext )
493 std::unique_ptr<COMPONENT_CLASS> effectiveClass = std::make_unique<COMPONENT_CLASS>(
496 for(
const wxString& className : aClassNames )
499 effectiveClass->AddConstituentClass( constituentClass );
511 std::unordered_set<wxString> classNames;
514 classNames.insert( className );
529 fp->BuildCourtyardCaches();
Information pertinent to a Pcbnew printed circuit board.
void AddCondition(const CONDITION_TYPE aCondition, const wxString &aPrimaryData, const wxString &aSecondaryData)
Sets the given condition type with the assocated match data.
wxString GetAssignmentInDRCLanguage() const
Returns the DRC rules language for this component class assignment.
void SetComponentClass(const wxString &aComponentClass)
Sets the resulting component class for matching footprints.
std::unordered_set< wxString > GetClassNames() const
Fetches a read-only map of the fundamental component classes.
static std::shared_ptr< COMPONENT_CLASS_ASSIGNMENT_RULE > CompileAssignmentRule(const COMPONENT_CLASS_ASSIGNMENT_DATA &aAssignment)
std::unordered_set< wxString > m_staticClassNamesCache
Cache of in-use static component class names Used for cleanup following netlist updates.
std::unordered_map< wxString, std::unique_ptr< COMPONENT_CLASS > > m_constituentClasses
All individual component classes from static assignments.
COMPONENT_CLASS * GetEffectiveStaticComponentClass(const std::unordered_set< wxString > &classNames)
Gets an effective component class for the given constituent class names.
long long int m_ticker
Monotonically increasing ticker to test cached component class validity.
void ForceComponentClassRecalculation() const
Forces the component class for all footprints to be recalculated.
COMPONENT_CLASS * getOrCreateEffectiveClass(const std::vector< wxString > &aClassNames, COMPONENT_CLASS::USAGE aContext)
Returns an effective component class for the given set of constituent class names Precondition: aClas...
static wxString GetFullClassNameForConstituents(const std::unordered_set< wxString > &classNames)
Gets the full effective class name for the given set of constituent classes.
COMPONENT_CLASS_MANAGER(BOARD *board)
void InvalidateComponentClasses()
Invalidates any caches component classes and recomputes caches if required.
void FinishNetlistUpdate()
Cleans up the manager after a board update Must be called after updating the PCB from the netlist.
std::vector< std::shared_ptr< COMPONENT_CLASS_ASSIGNMENT_RULE > > m_assignmentRules
Active component class assignment rules.
const COMPONENT_CLASS * GetCombinedComponentClass(const COMPONENT_CLASS *staticClass, const COMPONENT_CLASS *dynamicClass)
Gets the combined component class with the given static and dynamic constituent component classes.
static std::vector< wxString > sortClassNames(const std::unordered_set< wxString > &classNames)
Sorts the given class names in to canonical order.
void RebuildRequiredCaches(FOOTPRINT *aFootprint=nullptr) const
Rebuilds any caches that may be required by custom assignment rules.
COMPONENT_CLASS * getOrCreateConstituentClass(const wxString &aClassName, COMPONENT_CLASS::USAGE aContext)
Returns a constituent component class, re-using an existing instantiation where possible.
BOARD * m_board
The board these component classes are assigned to / from.
const COMPONENT_CLASS * GetNoneComponentClass() const
Returns the unassigned component class.
std::unordered_map< wxString, std::unique_ptr< COMPONENT_CLASS > > m_effectiveClasses
Generated effective (composite) static component classes.
const COMPONENT_CLASS * GetDynamicComponentClassesForFootprint(const FOOTPRINT *footprint)
Gets the dynamic component classes which match the given footprint.
void InitNetlistUpdate()
Prepare the manager for a board update Must be called prior to updating the PCB from the netlist.
std::shared_ptr< COMPONENT_CLASS > m_noneClass
The class to represent an unassigned component class.
bool SyncDynamicComponentClassAssignments(const std::vector< COMPONENT_CLASS_ASSIGNMENT_DATA > &aAssignments, bool aGenerateSheetClasses, const std::unordered_set< wxString > &aNewSheetPaths)
Synchronises all dynamic component class assignment rules.
A lightweight representation of a component class.
void SetUsageContext(const USAGE aUsageContext)
Sets the assignment context in which this component class is being used.
USAGE
The assignment context in which this component class is used.
USAGE GetUsageContext() const
Gets the assignment context in which this component class is being used.
const std::vector< COMPONENT_CLASS * > & GetConstituentClasses() const
Fetches a vector of the constituent classes for this (effective) class.
void ParseComponentClassAssignmentRules(std::vector< std::shared_ptr< COMPONENT_CLASS_ASSIGNMENT_RULE > > &aRules, REPORTER *aReporter)
virtual bool HasMessageOfSeverity(int aSeverityMask) const
Returns true if the reporter has one or more messages matching the specified severity mask.
A wrapper for reporting to a wxString object.
A filename or source description, a problem input line, a line number, a byte offset,...