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 (C) 2024 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 <memory>
24#include <unordered_map>
25#include <unordered_set>
26#include <wx/string.h>
27
28#include <board_item.h>
29
30/*
31 * A lightweight representation of a component class. The membership within
32 * m_consituentClasses allows determination of the type of class this is:
33 *
34 * m_constituentClasses.size() == 0: This is a null class (no assigment).
35 * m_name is empty.
36 * m_constituentClasses.size() == 1: This is an atomic class. The constituent class
37 * pointer refers to itself. m_name contains the name of the atomic class
38 * m_constituentClasses.size() > 1: This is a composite class. The constituent class
39 * pointers refer to all atomic members. m_name contains a comma-delimited list of
40 * all atomic member class names.
41 */
43{
44public:
45 COMPONENT_CLASS( const wxString& name ) : m_name( name ) {}
46
48 wxString GetName() const;
49
51 const wxString& GetFullName() const { return m_name; }
52
54 void AddConstituentClass( COMPONENT_CLASS* componentClass );
55
57 bool ContainsClassName( const wxString& className ) const;
58
60 bool IsEmpty() const;
61
63 const std::vector<COMPONENT_CLASS*>& GetConstituentClasses() const
64 {
66 }
67
68private:
70 wxString m_name;
71
73 std::vector<COMPONENT_CLASS*> m_constituentClasses;
74};
75
76/*
77 * A class to manage Component Classes in a board context
78 *
79 * This manager owns generated COMPONENT_CLASS objects, and guarantees that pointers to managed
80 * objects are valid for the duration of the board lifetime. Note that, in order to maintain this
81 * guarantee, there are two methods that must be called when updating the board from the netlist
82 * (InitNetlistUpdate and FinishNetlistUpdate).
83 */
85{
86public:
88
90 static wxString GetFullClassNameForConstituents( std::unordered_set<wxString>& classNames );
91
94 static wxString GetFullClassNameForConstituents( std::vector<wxString>& classNames );
95
99 COMPONENT_CLASS* GetEffectiveComponentClass( std::unordered_set<wxString>& classNames );
100
102 const COMPONENT_CLASS* GetNoneComponentClass() const { return m_noneClass.get(); }
103
106 void InitNetlistUpdate();
107
110 void FinishNetlistUpdate();
111
113 // All pointers to COMPONENT_CLASS objects will being invalid
114 void Reset();
115
117 const std::unordered_map<wxString, std::unique_ptr<COMPONENT_CLASS>>& GetClasses() const
118 {
119 return m_classes;
120 }
121
122protected:
124 std::unordered_map<wxString, std::unique_ptr<COMPONENT_CLASS>> m_classes;
125
127 std::unordered_map<wxString, std::unique_ptr<COMPONENT_CLASS>> m_effectiveClasses;
128
130 std::unordered_map<wxString, std::unique_ptr<COMPONENT_CLASS>> m_classesCache;
131
133 std::unordered_map<wxString, std::unique_ptr<COMPONENT_CLASS>> m_effectiveClassesCache;
134
136 std::unique_ptr<COMPONENT_CLASS> m_noneClass;
137};
138
139#endif
const char * name
Definition: DXF_plotter.cpp:57
std::unique_ptr< COMPONENT_CLASS > m_noneClass
The class to represent an unassigned component class.
std::unordered_map< wxString, std::unique_ptr< COMPONENT_CLASS > > m_classes
All individual component classes.
std::unordered_map< wxString, std::unique_ptr< COMPONENT_CLASS > > m_classesCache
Cache of all individual component classes (for netlist updating)
void Reset()
Resets the contents of the manager.
void FinishNetlistUpdate()
Cleans up the manager after a board update Must be called after updating the PCB from the netlist.
static wxString GetFullClassNameForConstituents(std::unordered_set< wxString > &classNames)
Gets the full effective class name for the given set of constituent classes.
std::unordered_map< wxString, std::unique_ptr< COMPONENT_CLASS > > m_effectiveClassesCache
Cache of all generated effective component classes (for netlist updating)
const COMPONENT_CLASS * GetNoneComponentClass() const
Returns the unassigned component class.
std::unordered_map< wxString, std::unique_ptr< COMPONENT_CLASS > > m_effectiveClasses
Generated effective component classes.
void InitNetlistUpdate()
Prepare the manager for a board update Must be called prior to updating the PCB from the netlist.
const std::unordered_map< wxString, std::unique_ptr< COMPONENT_CLASS > > & GetClasses() const
Fetches a read-only map of the fundamental component classes.
COMPONENT_CLASS * GetEffectiveComponentClass(std::unordered_set< wxString > &classNames)
Gets an effective component class for the given constituent class names.
void AddConstituentClass(COMPONENT_CLASS *componentClass)
Adds a constituent component class to an effective component class.
bool ContainsClassName(const wxString &className) const
Determines if this (effective) component class contains a specific sub-class.
std::vector< COMPONENT_CLASS * > m_constituentClasses
The COMPONENT_CLASS objects contributing to this complete component class.
COMPONENT_CLASS(const wxString &name)
const std::vector< COMPONENT_CLASS * > & GetConstituentClasses() const
Fetches a vector of the constituent classes for this (effective) class.
wxString m_name
The full name of the component class.
const wxString & GetFullName() const
Fetches the full name of this component class.
wxString GetName() const
Fetches the display name of this component class.
bool IsEmpty() const
Determines if this (effective) component class is empty (i.e. no classes defined)