KiCad PCB EDA Suite
CMP_READER Class Reference

Class CMP_READER reads a component footprint link file (*.cmp) format. More...

#include <netlist_reader.h>

Public Member Functions

 CMP_READER (LINE_READER *aLineReader)
 CMP_READER constructor. More...
 
 ~CMP_READER ()
 
bool Load (NETLIST *aNetlist) throw ( IO_ERROR, PARSE_ERROR )
 Function Load 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

Class CMP_READER reads a component footprint link file (*.cmp) format.

Definition at line 50 of file netlist_reader.h.

Constructor & Destructor Documentation

CMP_READER::CMP_READER ( LINE_READER aLineReader)
inline

CMP_READER constructor.

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 61 of file netlist_reader.h.

62  {
63  m_lineReader = aLineReader;
64  }
LINE_READER * m_lineReader
The line reader to read.
CMP_READER::~CMP_READER ( )
inline

Definition at line 66 of file netlist_reader.h.

References m_lineReader.

67  {
68  if( m_lineReader )
69  {
70  delete m_lineReader;
71  m_lineReader = NULL;
72  }
73  }
LINE_READER * m_lineReader
The line reader to read.

Member Function Documentation

bool CMP_READER::Load ( NETLIST aNetlist)
throw ( IO_ERROR,
PARSE_ERROR
)

Function Load read the *.cmp file format contains the component footprint assignments created by CvPcb into aNetlist.

Parameters
aNetlistis the NETLIST to read into.
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.

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

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 113 of file netlist_reader.cpp.

References LIB_ID::empty(), FROM_UTF8(), GetChars(), COMPONENT::GetFPID(), LIB_ID::Parse(), COMPONENT::SetAltFPID(), COMPONENT::SetFPID(), THROW_IO_ERROR, and TO_UTF8.

Referenced by LEGACY_NETLIST_READER::LoadNetlist().

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

Member Data Documentation

LINE_READER* CMP_READER::m_lineReader
private

The line reader to read.

Definition at line 52 of file netlist_reader.h.

Referenced by ~CMP_READER().


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