KiCad PCB EDA Suite
Loading...
Searching...
No Matches
odb_eda_data.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) 2024 KiCad Developers, see AUTHORS.txt for contributors.
5 * Author: SYSUEric <[email protected]>.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef _ODB_EDA_DATA_H_
22#define _ODB_EDA_DATA_H_
23
24
25#include <list>
26#include <memory>
27
28#include "odb_attribute.h"
29#include "odb_feature.h"
30
31
32class PKG_OUTLINE;
33class EDA_DATA : public ATTR_MANAGER
34{
35public:
36 EDA_DATA();
37
38 void Write( std::ostream& ost ) const;
39 size_t GetLyrIdx( const wxString& aLayerName );
40 std::vector<std::shared_ptr<FOOTPRINT>> GetEdaFootprints() const { return m_eda_footprints; }
41
43 {
44 friend EDA_DATA;
45
46 public:
47 enum class TYPE
48 {
49 COPPER,
51 HOLE
52 };
53
54 FEATURE_ID( TYPE t, size_t l, size_t fid ) : type( t ), layer( l ), feature_id( fid ) {}
55
57 size_t layer;
58 size_t feature_id;
59
60 void Write( std::ostream& ost ) const;
61 };
62
63 class SUB_NET
64 {
65 public:
66 SUB_NET( size_t aIndex, EDA_DATA* aEda ) : m_index( aIndex ), m_edadata( aEda ) {}
67 const size_t m_index;
68 void Write( std::ostream& ost ) const;
69
70 std::list<FEATURE_ID> feature_ids;
71 void AddFeatureID( FEATURE_ID::TYPE type, const wxString& layer, size_t feature_id );
72
73 virtual ~SUB_NET() {}
74
75 protected:
76 virtual void WriteSubnet( std::ostream& ost ) const = 0;
78 };
79
80 class SUB_NET_VIA : public SUB_NET
81 {
82 public:
83 SUB_NET_VIA( size_t aIndex, EDA_DATA* aEda ) : SUB_NET( aIndex, aEda ) {}
84 void WriteSubnet( std::ostream& ost ) const override;
85 };
86
87 class SUB_NET_TRACE : public SUB_NET
88 {
89 public:
90 SUB_NET_TRACE( size_t aIndex, EDA_DATA* aEda ) : SUB_NET( aIndex, aEda ) {}
91 void WriteSubnet( std::ostream& ost ) const override;
92 };
93
94 class SUB_NET_PLANE : public SUB_NET
95 {
96 public:
97 enum class FILL_TYPE
98 {
99 SOLID,
100 OUTLINE
101 };
102
103 enum class CUTOUT_TYPE
104 {
105 CIRCLE,
106 RECT,
107 OCTAGON,
108 EXACT
109 };
110
111 SUB_NET_PLANE( size_t aIndex, EDA_DATA* aEda, FILL_TYPE aFill, CUTOUT_TYPE aCutout,
112 size_t aFillSize ) :
113 SUB_NET( aIndex, aEda ), fill_type( aFill ), cutout_type( aCutout ),
114 fill_size( aFillSize )
115 {
116 }
117
120 size_t fill_size;
121
122 void WriteSubnet( std::ostream& ost ) const override;
123 };
124
126 {
127 public:
128 enum class SIDE
129 {
130 TOP,
131 BOTTOM
132 };
133
134 SUB_NET_TOEPRINT( size_t aIndex, EDA_DATA* aEda, SIDE aSide, size_t aCompNum,
135 size_t aToepNum ) :
136 SUB_NET( aIndex, aEda ), side( aSide ), comp_num( aCompNum ), toep_num( aToepNum )
137 {
138 }
139
141
143
144 size_t comp_num;
145 size_t toep_num;
146
147 void WriteSubnet( std::ostream& ost ) const override;
148 };
149
150 class NET : public ATTR_RECORD_WRITER
151 {
152 public:
153 NET( size_t aIndex, const wxString& aName ) : m_index( aIndex ), m_name( aName ) {}
154
155 const size_t m_index;
156 wxString m_name;
157 std::list<std::unique_ptr<SUB_NET>> subnets;
158
159 template <typename T, typename... Args>
160 T& AddSubnet( Args&&... args )
161 {
162 auto f = std::make_unique<T>( subnets.size(), std::forward<Args>( args )... );
163 auto& r = *f;
164 subnets.push_back( std::move( f ) );
165 return r;
166 }
167
168 void Write( std::ostream& ost ) const;
169 };
170
171 void AddNET( const NETINFO_ITEM* aNet );
172 NET& GetNet( size_t aNetcode ) { return nets_map.at( aNetcode ); }
173
174 class PIN
175 {
176 public:
177 PIN( const size_t aIndex, const wxString& aName ) : m_index( aIndex ), m_name( aName ) {}
178
179 const size_t m_index;
180 wxString m_name;
181
182 std::pair<wxString, wxString> m_center;
183
184 enum class TYPE
185 {
187 BLIND,
188 SURFACE
189 };
190
191 TYPE type = TYPE::SURFACE;
192
194 {
198 };
199
201
202 enum class MOUNT_TYPE
203 {
204 SMT,
208 PRESSFIT,
209 NON_BOARD,
210 HOLE,
212 };
214
215 std::list<std::unique_ptr<PKG_OUTLINE>> m_pinOutlines;
216
217 void Write( std::ostream& ost ) const;
218 };
219
221 {
222 public:
223 PACKAGE( const size_t aIndex, const wxString& afpName ) :
224 m_index( aIndex ), m_name( afpName ),
225 m_pitch( 0 ),
226 m_xmin( 0 ), m_ymin( 0 ),
227 m_xmax( 0 ), m_ymax( 0 )
228
229 {
230 }
231
232 const size_t m_index;
233 wxString m_name;
234
235 uint64_t m_pitch;
236 int64_t m_xmin, m_ymin, m_xmax, m_ymax; // Box points: leftlow, rightup
237
238 std::list<std::unique_ptr<PKG_OUTLINE>> m_pkgOutlines;
239
240 void AddPin( const PAD* aPad, size_t aPinNum );
241 const std::shared_ptr<PIN> GetEdaPkgPin( size_t aPadIndex ) const
242 {
243 return m_pinsVec.at( aPadIndex );
244 }
245
246 void Write( std::ostream& ost ) const;
247
248 private:
249 std::vector<std::shared_ptr<PIN>> m_pinsVec;
250 };
251
252 void AddPackage( const FOOTPRINT* aFp );
253 const PACKAGE& GetPackage( size_t aHash ) const { return packages_map.at( aHash ); }
254
255private:
256 std::map<size_t, NET> nets_map;
257 std::list<const NET*> nets;
258
259 std::map<size_t, PACKAGE> packages_map; //hash value, package
260 std::list<const PACKAGE*> packages;
261
262 std::map<wxString, size_t> layers_map;
263 std::vector<wxString> layers;
264 std::vector<std::shared_ptr<FOOTPRINT>> m_eda_footprints;
265};
266
268{
269public:
270 virtual void Write( std::ostream& ost ) const = 0;
271
272 virtual ~PKG_OUTLINE() = default;
273};
274
276{
277public:
278 OUTLINE_RECT( const VECTOR2I& aLowerLeft, size_t aWidth, size_t aHeight ) :
279 m_lower_left( aLowerLeft ), m_width( aWidth ), m_height( aHeight )
280 {
281 }
282
283 OUTLINE_RECT( const BOX2I& aBox ) :
284 OUTLINE_RECT( aBox.GetPosition(), aBox.GetWidth(), aBox.GetHeight() )
285 {
286 }
287
289 size_t m_width;
290 size_t m_height;
291
292 void Write( std::ostream& ost ) const override;
293};
294
295class ODB_SURFACE_DATA;
297{
298public:
300 FILL_T aFillType = FILL_T::FILLED_SHAPE )
301 {
302 if( !aPolygon.empty() && aPolygon[0].PointCount() >= 3 )
303 {
304 m_surfaces = std::make_unique<ODB_SURFACE_DATA>( aPolygon );
305 if( aFillType != FILL_T::NO_FILL )
306 {
307 m_surfaces->AddPolygonHoles( aPolygon );
308 }
309 }
310 }
311
312 std::unique_ptr<ODB_SURFACE_DATA> m_surfaces;
313
314 void Write( std::ostream& ost ) const override;
315};
316
318{
319public:
320 OUTLINE_SQUARE( const VECTOR2I& aCenter, size_t aHalfSide ) :
321 m_center( aCenter ), m_halfSide( aHalfSide )
322 {
323 }
326
327 void Write( std::ostream& ost ) const override;
328};
329
331{
332public:
333 OUTLINE_CIRCLE( const VECTOR2I& aCenter, size_t aRadius ) :
334 m_center( aCenter ), m_radius( aRadius )
335 {
336 }
338 size_t m_radius;
339
340 void Write( std::ostream& ost ) const override;
341};
342
343
344#endif // _ODB_EDA_DATA_H_
FEATURE_ID(TYPE t, size_t l, size_t fid)
Definition: odb_eda_data.h:54
void Write(std::ostream &ost) const
void Write(std::ostream &ost) const
T & AddSubnet(Args &&... args)
Definition: odb_eda_data.h:160
const size_t m_index
Definition: odb_eda_data.h:155
std::list< std::unique_ptr< SUB_NET > > subnets
Definition: odb_eda_data.h:157
wxString m_name
Definition: odb_eda_data.h:156
NET(size_t aIndex, const wxString &aName)
Definition: odb_eda_data.h:153
PACKAGE(const size_t aIndex, const wxString &afpName)
Definition: odb_eda_data.h:223
void AddPin(const PAD *aPad, size_t aPinNum)
std::vector< std::shared_ptr< PIN > > m_pinsVec
Definition: odb_eda_data.h:249
const std::shared_ptr< PIN > GetEdaPkgPin(size_t aPadIndex) const
Definition: odb_eda_data.h:241
const size_t m_index
Definition: odb_eda_data.h:232
wxString m_name
<! Reference number of the package to be used in CMP.
Definition: odb_eda_data.h:233
void Write(std::ostream &ost) const
std::list< std::unique_ptr< PKG_OUTLINE > > m_pkgOutlines
Definition: odb_eda_data.h:238
PIN(const size_t aIndex, const wxString &aName)
Definition: odb_eda_data.h:177
std::list< std::unique_ptr< PKG_OUTLINE > > m_pinOutlines
Definition: odb_eda_data.h:215
const size_t m_index
Definition: odb_eda_data.h:179
std::pair< wxString, wxString > m_center
Definition: odb_eda_data.h:182
void Write(std::ostream &ost) const
wxString m_name
Definition: odb_eda_data.h:180
ELECTRICAL_TYPE etype
Definition: odb_eda_data.h:200
MOUNT_TYPE mtype
Definition: odb_eda_data.h:213
void WriteSubnet(std::ostream &ost) const override
SUB_NET_PLANE(size_t aIndex, EDA_DATA *aEda, FILL_TYPE aFill, CUTOUT_TYPE aCutout, size_t aFillSize)
Definition: odb_eda_data.h:111
void WriteSubnet(std::ostream &ost) const override
SUB_NET_TOEPRINT(size_t aIndex, EDA_DATA *aEda, SIDE aSide, size_t aCompNum, size_t aToepNum)
Definition: odb_eda_data.h:134
SUB_NET_TRACE(size_t aIndex, EDA_DATA *aEda)
Definition: odb_eda_data.h:90
void WriteSubnet(std::ostream &ost) const override
SUB_NET_VIA(size_t aIndex, EDA_DATA *aEda)
Definition: odb_eda_data.h:83
void WriteSubnet(std::ostream &ost) const override
std::list< FEATURE_ID > feature_ids
Definition: odb_eda_data.h:70
EDA_DATA * m_edadata
Definition: odb_eda_data.h:77
void Write(std::ostream &ost) const
virtual ~SUB_NET()
Definition: odb_eda_data.h:73
const size_t m_index
Definition: odb_eda_data.h:67
void AddFeatureID(FEATURE_ID::TYPE type, const wxString &layer, size_t feature_id)
SUB_NET(size_t aIndex, EDA_DATA *aEda)
Definition: odb_eda_data.h:66
virtual void WriteSubnet(std::ostream &ost) const =0
std::list< const PACKAGE * > packages
Definition: odb_eda_data.h:260
std::map< wxString, size_t > layers_map
Definition: odb_eda_data.h:262
std::list< const NET * > nets
Definition: odb_eda_data.h:257
std::map< size_t, NET > nets_map
Definition: odb_eda_data.h:256
NET & GetNet(size_t aNetcode)
Definition: odb_eda_data.h:172
std::vector< wxString > layers
Definition: odb_eda_data.h:263
const PACKAGE & GetPackage(size_t aHash) const
Definition: odb_eda_data.h:253
std::map< size_t, PACKAGE > packages_map
Definition: odb_eda_data.h:259
void AddNET(const NETINFO_ITEM *aNet)
std::vector< std::shared_ptr< FOOTPRINT > > m_eda_footprints
Definition: odb_eda_data.h:264
size_t GetLyrIdx(const wxString &aLayerName)
void AddPackage(const FOOTPRINT *aFp)
void Write(std::ostream &ost) const
std::vector< std::shared_ptr< FOOTPRINT > > GetEdaFootprints() const
Definition: odb_eda_data.h:40
Handle the data for a net.
Definition: netinfo.h:56
void Write(std::ostream &ost) const override
OUTLINE_CIRCLE(const VECTOR2I &aCenter, size_t aRadius)
Definition: odb_eda_data.h:333
VECTOR2I m_center
Definition: odb_eda_data.h:337
void Write(std::ostream &ost) const override
std::unique_ptr< ODB_SURFACE_DATA > m_surfaces
Definition: odb_eda_data.h:312
OUTLINE_CONTOUR(const SHAPE_POLY_SET::POLYGON &aPolygon, FILL_T aFillType=FILL_T::FILLED_SHAPE)
Definition: odb_eda_data.h:299
VECTOR2I m_lower_left
Definition: odb_eda_data.h:288
size_t m_width
Definition: odb_eda_data.h:289
OUTLINE_RECT(const BOX2I &aBox)
Definition: odb_eda_data.h:283
size_t m_height
Definition: odb_eda_data.h:290
OUTLINE_RECT(const VECTOR2I &aLowerLeft, size_t aWidth, size_t aHeight)
Definition: odb_eda_data.h:278
void Write(std::ostream &ost) const override
OUTLINE_SQUARE(const VECTOR2I &aCenter, size_t aHalfSide)
Definition: odb_eda_data.h:320
VECTOR2I m_center
Definition: odb_eda_data.h:324
void Write(std::ostream &ost) const override
Definition: pad.h:54
virtual void Write(std::ostream &ost) const =0
virtual ~PKG_OUTLINE()=default
std::vector< SHAPE_LINE_CHAIN > POLYGON
represents a single polygon outline with holes.
FILL_T
Definition: eda_shape.h:55