KiCad PCB EDA Suite
Loading...
Searching...
No Matches
odb_feature.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 along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21
22#ifndef _ODB_FEATURE_H_
23#define _ODB_FEATURE_H_
24
25#include "odb_attribute.h"
27
28#include <list>
29#include "math/vector2d.h"
30#include "odb_defines.h"
31
32
33enum class ODB_DIRECTION
34{
37};
38
39
40class ODB_LINE;
41class ODB_ARC;
42class ODB_PAD;
43class ODB_SURFACE;
44class ODB_FEATURE;
45class PCB_IO_ODBPP;
46class FOOTPRINT;
47class PAD;
48class PCB_VIA;
49
51{
52public:
53 FEATURES_MANAGER( BOARD* aBoard, PCB_IO_ODBPP* aPlugin, const wxString& aLayerName ) :
54 m_board( aBoard ), m_plugin( aPlugin ), m_layerName( aLayerName )
55 {
56 }
57
58 virtual ~FEATURES_MANAGER() { m_featuresList.clear(); }
59
60 void InitFeatureList( PCB_LAYER_ID aLayer, std::vector<BOARD_ITEM*>& aItems );
61
62 void AddFeatureLine( const VECTOR2I& aStart, const VECTOR2I& aEnd, uint64_t aWidth );
63
64 void AddFeatureArc( const VECTOR2I& aStart, const VECTOR2I& aEnd, const VECTOR2I& aCenter,
65 uint64_t aWidth, ODB_DIRECTION aDirection );
66
67 void AddPadCircle( const VECTOR2I& aCenter, uint64_t aDiameter, const EDA_ANGLE& aAngle,
68 bool aMirror, double aResize = 1.0 );
69
70 void AddPadShape( const PAD& aPad, PCB_LAYER_ID aLayer );
71
72 void AddFeatureSurface( const SHAPE_POLY_SET::POLYGON& aPolygon,
73 FILL_T aFillType = FILL_T::FILLED_SHAPE );
74
75 void AddShape( const PCB_SHAPE& aShape, PCB_LAYER_ID aLayer = UNDEFINED_LAYER );
76
77 void AddVia( const PCB_VIA* aVia, PCB_LAYER_ID aLayer );
78
79 void AddViaDrillHole( const PCB_VIA* aVia, PCB_LAYER_ID aLayer );
80
81 void AddViaProtection( const PCB_VIA* aVia, bool drill, PCB_LAYER_ID aLayer );
82
83 bool AddContour( const SHAPE_POLY_SET& aPolySet, int aOutline = 0,
84 FILL_T aFillType = FILL_T::FILLED_SHAPE );
85
86 bool AddPolygon( const SHAPE_POLY_SET::POLYGON& aPolygon, FILL_T aFillType, int aWidth,
87 LINE_STYLE aDashType );
88
90
91 void GenerateFeatureFile( std::ostream& ost ) const;
92
93 void GenerateProfileFeatures( std::ostream& ost ) const;
94
95private:
96 inline uint32_t AddCircleSymbol( const wxString& aDiameter )
97 {
98 return GetSymbolIndex( m_circleSymMap, "r" + aDiameter );
99 }
100
101 uint32_t AddRoundDonutSymbol( const wxString& aOuterDim, const wxString& aInnerDim )
102 {
103 wxString sym = "donut_r" + aOuterDim + ODB_DIM_X + aInnerDim;
104 return GetSymbolIndex( m_roundDonutSymMap, sym );
105 }
106
107 uint32_t AddRectSymbol( const wxString& aWidth, const wxString& aHeight )
108 {
109 wxString sym = "rect" + aWidth + ODB_DIM_X + aHeight;
110 return GetSymbolIndex( m_rectSymMap, sym );
111 }
112
113 uint32_t AddOvalSymbol( const wxString& aWidth, const wxString& aHeight )
114 {
115 wxString sym = "oval" + aWidth + ODB_DIM_X + aHeight;
116 return GetSymbolIndex( m_ovalSymMap, sym );
117 }
118
119 uint32_t AddRoundRectSymbol( const wxString& aWidth, const wxString& aHeight,
120 const wxString& aRadius )
121 {
122 wxString sym = "rect" + aWidth + ODB_DIM_X + aHeight + ODB_DIM_X + ODB_DIM_R + aRadius;
123 return GetSymbolIndex( m_roundRectSymMap, sym );
124 }
125
126 uint32_t AddRoundRectDonutSymbol( const wxString& aOuterWidth, const wxString& aOuterHeight,
127 const wxString& aLineWidth, const wxString& aRadius )
128 {
129 wxString sym = "donut_rc" + aOuterWidth + ODB_DIM_X + aOuterHeight + ODB_DIM_X + aLineWidth
130 + ODB_DIM_X + ODB_DIM_R + aRadius;
132 }
133
134 uint32_t AddChamferRectSymbol( const wxString& aWidth, const wxString& aHeight,
135 const wxString& aRadius, int aPositions )
136 {
137 wxString sym = "rect" + aWidth + ODB_DIM_X + aHeight + ODB_DIM_X + ODB_DIM_C + aRadius;
138
139 if( aPositions != RECT_CHAMFER_ALL )
140 {
141 sym += ODB_DIM_X;
142 if( aPositions & RECT_CHAMFER_TOP_RIGHT )
143 sym += "1";
144 if( aPositions & RECT_CHAMFER_TOP_LEFT )
145 sym += "2";
146 if( aPositions & RECT_CHAMFER_BOTTOM_LEFT )
147 sym += "3";
148 if( aPositions & RECT_CHAMFER_BOTTOM_RIGHT )
149 sym += "4";
150 }
151
152 return GetSymbolIndex( m_chamRectSymMap, sym );
153 }
154
155
156 uint32_t GetSymbolIndex( std::map<wxString, uint32_t>& aSymMap, const wxString& aKey )
157 {
158 if( aSymMap.count( aKey ) )
159 {
160 return aSymMap.at( aKey );
161 }
162 else
163 {
164 uint32_t index = m_symIndex;
165 m_symIndex++;
166 aSymMap.emplace( aKey, index );
167 m_allSymMap.emplace( index, aKey );
168 return index;
169 }
170 }
171
172 std::map<wxString, uint32_t> m_circleSymMap; // diameter -> symbol index
173 std::map<wxString, uint32_t> m_roundDonutSymMap;
174 std::map<wxString, uint32_t> m_padSymMap; // name -> symbol index
175 std::map<wxString, uint32_t> m_rectSymMap; // w,h -> symbol index
176 std::map<wxString, uint32_t> m_ovalSymMap; // w,h -> symbol index
177 std::map<wxString, uint32_t> m_roundRectSymMap;
178 std::map<wxString, uint32_t> m_roundRectDonutSymMap;
179 std::map<wxString, uint32_t> m_chamRectSymMap;
180
181 std::map<uint32_t, wxString> m_allSymMap;
182
183 template <typename T, typename... Args>
184 void AddFeature( Args&&... args )
185 {
186 auto feature = std::make_unique<T>( m_featuresList.size(), std::forward<Args>( args )... );
187
188 m_featuresList.emplace_back( std::move( feature ) );
189 }
190
191 inline PCB_IO_ODBPP* GetODBPlugin() { return m_plugin; }
192
195 wxString m_layerName;
196 uint32_t m_symIndex = 0;
197
198 std::list<std::unique_ptr<ODB_FEATURE>> m_featuresList;
199 std::map<BOARD_ITEM*, std::vector<uint32_t>> m_featureIDMap;
200};
201
202
204{
205public:
206 // template <typename T> using check_type = attribute::is_feature<T>;
207 ODB_FEATURE( uint32_t aIndex ) : m_index( aIndex ) {}
208 virtual void WriteFeatures( std::ostream& ost );
209
210 virtual ~ODB_FEATURE() = default;
211
212protected:
213 enum class FEATURE_TYPE
214 {
219 };
220
222
223 virtual void WriteRecordContent( std::ostream& ost ) = 0;
224
225 const uint32_t m_index;
226};
227
228class ODB_LINE : public ODB_FEATURE
229{
230public:
231 ODB_LINE( uint32_t aIndex, const std::pair<wxString, wxString>& aStart,
232 const std::pair<wxString, wxString>& aEnd, uint32_t aSym ) :
233 ODB_FEATURE( aIndex ), m_start( aStart ), m_end( aEnd ), m_symIndex( aSym )
234 {
235 }
236
237 inline virtual FEATURE_TYPE GetFeatureType() override { return FEATURE_TYPE::LINE; }
238
239protected:
240 virtual void WriteRecordContent( std::ostream& ost ) override;
241
242private:
243 std::pair<wxString, wxString> m_start;
244 std::pair<wxString, wxString> m_end;
245 uint32_t m_symIndex;
246};
247
248
249class ODB_ARC : public ODB_FEATURE
250{
251public:
252 inline virtual FEATURE_TYPE GetFeatureType() override { return FEATURE_TYPE::ARC; }
253
254
255 ODB_ARC( uint32_t aIndex, const std::pair<wxString, wxString>& aStart,
256 const std::pair<wxString, wxString>& aEnd,
257 const std::pair<wxString, wxString>& aCenter, uint32_t aSym,
258 ODB_DIRECTION aDirection ) :
259 ODB_FEATURE( aIndex ), m_start( aStart ), m_end( aEnd ), m_center( aCenter ),
260 m_symIndex( aSym ), m_direction( aDirection )
261 {
262 }
263
264protected:
265 virtual void WriteRecordContent( std::ostream& ost ) override;
266
267private:
268 std::pair<wxString, wxString> m_start;
269 std::pair<wxString, wxString> m_end;
270 std::pair<wxString, wxString> m_center;
271 uint32_t m_symIndex;
273};
274
275class ODB_PAD : public ODB_FEATURE
276{
277public:
278 ODB_PAD( uint32_t aIndex, const std::pair<wxString, wxString>& aCenter, uint32_t aSym,
279 EDA_ANGLE aAngle = ANGLE_0, bool aMirror = false, double aResize = 1.0 ) :
280 ODB_FEATURE( aIndex ), m_center( aCenter ), m_symIndex( aSym ), m_angle( aAngle ),
281 m_mirror( aMirror ), m_resize( aResize )
282 {
283 }
284
285 inline virtual FEATURE_TYPE GetFeatureType() override { return FEATURE_TYPE::PAD; }
286
287protected:
288 virtual void WriteRecordContent( std::ostream& ost ) override;
289
290private:
291 std::pair<wxString, wxString> m_center;
292 uint32_t m_symIndex;
295 double m_resize;
296};
297
298class ODB_SURFACE_DATA;
300{
301public:
302 ODB_SURFACE( uint32_t aIndex, const SHAPE_POLY_SET::POLYGON& aPolygon,
303 FILL_T aFillType = FILL_T::FILLED_SHAPE );
304
305 virtual ~ODB_SURFACE() = default;
306
307 inline virtual FEATURE_TYPE GetFeatureType() override { return FEATURE_TYPE::SURFACE; }
308
309 std::unique_ptr<ODB_SURFACE_DATA> m_surfaces;
310
311protected:
312 virtual void WriteRecordContent( std::ostream& ost ) override;
313};
314
315
317{
318public:
319 ODB_SURFACE_DATA( const SHAPE_POLY_SET::POLYGON& aPolygon );
320
322 {
323 enum class LINE_TYPE
324 {
327 };
328 SURFACE_LINE() = default;
329
330 SURFACE_LINE( const VECTOR2I& aEnd ) : m_end( aEnd ) {}
331
332 SURFACE_LINE( const VECTOR2I& aEnd, const VECTOR2I& aCenter, ODB_DIRECTION aDirection ) :
333 m_end( aEnd ), m_type( LINE_TYPE::ARC ), m_center( aCenter ),
334 m_direction( aDirection )
335 {
336 }
337
340
343 };
344
345 void AddPolygonHoles( const SHAPE_POLY_SET::POLYGON& aPolygon );
346 void WriteData( std::ostream& ost ) const;
347
348 std::vector<std::vector<SURFACE_LINE>> m_polygons;
349};
350
351
352#endif // _ODB_FEATURE_H_
int index
ATTR_MANAGER()=default
ATTR_RECORD_WRITER()=default
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:322
void AddPadShape(const PAD &aPad, PCB_LAYER_ID aLayer)
uint32_t AddRoundRectDonutSymbol(const wxString &aOuterWidth, const wxString &aOuterHeight, const wxString &aLineWidth, const wxString &aRadius)
std::map< wxString, uint32_t > m_circleSymMap
uint32_t m_symIndex
void AddShape(const PCB_SHAPE &aShape, PCB_LAYER_ID aLayer=UNDEFINED_LAYER)
uint32_t AddRectSymbol(const wxString &aWidth, const wxString &aHeight)
std::map< wxString, uint32_t > m_chamRectSymMap
void AddVia(const PCB_VIA *aVia, PCB_LAYER_ID aLayer)
std::map< wxString, uint32_t > m_rectSymMap
PCB_IO_ODBPP * GetODBPlugin()
void InitFeatureList(PCB_LAYER_ID aLayer, std::vector< BOARD_ITEM * > &aItems)
void AddFeatureLine(const VECTOR2I &aStart, const VECTOR2I &aEnd, uint64_t aWidth)
PCB_IO_ODBPP * m_plugin
void AddViaProtection(const PCB_VIA *aVia, bool drill, PCB_LAYER_ID aLayer)
void AddFeatureArc(const VECTOR2I &aStart, const VECTOR2I &aEnd, const VECTOR2I &aCenter, uint64_t aWidth, ODB_DIRECTION aDirection)
uint32_t GetSymbolIndex(std::map< wxString, uint32_t > &aSymMap, const wxString &aKey)
std::map< uint32_t, wxString > m_allSymMap
bool AddPolygon(const SHAPE_POLY_SET::POLYGON &aPolygon, FILL_T aFillType, int aWidth, LINE_STYLE aDashType)
void GenerateFeatureFile(std::ostream &ost) const
std::map< BOARD_ITEM *, std::vector< uint32_t > > m_featureIDMap
void AddViaDrillHole(const PCB_VIA *aVia, PCB_LAYER_ID aLayer)
std::map< wxString, uint32_t > m_roundRectDonutSymMap
FEATURES_MANAGER(BOARD *aBoard, PCB_IO_ODBPP *aPlugin, const wxString &aLayerName)
Definition odb_feature.h:53
std::map< wxString, uint32_t > m_ovalSymMap
void AddPadCircle(const VECTOR2I &aCenter, uint64_t aDiameter, const EDA_ANGLE &aAngle, bool aMirror, double aResize=1.0)
std::map< wxString, uint32_t > m_roundDonutSymMap
std::map< wxString, uint32_t > m_roundRectSymMap
void AddFeatureSurface(const SHAPE_POLY_SET::POLYGON &aPolygon, FILL_T aFillType=FILL_T::FILLED_SHAPE)
uint32_t AddRoundRectSymbol(const wxString &aWidth, const wxString &aHeight, const wxString &aRadius)
wxString m_layerName
uint32_t AddOvalSymbol(const wxString &aWidth, const wxString &aHeight)
void GenerateProfileFeatures(std::ostream &ost) const
std::list< std::unique_ptr< ODB_FEATURE > > m_featuresList
void AddFeature(Args &&... args)
bool AddPolygonCutouts(const SHAPE_POLY_SET::POLYGON &aPolygon)
virtual ~FEATURES_MANAGER()
Definition odb_feature.h:58
uint32_t AddCircleSymbol(const wxString &aDiameter)
Definition odb_feature.h:96
uint32_t AddChamferRectSymbol(const wxString &aWidth, const wxString &aHeight, const wxString &aRadius, int aPositions)
std::map< wxString, uint32_t > m_padSymMap
uint32_t AddRoundDonutSymbol(const wxString &aOuterDim, const wxString &aInnerDim)
bool AddContour(const SHAPE_POLY_SET &aPolySet, int aOutline=0, FILL_T aFillType=FILL_T::FILLED_SHAPE)
std::pair< wxString, wxString > m_end
std::pair< wxString, wxString > m_start
ODB_ARC(uint32_t aIndex, const std::pair< wxString, wxString > &aStart, const std::pair< wxString, wxString > &aEnd, const std::pair< wxString, wxString > &aCenter, uint32_t aSym, ODB_DIRECTION aDirection)
uint32_t m_symIndex
virtual void WriteRecordContent(std::ostream &ost) override
virtual FEATURE_TYPE GetFeatureType() override
ODB_DIRECTION m_direction
std::pair< wxString, wxString > m_center
virtual void WriteRecordContent(std::ostream &ost)=0
virtual ~ODB_FEATURE()=default
virtual void WriteFeatures(std::ostream &ost)
virtual FEATURE_TYPE GetFeatureType()=0
const uint32_t m_index
ODB_FEATURE(uint32_t aIndex)
virtual void WriteRecordContent(std::ostream &ost) override
ODB_LINE(uint32_t aIndex, const std::pair< wxString, wxString > &aStart, const std::pair< wxString, wxString > &aEnd, uint32_t aSym)
virtual FEATURE_TYPE GetFeatureType() override
std::pair< wxString, wxString > m_start
std::pair< wxString, wxString > m_end
uint32_t m_symIndex
ODB_PAD(uint32_t aIndex, const std::pair< wxString, wxString > &aCenter, uint32_t aSym, EDA_ANGLE aAngle=ANGLE_0, bool aMirror=false, double aResize=1.0)
uint32_t m_symIndex
virtual void WriteRecordContent(std::ostream &ost) override
virtual FEATURE_TYPE GetFeatureType() override
double m_resize
bool m_mirror
EDA_ANGLE m_angle
std::pair< wxString, wxString > m_center
void WriteData(std::ostream &ost) const
std::vector< std::vector< SURFACE_LINE > > m_polygons
ODB_SURFACE_DATA(const SHAPE_POLY_SET::POLYGON &aPolygon)
void AddPolygonHoles(const SHAPE_POLY_SET::POLYGON &aPolygon)
std::unique_ptr< ODB_SURFACE_DATA > m_surfaces
virtual void WriteRecordContent(std::ostream &ost) override
virtual FEATURE_TYPE GetFeatureType() override
virtual ~ODB_SURFACE()=default
ODB_SURFACE(uint32_t aIndex, const SHAPE_POLY_SET::POLYGON &aPolygon, FILL_T aFillType=FILL_T::FILLED_SHAPE)
Definition pad.h:55
Represent a set of closed polygons.
std::vector< SHAPE_LINE_CHAIN > POLYGON
represents a single polygon outline with holes.
static constexpr EDA_ANGLE ANGLE_0
Definition eda_angle.h:411
FILL_T
Definition eda_shape.h:56
@ FILLED_SHAPE
Fill with object color.
Definition eda_shape.h:58
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:60
@ UNDEFINED_LAYER
Definition layer_ids.h:61
#define ODB_DIM_R
Definition odb_defines.h:30
#define ODB_DIM_C
Definition odb_defines.h:31
#define ODB_DIM_X
Definition odb_defines.h:29
ODB_DIRECTION
Definition odb_feature.h:34
LINE_STYLE
Dashed line types.
SURFACE_LINE(const VECTOR2I &aEnd)
SURFACE_LINE(const VECTOR2I &aEnd, const VECTOR2I &aCenter, ODB_DIRECTION aDirection)
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695