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