KiCad PCB EDA Suite
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
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 along
17 * with this program. If not, see <http://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
51 GetFullClassNameForConstituents( const std::unordered_set<wxString>& classNames );
52
55 static wxString GetFullClassNameForConstituents( const std::vector<wxString>& classNames );
56
61 GetEffectiveStaticComponentClass( const std::unordered_set<wxString>& classNames );
62
64 const COMPONENT_CLASS* GetNoneComponentClass() const { return m_noneClass.get(); }
65
68 void InitNetlistUpdate();
69
73
75 std::unordered_set<wxString> GetClassNames() const;
76
80 const std::vector<COMPONENT_CLASS_ASSIGNMENT_DATA>& aAssignments,
81 bool aGenerateSheetClasses, const std::unordered_set<wxString>& aNewSheetPaths );
82
85
88 const COMPONENT_CLASS* dynamicClass );
89
94
97 long long int GetTicker() const { return m_ticker; }
98
102
105 void RebuildRequiredCaches( FOOTPRINT* aFootprint = nullptr ) const;
106
109
110 static std::shared_ptr<COMPONENT_CLASS_ASSIGNMENT_RULE>
112
113protected:
115 static std::vector<wxString> sortClassNames( const std::unordered_set<wxString>& classNames );
116
118 COMPONENT_CLASS* getOrCreateConstituentClass( const wxString& aClassName,
119 COMPONENT_CLASS::USAGE aContext );
120
123 COMPONENT_CLASS* getOrCreateEffectiveClass( const std::vector<wxString>& aClassNames,
124 COMPONENT_CLASS::USAGE aContext );
125
128
130 std::shared_ptr<COMPONENT_CLASS> m_noneClass;
131
133 std::unordered_map<wxString, std::unique_ptr<COMPONENT_CLASS>> m_constituentClasses;
134
136 std::unordered_map<wxString, std::unique_ptr<COMPONENT_CLASS>> m_effectiveClasses;
137
140 std::unordered_set<wxString> m_staticClassNamesCache;
141
142
144 std::vector<std::shared_ptr<COMPONENT_CLASS_ASSIGNMENT_RULE>> m_assignmentRules;
145
148
150 long long int m_ticker{ 0 };
151};
152
153#endif
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:297
Class which represents a component class assignment rule.
A class to manage Component Classes in a board context.
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...
bool HasCustomAssignmentConditions() const
Determines whether any custom dynamic rules have a custom assignment condition.
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.