KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 <eda_shape.h>
28#include <layer_ids.h> // PCB_LAYER_ID
29#include <font/font.h>
31#include <stroke_params.h>
32
33#include <wx/xml/xml.h>
34#include <memory>
35
36class BOARD;
37class BOARD_ITEM;
38class EDA_TEXT;
39class FOOTPRINT;
41class NETINFO_ITEM;
42class PAD;
43class PCB_SHAPE;
44class PCB_VIA;
46class SHAPE_POLY_SET;
47class SHAPE_SEGMENT;
48
50{
51public:
56 PCB_IO_IPC2581() : PCB_IO( wxS( "IPC-2581" ) )
57 {
59 m_total_bytes = 0;
60 m_scale = 1.0;
61 m_sigfig = 3;
62 m_version = 'B';
63 m_enterpriseNode = nullptr;
64 m_board = nullptr;
65 m_props = nullptr;
66 m_shape_user_node = nullptr;
67 m_shape_std_node = nullptr;
68 m_line_node = nullptr;
69 m_last_padstack = nullptr;
70 m_progress_reporter = nullptr;
71 m_xml_doc = nullptr;
72 m_xml_root = nullptr;
73 }
74
75 ~PCB_IO_IPC2581() override;
76
80 // BOARD* LoadBoard( const wxString& aFileName, BOARD* aAppendToMe,
81 // const STRING_UTF8_MAP* aProperties = nullptr, PROJECT* aProject = nullptr ) override;
82
83 void SaveBoard( const wxString& aFileName, BOARD* aBoard,
84 const STRING_UTF8_MAP* aProperties = nullptr ) override;
85
87 {
88 return IO_BASE::IO_FILE_DESC( wxEmptyString, {}, {}, false, false, true );
89 }
90
92 {
93 // No library description for this plugin
94 return IO_BASE::IO_FILE_DESC( wxEmptyString, {} );
95 }
96
97 std::vector<FOOTPRINT*> GetImportedCachedLibraryFootprints() override;
98
99 long long GetLibraryTimestamp( const wxString& aLibraryPath ) const override
100 {
101 return 0;
102 }
103
104 // Reading currently disabled
105 bool CanReadBoard( const wxString& aFileName ) const override
106 {
107 return false;
108 }
109
110 // Reading currently disabled
111 bool CanReadFootprint( const wxString& aFileName ) const override
112 {
113 return false;
114 }
115
116 // Reading currently disabled
117 bool CanReadLibrary( const wxString& aFileName ) const override
118 {
119 return false;
120 }
121
122
129 // static std::map<wxString, PCB_LAYER_ID> DefaultLayerMappingCallback(
130 // const std::vector<INPUT_LAYER_DESC>& aInputLayerDescriptionVector );
131
137 // void RegisterLayerMappingCallback( LAYER_MAPPING_HANDLER aLayerMappingHandler ) override
138 // {};
139
140private:
141
147
152 wxXmlNode* generateXmlHeader();
153
159 wxXmlNode* generateContentSection();
160
165 wxXmlNode* generateLogisticSection();
166
172 wxXmlNode* generateHistorySection();
173
178 wxXmlNode* generateBOMSection( wxXmlNode* aEcadNode );
179
184 wxXmlNode* generateEcadSection();
185
190 wxXmlNode* generateAvlSection();
191
192 void generateCadLayers( wxXmlNode* aCadLayerNode );
193
194 void generateDrillLayers( wxXmlNode* aCadLayerNode );
195
196 void generateStepSection( wxXmlNode* aCadNode );
197
198 void generateProfile( wxXmlNode* aStepNode );
199
200 void generateLogicalNets( wxXmlNode* aStepNode );
201
202 void generatePhyNetGroup( wxXmlNode* aStepNode );
203
204 void generateLayerFeatures( wxXmlNode* aStepNode );
205
206 void generateLayerSetDrill( wxXmlNode* aStepNode );
207
208 void generateLayerSetNet( wxXmlNode* aLayerNode, PCB_LAYER_ID aLayer, std::vector<BOARD_ITEM*>& aItems );
209
210 wxXmlNode* generateContentStackup( wxXmlNode* aContentNode );
211
212 void generateComponents( wxXmlNode* aStepNode );
213
214 void addCadHeader( wxXmlNode* aEcadNode );
215
216 wxXmlNode* addPackage( wxXmlNode* aStepNode, FOOTPRINT* aFootprint );
217
218 void addPad( wxXmlNode* aContentNode, const PAD* aPad, PCB_LAYER_ID aLayer );
219
220 void addVia( wxXmlNode* aContentNode, const PCB_VIA* aVia, PCB_LAYER_ID aLayer );
221
222 void addPadStack( wxXmlNode* aContentNode, const PAD* aPad );
223
224 void addPadStack( wxXmlNode* aContentNode, const PCB_VIA* aVia );
225
226 void addLocationNode( wxXmlNode* aContentNode, double aX, double aY );
227
228 void addLocationNode( wxXmlNode* aContentNode, const PAD& aPad, bool aRelative );
229
230 void addLocationNode( wxXmlNode* aContentNode, const PCB_SHAPE& aShape );
231
232 void addShape( wxXmlNode* aContentNode, const PCB_SHAPE& aShape );
233
234 void addShape( wxXmlNode* aContentNode, const PAD& aPad, PCB_LAYER_ID aLayer );
235
236 void addSlotCavity( wxXmlNode* aContentNode, const PAD& aPad, const wxString& aName );
237
238 void addText( wxXmlNode* aContentNode, EDA_TEXT* aShape, const KIFONT::METRICS& aFontMetrics );
239
240 void addLineDesc( wxXmlNode* aNode, int aWidth, LINE_STYLE aDashType, bool aForce = false );
241
242 void addFillDesc( wxXmlNode* aNode, FILL_T aFillType, bool aForce = false );
243
244 bool addPolygonNode( wxXmlNode* aParentNode, const SHAPE_POLY_SET::POLYGON& aPolygon,
245 FILL_T aFillType = FILL_T::FILLED_SHAPE, int aWidth = 0,
246 LINE_STYLE aDashType = LINE_STYLE::SOLID );
247
248 bool addPolygonCutouts( wxXmlNode* aParentNode, const SHAPE_POLY_SET::POLYGON& aPolygon );
249
250 bool addOutlineNode( wxXmlNode* aParentNode, const SHAPE_POLY_SET& aPolySet, int aWidth = 0,
251 LINE_STYLE aDashType = LINE_STYLE::SOLID );
252
253 bool addContourNode( wxXmlNode* aParentNode, const SHAPE_POLY_SET& aPolySet, int aOutline = 0,
254 FILL_T aFillType = FILL_T::FILLED_SHAPE, int aWidth = 0,
255 LINE_STYLE aDashType = LINE_STYLE::SOLID );
256
257 size_t lineHash( int aWidth, LINE_STYLE aDashType );
258
259 size_t shapeHash( const PCB_SHAPE& aShape );
260
261 wxString genString( const wxString& aStr, const char* aPrefix = nullptr ) const;
262
263 wxString floatVal( double aVal );
264
265 wxString pinName( const PAD* aPad ) const;
266
267 wxString componentName( FOOTPRINT* aFootprint );
268
269 void addXY( wxXmlNode* aNode, const VECTOR2I& aVec, const char* aXName = nullptr,
270 const char* aYName = nullptr );
271
272 void addAttribute( wxXmlNode* aNode, const wxString& aName, const wxString& aValue );
273
274 wxXmlNode* insertNode( wxXmlNode* aParent, const wxString& aName );
275
276 wxXmlNode* appendNode( wxXmlNode* aParent, const wxString& aName );
277
278 void appendNode( wxXmlNode* aParent, wxXmlNode* aNode );
279
280 void insertNode( wxXmlNode* aParent, wxXmlNode* aNode );
281
282 void insertNodeAfter( wxXmlNode* aPrev, wxXmlNode* aNode );
283
284 void addLayerAttributes( wxXmlNode* aNode, PCB_LAYER_ID aLayer );
285
286 bool isValidLayerFor2581( PCB_LAYER_ID aLayer );
287private:
290
291 size_t m_total_bytes; //<! Total number of bytes to be written
292
293 wxString m_units_str; //<! Output string for units
294 double m_scale; //<! Scale factor from IU to IPC2581 units (mm, micron, in)
295 int m_sigfig; //<! Max number of digits past the decimal point
296 char m_version; //<! Currently, either 'B' or 'C' for the IPC2581 version
297 wxString m_OEMRef; //<! If set, field name containing the internal ID of parts
298 wxString m_mpn; //<! If set, field name containing the manufacturer part number
299 wxString m_mfg; //<! If set, field name containing the part manufacturer
300 wxString m_distpn; //<! If set, field name containing the distributor part number
301 wxString m_dist; //<! If set, field name containing the distributor name
302
303 // Node pointer to the main enterprise node to be used for adding
304 // enterprises later when forming the AVL
306
308 std::vector<FOOTPRINT*> m_loaded_footprints;
310
311 std::map<size_t, wxString> m_user_shape_dict; //<! Map between shape hash values and reference id string
312 wxXmlNode* m_shape_user_node; //<! Output XML node for reference shapes in UserDict
313
314 std::map<size_t, wxString> m_std_shape_dict; //<! Map between shape hash values and reference id string
315 wxXmlNode* m_shape_std_node; //<! Output XML node for reference shapes in StandardDict
316
317 std::map<size_t, wxString> m_line_dict; //<! Map between line hash values and reference id string
318 wxXmlNode* m_line_node; //<! Output XML node for reference lines in LineDict
319
320 std::map<size_t, wxString> m_padstack_dict; //<! Map between padstack hash values and reference id string (PADSTACK_##)
321 std::vector<wxXmlNode*> m_padstacks; //<! Holding vector for padstacks. These need to be inserted prior to the components
322 wxXmlNode* m_last_padstack; //<! Pointer to padstack list where we can insert the VIA padstacks once we process tracks
323
324 std::map<size_t, wxString>
325 m_footprint_dict; //<! Map between the footprint hash values and reference id string (<fpid>_##)
326
327 std::map<wxString, FOOTPRINT*>
328 m_footprint_refdes_dict; //<! Map between sanitized refdes and footprint pointer
329
330 std::map<FOOTPRINT*, wxString>
331 m_footprint_refdes_reverse_dict; //<! Reverse lookup for
332
333 std::map<FOOTPRINT*, wxString>
334 m_OEMRef_dict; //<! Reverse map from the footprint pointer to the reference id string assigned for components
335
336 std::map<int, std::vector<std::pair<wxString, wxString>>>
337 m_net_pin_dict; //<! Map from netcode to the component/pin pairs in the net
338
339 std::map<PCB_LAYER_ID, wxString>
340 m_layer_name_map; //<! Mapping layer name in 2581 to the internal layer id
341
342 std::map<std::pair<PCB_LAYER_ID, PCB_LAYER_ID>, std::vector<BOARD_ITEM*>>
343 m_drill_layers; //<! Drill sets are output as layers (to/from pairs)
344
345 std::map<std::pair<PCB_LAYER_ID, PCB_LAYER_ID>, std::vector<PAD*>>
346 m_slot_holes; //<! Storage vector of slotted holes that need to be output as cutouts
347
349
350 std::set<wxUniChar> m_acceptable_chars; //<! IPC2581B and C have differing sets of allowed characters in names
351
352 wxXmlDocument* m_xml_doc;
353 wxXmlNode* m_xml_root;
354};
355
356#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:77
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:282
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:83
Plugin class for import plugins that support remappable layers.
Handle the data for a net.
Definition: netinfo.h:56
Definition: pad.h:59
void addText(wxXmlNode *aContentNode, EDA_TEXT *aShape, const KIFONT::METRICS &aFontMetrics)
bool CanReadBoard(const wxString &aFileName) const override
Checks if this PCB_IO can read the specified board file.
void generateLayerSetDrill(wxXmlNode *aStepNode)
bool m_show_layer_mapping_warnings
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 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 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()
Return the automapped layers.
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)
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)
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.
PCB_IO_IPC2581()
PCB_IO_IPC2581.
wxXmlNode * generateContentStackup(wxXmlNode *aContentNode)
void addShape(wxXmlNode *aContentNode, const PCB_SHAPE &aShape)
void addCadHeader(wxXmlNode *aEcadNode)
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.
void generateLogicalNets(wxXmlNode *aStepNode)
void addFillDesc(wxXmlNode *aNode, FILL_T aFillType, bool aForce=false)
std::map< size_t, wxString > m_user_shape_dict
const STRING_UTF8_MAP * m_props
size_t shapeHash(const PCB_SHAPE &aShape)
void generatePhyNetGroup(wxXmlNode *aStepNode)
~PCB_IO_IPC2581() override
This program source code file is part of KiCad, a free EDA CAD application.
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.
wxString floatVal(double aVal)
void SaveBoard(const wxString &aFileName, BOARD *aBoard, const STRING_UTF8_MAP *aProperties=nullptr) override
Write aBoard to a storage file in a format that this PCB_IO implementation knows about or it can be u...
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.
LAYER_MAPPING_HANDLER m_layerMappingHandler
void addLocationNode(wxXmlNode *aContentNode, double aX, double aY)
bool addPolygonNode(wxXmlNode *aParentNode, const SHAPE_POLY_SET::POLYGON &aPolygon, FILL_T aFillType=FILL_T::FILLED_SHAPE, int aWidth=0, LINE_STYLE aDashType=LINE_STYLE::SOLID)
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:72
A progress reporter interface for use in multi-threaded environments.
Represent a set of closed polygons.
std::vector< SHAPE_LINE_CHAIN > POLYGON
represents a single polygon outline with holes.
A name/value tuple with unique names and optional values.
FILL_T
Definition: eda_shape.h:55
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
std::function< std::map< wxString, PCB_LAYER_ID >(const std::vector< INPUT_LAYER_DESC > &)> LAYER_MAPPING_HANDLER
Pointer to a function that takes a map of source and KiCad layers and returns a re-mapped version.
LINE_STYLE
Dashed line types.
Definition: stroke_params.h:48
Container that describes file type info.
Definition: io_base.h:39