KiCad PCB EDA Suite
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
component_class.cpp
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
22#include <wx/intl.h>
23
24
26{
27 m_constituentClasses.push_back( componentClass );
28}
29
30
31const COMPONENT_CLASS* COMPONENT_CLASS::GetConstituentClass( const wxString& className ) const
32{
33 const auto itr = std::ranges::find_if( m_constituentClasses,
34 [&className]( const COMPONENT_CLASS* testClass )
35 {
36 return testClass->GetName() == className;
37 } );
38
39 if( itr != m_constituentClasses.end() )
40 return *itr;
41
42 return nullptr;
43}
44
45
46bool COMPONENT_CLASS::ContainsClassName( const wxString& className ) const
47{
48 return GetConstituentClass( className ) != nullptr;
49}
50
51
53{
54 if( m_constituentClasses.size() == 0 )
55 return wxT( "<None>" );
56
57 if( m_constituentClasses.size() == 1 )
58 return m_name;
59
60 wxASSERT( m_constituentClasses.size() >= 2 );
61
62 wxString name;
63
64 if( m_constituentClasses.size() == 2 )
65 {
66 name.Printf( _( "%s and %s" ), m_constituentClasses[0]->GetName(),
68 }
69 else if( m_constituentClasses.size() == 3 )
70 {
71 name.Printf( _( "%s, %s and %s" ), m_constituentClasses[0]->GetName(),
73 }
74 else if( m_constituentClasses.size() > 3 )
75 {
76 name.Printf( _( "%s, %s and %d more" ), m_constituentClasses[0]->GetName(),
78 static_cast<int>( m_constituentClasses.size() - 2 ) );
79 }
80
81 return name;
82}
83
84
86{
87 return m_constituentClasses.empty();
88}
89
90
91bool COMPONENT_CLASS::operator==( const COMPONENT_CLASS& aComponent ) const
92{
93 return GetName() == aComponent.GetName();
94}
95
96
97bool COMPONENT_CLASS::operator!=( const COMPONENT_CLASS& aComponent ) const
98{
99 return !( *this == aComponent );
100}
const char * name
Definition: DXF_plotter.cpp:59
A lightweight representation of a component class.
bool operator!=(const COMPONENT_CLASS &aComponent) const
Tests two component classes for inequality based on full class name.
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 constituent class.
std::vector< COMPONENT_CLASS * > m_constituentClasses
The COMPONENT_CLASS objects contributing to this complete component class.
const wxString & GetName() const
Fetches the full name of this component class.
wxString m_name
The full name of the component class.
bool operator==(const COMPONENT_CLASS &aComponent) const
Tests two component classes for equality based on full class name.
const COMPONENT_CLASS * GetConstituentClass(const wxString &className) const
Returns a named constituent class of this component class, or nullptr if not found.
wxString GetHumanReadableName() const
Gets the consolidated name of this component class (which may be an aggregate).
bool IsEmpty() const
Determines if this (effective) component class is empty (i.e. no classes defined)
#define _(s)