1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2020 Jon Evans <jon@craftyjon.com>
5  * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
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 #include <wx/string.h>
22 
23 class BOARD;
24 class wxWindow;
25 
26 
27 /* Structure for holding the D-356 record fields.
28  * Useful because 356A (when implemented) must be sorted before outputting it */
29 struct D356_RECORD
30 {
31     bool       smd;
32     bool       hole;
33     wxString   netname;
34     wxString   refdes;
35     wxString   pin;
36     bool       midpoint;
37     int        drill;
38     bool       mechanical;
39     int        access;      // Access 0 is 'both sides'
40     int        soldermask;
41     // All these in PCB units, will be output in decimils
42     int        x_location;
43     int        y_location;
44     int        x_size;
45     int        y_size;
46     int        rotation;
47 };
48 
49 
50 /**
51  * Wrapper to expose an API for writing IPC-D356 files
52  */
53 class IPC356D_WRITER
54 {
55 public:
56     /**
57      * Constructs an IPC-356D file writer
58      * @param aPcb is the board to extract a netlist from
59      * @param aParent will be used as the parent for any warning dialogs
60      */
61     IPC356D_WRITER( BOARD* aPcb, wxWindow* aParent = nullptr ) :
m_pcb(aPcb)62             m_pcb( aPcb ), m_parent( aParent )
63     {}
64 
~IPC356D_WRITER()65     virtual ~IPC356D_WRITER() {}
66 
67     /**
68      * Generates and writes the netlist to a given path
69      * @param aFilename is the full path and name of the output file
70      */
71     void Write( const wxString& aFilename );
72 
73 private:
74     BOARD*    m_pcb;
75     wxWindow* m_parent;
76 
77     /// Writes a list of records to the given output stream
78     void write_D356_records( std::vector<D356_RECORD> &aRecords, FILE* aFile );
79 };
80