41 const std::unordered_set<wxString>& classNames )
44 if( classNames.size() == 0 )
48 if( classNames.size() == 1 )
50 const wxString& className = *classNames.begin();
56 const std::vector<wxString> sortedClassNames =
sortClassNames( classNames );
65 return effectiveClass;
92 std::unordered_set<const COMPONENT_CLASS*> classesToDelete;
100 classesToDelete.insert( staticClass );
104 if( combinedCompClass->ContainsClassName( className ) )
105 classesToDelete.insert( combinedCompClass.get() );
111 if( !classesToDelete.empty() )
115 if( classesToDelete.count( footprint->GetStaticComponentClass() ) )
116 footprint->SetStaticComponentClass(
nullptr );
128 std::unordered_set<wxString> effectiveClassesToDelete;
132 if( combinedCompClass->ContainsClassName( className ) )
133 effectiveClassesToDelete.insert( combinedFullName );
136 for(
const wxString& classNameToDelete : effectiveClassesToDelete )
156 const std::unordered_set<wxString>& classNames )
158 const std::vector<wxString> sortedClassNames =
sortClassNames( classNames );
167 if( classNames.size() == 0 )
168 return wxEmptyString;
170 wxString fullName = classNames[0];
172 for( std::size_t i = 1; i < classNames.size(); ++i )
175 fullName += classNames[i];
183 const std::vector<COMPONENT_CLASS_ASSIGNMENT_DATA>& aAssignments,
184 bool aGenerateSheetClasses,
const std::unordered_set<wxString>& aNewSheetPaths )
192 std::unordered_set<wxString> prevClassNames;
195 prevClassNames.insert( rule->GetComponentClass() );
200 std::vector<std::shared_ptr<COMPONENT_CLASS_ASSIGNMENT_RULE>> rules;
207 rules.emplace_back( std::move( rule ) );
213 if( aGenerateSheetClasses )
215 std::unordered_set<wxString> sheetNames = aNewSheetPaths;
218 sheetNames.insert( footprint->GetSheetname() );
220 for( wxString sheetName : sheetNames )
224 if( sheetName.empty() || sheetName == wxT(
"/" ) )
227 sheetName.Replace( wxT(
"\"" ), wxT(
"" ) );
228 sheetName.Replace( wxT(
"'" ), wxT(
"" ) );
233 sheetName, wxEmptyString );
235 std::shared_ptr<COMPONENT_CLASS_ASSIGNMENT_RULE> rule =
239 rules.emplace_back( std::move( rule ) );
252 wxString className = rule->GetComponentClass();
253 prevClassNames.erase( className );
259 for(
const wxString& className : prevClassNames )
266 std::unordered_set<wxString> classesToDelete;
270 if( combinedCompClass->ContainsClassName( className ) )
271 classesToDelete.insert( combinedFullName );
274 for(
const wxString& classNameToDelete : classesToDelete )
292std::shared_ptr<COMPONENT_CLASS_ASSIGNMENT_RULE>
298 if( ruleSource.empty() )
301 DRC_RULES_PARSER parser( ruleSource, wxT(
"Component class assignment rule" ) );
305 std::vector<std::shared_ptr<COMPONENT_CLASS_ASSIGNMENT_RULE>> parsed;
313 if( parsed.size() != 1 )
329 std::unordered_set<wxString> classNames;
334 classNames.insert( compClass->GetName() );
340 classNames.insert( compClass->GetName() );
343 if( classNames.empty() )
346 if( classNames.size() == 1 )
352 const std::vector<wxString> sortedClassNames =
sortClassNames( classNames );
358 std::unique_ptr<COMPONENT_CLASS> combinedClass = std::make_unique<COMPONENT_CLASS>(
361 for(
const wxString& className : sortedClassNames )
382 for(
const auto& footprint :
m_board->Footprints() )
384 footprint->RecomputeComponentClass();
392 std::unordered_set<wxString> classNames;
397 if( rule->Matches( footprint ) )
398 classNames.insert( rule->GetComponentClass() );
402 const std::vector<wxString> sortedClassNames =
sortClassNames( classNames );
406 if( classNames.empty() )
410 if( classNames.size() == 1 )
421 std::vector<wxString> sortedClassNames( classNames.begin(), classNames.end() );
423 std::ranges::sort( sortedClassNames,
424 [](
const wxString& str1,
const wxString& str2 )
426 return str1.Cmp( str2 ) < 0;
429 return sortedClassNames;
440 wxFAIL_MSG(
"Can't create a STATIC_AND_DYNAMIC or EFFECTIVE constituent component class" );
454 std::unique_ptr<COMPONENT_CLASS> newClass =
455 std::make_unique<COMPONENT_CLASS>( aClassName, aContext );
456 newClass->AddConstituentClass( newClass.get() );
476 if( constituentClass->GetUsageContext() != aContext )
482 std::unique_ptr<COMPONENT_CLASS> effectiveClass = std::make_unique<COMPONENT_CLASS>(
485 for(
const wxString& className : aClassNames )
488 effectiveClass->AddConstituentClass( constituentClass );
500 std::unordered_set<wxString> classNames;
503 classNames.insert( className );
518 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)
Computes and returns an effective component class for a (possibly empty) set of constituent class nam...
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)
A wrapper for reporting to a wxString object.
A filename or source description, a problem input line, a line number, a byte offset,...
IbisParser parser & reporter