KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pads_sch_symbol_builder.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) 2025 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 3
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU 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 PADS_SCH_SYMBOL_BUILDER_H_
21#define PADS_SCH_SYMBOL_BUILDER_H_
22
24#include <lib_id.h>
25#include <map>
26#include <memory>
27#include <optional>
28#include <string>
29
30class LIB_SYMBOL;
31class SCH_SHAPE;
32class SCH_PIN;
33class SCH_SHEET;
34class SCH_TEXT;
35class SCHEMATIC;
36
37namespace PADS_SCH
38{
39
44{
45public:
46 PADS_SCH_SYMBOL_BUILDER( const PARAMETERS& aParams );
48
52 LIB_SYMBOL* BuildSymbol( const SYMBOL_DEF& aSymbolDef );
53
58 LIB_SYMBOL* GetOrCreateSymbol( const SYMBOL_DEF& aSymbolDef );
59
60 bool HasSymbol( const std::string& aName ) const;
61
62 LIB_SYMBOL* GetSymbol( const std::string& aName ) const;
63
64 static bool IsPowerSymbol( const std::string& aName );
65
69 static std::optional<LIB_ID> GetKiCadPowerSymbolId( const std::string& aPadsName );
70
75 LIB_SYMBOL* BuildKiCadPowerSymbol( const std::string& aKiCadName );
76
81 static std::string GetPowerStyleFromVariant( const std::string& aDecalName,
82 const std::string& aPinType );
83
91 static int NextFreePowerOrdinal( SCH_SHEET* aSheet );
92
99 const std::vector<SYMBOL_DEF>& aSymbolDefs );
100
106 const std::vector<SYMBOL_DEF>& aSymbolDefs );
107
113 const SYMBOL_DEF& aSymbolDef );
114
120 const SYMBOL_DEF& aSymbolDef,
121 const std::string& aPinNumber );
122
128 const SYMBOL_DEF& aSymbolDef,
129 const std::vector<std::string>& aPinNumbers );
130
135 const PARTTYPE_DEF& aPartType,
136 const SYMBOL_DEF& aSymbolDef,
137 const std::vector<std::string>& aPinNumbers,
138 const std::string& aCacheKey );
139
143 void AddHiddenPowerPins( LIB_SYMBOL* aSymbol,
144 const std::vector<PARTTYPE_DEF::SIGPIN>& aSigpins );
145
146private:
147 int toKiCadUnits( double aPadsValue ) const;
148
153 SCH_SHAPE* createShape( const SYMBOL_GRAPHIC& aGraphic );
154
155 std::vector<SCH_SHAPE*> createShapes( const SYMBOL_GRAPHIC& aGraphic );
156
158 static std::vector<SYMBOL_PIN> applyGateOverrides( const std::vector<SYMBOL_PIN>& aDecalPins,
159 const GATE_DEF& aGate );
160
163 static bool isDiodeAKPinSet( const std::vector<SYMBOL_PIN>& aPins );
164
165 SCH_PIN* createPin( const SYMBOL_PIN& aPin, LIB_SYMBOL* aParent, bool aMapDiodeAK = false );
166
169 SCH_TEXT* createSymbolText( const SYMBOL_TEXT& aText, int aUnit = 0 );
170
171 int mapPinType( PIN_TYPE aPadsType );
172
174 std::map<std::string, std::unique_ptr<LIB_SYMBOL>> m_symbolCache;
175};
176
177} // namespace PADS_SCH
178
179#endif // PADS_SCH_SYMBOL_BUILDER_H_
Define a library symbol object.
Definition lib_symbol.h:119
LIB_SYMBOL * BuildMultiUnitSymbol(const PARTTYPE_DEF &aPartType, const std::vector< SYMBOL_DEF > &aSymbolDefs)
Build a composite multi-unit symbol from a multi-gate PARTTYPE.
bool HasSymbol(const std::string &aName) const
void AddHiddenPowerPins(LIB_SYMBOL *aSymbol, const std::vector< PARTTYPE_DEF::SIGPIN > &aSigpins)
Add hidden PT_POWER_IN pins from PARTTYPE SIGPIN entries, skipping duplicate numbers.
static std::vector< SYMBOL_PIN > applyGateOverrides(const std::vector< SYMBOL_PIN > &aDecalPins, const GATE_DEF &aGate)
Return the decal's pins with the gate's name, number and type overrides applied.
LIB_SYMBOL * GetSymbol(const std::string &aName) const
int toKiCadUnits(double aPadsValue) const
LIB_SYMBOL * GetOrCreateMultiUnitSymbol(const PARTTYPE_DEF &aPartType, const std::vector< SYMBOL_DEF > &aSymbolDefs)
Return the cached multi-unit symbol for the PARTTYPE, building it if needed, so all instances of the ...
static std::optional< LIB_ID > GetKiCadPowerSymbolId(const std::string &aPadsName)
Map a PADS power symbol name to a KiCad power library LIB_ID, or nullopt if unmapped.
std::vector< SCH_SHAPE * > createShapes(const SYMBOL_GRAPHIC &aGraphic)
LIB_SYMBOL * BuildKiCadPowerSymbol(const std::string &aKiCadName)
Build a power symbol using hard-coded KiCad-standard graphics, or nullptr if the name is unrecognized...
PADS_SCH_SYMBOL_BUILDER(const PARAMETERS &aParams)
SCH_PIN * createPin(const SYMBOL_PIN &aPin, LIB_SYMBOL *aParent, bool aMapDiodeAK=false)
static bool IsPowerSymbol(const std::string &aName)
static std::string GetPowerStyleFromVariant(const std::string &aDecalName, const std::string &aPinType)
Map a PADS special_variant decal name and pin type to a power symbol style name for BuildKiCadPowerSy...
SCH_SHAPE * createShape(const SYMBOL_GRAPHIC &aGraphic)
Create a SCH_SHAPE from a PADS graphic element.
LIB_SYMBOL * GetOrCreateSymbol(const SYMBOL_DEF &aSymbolDef)
Return the cached symbol for the given definition, building and caching it if needed.
LIB_SYMBOL * GetOrCreateConnectorPinSymbol(const PARTTYPE_DEF &aPartType, const SYMBOL_DEF &aSymbolDef, const std::string &aPinNumber)
Return a connector symbol variant carrying a specific pin number, since PADS connectors reuse one dec...
LIB_SYMBOL * GetOrCreateMultiUnitConnectorSymbol(const PARTTYPE_DEF &aPartType, const SYMBOL_DEF &aSymbolDef, const std::vector< std::string > &aPinNumbers, const std::string &aCacheKey)
Return the cached multi-unit connector symbol, building it if needed.
LIB_SYMBOL * BuildMultiUnitConnectorSymbol(const PARTTYPE_DEF &aPartType, const SYMBOL_DEF &aSymbolDef, const std::vector< std::string > &aPinNumbers)
Build a multi-unit connector symbol with one unit per pin, letting all of a connector's individually ...
std::map< std::string, std::unique_ptr< LIB_SYMBOL > > m_symbolCache
LIB_SYMBOL * BuildSymbol(const SYMBOL_DEF &aSymbolDef)
Build a KiCad LIB_SYMBOL from a PADS symbol definition.
static bool isDiodeAKPinSet(const std::vector< SYMBOL_PIN > &aPins)
True when aPins is a bare two-pin A/K pair, i.e.
SCH_TEXT * createSymbolText(const SYMBOL_TEXT &aText, int aUnit=0)
Build the configured SCH_TEXT for one symbol text field, or nullptr when its content is empty.
LIB_SYMBOL * GetOrCreatePartTypeSymbol(const PARTTYPE_DEF &aPartType, const SYMBOL_DEF &aSymbolDef)
Return a single-gate symbol with PARTTYPE pin overrides applied at build time.
static int NextFreePowerOrdinal(SCH_SHEET *aSheet)
Return the first 1-based ordinal that no "#PWRnnnn" reference under aSheet uses.
Holds all the data relating to one schematic.
Definition schematic.h:148
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:48