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
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21
22#pragma once
23
24#include "odb_attribute.h"
26
27#include <list>
28#include <math/vector2d.h>
29#include <common.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;
50class PCB_TRACK;
51
53{
54public:
55 FEATURES_MANAGER( BOARD* aBoard, PCB_IO_ODBPP* aPlugin, const wxString& aLayerName ) :
56 m_board( aBoard ),
57 m_plugin( aPlugin ),
58 m_layerName( aLayerName )
59 {}
60
61 virtual ~FEATURES_MANAGER() { m_featuresList.clear(); }
62
63 void AddPad( PCB_LAYER_ID aLayer, PAD* pad );
64 void AddDimension( PCB_LAYER_ID aLayer, PCB_DIMENSION_BASE* dimension );
65 void AddShape( PCB_LAYER_ID aLayer, PCB_SHAPE* shape );
66 void AddText( PCB_LAYER_ID aLayer, BOARD_ITEM* item, RESOLUTION_CONTEXT aContext );
67 void AddZone( PCB_LAYER_ID aLayer, ZONE* zone );
68 void AddTrack( PCB_LAYER_ID aLayer, PCB_TRACK* track );
69
70 void InitFeatureList( PCB_LAYER_ID aLayer, std::vector<BOARD_ITEM*>& aItems );
71
72 void AddFeatureLine( const VECTOR2I& aStart, const VECTOR2I& aEnd, uint64_t aWidth );
73
74 void AddFeatureArc( const VECTOR2I& aStart, const VECTOR2I& aEnd, const VECTOR2I& aCenter,
75 uint64_t aWidth, ODB_DIRECTION aDirection );
76
77 void AddPadCircle( const VECTOR2I& aCenter, uint64_t aDiameter, const EDA_ANGLE& aAngle,
78 bool aMirror, double aResize = 1.0 );
79
80 void AddPadShape( const PAD& aPad, PCB_LAYER_ID aLayer );
81
82 void AddFeatureSurface( const SHAPE_POLY_SET::POLYGON& aPolygon,
83 FILL_T aFillType = FILL_T::FILLED_SHAPE );
84
85 void AddShape( const PCB_SHAPE& aShape, PCB_LAYER_ID aLayer = UNDEFINED_LAYER );
86
87 void AddVia( const PCB_VIA* aVia, PCB_LAYER_ID aLayer );
88
89 void AddViaDrillHole( const PCB_VIA* aVia, PCB_LAYER_ID aLayer );
90
91 void AddViaProtection( const PCB_VIA* aVia, bool drill, PCB_LAYER_ID aLayer );
92
93 bool AddContour( const SHAPE_POLY_SET& aPolySet, int aOutline = 0,
94 FILL_T aFillType = FILL_T::FILLED_SHAPE );
95
96 bool AddPolygon( const SHAPE_POLY_SET::POLYGON& aPolygon, FILL_T aFillType, int aWidth,
97 LINE_STYLE aDashType );
98
100
101 void GenerateFeatureFile( std::ostream& ost ) const;
102
103 void GenerateProfileFeatures( std::ostream& ost ) const;
104
105private:
106 inline uint32_t AddCircleSymbol( const wxString& aDiameter )
107 {
108 return GetSymbolIndex( m_circleSymMap, "r" + aDiameter );
109 }
110
111 uint32_t AddRoundDonutSymbol( const wxString& aOuterDim, const wxString& aInnerDim )
112 {
113 wxString sym = "donut_r" + aOuterDim + ODB_DIM_X + aInnerDim;
114 return GetSymbolIndex( m_roundDonutSymMap, sym );
115 }
116
117 uint32_t AddRectSymbol( const wxString& aWidth, const wxString& aHeight )
118 {
119 wxString sym = "rect" + aWidth + ODB_DIM_X + aHeight;
120 return GetSymbolIndex( m_rectSymMap, sym );
121 }
122
123 uint32_t AddOvalSymbol( const wxString& aWidth, const wxString& aHeight )
124 {
125 wxString sym = "oval" + aWidth + ODB_DIM_X + aHeight;
126 return GetSymbolIndex( m_ovalSymMap, sym );
127 }
128
129 uint32_t AddRoundRectSymbol( const wxString& aWidth, const wxString& aHeight,
130 const wxString& aRadius )
131 {
132 wxString sym = "rect" + aWidth + ODB_DIM_X + aHeight + ODB_DIM_X + ODB_DIM_R + aRadius;
133 return GetSymbolIndex( m_roundRectSymMap, sym );
134 }
135
136 uint32_t AddRoundRectDonutSymbol( const wxString& aOuterWidth, const wxString& aOuterHeight,
137 const wxString& aLineWidth, const wxString& aRadius )
138 {
139 wxString sym = "donut_rc" + aOuterWidth + ODB_DIM_X + aOuterHeight + ODB_DIM_X + aLineWidth
140 + ODB_DIM_X + ODB_DIM_R + aRadius;
142 }
143
144 uint32_t AddChamferRectSymbol( const wxString& aWidth, const wxString& aHeight,
145 const wxString& aRadius, int aPositions )
146 {
147 wxString sym = "rect" + aWidth + ODB_DIM_X + aHeight + ODB_DIM_X + ODB_DIM_C + aRadius;
148
149 if( aPositions != RECT_CHAMFER_ALL )
150 {
151 sym += ODB_DIM_X;
152 if( aPositions & RECT_CHAMFER_TOP_RIGHT )
153 sym += "1";
154 if( aPositions & RECT_CHAMFER_TOP_LEFT )
155 sym += "2";
156 if( aPositions & RECT_CHAMFER_BOTTOM_LEFT )
157 sym += "3";
158 if( aPositions & RECT_CHAMFER_BOTTOM_RIGHT )
159 sym += "4";
160 }
161
162 return GetSymbolIndex( m_chamRectSymMap, sym );
163 }
164
165
166 uint32_t GetSymbolIndex( std::map<wxString, uint32_t>& aSymMap, const wxString& aKey )
167 {
168 if( aSymMap.count( aKey ) )
169 {
170 return aSymMap.at( aKey );
171 }
172 else
173 {
174 uint32_t index = m_symIndex;
175 m_symIndex++;
176 aSymMap.emplace( aKey, index );
177 m_allSymMap.emplace( index, aKey );
178 return index;
179 }
180 }
181
182 std::map<wxString, uint32_t> m_circleSymMap; // diameter -> symbol index
183 std::map<wxString, uint32_t> m_roundDonutSymMap;
184 std::map<wxString, uint32_t> m_padSymMap; // name -> symbol index
185 std::map<wxString, uint32_t> m_rectSymMap; // w,h -> symbol index
186 std::map<wxString, uint32_t> m_ovalSymMap; // w,h -> symbol index
187 std::map<wxString, uint32_t> m_roundRectSymMap;
188 std::map<wxString, uint32_t> m_roundRectDonutSymMap;
189 std::map<wxString, uint32_t> m_chamRectSymMap;
190
191 std::map<uint32_t, wxString> m_allSymMap;
192
193 template <typename T, typename... Args>
194 void AddFeature( Args&&... args )
195 {
196 auto feature = std::make_unique<T>( m_featuresList.size(), std::forward<Args>( args )... );
197
198 m_featuresList.emplace_back( std::move( feature ) );
199 }
200
201 inline PCB_IO_ODBPP* GetODBPlugin() { return m_plugin; }
202
205 wxString m_layerName;
206 uint32_t m_symIndex = 0;
207
208 std::list<std::unique_ptr<ODB_FEATURE>> m_featuresList;
209 std::map<BOARD_ITEM*, std::vector<uint32_t>> m_featureIDMap;
210};
211
212
214{
215public:
216 // template <typename T> using check_type = attribute::is_feature<T>;
217 ODB_FEATURE( uint32_t aIndex ) : m_index( aIndex ) {}
218 virtual void WriteFeatures( std::ostream& ost );
219
220 virtual ~ODB_FEATURE() = default;
221
222protected:
223 enum class FEATURE_TYPE
224 {
229 };
230
232
233 virtual void WriteRecordContent( std::ostream& ost ) = 0;
234
235 const uint32_t m_index;
236};
237
238class ODB_LINE : public ODB_FEATURE
239{
240public:
241 ODB_LINE( uint32_t aIndex, const std::pair<wxString, wxString>& aStart,
242 const std::pair<wxString, wxString>& aEnd, uint32_t aSym ) :
243 ODB_FEATURE( aIndex ),
244 m_start( aStart ),
245 m_end( aEnd ),
246 m_symIndex( aSym )
247 {}
248
249 inline virtual FEATURE_TYPE GetFeatureType() override { return FEATURE_TYPE::LINE; }
250
251protected:
252 virtual void WriteRecordContent( std::ostream& ost ) override;
253
254private:
255 std::pair<wxString, wxString> m_start;
256 std::pair<wxString, wxString> m_end;
257 uint32_t m_symIndex;
258};
259
260
261class ODB_ARC : public ODB_FEATURE
262{
263public:
264 inline virtual FEATURE_TYPE GetFeatureType() override { return FEATURE_TYPE::ARC; }
265
266
267 ODB_ARC( uint32_t aIndex, const std::pair<wxString, wxString>& aStart,
268 const std::pair<wxString, wxString>& aEnd,
269 const std::pair<wxString, wxString>& aCenter, uint32_t aSym,
270 ODB_DIRECTION aDirection ) :
271 ODB_FEATURE( aIndex ),
272 m_start( aStart ),
273 m_end( aEnd ),
274 m_center( aCenter ),
275 m_symIndex( aSym ),
276 m_direction( aDirection )
277 {}
278
279protected:
280 virtual void WriteRecordContent( std::ostream& ost ) override;
281
282private:
283 std::pair<wxString, wxString> m_start;
284 std::pair<wxString, wxString> m_end;
285 std::pair<wxString, wxString> m_center;
286 uint32_t m_symIndex;
288};
289
290class ODB_PAD : public ODB_FEATURE
291{
292public:
293 ODB_PAD( uint32_t aIndex, const std::pair<wxString, wxString>& aCenter, uint32_t aSym,
294 EDA_ANGLE aAngle = ANGLE_0, bool aMirror = false, double aResize = 1.0 ) :
295 ODB_FEATURE( aIndex ),
296 m_center( aCenter ),
297 m_symIndex( aSym ),
298 m_angle( aAngle ),
299 m_mirror( aMirror ),
300 m_resize( aResize )
301 {
302 }
303
304 inline virtual FEATURE_TYPE GetFeatureType() override { return FEATURE_TYPE::PAD; }
305
306protected:
307 virtual void WriteRecordContent( std::ostream& ost ) override;
308
309private:
310 std::pair<wxString, wxString> m_center;
311 uint32_t m_symIndex;
314 double m_resize;
315};
316
317class ODB_SURFACE_DATA;
319{
320public:
321 ODB_SURFACE( uint32_t aIndex, const SHAPE_POLY_SET::POLYGON& aPolygon,
322 FILL_T aFillType = FILL_T::FILLED_SHAPE );
323
324 virtual ~ODB_SURFACE() = default;
325
326 inline virtual FEATURE_TYPE GetFeatureType() override { return FEATURE_TYPE::SURFACE; }
327
328 std::unique_ptr<ODB_SURFACE_DATA> m_surfaces;
329
330protected:
331 virtual void WriteRecordContent( std::ostream& ost ) override;
332};
333
334
336{
337public:
338 ODB_SURFACE_DATA( const SHAPE_POLY_SET::POLYGON& aPolygon );
339
341 {
342 enum class LINE_TYPE
343 {
346 };
347
348 SURFACE_LINE() = default;
349
350 SURFACE_LINE( const VECTOR2I& aEnd ) :
351 m_end( aEnd )
352 {}
353
354 SURFACE_LINE( const VECTOR2I& aEnd, const VECTOR2I& aCenter, ODB_DIRECTION aDirection ) :
355 m_end( aEnd ),
356 m_type( LINE_TYPE::ARC ),
357 m_center( aCenter ),
358 m_direction( aDirection )
359 {}
360
363
366 };
367
368 void AddPolygonHoles( const SHAPE_POLY_SET::POLYGON& aPolygon );
369 void WriteData( std::ostream& ost ) const;
370
371 std::vector<std::vector<SURFACE_LINE>> m_polygons;
372};
int index
ATTR_MANAGER()=default
ATTR_RECORD_WRITER()=default
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:84
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:409
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
uint32_t AddRectSymbol(const wxString &aWidth, const wxString &aHeight)
void AddPad(PCB_LAYER_ID aLayer, PAD *pad)
std::map< wxString, uint32_t > m_chamRectSymMap
void AddVia(const PCB_VIA *aVia, PCB_LAYER_ID aLayer)
void AddDimension(PCB_LAYER_ID aLayer, PCB_DIMENSION_BASE *dimension)
std::map< wxString, uint32_t > m_rectSymMap
PCB_IO_ODBPP * GetODBPlugin()
void AddShape(PCB_LAYER_ID aLayer, PCB_SHAPE *shape)
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:55
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
void AddTrack(PCB_LAYER_ID aLayer, PCB_TRACK *track)
void AddZone(PCB_LAYER_ID aLayer, ZONE *zone)
std::map< wxString, uint32_t > m_roundRectSymMap
void AddText(PCB_LAYER_ID aLayer, BOARD_ITEM *item, RESOLUTION_CONTEXT aContext)
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:61
uint32_t AddCircleSymbol(const wxString &aDiameter)
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:61
Abstract dimension API.
Represent a set of closed polygons.
std::vector< SHAPE_LINE_CHAIN > POLYGON
represents a single polygon outline with holes.
Handle a list of polygons defining a copper zone.
Definition zone.h:70
RESOLUTION_CONTEXT
Definition common.h:87
static constexpr EDA_ANGLE ANGLE_0
Definition eda_angle.h:422
FILL_T
Definition eda_fill.h:29
@ FILLED_SHAPE
Fill with object color.
Definition eda_fill.h:31
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ UNDEFINED_LAYER
Definition layer_ids.h:57
#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:683