KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pads_sch_schematic_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_SCHEMATIC_BUILDER_H_
21#define PADS_SCH_SCHEMATIC_BUILDER_H_
22
24#include <sch_label.h>
25#include <map>
26#include <set>
27#include <vector>
28#include <memory>
29#include <wx/string.h>
30
31class SCH_SCREEN;
32class SCH_SHEET;
33class SCH_SHEET_PATH;
34class SCH_SHEET_PIN;
35class SCH_HIERLABEL;
36class SCH_GLOBALLABEL;
37class SCH_LINE;
38class SCH_JUNCTION;
39class SCH_LABEL;
41class SCH_SYMBOL;
42class SCHEMATIC;
43
44namespace PADS_SCH
45{
46
52{
53public:
54 PADS_SCH_SCHEMATIC_BUILDER( const PARAMETERS& aParams, SCHEMATIC* aSchematic );
56
57 int CreateWires( const std::vector<SCH_SIGNAL>& aSignals, SCH_SCREEN* aScreen );
58
59 SCH_LINE* CreateWire( const WIRE_SEGMENT& aWire );
60
61 int CreateJunctions( const std::vector<SCH_SIGNAL>& aSignals, SCH_SCREEN* aScreen );
62
77 int CreateNetLabels( const std::vector<SCH_SIGNAL>& aSignals, SCH_SCREEN* aScreen,
78 const std::set<std::string>& aSignalOpcIds,
79 const std::set<std::string>& aSkipSignals = {},
80 const std::map<std::string, NETNAME_LABEL>& aNetNameLabels = {} );
81
90 static SPIN_STYLE SpinFromNetNameLabel( const NETNAME_LABEL& aLabel );
91
96 SCH_GLOBALLABEL* CreateNetLabel( const SCH_SIGNAL& aSignal, const VECTOR2I& aPosition,
97 SPIN_STYLE aOrientation = SPIN_STYLE::RIGHT );
98
99 int CreateBusWires( const std::vector<SCH_SIGNAL>& aSignals, SCH_SCREEN* aScreen );
100
101 SCH_LINE* CreateBusWire( const WIRE_SEGMENT& aWire );
102
103 static bool IsBusSignal( const std::string& aName );
104
108 void ApplyPartAttributes( SCH_SYMBOL* aSymbol, const PART_PLACEMENT& aPlacement );
109
110 void ApplyFieldSettings( SCH_SYMBOL* aSymbol, const PART_PLACEMENT& aPlacement );
111
115 int CreateCustomFields( SCH_SYMBOL* aSymbol, const PART_PLACEMENT& aPlacement );
116
121 void CreateTitleBlock( SCH_SCREEN* aScreen );
122
127 SCH_SHEET* CreateHierarchicalSheet( int aSheetNumber, int aTotalSheets,
128 SCH_SHEET* aParentSheet,
129 const wxString& aBaseFilename );
130
132
136 VECTOR2I CalculateSheetPosition( int aSheetIndex, int aTotalSheets ) const;
137
142 SCH_SHEET_PIN* CreateSheetPin( SCH_SHEET* aSheet, const std::string& aSignalName,
143 int aPinIndex );
144
149 SCH_HIERLABEL* CreateHierLabel( const std::string& aSignalName, const VECTOR2I& aPosition,
150 SCH_SCREEN* aScreen );
151
155 static bool IsGlobalSignal( const std::string& aSignalName,
156 const std::set<int>& aSheetNumbers );
157
161 static SPIN_STYLE computeLabelOrientation( const VECTOR2I& aLabelPos,
162 const VECTOR2I& aAdjacentPos );
163
164private:
165 int toKiCadUnits( double aPadsValue ) const;
166
170 int toKiCadY( double aPadsY ) const;
171
175 std::vector<VECTOR2I> findJunctionPoints( const std::vector<SCH_SIGNAL>& aSignals );
176
177 VECTOR2I chooseLabelPosition( const SCH_SIGNAL& aSignal );
178
182 wxString convertNetName( const std::string& aName ) const;
183
187};
188
189} // namespace PADS_SCH
190
191#endif // PADS_SCH_SCHEMATIC_BUILDER_H_
SCH_LINE * CreateWire(const WIRE_SEGMENT &aWire)
std::vector< VECTOR2I > findJunctionPoints(const std::vector< SCH_SIGNAL > &aSignals)
Find points where 3+ wire segments meet.
static SPIN_STYLE SpinFromNetNameLabel(const NETNAME_LABEL &aLabel)
Map a PADS NETNAMES label entry to a KiCad global-label spin style.
int toKiCadY(double aPadsY) const
Convert PADS Y coordinate to KiCad Y, accounting for Y-axis inversion and page offset.
SCH_SHEET_PIN * CreateSheetPin(SCH_SHEET *aSheet, const std::string &aSignalName, int aPinIndex)
Create a sheet pin that connects to a hierarchical label in the sub-schematic.
int CreateJunctions(const std::vector< SCH_SIGNAL > &aSignals, SCH_SCREEN *aScreen)
void ApplyPartAttributes(SCH_SYMBOL *aSymbol, const PART_PLACEMENT &aPlacement)
Set reference, value, footprint and other fields on a symbol from a part placement.
PADS_SCH_SCHEMATIC_BUILDER(const PARAMETERS &aParams, SCHEMATIC *aSchematic)
void CreateTitleBlock(SCH_SCREEN *aScreen)
Set the title block from PADS fields, checking custom names too because PADS designs often leave the ...
VECTOR2I CalculateSheetPosition(int aSheetIndex, int aTotalSheets) const
Position a sheet symbol in a roughly square grid on the parent.
static SPIN_STYLE computeLabelOrientation(const VECTOR2I &aLabelPos, const VECTOR2I &aAdjacentPos)
Orient a label opposite to the wire direction at its position so it clears the wire.
int CreateCustomFields(SCH_SYMBOL *aSymbol, const PART_PLACEMENT &aPlacement)
Create KiCad user fields for PADS attributes that have no standard-field mapping.
VECTOR2I chooseLabelPosition(const SCH_SIGNAL &aSignal)
SCH_LINE * CreateBusWire(const WIRE_SEGMENT &aWire)
SCH_HIERLABEL * CreateHierLabel(const std::string &aSignalName, const VECTOR2I &aPosition, SCH_SCREEN *aScreen)
Create a hierarchical label that connects to a sheet pin on the parent.
void ApplyFieldSettings(SCH_SYMBOL *aSymbol, const PART_PLACEMENT &aPlacement)
int CreateWires(const std::vector< SCH_SIGNAL > &aSignals, SCH_SCREEN *aScreen)
SCH_GLOBALLABEL * CreateNetLabel(const SCH_SIGNAL &aSignal, const VECTOR2I &aPosition, SPIN_STYLE aOrientation=SPIN_STYLE::RIGHT)
Create a net label.
static bool IsGlobalSignal(const std::string &aSignalName, const std::set< int > &aSheetNumbers)
A signal is global when it spans multiple sheets or is a common power net.
int CreateBusWires(const std::vector< SCH_SIGNAL > &aSignals, SCH_SCREEN *aScreen)
wxString convertNetName(const std::string &aName) const
Convert a PADS net name to a KiCad label, mapping a "/" prefix to a "~{}" overbar.
SCH_SHEET * CreateHierarchicalSheet(int aSheetNumber, int aTotalSheets, SCH_SHEET *aParentSheet, const wxString &aBaseFilename)
Create a sub-sheet positioned on its parent and backed by its own screen.
int CreateNetLabels(const std::vector< SCH_SIGNAL > &aSignals, SCH_SCREEN *aScreen, const std::set< std::string > &aSignalOpcIds, const std::set< std::string > &aSkipSignals={}, const std::map< std::string, NETNAME_LABEL > &aNetNameLabels={})
Create net labels for named signals.
static bool IsBusSignal(const std::string &aName)
Holds all the data relating to one schematic.
Definition schematic.h:149
Class for a wire to bus entry.
Segment description base class to describe items which have 2 end points (track, wire,...
Definition sch_line.h:39
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:48
Schematic symbol object.
Definition sch_symbol.h:73
Spin style for labels of all kinds on schematics.
Definition sch_label.h:38
Wire segment connecting two endpoints through coordinate vertices.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708