KiCad PCB EDA Suite
Loading...
Searching...
No Matches
component_class_manager.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 modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * 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 PCBNEW_COMPONENT_CLASS_MANAGER_H
21#define PCBNEW_COMPONENT_CLASS_MANAGER_H
22
23#include <unordered_map>
24#include <unordered_set>
25#include <wx/string.h>
26
29
30
31class BOARD;
33class DRC_TOOL;
34class FOOTPRINT;
35
45{
46public:
47 explicit COMPONENT_CLASS_MANAGER( BOARD* board );
48
50 static wxString GetFullClassNameForConstituents( const std::unordered_set<wxString>& classNames );
51
54 static wxString GetFullClassNameForConstituents( const std::vector<wxString>& classNames );
55
67 COMPONENT_CLASS* GetEffectiveStaticComponentClass( const std::unordered_set<wxString>& classNames );
68
70 const COMPONENT_CLASS* GetNoneComponentClass() const { return m_noneClass.get(); }
71
74 void InitNetlistUpdate();
75
79
81 std::unordered_set<wxString> GetClassNames() const;
82
86 const std::vector<COMPONENT_CLASS_ASSIGNMENT_DATA>& aAssignments,
87 bool aGenerateSheetClasses, const std::unordered_set<wxString>& aNewSheetPaths );
88
91
94 const COMPONENT_CLASS* dynamicClass );
95
100
103 long long int GetTicker() const { return m_ticker; }
104
108
111 void RebuildRequiredCaches( FOOTPRINT* aFootprint = nullptr ) const;
112
113 static std::shared_ptr<COMPONENT_CLASS_ASSIGNMENT_RULE>
115
116protected:
118 static std::vector<wxString> sortClassNames( const std::unordered_set<wxString>& classNames );
119
121 COMPONENT_CLASS* getOrCreateConstituentClass( const wxString& aClassName,
122 COMPONENT_CLASS::USAGE aContext );
123
126 COMPONENT_CLASS* getOrCreateEffectiveClass( const std::vector<wxString>& aClassNames,
127 COMPONENT_CLASS::USAGE aContext );
128
131
133 std::shared_ptr<COMPONENT_CLASS> m_noneClass;
134
136 std::unordered_map<wxString, std::unique_ptr<COMPONENT_CLASS>> m_constituentClasses;
137
139 std::unordered_map<wxString, std::unique_ptr<COMPONENT_CLASS>> m_effectiveClasses;
140
143 std::unordered_set<wxString> m_staticClassNamesCache;
144
145
147 std::vector<std::shared_ptr<COMPONENT_CLASS_ASSIGNMENT_RULE>> m_assignmentRules;
148
150 long long int m_ticker{ 0 };
151};
152
153#endif
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:410
Class which represents a component class assignment rule.
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.
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.
long long int GetTicker() const
Gets the component class validity ticker Used to check validity of cached component classes.
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.
USAGE
The assignment context in which this component class is used.