KiCad PCB EDA Suite
Loading...
Searching...
No Matches
target3001_sch_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 The 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 2
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 TARGET3001_SCH_BUILDER_H
21#define TARGET3001_SCH_BUILDER_H
22
23#include <functional>
24#include <map>
25#include <optional>
26#include <set>
27#include <vector>
28
29#include <math/box2.h>
30#include <math/vector2d.h>
31
34
35class LIB_SYMBOL;
36class REPORTER;
37class SCH_ITEM;
38class SCH_LINE;
39class SCH_SCREEN;
40class SCH_SHEET;
41class SCH_TEXT;
42class SCHEMATIC;
43
44
52class SCH_BITMAP;
53
55{
56public:
57 TARGET3001_SCH_BUILDER( SCHEMATIC* aSchematic, SCH_SHEET* aRootSheet, const TARGET3001::PROJECT& aProject,
58 const wxString& aFileName, REPORTER* aReporter );
59
60 void Build();
61
62private:
64 struct PIN_END
65 {
66 int sheet;
68 float direction;
69 bool power;
70 };
71
73 static int sheetOf( const TARGET3001::ELEMENT& aElem );
74
76 SCH_SCREEN* screen( int aSheet );
77
78 void addComponent( const TARGET3001::ELEMENT& aComponent );
79 void addConnections( const TARGET3001::ELEMENT& aSignal );
80 void addFreeItem( const TARGET3001::ELEMENT& aElem );
81 void addFreeSymbol( const TARGET3001::ELEMENT& aSymbol );
82
87 void addGateBodies( LIB_SYMBOL* aLib, const std::vector<const TARGET3001::ELEMENT*>& aGates, bool aFieldTexts,
88 const std::map<uint16_t, wxString>& aPadNumbers = {} ) const;
89
91 SCH_ITEM* makeGraphic( const TARGET3001::ELEMENT& aElem, const VECTOR2I& aOrigin, bool aInSymbol ) const;
92
94 SCH_BITMAP* makePicture( const TARGET3001::ELEMENT& aElem ) const;
95
96 void addToSheet( int aSheet, SCH_ITEM* aItem );
97
99 void addNetItem( int aSheet, SCH_ITEM* aItem, int aSignal );
100
105 void separateSignals( int aSheet );
106
112 std::optional<VECTOR2I> bendAround( int aSheet, int aSignal, const VECTOR2I& aPos,
113 std::vector<std::pair<SCH_LINE*, int>>& aWires,
114 const std::function<bool( const VECTOR2I& )>& aIsFree );
115
117 bool joinsGlobally( const TARGET3001::ELEMENT& aSignal ) const;
118
120 std::optional<VECTOR2I> labelAnchor( const TARGET3001::ELEMENT& aSignal, int aSheet, const VECTOR2I& aPos ) const;
121
123 void joinSignalPieces();
124
130 void joinPieces( int aSignal, const std::map<int, std::vector<SCH_ITEM*>>& aItems );
131
132 void finishSheets();
133
135 static VECTOR2I toSch( int32_t aX, int32_t aY );
136 static int toSch( int32_t aLength );
137
141 wxString m_fileName;
143
144 std::map<int, SCH_SHEET*> m_sheets;
145 std::map<int, BOX2I> m_extents;
146 std::map<int, std::vector<SCH_ITEM*>> m_pending;
149 std::map<int, std::set<int>> m_powerSheets;
150 std::map<int, std::vector<std::pair<SCH_ITEM*, int>>> m_netItems;
151 std::map<int, std::vector<std::pair<VECTOR2I, int>>> m_pinSignals;
152 std::set<int> m_globalSignals;
153 std::map<int, std::vector<PIN_END>> m_pinEnds;
156};
157
158#endif // TARGET3001_SCH_BUILDER_H
Define a library symbol object.
Definition lib_symbol.h:114
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
Holds all the data relating to one schematic.
Definition schematic.h:149
Object to handle a bitmap image that can be inserted in a schematic.
Definition sch_bitmap.h:36
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:170
Segment description base class to describe items which have 2 end points (track, wire,...
Definition sch_line.h:39
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:48
Maps TARGET 3001!
void addNetItem(int aSheet, SCH_ITEM *aItem, int aSignal)
Add a wire, junction or label of signal aSignal; separateSignals() keeps it apart from other signals.
const TARGET3001::PROJECT & m_project
TARGET3001_SCH_BUILDER(SCHEMATIC *aSchematic, SCH_SHEET *aRootSheet, const TARGET3001::PROJECT &aProject, const wxString &aFileName, REPORTER *aReporter)
void addToSheet(int aSheet, SCH_ITEM *aItem)
void addFreeItem(const TARGET3001::ELEMENT &aElem)
bool joinsGlobally(const TARGET3001::ELEMENT &aSignal) const
True when the signal's labels must be global: it reaches several sheets or meets supply symbols.
static VECTOR2I toSch(int32_t aX, int32_t aY)
Sheet position in KiCad units, before the per-sheet page offset is applied.
std::map< int, std::vector< PIN_END > > m_pinEnds
placed pins of each signal, by signal ID
SCH_BITMAP * makePicture(const TARGET3001::ELEMENT &aElem) const
Image a rectangle shows instead of its fill, or nullptr when it has none.
std::map< int, std::set< int > > m_powerSheets
sheets holding a power symbol, by signal ID
void joinSignalPieces()
Join the pieces of every signal as separateSignals() left them; see joinPieces()
SCH_ITEM * makeGraphic(const TARGET3001::ELEMENT &aElem, const VECTOR2I &aOrigin, bool aInSymbol) const
Add graphics shared by free items and symbol bodies; returns nullptr for unsupported items.
std::map< int, BOX2I > m_extents
drawn extent of each sheet
void addFreeSymbol(const TARGET3001::ELEMENT &aSymbol)
void joinPieces(int aSignal, const std::map< int, std::vector< SCH_ITEM * > > &aItems)
Join the pieces of signal aSignal that KiCad would see apart, since the file joins a signal's items b...
std::map< int, std::vector< std::pair< SCH_ITEM *, int > > > m_netItems
items and their signal, by sheet
std::map< int, std::vector< std::pair< VECTOR2I, int > > > m_pinSignals
pin points and signal, by sheet
TARGET3001::FONTS m_fonts
lookup cache, filled while drawing
std::optional< VECTOR2I > labelAnchor(const TARGET3001::ELEMENT &aSignal, int aSheet, const VECTOR2I &aPos) const
Point on the signal's own wires or pins nearest a name drawn at aPos, if it is close enough to name t...
std::optional< VECTOR2I > bendAround(int aSheet, int aSignal, const VECTOR2I &aPos, std::vector< std::pair< SCH_LINE *, int > > &aWires, const std::function< bool(const VECTOR2I &)> &aIsFree)
Bend the wires of aSignal that pass through aPos around it, one gap aside on a side aIsFree accepts,...
void addGateBodies(LIB_SYMBOL *aLib, const std::vector< const TARGET3001::ELEMENT * > &aGates, bool aFieldTexts, const std::map< uint16_t, wxString > &aPadNumbers={}) const
Draw each gate's body as one unit of aLib; aFieldTexts leaves reference and value texts to fields.
void addComponent(const TARGET3001::ELEMENT &aComponent)
void addConnections(const TARGET3001::ELEMENT &aSignal)
std::map< int, std::vector< SCH_ITEM * > > m_pending
std::set< int > m_globalSignals
signals joined by global labels
void separateSignals(int aSheet)
Move apart items of different signals that touch where KiCad would join them, since the file connects...
SCH_SCREEN * screen(int aSheet)
Screen for a 1-based sheet number, created on first use.
std::map< int, SCH_SHEET * > m_sheets
by 1-based sheet number
static int sheetOf(const TARGET3001::ELEMENT &aElem)
Sheet number of a schematic element, or 0 for board elements.
One element of any class.
bool power
pin of a supply symbol, which names its net globally
float direction
file direction, pointing from the end to the body
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708