KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_io_ipc2581.h
Go to the documentation of this file.
1
19
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 <array>
37#include <memory>
38#include <map>
39#include <set>
40
41class BOARD;
42class BOARD_ITEM;
43class EDA_TEXT;
44class FOOTPRINT;
46class NETINFO_ITEM;
47class PAD;
48class PADSTACK;
49class PCB_SHAPE;
50class PCB_VIA;
51class PCB_TEXT;
53class SHAPE_POLY_SET;
54class SHAPE_SEGMENT;
55
56class PCB_IO_IPC2581 : public PCB_IO
57{
58public:
59 PCB_IO_IPC2581() : PCB_IO( wxS( "IPC-2581" ) )
60 {
61 m_total_bytes = 0;
62 m_scale = 1.0;
63 m_sigfig = 3;
64 m_version = 'B';
65 m_enterpriseNode = nullptr;
66 m_board = nullptr;
67 m_props = nullptr;
68 m_shape_user_node = nullptr;
69 m_shape_std_node = nullptr;
70 m_line_node = nullptr;
71 m_last_padstack = nullptr;
73 m_cad_header_node = nullptr;
74 m_progress_reporter = nullptr;
75 m_xml_doc = nullptr;
76 m_xml_root = nullptr;
77 m_contentNode = nullptr;
78 m_lastAppendedNode = nullptr;
79 }
80
81 ~PCB_IO_IPC2581() override;
82
83 // BOARD* LoadBoard( const wxString& aFileName, BOARD* aAppendToMe,
84 // const std::map<std::string, UTF8>* aProperties = nullptr,
85 // PROJECT* aProject = nullptr ) override;
86
87 void SaveBoard( const wxString& aFileName, BOARD* aBoard,
88 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
89
91 {
92 return IO_BASE::IO_FILE_DESC( wxEmptyString, {}, {}, false, false, true );
93 }
94
96 {
97 // No library description for this plugin
98 return IO_BASE::IO_FILE_DESC( wxEmptyString, {} );
99 }
100
101 std::vector<FOOTPRINT*> GetImportedCachedLibraryFootprints() override;
102
103 long long GetLibraryTimestamp( const wxString& aLibraryPath ) const override
104 {
105 return 0;
106 }
107
108 // Reading currently disabled
109 bool CanReadBoard( const wxString& aFileName ) const override
110 {
111 return false;
112 }
113
114 // Reading currently disabled
115 bool CanReadFootprint( const wxString& aFileName ) const override
116 {
117 return false;
118 }
119
120 // Reading currently disabled
121 bool CanReadLibrary( const wxString& aFileName ) const override
122 {
123 return false;
124 }
125
126
127private:
128
133
137 wxXmlNode* generateXmlHeader();
138
144 wxXmlNode* generateContentSection();
145
150 wxXmlNode* generateLogisticSection();
151
157 wxXmlNode* generateHistorySection();
158
163 wxXmlNode* generateBOMSection( wxXmlNode* aEcadNode );
164
169 wxXmlNode* generateEcadSection();
170
175 wxXmlNode* generateAvlSection();
176
177 void generateCadLayers( wxXmlNode* aCadLayerNode );
178
179 void generateCadSpecs( wxXmlNode* aCadLayerNode );
180
181 void generateStackup( wxXmlNode* aCadLayerNode );
182
183 void generateDrillLayers( wxXmlNode* aCadLayerNode );
184
185 void generateAuxilliaryLayers( wxXmlNode* aCadLayerNode );
186
187 void generateStepSection( wxXmlNode* aCadNode );
188
189 void generateProfile( wxXmlNode* aStepNode );
190
191 void generateLogicalNets( wxXmlNode* aStepNode );
192
193 void generatePhyNetGroup( wxXmlNode* aStepNode );
194
195 void generateLayerFeatures( wxXmlNode* aStepNode );
196
197 void generateLayerSetDrill( wxXmlNode* aStepNode );
198
199 void generateLayerSetNet( wxXmlNode* aLayerNode, PCB_LAYER_ID aLayer, std::vector<BOARD_ITEM*>& aItems );
200
201 void generateLayerSetAuxilliary( wxXmlNode* aStepNode );
202
203 wxXmlNode* generateContentStackup( wxXmlNode* aContentNode );
204
205 void generateComponents( wxXmlNode* aStepNode );
206
207 void addCadHeader( wxXmlNode* aEcadNode );
208
209 wxXmlNode* addPackage( wxXmlNode* aStepNode, FOOTPRINT* aFootprint );
210
211 void addPad( wxXmlNode* aContentNode, const PAD* aPad, PCB_LAYER_ID aLayer );
212
213 void addVia( wxXmlNode* aContentNode, const PCB_VIA* aVia, PCB_LAYER_ID aLayer );
214
215 void addPadStack( wxXmlNode* aContentNode, const PAD* aPad );
216
217 void addPadStack( wxXmlNode* aContentNode, const PCB_VIA* aVia );
218
219 void ensureBackdrillSpecs( const wxString& aPadstackName, const PADSTACK& aPadstack );
220
221 void addBackdrillSpecRefs( wxXmlNode* aHoleNode, const wxString& aPadstackName );
222
224
225 void addLocationNode( wxXmlNode* aContentNode, double aX, double aY );
226
227 void addLocationNode( wxXmlNode* aContentNode, const PAD& aPad, bool aRelative );
228
229 void addLocationNode( wxXmlNode* aContentNode, const PCB_SHAPE& aShape );
230
231 void addShape( wxXmlNode* aContentNode, const PCB_SHAPE& aShape, bool aInline = false );
232
233 void addShape( wxXmlNode* aContentNode, const PAD& aPad, PCB_LAYER_ID aLayer );
234
235 void addSlotCavity( wxXmlNode* aContentNode, const PAD& aPad, const wxString& aName );
236
237 void addKnockoutText( wxXmlNode* aContentNode, PCB_TEXT* aText );
238
239 void addText( wxXmlNode* aContentNode, EDA_TEXT* aShape, const KIFONT::METRICS& aFontMetrics );
240
241 void addLineDesc( wxXmlNode* aNode, int aWidth, LINE_STYLE aDashType, bool aForce = false );
242
243 void addFillDesc( wxXmlNode* aNode, FILL_T aFillType, bool aForce = false );
244
245 bool addPolygonNode( wxXmlNode* aParentNode, const SHAPE_LINE_CHAIN& aPolygon,
246 FILL_T aFillType = FILL_T::FILLED_SHAPE, int aWidth = 0,
247 LINE_STYLE aDashType = LINE_STYLE::SOLID );
248
249 bool addPolygonCutouts( wxXmlNode* aParentNode, const SHAPE_POLY_SET::POLYGON& aPolygon );
250
251 bool addOutlineNode( wxXmlNode* aParentNode, const SHAPE_POLY_SET& aPolySet, int aWidth = 0,
252 LINE_STYLE aDashType = LINE_STYLE::SOLID );
253
254 bool addContourNode( wxXmlNode* aParentNode, const SHAPE_POLY_SET& aPolySet, int aOutline = 0,
255 FILL_T aFillType = FILL_T::FILLED_SHAPE, int aWidth = 0,
256 LINE_STYLE aDashType = LINE_STYLE::SOLID );
257
258 size_t lineHash( int aWidth, LINE_STYLE aDashType );
259
260 size_t shapeHash( const PCB_SHAPE& aShape );
261
262 wxString sanitizeId( const wxString& aStr ) const;
263 wxString genString( const wxString& aStr, const char* aPrefix = nullptr ) const;
264 wxString genLayerString( PCB_LAYER_ID aLayer, const char* aPrefix ) const;
265 wxString genLayersString( PCB_LAYER_ID aTop, PCB_LAYER_ID aBottom, const char* aPrefix ) const;
266
267 wxString floatVal( double aVal, int aSigFig = -1 ) const;
268
269 wxString pinName( const PAD* aPad ) const;
270
271 wxString componentName( FOOTPRINT* aFootprint );
272
273 void addXY( wxXmlNode* aNode, const VECTOR2I& aVec, const char* aXName = nullptr,
274 const char* aYName = nullptr );
275
276 void addAttribute( wxXmlNode* aNode, const wxString& aName, const wxString& aValue );
277
278 wxXmlNode* insertNode( wxXmlNode* aParent, const wxString& aName );
279
280 wxXmlNode* appendNode( wxXmlNode* aParent, const wxString& aName );
281
282 void appendNode( wxXmlNode* aParent, wxXmlNode* aNode );
283
284 void insertNode( wxXmlNode* aParent, wxXmlNode* aNode );
285
286 void insertNodeAfter( wxXmlNode* aPrev, wxXmlNode* aNode );
287
288 void deleteNode( wxXmlNode*& aNode );
289
290 void addLayerAttributes( wxXmlNode* aNode, PCB_LAYER_ID aLayer );
291
292 bool isValidLayerFor2581( PCB_LAYER_ID aLayer );
293private:
294
295 size_t m_total_bytes; //<! Total number of bytes to be written
296
297 wxString m_units_str; //<! Output string for units
298 double m_scale; //<! Scale factor from IU to IPC2581 units (mm, micron, in)
299 int m_sigfig; //<! Max number of digits past the decimal point
300 char m_version; //<! Currently, either 'B' or 'C' for the IPC2581 version
301 wxString m_OEMRef; //<! If set, field name containing the internal ID of parts
302 wxString m_mpn; //<! If set, field name containing the manufacturer part number
303 wxString m_mfg; //<! If set, field name containing the part manufacturer
304 wxString m_distpn; //<! If set, field name containing the distributor part number
305 wxString m_dist; //<! If set, field name containing the distributor name
306 wxString m_bomRev; //<! BOM revision string for the BomHeader element
307
308 // Node pointer to the main enterprise node to be used for adding
309 // enterprises later when forming the AVL
311
313 std::vector<FOOTPRINT*> m_loaded_footprints;
314 const std::map<std::string, UTF8>* m_props;
315
316 std::map<size_t, wxString> m_user_shape_dict; //<! Map between shape hash values and reference id string
317 wxXmlNode* m_shape_user_node; //<! Output XML node for reference shapes in UserDict
318
319 std::map<size_t, wxString> m_std_shape_dict; //<! Map between shape hash values and reference id string
320 wxXmlNode* m_shape_std_node; //<! Output XML node for reference shapes in StandardDict
321
322 std::map<size_t, wxString> m_line_dict; //<! Map between line hash values and reference id string
323 wxXmlNode* m_line_node; //<! Output XML node for reference lines in LineDict
324
325 std::map<size_t, wxString> m_padstack_dict; //<! Map between padstack hash values and reference id string (PADSTACK_##)
326 std::vector<wxXmlNode*> m_padstacks; //<! Holding vector for padstacks. These need to be inserted prior to the components
327 wxXmlNode* m_last_padstack; //<! Pointer to padstack list where we can insert the VIA padstacks once we process tracks
328
329 std::map<wxString, std::array<wxString, 3>> m_padstack_backdrill_specs;
330 std::map<wxString, wxXmlNode*> m_backdrill_spec_nodes;
331 std::set<wxString> m_backdrill_spec_used;
334
335 std::map<size_t, wxString>
336 m_footprint_dict; //<! Map between the footprint hash values and reference id string (<fpid>_##)
337
338 std::map<wxString, FOOTPRINT*>
339 m_footprint_refdes_dict; //<! Map between sanitized refdes and footprint pointer
340
341 std::map<FOOTPRINT*, wxString>
342 m_footprint_refdes_reverse_dict; //<! Reverse lookup for
343
344 std::map<FOOTPRINT*, wxString>
345 m_OEMRef_dict; //<! Reverse map from the footprint pointer to the reference id string assigned for components
346
347 std::map<int, std::vector<std::pair<wxString, wxString>>>
348 m_net_pin_dict; //<! Map from netcode to the component/pin pairs in the net
349
350 std::map<PCB_LAYER_ID, wxString>
351 m_layer_name_map; //<! Mapping layer name in 2581 to the internal layer id
352
353 std::map<std::pair<PCB_LAYER_ID, PCB_LAYER_ID>, std::vector<BOARD_ITEM*>>
354 m_drill_layers; //<! Drill sets are output as layers (to/from pairs)
355
356 std::map<std::pair<PCB_LAYER_ID, PCB_LAYER_ID>, std::vector<PAD*>>
357 m_slot_holes; //<! Storage vector of slotted holes that need to be output as cutouts
358
359 std::map<std::tuple<auxLayerType, PCB_LAYER_ID, PCB_LAYER_ID>, std::vector<BOARD_ITEM*>>
361
363
364 mutable std::set<wxString> m_element_names; //<! Track generated element names
365 mutable std::map<wxString, wxString> m_generated_names; //<! Map input keys to unique names
366
367 std::set<wxUniChar> m_acceptable_chars; //<! IPC2581B and C have differing sets of allowed characters in names
368
369 wxXmlDocument* m_xml_doc;
370 wxXmlNode* m_xml_root;
371 wxXmlNode* m_contentNode;
372
374};
375
376#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:84
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:323
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition eda_text.h:93
Handle the data for a net.
Definition netinfo.h:50
A PADSTACK defines the characteristics of a single or multi-layer pad, in the IPC sense of the word.
Definition padstack.h:157
Definition pad.h:55
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 addBackdrillSpecRefs(wxXmlNode *aHoleNode, const wxString &aPadstackName)
void generateDrillLayers(wxXmlNode *aCadLayerNode)
wxString sanitizeId(const wxString &aStr) const
wxXmlNode * addPackage(wxXmlNode *aStepNode, FOOTPRINT *aFootprint)
void generateComponents(wxXmlNode *aStepNode)
std::map< wxString, std::array< wxString, 3 > > m_padstack_backdrill_specs
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)
void addShape(wxXmlNode *aContentNode, const PCB_SHAPE &aShape, bool aInline=false)
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)
void deleteNode(wxXmlNode *&aNode)
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.
wxXmlNode * m_contentNode
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.
std::map< wxString, wxXmlNode * > m_backdrill_spec_nodes
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::set< wxString > m_element_names
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 generateAuxilliaryLayers(wxXmlNode *aCadLayerNode)
wxXmlNode * m_cad_header_node
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)
void pruneUnusedBackdrillSpecs()
std::set< wxUniChar > m_acceptable_chars
void addLayerAttributes(wxXmlNode *aNode, PCB_LAYER_ID aLayer)
wxXmlNode * generateXmlHeader()
Creates the XML header for IPC-2581.
void ensureBackdrillSpecs(const wxString &aPadstackName, const PADSTACK &aPadstack)
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
std::map< wxString, wxString > m_generated_names
const IO_BASE::IO_FILE_DESC GetBoardFileDesc() const override
Returns board file description for the PCB_IO.
std::set< wxString > m_backdrill_spec_used
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_lastAppendedNode
Optimization for appendNode to avoid O(n) child traversal.
wxXmlNode * m_enterpriseNode
PCB_IO(const wxString &aName)
Definition pcb_io.h:346
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:59
@ FILLED_SHAPE
Fill with object color.
Definition eda_shape.h:61
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:60
LINE_STYLE
Dashed line types.
Container that describes file type info.
Definition io_base.h:43
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:687