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 The 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
18 * along with this program. If not, see <https://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#include <set>
28
29#include "odb_attribute.h"
30#include "odb_feature.h"
31
32
33class PAD;
34class PKG_OUTLINE;
35class PCB_IO_ODBPP;
36
37class EDA_DATA : public ATTR_MANAGER
38{
39public:
40 EDA_DATA();
41
42 void Write( std::ostream& ost, const ODB_FORMAT& aFormat ) const;
43 void WriteShortf( std::ostream& ost, const ODB_FORMAT& aFormat ) const;
44 size_t GetLyrIdx( const wxString& aLayerName );
45 void AssignNetUids( PCB_IO_ODBPP& aPlugin );
46 bool AddShort( const std::set<int>& aNetCodes, const wxString& aLayer,
47 size_t aFeatureIndex, uint32_t aUid );
48 bool HasShorts() const { return !m_shorts.empty(); }
49 std::vector<std::shared_ptr<FOOTPRINT>> GetEdaFootprints() const { return m_eda_footprints; }
50
52 {
53 friend EDA_DATA;
54
55 public:
56 enum class TYPE
57 {
61 };
62
63 FEATURE_ID( TYPE t, size_t l, size_t fid ) : type( t ), layer( l ), feature_id( fid ) {}
64
66 size_t layer;
67 size_t feature_id;
68
69 void Write( std::ostream& ost ) const;
70 };
71
72 class SUB_NET
73 {
74 public:
75 SUB_NET( size_t aIndex, EDA_DATA* aEda ) : m_index( aIndex ), m_edadata( aEda ) {}
76 const size_t m_index;
77 void Write( std::ostream& ost ) const;
78
79 std::list<FEATURE_ID> feature_ids;
80 void AddFeatureID( FEATURE_ID::TYPE type, const wxString& layer, size_t feature_id );
81
82 virtual ~SUB_NET() {}
83
84 protected:
85 virtual void WriteSubnet( std::ostream& ost ) const = 0;
87 };
88
89 class SUB_NET_VIA : public SUB_NET
90 {
91 public:
92 SUB_NET_VIA( size_t aIndex, EDA_DATA* aEda ) : SUB_NET( aIndex, aEda ) {}
93 void WriteSubnet( std::ostream& ost ) const override;
94 };
95
96 class SUB_NET_TRACE : public SUB_NET
97 {
98 public:
99 SUB_NET_TRACE( size_t aIndex, EDA_DATA* aEda ) : SUB_NET( aIndex, aEda ) {}
100 void WriteSubnet( std::ostream& ost ) const override;
101 };
102
103 class SUB_NET_PLANE : public SUB_NET
104 {
105 public:
106 enum class FILL_TYPE
107 {
110 };
111
119
120 SUB_NET_PLANE( size_t aIndex, EDA_DATA* aEda, FILL_TYPE aFill, CUTOUT_TYPE aCutout,
121 size_t aFillSize ) :
122 SUB_NET( aIndex, aEda ), fill_type( aFill ), cutout_type( aCutout ),
123 fill_size( aFillSize )
124 {
125 }
126
129 size_t fill_size;
130
131 void WriteSubnet( std::ostream& ost ) const override;
132 };
133
135 {
136 public:
137 enum class SIDE
138 {
141 };
142
143 SUB_NET_TOEPRINT( size_t aIndex, EDA_DATA* aEda, SIDE aSide, size_t aCompNum,
144 size_t aToepNum ) :
145 SUB_NET( aIndex, aEda ), side( aSide ), comp_num( aCompNum ), toep_num( aToepNum )
146 {
147 }
148
150
152
153 size_t comp_num;
154 size_t toep_num;
155
156 void WriteSubnet( std::ostream& ost ) const override;
157 };
158
159 class NET : public ATTR_RECORD_WRITER
160 {
161 public:
162 NET( size_t aIndex, const wxString& aName ) : m_index( aIndex ), m_name( aName ) {}
163
164 const size_t m_index;
165 wxString m_name;
166 uint32_t m_uid = 0;
167 std::list<std::unique_ptr<SUB_NET>> subnets;
168
169 template <typename T, typename... Args>
170 T& AddSubnet( Args&&... args )
171 {
172 auto f = std::make_unique<T>( subnets.size(), std::forward<Args>( args )... );
173 auto& r = *f;
174 subnets.push_back( std::move( f ) );
175 return r;
176 }
177
178 void Write( std::ostream& ost, bool aIncludeComponents ) const;
179 };
180
181 void AddNET( const NETINFO_ITEM* aNet, const wxString& aName );
182 NET& GetNet( size_t aNetcode ) { return nets_map.at( aNetcode ); }
183
184 class PIN
185 {
186 public:
187 PIN( const size_t aIndex, const wxString& aName ) : m_index( aIndex ), m_name( aName ) {}
188
189 const size_t m_index;
190 wxString m_name;
191
192 std::pair<wxString, wxString> m_center;
193
194 enum class TYPE
195 {
199 };
200
201 TYPE type = TYPE::SURFACE;
202
209
211
224
225 std::list<std::unique_ptr<PKG_OUTLINE>> m_pinOutlines;
226
227 void Write( std::ostream& ost, const ODB_FORMAT& aFormat ) const;
228 };
229
231 {
232 public:
233 PACKAGE( const size_t aIndex, const wxString& afpName ) :
234 m_index( aIndex ), m_name( afpName ),
235 m_pitch( 0 ),
236 m_xmin( 0 ), m_ymin( 0 ),
237 m_xmax( 0 ), m_ymax( 0 )
238
239 {
240 }
241
242 const size_t m_index;
243 wxString m_name;
244
245 uint64_t m_pitch;
246 int64_t m_xmin, m_ymin, m_xmax, m_ymax; // Box points: leftlow, rightup
247
248 std::list<std::unique_ptr<PKG_OUTLINE>> m_pkgOutlines;
249
250 void AddPin( const PAD* aPad, size_t aPinNum, const ODB_FORMAT& aFormat );
251 const std::shared_ptr<PIN> GetEdaPkgPin( size_t aPadIndex ) const
252 {
253 return m_pinsVec.at( aPadIndex );
254 }
255
256 void Write( std::ostream& ost, const ODB_FORMAT& aFormat ) const;
257
258 private:
259 std::vector<std::shared_ptr<PIN>> m_pinsVec;
260 };
261
262 void AddPackage( const FOOTPRINT* aFp, const ODB_FORMAT& aFormat );
263 const PACKAGE& GetPackage( size_t aHash ) const { return packages_map.at( aHash ); }
264
265private:
267 {
268 std::set<uint32_t> m_netUids;
271 uint32_t m_uid;
272 };
273
274 std::map<size_t, NET> nets_map;
275 std::list<NET*> nets;
276 std::vector<SHORT_NET> m_shorts;
277
278 std::map<size_t, PACKAGE> packages_map; //hash value, package
279 std::list<const PACKAGE*> packages;
280
281 std::map<wxString, size_t> layers_map;
282 std::vector<wxString> layers;
283 std::vector<std::shared_ptr<FOOTPRINT>> m_eda_footprints;
284};
285
287{
288public:
289 virtual void Write( std::ostream& ost, const ODB_FORMAT& aFormat ) const = 0;
290
291 virtual ~PKG_OUTLINE() = default;
292};
293
295{
296public:
297 OUTLINE_RECT( const VECTOR2I& aLowerLeft, size_t aWidth, size_t aHeight ) :
298 m_lower_left( aLowerLeft ), m_width( aWidth ), m_height( aHeight )
299 {
300 }
301
302 OUTLINE_RECT( const BOX2I& aBox ) :
303 OUTLINE_RECT( aBox.GetPosition(), aBox.GetWidth(), aBox.GetHeight() )
304 {
305 }
306
308 size_t m_width;
309 size_t m_height;
310
311 void Write( std::ostream& ost, const ODB_FORMAT& aFormat ) const override;
312};
313
314class ODB_SURFACE_DATA;
316{
317public:
319 FILL_T aFillType = FILL_T::FILLED_SHAPE )
320 {
321 if( !aPolygon.empty() && aPolygon[0].PointCount() >= 3 )
322 {
323 m_surfaces = std::make_unique<ODB_SURFACE_DATA>( aPolygon );
324 if( aFillType != FILL_T::NO_FILL )
325 {
326 m_surfaces->AddPolygonHoles( aPolygon );
327 }
328 }
329 }
330
331 std::unique_ptr<ODB_SURFACE_DATA> m_surfaces;
332
333 void Write( std::ostream& ost, const ODB_FORMAT& aFormat ) const override;
334};
335
337{
338public:
339 OUTLINE_SQUARE( const VECTOR2I& aCenter, size_t aHalfSide ) :
340 m_center( aCenter ), m_halfSide( aHalfSide )
341 {
342 }
345
346 void Write( std::ostream& ost, const ODB_FORMAT& aFormat ) const override;
347};
348
350{
351public:
352 OUTLINE_CIRCLE( const VECTOR2I& aCenter, size_t aRadius ) :
353 m_center( aCenter ), m_radius( aRadius )
354 {
355 }
357 size_t m_radius;
358
359 void Write( std::ostream& ost, const ODB_FORMAT& aFormat ) const override;
360};
361
362
363#endif // _ODB_EDA_DATA_H_
BOX2< VECTOR2I > BOX2I
Definition box2.h:914
ATTR_MANAGER()=default
ATTR_RECORD_WRITER()=default
FEATURE_ID(TYPE t, size_t l, size_t fid)
void Write(std::ostream &ost) const
T & AddSubnet(Args &&... args)
const size_t m_index
std::list< std::unique_ptr< SUB_NET > > subnets
void Write(std::ostream &ost, bool aIncludeComponents) const
wxString m_name
NET(size_t aIndex, const wxString &aName)
PACKAGE(const size_t aIndex, const wxString &afpName)
void AddPin(const PAD *aPad, size_t aPinNum, const ODB_FORMAT &aFormat)
std::vector< std::shared_ptr< PIN > > m_pinsVec
void Write(std::ostream &ost, const ODB_FORMAT &aFormat) const
const std::shared_ptr< PIN > GetEdaPkgPin(size_t aPadIndex) const
const size_t m_index
wxString m_name
<! Reference number of the package to be used in CMP.
std::list< std::unique_ptr< PKG_OUTLINE > > m_pkgOutlines
PIN(const size_t aIndex, const wxString &aName)
std::list< std::unique_ptr< PKG_OUTLINE > > m_pinOutlines
const size_t m_index
void Write(std::ostream &ost, const ODB_FORMAT &aFormat) const
std::pair< wxString, wxString > m_center
wxString m_name
ELECTRICAL_TYPE etype
MOUNT_TYPE mtype
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)
void WriteSubnet(std::ostream &ost) const override
SUB_NET_TOEPRINT(size_t aIndex, EDA_DATA *aEda, SIDE aSide, size_t aCompNum, size_t aToepNum)
SUB_NET_TRACE(size_t aIndex, EDA_DATA *aEda)
void WriteSubnet(std::ostream &ost) const override
SUB_NET_VIA(size_t aIndex, EDA_DATA *aEda)
void WriteSubnet(std::ostream &ost) const override
std::list< FEATURE_ID > feature_ids
EDA_DATA * m_edadata
void Write(std::ostream &ost) const
const size_t m_index
void AddFeatureID(FEATURE_ID::TYPE type, const wxString &layer, size_t feature_id)
SUB_NET(size_t aIndex, EDA_DATA *aEda)
virtual void WriteSubnet(std::ostream &ost) const =0
bool AddShort(const std::set< int > &aNetCodes, const wxString &aLayer, size_t aFeatureIndex, uint32_t aUid)
std::list< const PACKAGE * > packages
std::list< NET * > nets
std::map< wxString, size_t > layers_map
std::map< size_t, NET > nets_map
void AssignNetUids(PCB_IO_ODBPP &aPlugin)
NET & GetNet(size_t aNetcode)
std::vector< wxString > layers
bool HasShorts() const
void WriteShortf(std::ostream &ost, const ODB_FORMAT &aFormat) const
void AddPackage(const FOOTPRINT *aFp, const ODB_FORMAT &aFormat)
const PACKAGE & GetPackage(size_t aHash) const
void Write(std::ostream &ost, const ODB_FORMAT &aFormat) const
std::map< size_t, PACKAGE > packages_map
std::vector< SHORT_NET > m_shorts
void AddNET(const NETINFO_ITEM *aNet, const wxString &aName)
std::vector< std::shared_ptr< FOOTPRINT > > m_eda_footprints
size_t GetLyrIdx(const wxString &aLayerName)
std::vector< std::shared_ptr< FOOTPRINT > > GetEdaFootprints() const
Handle the data for a net.
Definition netinfo.h:50
void Write(std::ostream &ost, const ODB_FORMAT &aFormat) const override
OUTLINE_CIRCLE(const VECTOR2I &aCenter, size_t aRadius)
VECTOR2I m_center
void Write(std::ostream &ost, const ODB_FORMAT &aFormat) const override
std::unique_ptr< ODB_SURFACE_DATA > m_surfaces
OUTLINE_CONTOUR(const SHAPE_POLY_SET::POLYGON &aPolygon, FILL_T aFillType=FILL_T::FILLED_SHAPE)
VECTOR2I m_lower_left
OUTLINE_RECT(const BOX2I &aBox)
void Write(std::ostream &ost, const ODB_FORMAT &aFormat) const override
OUTLINE_RECT(const VECTOR2I &aLowerLeft, size_t aWidth, size_t aHeight)
OUTLINE_SQUARE(const VECTOR2I &aCenter, size_t aHalfSide)
VECTOR2I m_center
void Write(std::ostream &ost, const ODB_FORMAT &aFormat) const override
Definition pad.h:61
virtual ~PKG_OUTLINE()=default
virtual void Write(std::ostream &ost, const ODB_FORMAT &aFormat) const =0
std::vector< SHAPE_LINE_CHAIN > POLYGON
represents a single polygon outline with holes.
FILL_T
Definition eda_fill.h:29
@ NO_FILL
Definition eda_fill.h:30
@ FILLED_SHAPE
Fill with object color.
Definition eda_fill.h:31
std::set< uint32_t > m_netUids
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708