KiCad PCB EDA Suite
CMP_READER Class Reference

Read a component footprint link file (*.cmp) format. More...

#include <netlist_reader.h>

Public Member Functions

 CMP_READER (LINE_READER *aLineReader)
 
 ~CMP_READER ()
 
bool Load (NETLIST *aNetlist)
 Read the *.cmp file format contains the component footprint assignments created by CvPcb into aNetlist. More...
 

Private Attributes

LINE_READERm_lineReader
 The line reader to read. More...
 

Detailed Description

Read a component footprint link file (*.cmp) format.

Definition at line 44 of file netlist_reader.h.

Constructor & Destructor Documentation

◆ CMP_READER()

CMP_READER::CMP_READER ( LINE_READER aLineReader)
inline
Parameters
aLineReaderis a LINE_READER (in fact a FILE_LINE_READER) which is owned by me ( and deleted by me) to read the component footprint link file.

Definition at line 52 of file netlist_reader.h.

53 {
54 m_lineReader = aLineReader;
55 }
LINE_READER * m_lineReader
The line reader to read.

References m_lineReader.

◆ ~CMP_READER()

CMP_READER::~CMP_READER ( )
inline

Definition at line 57 of file netlist_reader.h.

58 {
59 if( m_lineReader )
60 {
61 delete m_lineReader;
62 m_lineReader = nullptr;
63 }
64 }

References m_lineReader.

Member Function Documentation

◆ Load()

bool CMP_READER::Load ( NETLIST aNetlist)

Read the *.cmp file format contains the component footprint assignments created by CvPcb into aNetlist.

Sample file footprint assignment entry:

Cmp-Mod V01 Genere by CvPcb 29/10/2003-13: 11:6 * BeginCmp TimeStamp = /32307DE2/AA450F67; Reference = C1; ValeurCmp = 47uF; IdModule = CP6; EndCmp

Todo:
At some point in the future, use the footprint field in the new s-expression netlist file to assign a footprint to a component instead of using a secondary (*.cmp) file.
Parameters
aNetlistis the NETLIST to read into.
Exceptions
IO_ERRORif a the LINE_READER IO error occurs.
PARSE_ERRORif an error occurs while parsing the file.
Returns
true if OK, false if a component reference found in the .cmp file is not found in netlist, which means the .cmp file is not updated. This is an usual case, in CvPcb, but can be used to print a warning in Pcbnew.

Definition at line 115 of file netlist_reader.cpp.

116{
117 wxCHECK_MSG( aNetlist != nullptr, true, wxT( "No netlist passed to CMP_READER::Load()" ) );
118
119 wxString reference; // Stores value read from line like Reference = BUS1;
120 wxString timestamp; // Stores value read from line like TimeStamp = /32307DE2/AA450F67;
121 wxString footprint; // Stores value read from line like IdModule = CP6;
122 wxString buffer;
123 wxString value;
124
125 bool ok = true;
126
127 while( m_lineReader->ReadLine() )
128 {
129 buffer = FROM_UTF8( m_lineReader->Line() );
130
131 if( !buffer.StartsWith( wxT( "BeginCmp" ) ) )
132 continue;
133
134 // Begin component description.
135 reference.Empty();
136 footprint.Empty();
137 timestamp.Empty();
138
139 while( m_lineReader->ReadLine() )
140 {
141 buffer = FROM_UTF8( m_lineReader->Line() );
142
143 if( buffer.StartsWith( wxT( "EndCmp" ) ) )
144 break;
145
146 // store string value, stored between '=' and ';' delimiters.
147 value = buffer.AfterFirst( '=' );
148 value = value.BeforeLast( ';' );
149 value.Trim( true );
150 value.Trim( false );
151
152 if( buffer.StartsWith( wxT( "Reference" ) ) )
153 {
154 reference = value;
155 continue;
156 }
157
158 if( buffer.StartsWith( wxT( "IdModule =" ) ) )
159 {
160 footprint = value;
161 continue;
162 }
163
164 if( buffer.StartsWith( wxT( "TimeStamp =" ) ) )
165 {
166 timestamp = value;
167 continue;
168 }
169 }
170
171 // Find the corresponding item in component list:
172 COMPONENT* component = aNetlist->GetComponentByReference( reference );
173
174 // The corresponding component could no longer existing in the netlist. This
175 // can happen when it is removed from schematic and still exists in footprint
176 // assignment list. This is an usual case during the life of a design.
177 if( component )
178 {
179 LIB_ID fpid;
180
181 if( !footprint.IsEmpty() && fpid.Parse( footprint, true ) >= 0 )
182 {
183 wxString error;
184 error.Printf( _( "Invalid footprint ID in\nfile: '%s'\nline: %d" ),
186
187 THROW_IO_ERROR( error );
188 }
189
190 // For checking purpose, store the existing LIB_ID (if any) in the alternate fpid copy
191 // if this existing LIB_ID differs from the LIB_ID read from the .cmp file.
192 // CvPcb can ask for user to chose the right LIB_ID.
193 // It happens if the LIB_ID was modified outside CvPcb.
194 if( fpid != component->GetFPID() && !component->GetFPID().empty() )
195 component->SetAltFPID( component->GetFPID() );
196
197 component->SetFPID( fpid );
198 }
199 else
200 {
201 ok = false; // can be used to display a warning in Pcbnew.
202 }
203 }
204
205 return ok;
206}
Store all of the related footprint information found in a netlist.
Definition: pcb_netlist.h:85
void SetAltFPID(const LIB_ID &aFPID)
Definition: pcb_netlist.h:140
void SetFPID(const LIB_ID &aFPID)
Definition: pcb_netlist.h:137
const LIB_ID & GetFPID() const
Definition: pcb_netlist.h:138
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition: lib_id.cpp:50
bool empty() const
Definition: lib_id.h:186
virtual char * ReadLine()=0
Read a line of text into the buffer and increments the line number counter.
virtual const wxString & GetSource() const
Returns the name of the source of the lines in an abstract sense.
Definition: richio.h:109
virtual unsigned LineNumber() const
Return the line number of the last line read from this LINE_READER.
Definition: richio.h:135
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:117
COMPONENT * GetComponentByReference(const wxString &aReference)
Return a COMPONENT by aReference.
#define _(s)
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:110

References _, LIB_ID::empty(), FROM_UTF8(), NETLIST::GetComponentByReference(), COMPONENT::GetFPID(), LINE_READER::GetSource(), LINE_READER::Line(), LINE_READER::LineNumber(), m_lineReader, LIB_ID::Parse(), LINE_READER::ReadLine(), COMPONENT::SetAltFPID(), COMPONENT::SetFPID(), and THROW_IO_ERROR.

Referenced by LEGACY_NETLIST_READER::LoadNetlist(), and KICAD_NETLIST_READER::LoadNetlist().

Member Data Documentation

◆ m_lineReader

LINE_READER* CMP_READER::m_lineReader
private

The line reader to read.

Definition at line 95 of file netlist_reader.h.

Referenced by CMP_READER(), Load(), and ~CMP_READER().


The documentation for this class was generated from the following files: