KiCad PCB EDA Suite
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
pcb_io_ipc2581.h
Go to the documentation of this file.
1
20#ifndef PCB_IO_IPC2581_H_
21#define PCB_IO_IPC2581_H_
22
23#include <pcb_io/pcb_io.h>
24#include <pcb_io/pcb_io_mgr.h>
26
27#include "ipc2581_types.h"
28
29#include <eda_shape.h>
30#include <layer_ids.h> // PCB_LAYER_ID
31#include <font/font.h>
33#include <stroke_params.h>
34
35#include <wx/xml/xml.h>
36#include <memory>
37
38class BOARD;
39class BOARD_ITEM;
40class EDA_TEXT;
41class FOOTPRINT;
43class NETINFO_ITEM;
44class PAD;
45class PCB_SHAPE;
46class PCB_VIA;
47class PCB_TEXT;
49class SHAPE_POLY_SET;
50class SHAPE_SEGMENT;
51
52class PCB_IO_IPC2581 : public PCB_IO
53{
54public:
55 PCB_IO_IPC2581() : PCB_IO( wxS( "IPC-2581" ) )
56 {
57 m_total_bytes = 0;
58 m_scale = 1.0;
59 m_sigfig = 3;
60 m_version = 'B';
61 m_enterpriseNode = nullptr;
62 m_board = nullptr;
63 m_props = nullptr;
64 m_shape_user_node = nullptr;
65 m_shape_std_node = nullptr;
66 m_line_node = nullptr;
67 m_last_padstack = nullptr;
68 m_progress_reporter = nullptr;
69 m_xml_doc = nullptr;
70 m_xml_root = nullptr;
71 }
72
73 ~PCB_IO_IPC2581() override;
74
75 // BOARD* LoadBoard( const wxString& aFileName, BOARD* aAppendToMe,
76 // const std::map<std::string, UTF8>* aProperties = nullptr,
77 // PROJECT* aProject = nullptr ) override;
78
79 void SaveBoard( const wxString& aFileName, BOARD* aBoard,
80 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
81
83 {
84 return IO_BASE::IO_FILE_DESC( wxEmptyString, {}, {}, false, false, true );
85 }
86
88 {
89 // No library description for this plugin
90 return IO_BASE::IO_FILE_DESC( wxEmptyString, {} );
91 }
92
93 std::vector<FOOTPRINT*> GetImportedCachedLibraryFootprints() override;
94
95 long long GetLibraryTimestamp( const wxString& aLibraryPath ) const override
96 {
97 return 0;
98 }
99
100 // Reading currently disabled
101 bool CanReadBoard( const wxString& aFileName ) const override
102 {
103 return false;
104 }
105
106 // Reading currently disabled
107 bool CanReadFootprint( const wxString& aFileName ) const override
108 {
109 return false;
110 }
111
112 // Reading currently disabled
113 bool CanReadLibrary( const wxString& aFileName ) const override
114 {
115 return false;
116 }
117
118
119private:
120
125
129 wxXmlNode* generateXmlHeader();
130
136 wxXmlNode* generateContentSection();
137
142 wxXmlNode* generateLogisticSection();
143
149 wxXmlNode* generateHistorySection();
150
155 wxXmlNode* generateBOMSection( wxXmlNode* aEcadNode );
156
161 wxXmlNode* generateEcadSection();
162
167 wxXmlNode* generateAvlSection();
168
169 void generateCadLayers( wxXmlNode* aCadLayerNode );
170
171 void generateCadSpecs( wxXmlNode* aCadLayerNode );
172
173 void generateStackup( wxXmlNode* aCadLayerNode );
174
175 void generateDrillLayers( wxXmlNode* aCadLayerNode );
176
177 void generateAuxilliaryLayers( wxXmlNode* aCadLayerNode );
178
179 void generateStepSection( wxXmlNode* aCadNode );
180
181 void generateProfile( wxXmlNode* aStepNode );
182
183 void generateLogicalNets( wxXmlNode* aStepNode );
184
185 void generatePhyNetGroup( wxXmlNode* aStepNode );
186
187 void generateLayerFeatures( wxXmlNode* aStepNode );
188
189 void generateLayerSetDrill( wxXmlNode* aStepNode );
190
191 void generateLayerSetNet( wxXmlNode* aLayerNode, PCB_LAYER_ID aLayer, std::vector<BOARD_ITEM*>& aItems );
192
193 void generateLayerSetAuxilliary( wxXmlNode* aStepNode );
194
195 wxXmlNode* generateContentStackup( wxXmlNode* aContentNode );
196
197 void generateComponents( wxXmlNode* aStepNode );
198
199 void addCadHeader( wxXmlNode* aEcadNode );
200
201 wxXmlNode* addPackage( wxXmlNode* aStepNode, FOOTPRINT* aFootprint );
202
203 void addPad( wxXmlNode* aContentNode, const PAD* aPad, PCB_LAYER_ID aLayer );
204
205 void addVia( wxXmlNode* aContentNode, const PCB_VIA* aVia, PCB_LAYER_ID aLayer );
206
207 void addPadStack( wxXmlNode* aContentNode, const PAD* aPad );
208
209 void addPadStack( wxXmlNode* aContentNode, const PCB_VIA* aVia );
210
211 void addLocationNode( wxXmlNode* aContentNode, double aX, double aY );
212
213 void addLocationNode( wxXmlNode* aContentNode, const PAD& aPad, bool aRelative );
214
215 void addLocationNode( wxXmlNode* aContentNode, const PCB_SHAPE& aShape );
216
217 void addShape( wxXmlNode* aContentNode, const PCB_SHAPE& aShape );
218
219 void addShape( wxXmlNode* aContentNode, const PAD& aPad, PCB_LAYER_ID aLayer );
220
221 void addSlotCavity( wxXmlNode* aContentNode, const PAD& aPad, const wxString& aName );
222
223 void addKnockoutText( wxXmlNode* aContentNode, PCB_TEXT* aText );
224
225 void addText( wxXmlNode* aContentNode, EDA_TEXT* aShape, const KIFONT::METRICS& aFontMetrics );
226
227 void addLineDesc( wxXmlNode* aNode, int aWidth, LINE_STYLE aDashType, bool aForce = false );
228
229 void addFillDesc( wxXmlNode* aNode, FILL_T aFillType, bool aForce = false );
230
231 bool addPolygonNode( wxXmlNode* aParentNode, const SHAPE_LINE_CHAIN& aPolygon,
232 FILL_T aFillType = FILL_T::FILLED_SHAPE, int aWidth = 0,
233 LINE_STYLE aDashType = LINE_STYLE::SOLID );
234
235 bool addPolygonCutouts( wxXmlNode* aParentNode, const SHAPE_POLY_SET::POLYGON& aPolygon );
236
237 bool addOutlineNode( wxXmlNode* aParentNode, const SHAPE_POLY_SET& aPolySet, int aWidth = 0,
238 LINE_STYLE aDashType = LINE_STYLE::SOLID );
239
240 bool addContourNode( wxXmlNode* aParentNode, const SHAPE_POLY_SET& aPolySet, int aOutline = 0,
241 FILL_T aFillType = FILL_T::FILLED_SHAPE, int aWidth = 0,
242 LINE_STYLE aDashType = LINE_STYLE::SOLID );
243
244 size_t lineHash( int aWidth, LINE_STYLE aDashType );
245
246 size_t shapeHash( const PCB_SHAPE& aShape );
247
248 wxString genString( const wxString& aStr, const char* aPrefix = nullptr ) const;
249 wxString genLayerString( PCB_LAYER_ID aLayer, const char* aPrefix ) const;
250 wxString genLayersString( PCB_LAYER_ID aTop, PCB_LAYER_ID aBottom, const char* aPrefix ) const;
251
252 wxString floatVal( double aVal, int aSigFig = -1 ) const;
253
254 wxString pinName( const PAD* aPad ) const;
255
256 wxString componentName( FOOTPRINT* aFootprint );
257
258 void addXY( wxXmlNode* aNode, const VECTOR2I& aVec, const char* aXName = nullptr,
259 const char* aYName = nullptr );
260
261 void addAttribute( wxXmlNode* aNode, const wxString& aName, const wxString& aValue );
262
263 wxXmlNode* insertNode( wxXmlNode* aParent, const wxString& aName );
264
265 wxXmlNode* appendNode( wxXmlNode* aParent, const wxString& aName );
266
267 void appendNode( wxXmlNode* aParent, wxXmlNode* aNode );
268
269 void insertNode( wxXmlNode* aParent, wxXmlNode* aNode );
270
271 void insertNodeAfter( wxXmlNode* aPrev, wxXmlNode* aNode );
272
273 void addLayerAttributes( wxXmlNode* aNode, PCB_LAYER_ID aLayer );
274
275 bool isValidLayerFor2581( PCB_LAYER_ID aLayer );
276private:
277
278 size_t m_total_bytes; //<! Total number of bytes to be written
279
280 wxString m_units_str; //<! Output string for units
281 double m_scale; //<! Scale factor from IU to IPC2581 units (mm, micron, in)
282 int m_sigfig; //<! Max number of digits past the decimal point
283 char m_version; //<! Currently, either 'B' or 'C' for the IPC2581 version
284 wxString m_OEMRef; //<! If set, field name containing the internal ID of parts
285 wxString m_mpn; //<! If set, field name containing the manufacturer part number
286 wxString m_mfg; //<! If set, field name containing the part manufacturer
287 wxString m_distpn; //<! If set, field name containing the distributor part number
288 wxString m_dist; //<! If set, field name containing the distributor name
289
290 // Node pointer to the main enterprise node to be used for adding
291 // enterprises later when forming the AVL
293
295 std::vector<FOOTPRINT*> m_loaded_footprints;
296 const std::map<std::string, UTF8>* m_props;
297
298 std::map<size_t, wxString> m_user_shape_dict; //<! Map between shape hash values and reference id string
299 wxXmlNode* m_shape_user_node; //<! Output XML node for reference shapes in UserDict
300
301 std::map<size_t, wxString> m_std_shape_dict; //<! Map between shape hash values and reference id string
302 wxXmlNode* m_shape_std_node; //<! Output XML node for reference shapes in StandardDict
303
304 std::map<size_t, wxString> m_line_dict; //<! Map between line hash values and reference id string
305 wxXmlNode* m_line_node; //<! Output XML node for reference lines in LineDict
306
307 std::map<size_t, wxString> m_padstack_dict; //<! Map between padstack hash values and reference id string (PADSTACK_##)
308 std::vector<wxXmlNode*> m_padstacks; //<! Holding vector for padstacks. These need to be inserted prior to the components
309 wxXmlNode* m_last_padstack; //<! Pointer to padstack list where we can insert the VIA padstacks once we process tracks
310
311 std::map<size_t, wxString>
312 m_footprint_dict; //<! Map between the footprint hash values and reference id string (<fpid>_##)
313
314 std::map<wxString, FOOTPRINT*>
315 m_footprint_refdes_dict; //<! Map between sanitized refdes and footprint pointer
316
317 std::map<FOOTPRINT*, wxString>
318 m_footprint_refdes_reverse_dict; //<! Reverse lookup for
319
320 std::map<FOOTPRINT*, wxString>
321 m_OEMRef_dict; //<! Reverse map from the footprint pointer to the reference id string assigned for components
322
323 std::map<int, std::vector<std::pair<wxString, wxString>>>
324 m_net_pin_dict; //<! Map from netcode to the component/pin pairs in the net
325
326 std::map<PCB_LAYER_ID, wxString>
327 m_layer_name_map; //<! Mapping layer name in 2581 to the internal layer id
328
329 std::map<std::pair<PCB_LAYER_ID, PCB_LAYER_ID>, std::vector<BOARD_ITEM*>>
330 m_drill_layers; //<! Drill sets are output as layers (to/from pairs)
331
332 std::map<std::pair<PCB_LAYER_ID, PCB_LAYER_ID>, std::vector<PAD*>>
333 m_slot_holes; //<! Storage vector of slotted holes that need to be output as cutouts
334
335 std::map<std::tuple<auxLayerType, PCB_LAYER_ID, PCB_LAYER_ID>, std::vector<BOARD_ITEM*>>
337
339
340 std::set<wxUniChar> m_acceptable_chars; //<! IPC2581B and C have differing sets of allowed characters in names
341
342 wxXmlDocument* m_xml_doc;
343 wxXmlNode* m_xml_root;
344};
345
346#endif // PCB_IO_IPC2581_H_
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:78
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:297
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:80
Handle the data for a net.
Definition: netinfo.h:56
Definition: pad.h:54
void addText(wxXmlNode *aContentNode, EDA_TEXT *aShape, const KIFONT::METRICS &aFontMetrics)
wxString floatVal(double aVal, int aSigFig=-1) const
bool CanReadBoard(const wxString &aFileName) const override
Checks if this PCB_IO can read the specified board file.
void generateLayerSetDrill(wxXmlNode *aStepNode)
wxString genLayerString(PCB_LAYER_ID aLayer, const char *aPrefix) const
wxXmlNode * generateContentSection()
Creates the Content section of the XML file.
wxXmlNode * appendNode(wxXmlNode *aParent, const wxString &aName)
void generateDrillLayers(wxXmlNode *aCadLayerNode)
wxXmlNode * addPackage(wxXmlNode *aStepNode, FOOTPRINT *aFootprint)
void generateComponents(wxXmlNode *aStepNode)
bool addContourNode(wxXmlNode *aParentNode, const SHAPE_POLY_SET &aPolySet, int aOutline=0, FILL_T aFillType=FILL_T::FILLED_SHAPE, int aWidth=0, LINE_STYLE aDashType=LINE_STYLE::SOLID)
wxString componentName(FOOTPRINT *aFootprint)
bool addOutlineNode(wxXmlNode *aParentNode, const SHAPE_POLY_SET &aPolySet, int aWidth=0, LINE_STYLE aDashType=LINE_STYLE::SOLID)
void generateStackup(wxXmlNode *aCadLayerNode)
std::map< std::tuple< auxLayerType, PCB_LAYER_ID, PCB_LAYER_ID >, std::vector< BOARD_ITEM * > > m_auxilliary_Layers
bool addPolygonNode(wxXmlNode *aParentNode, const SHAPE_LINE_CHAIN &aPolygon, FILL_T aFillType=FILL_T::FILLED_SHAPE, int aWidth=0, LINE_STYLE aDashType=LINE_STYLE::SOLID)
void generateLayerSetNet(wxXmlNode *aLayerNode, PCB_LAYER_ID aLayer, std::vector< BOARD_ITEM * > &aItems)
bool isValidLayerFor2581(PCB_LAYER_ID aLayer)
void insertNodeAfter(wxXmlNode *aPrev, wxXmlNode *aNode)
void generateCadLayers(wxXmlNode *aCadLayerNode)
std::vector< wxXmlNode * > m_padstacks
wxString pinName(const PAD *aPad) const
void generateCadSpecs(wxXmlNode *aCadLayerNode)
void addVia(wxXmlNode *aContentNode, const PCB_VIA *aVia, PCB_LAYER_ID aLayer)
void addSlotCavity(wxXmlNode *aContentNode, const PAD &aPad, const wxString &aName)
wxXmlNode * m_last_padstack
size_t lineHash(int aWidth, LINE_STYLE aDashType)
std::map< size_t, wxString > m_std_shape_dict
void addAttribute(wxXmlNode *aNode, const wxString &aName, const wxString &aValue)
wxXmlNode * m_shape_user_node
wxXmlNode * generateAvlSection()
Creates the Approved Vendor List section.
wxXmlNode * generateHistorySection()
Creates the history section.
void addXY(wxXmlNode *aNode, const VECTOR2I &aVec, const char *aXName=nullptr, const char *aYName=nullptr)
wxXmlNode * m_shape_std_node
void addPadStack(wxXmlNode *aContentNode, const PAD *aPad)
std::map< FOOTPRINT *, wxString > m_OEMRef_dict
void clearLoadedFootprints()
Frees the memory allocated for the loaded footprints in m_loaded_footprints.
wxString m_units_str
std::map< std::pair< PCB_LAYER_ID, PCB_LAYER_ID >, std::vector< PAD * > > m_slot_holes
std::map< size_t, wxString > m_footprint_dict
wxXmlNode * generateLogisticSection()
Creates the logistical data header.
std::map< size_t, wxString > m_line_dict
void addLineDesc(wxXmlNode *aNode, int aWidth, LINE_STYLE aDashType, bool aForce=false)
void addKnockoutText(wxXmlNode *aContentNode, PCB_TEXT *aText)
long long GetLibraryTimestamp(const wxString &aLibraryPath) const override
Generate a timestamp representing all the files in the library (including the library directory).
std::map< size_t, wxString > m_padstack_dict
std::map< std::pair< PCB_LAYER_ID, PCB_LAYER_ID >, std::vector< BOARD_ITEM * > > m_drill_layers
std::map< wxString, FOOTPRINT * > m_footprint_refdes_dict
void generateProfile(wxXmlNode *aStepNode)
void generateLayerFeatures(wxXmlNode *aStepNode)
void SaveBoard(const wxString &aFileName, BOARD *aBoard, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Write aBoard to a storage file in a format that this PCB_IO implementation knows about or it can be u...
bool CanReadFootprint(const wxString &aFileName) const override
Checks if this PCB_IO can read a footprint from specified file or directory.
wxXmlNode * generateBOMSection(wxXmlNode *aEcadNode)
Creates the BOM section.
wxXmlNode * generateContentStackup(wxXmlNode *aContentNode)
void addShape(wxXmlNode *aContentNode, const PCB_SHAPE &aShape)
void generateAuxilliaryLayers(wxXmlNode *aCadLayerNode)
void addCadHeader(wxXmlNode *aEcadNode)
void generateLayerSetAuxilliary(wxXmlNode *aStepNode)
PROGRESS_REPORTER * m_progress_reporter
std::vector< FOOTPRINT * > GetImportedCachedLibraryFootprints() override
Return a container with the cached library footprints generated in the last call to Load.
const std::map< std::string, UTF8 > * m_props
wxString genLayersString(PCB_LAYER_ID aTop, PCB_LAYER_ID aBottom, const char *aPrefix) const
void generateLogicalNets(wxXmlNode *aStepNode)
void addFillDesc(wxXmlNode *aNode, FILL_T aFillType, bool aForce=false)
std::map< size_t, wxString > m_user_shape_dict
size_t shapeHash(const PCB_SHAPE &aShape)
void generatePhyNetGroup(wxXmlNode *aStepNode)
~PCB_IO_IPC2581() override
wxString genString(const wxString &aStr, const char *aPrefix=nullptr) const
const IO_BASE::IO_FILE_DESC GetLibraryDesc() const override
Get the descriptor for the library container that this IO plugin operates on.
wxXmlNode * m_xml_root
std::vector< FOOTPRINT * > m_loaded_footprints
bool addPolygonCutouts(wxXmlNode *aParentNode, const SHAPE_POLY_SET::POLYGON &aPolygon)
std::set< wxUniChar > m_acceptable_chars
void addLayerAttributes(wxXmlNode *aNode, PCB_LAYER_ID aLayer)
wxXmlNode * generateXmlHeader()
Creates the XML header for IPC-2581.
wxXmlNode * generateEcadSection()
Creates the ECAD section.
wxXmlDocument * m_xml_doc
bool CanReadLibrary(const wxString &aFileName) const override
Checks if this IO object can read the specified library file/directory.
wxXmlNode * insertNode(wxXmlNode *aParent, const wxString &aName)
void addPad(wxXmlNode *aContentNode, const PAD *aPad, PCB_LAYER_ID aLayer)
void generateStepSection(wxXmlNode *aCadNode)
std::map< PCB_LAYER_ID, wxString > m_layer_name_map
const IO_BASE::IO_FILE_DESC GetBoardFileDesc() const override
Returns board file description for the PCB_IO.
void addLocationNode(wxXmlNode *aContentNode, double aX, double aY)
wxXmlNode * m_line_node
std::map< int, std::vector< std::pair< wxString, wxString > > > m_net_pin_dict
std::map< FOOTPRINT *, wxString > m_footprint_refdes_reverse_dict
wxXmlNode * m_enterpriseNode
A base class that BOARD loading and saving plugins should derive from.
Definition: pcb_io.h:71
A progress reporter interface for use in multi-threaded environments.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Represent a set of closed polygons.
std::vector< SHAPE_LINE_CHAIN > POLYGON
represents a single polygon outline with holes.
FILL_T
Definition: eda_shape.h:56
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
LINE_STYLE
Dashed line types.
Definition: stroke_params.h:46
Container that describes file type info.
Definition: io_base.h:43