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 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
91 GetFullClassNameForConstituents( const std::unordered_set<wxString>& classNames );
92
95 static wxString GetFullClassNameForConstituents( const std::vector<wxString>& classNames );
96
100 COMPONENT_CLASS* GetEffectiveComponentClass( const std::unordered_set<wxString>& classNames );
101
103 const COMPONENT_CLASS* GetNoneComponentClass() const { return m_noneClass.get(); }
104
107 void InitNetlistUpdate();
108
111 void FinishNetlistUpdate();
112
114 // All pointers to COMPONENT_CLASS objects will being invalid
115 void Reset();
116
118 const std::unordered_map<wxString, std::unique_ptr<COMPONENT_CLASS>>& GetClasses() const
119 {
120 return m_classes;
121 }
122
123protected:
125 std::unordered_map<wxString, std::unique_ptr<COMPONENT_CLASS>> m_classes;
126
128 std::unordered_map<wxString, std::unique_ptr<COMPONENT_CLASS>> m_effectiveClasses;
129
131 std::unordered_map<wxString, std::unique_ptr<COMPONENT_CLASS>> m_classesCache;
132
134 std::unordered_map<wxString, std::unique_ptr<COMPONENT_CLASS>> m_effectiveClassesCache;
135
137 std::unique_ptr<COMPONENT_CLASS> m_noneClass;
138};
139
140#endif
const char * name
Definition: DXF_plotter.cpp:59
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)
COMPONENT_CLASS * GetEffectiveComponentClass(const std::unordered_set< wxString > &classNames)
Gets an effective component class for the given constituent class names.
void Reset()
Resets the contents of the manager.
static wxString GetFullClassNameForConstituents(const std::unordered_set< wxString > &classNames)
Gets the full effective class name for the given set of constituent classes.
void FinishNetlistUpdate()
Cleans up the manager after a board update Must be called after updating the PCB from the netlist.
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.
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)