34 m_board( board ), m_hasCustomAssignmentConditions( false )
53 const std::unordered_set<wxString>& classNames )
56 if( classNames.size() == 0 )
60 if( classNames.size() == 1 )
62 const wxString& className = *classNames.begin();
68 const std::vector<wxString> sortedClassNames =
sortClassNames( classNames );
77 return effectiveClass;
108 std::unordered_set<wxString> classesToDelete;
112 if( combinedCompClass->ContainsClassName( className ) )
113 classesToDelete.insert( combinedFullName );
116 for(
const wxString& classNameToDelete : classesToDelete )
136 const std::unordered_set<wxString>& classNames )
138 const std::vector<wxString> sortedClassNames =
sortClassNames( classNames );
147 if( classNames.size() == 0 )
148 return wxEmptyString;
150 wxString fullName = classNames[0];
152 for( std::size_t i = 1; i < classNames.size(); ++i )
155 fullName += classNames[i];
163 const std::vector<COMPONENT_CLASS_ASSIGNMENT_DATA>& aAssignments,
164 bool aGenerateSheetClasses,
const std::unordered_set<wxString>& aNewSheetPaths )
173 std::unordered_set<wxString> prevClassNames;
176 prevClassNames.insert( rule->GetComponentClass() );
181 std::vector<std::shared_ptr<COMPONENT_CLASS_ASSIGNMENT_RULE>> rules;
185 if( assignment.GetConditions().contains(
194 rules.emplace_back( std::move( rule ) );
200 if( aGenerateSheetClasses )
202 std::unordered_set<wxString> sheetNames = aNewSheetPaths;
205 sheetNames.insert( footprint->GetSheetname() );
207 for( wxString sheetName : sheetNames )
211 if( sheetName.empty() || sheetName == wxT(
"/" ) )
214 sheetName.Replace( wxT(
"\"" ), wxT(
"" ) );
215 sheetName.Replace( wxT(
"'" ), wxT(
"" ) );
220 sheetName, wxEmptyString );
222 std::shared_ptr<COMPONENT_CLASS_ASSIGNMENT_RULE> rule =
226 rules.emplace_back( std::move( rule ) );
239 wxString className = rule->GetComponentClass();
240 prevClassNames.erase( className );
246 for(
const wxString& className : prevClassNames )
253 std::unordered_set<wxString> classesToDelete;
257 if( combinedCompClass->ContainsClassName( className ) )
258 classesToDelete.insert( combinedFullName );
261 for(
const wxString& classNameToDelete : classesToDelete )
279std::shared_ptr<COMPONENT_CLASS_ASSIGNMENT_RULE>
285 if( ruleSource.empty() )
288 DRC_RULES_PARSER parser( ruleSource, wxT(
"Component class assignment rule" ) );
292 std::vector<std::shared_ptr<COMPONENT_CLASS_ASSIGNMENT_RULE>> parsed;
300 if( parsed.size() != 1 )
316 std::unordered_set<wxString> classNames;
321 classNames.insert( compClass->GetName() );
327 classNames.insert( compClass->GetName() );
330 if( classNames.empty() )
333 if( classNames.size() == 1 )
339 const std::vector<wxString> sortedClassNames =
sortClassNames( classNames );
345 std::unique_ptr<COMPONENT_CLASS> combinedClass = std::make_unique<COMPONENT_CLASS>(
348 for(
const wxString& className : sortedClassNames )
371 footprint->RecomputeComponentClass();
379 std::unordered_set<wxString> classNames;
384 if( rule->Matches( footprint ) )
385 classNames.insert( rule->GetComponentClass() );
389 const std::vector<wxString> sortedClassNames =
sortClassNames( classNames );
393 if( classNames.empty() )
397 if( classNames.size() == 1 )
408 std::vector<wxString> sortedClassNames( classNames.begin(), classNames.end() );
410 std::ranges::sort( sortedClassNames,
411 [](
const wxString& str1,
const wxString& str2 )
413 return str1.Cmp( str2 ) < 0;
416 return sortedClassNames;
427 wxFAIL_MSG(
"Can't create a STATIC_AND_DYNAMIC or EFFECTIVE constituent component class" );
441 std::unique_ptr<COMPONENT_CLASS> newClass =
442 std::make_unique<COMPONENT_CLASS>( aClassName, aContext );
443 newClass->AddConstituentClass( newClass.get() );
463 if( constituentClass->GetUsageContext() != aContext )
469 std::unique_ptr<COMPONENT_CLASS> effectiveClass = std::make_unique<COMPONENT_CLASS>(
472 for(
const wxString& className : aClassNames )
475 effectiveClass->AddConstituentClass( constituentClass );
487 std::unordered_set<wxString> classNames;
490 classNames.insert( className );
505 fp->BuildCourtyardCaches();
Information pertinent to a Pcbnew printed circuit board.
const FOOTPRINTS & Footprints() const
wxString GetAssignmentInDRCLanguage() const
Returns the DRC rules language for this component class assignment.
void SetCondition(const CONDITION_TYPE aCondition, const wxString &aPrimaryData, const wxString &aSecondaryData)
Sets the given condition type with the assocated match data.
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.
bool m_hasCustomAssignmentConditions
Quick lookup of presence of custom dynamic assignment conditions.
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)
A wrapper for reporting to a wxString object.
bool HasMessageOfSeverity(int aSeverityMask) const override
Returns true if the reporter has one or more messages matching the specified severity mask.
A filename or source description, a problem input line, a line number, a byte offset,...