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)
 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)

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

References LIB_ID::empty(), FROM_UTF8(), GetChars(), 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().

113 {
114  wxCHECK_MSG( aNetlist != NULL,true, wxT( "No netlist passed to CMP_READER::Load()" ) );
115 
116  wxString reference; // Stores value read from line like Reference = BUS1;
117  wxString timestamp; // Stores value read from line like TimeStamp = /32307DE2/AA450F67;
118  wxString footprint; // Stores value read from line like IdModule = CP6;
119  wxString buffer;
120  wxString value;
121 
122  bool ok = true;
123 
124  while( m_lineReader->ReadLine() )
125  {
126  buffer = FROM_UTF8( m_lineReader->Line() );
127 
128  if( !buffer.StartsWith( wxT( "BeginCmp" ) ) )
129  continue;
130 
131  // Begin component description.
132  reference.Empty();
133  footprint.Empty();
134  timestamp.Empty();
135 
136  while( m_lineReader->ReadLine() )
137  {
138  buffer = FROM_UTF8( m_lineReader->Line() );
139 
140  if( buffer.StartsWith( wxT( "EndCmp" ) ) )
141  break;
142 
143  // store string value, stored between '=' and ';' delimiters.
144  value = buffer.AfterFirst( '=' );
145  value = value.BeforeLast( ';' );
146  value.Trim( true );
147  value.Trim( false );
148 
149  if( buffer.StartsWith( wxT( "Reference" ) ) )
150  {
151  reference = value;
152  continue;
153  }
154 
155  if( buffer.StartsWith( wxT( "IdModule =" ) ) )
156  {
157  footprint = value;
158  continue;
159  }
160 
161  if( buffer.StartsWith( wxT( "TimeStamp =" ) ) )
162  {
163  timestamp = value;
164  continue;
165  }
166  }
167 
168  // Find the corresponding item in component list:
169  COMPONENT* component = aNetlist->GetComponentByReference( reference );
170 
171  // The corresponding component could no longer existing in the netlist. This
172  // can happen when it is removed from schematic and still exists in footprint
173  // assignment list. This is an usual case during the life of a design.
174  if( component )
175  {
176  LIB_ID fpid;
177 
178  if( !footprint.IsEmpty() && fpid.Parse( footprint ) >= 0 )
179  {
180  wxString error;
181  error.Printf( _( "invalid footprint ID in\nfile: <%s>\nline: %d" ),
184 
185  THROW_IO_ERROR( error );
186  }
187 
188  // For checking purpose, store the existing LIB_ID (if any) in the alternate fpid copy
189  // if this existing LIB_ID differs from the LIB_ID read from the .cmp file.
190  // CvPcb can ask for user to chose the right LIB_ID.
191  // It happens if the LIB_ID was modified outside CvPcb.
192  if( fpid != component->GetFPID() && !component->GetFPID().empty() )
193  component->SetAltFPID( component->GetFPID() );
194 
195  component->SetFPID( fpid );
196  }
197  else
198  {
199  ok = false; // can be used to display a warning in Pcbnew.
200  }
201  }
202 
203  return ok;
204 }
void SetAltFPID(const LIB_ID &aFPID)
Definition: pcb_netlist.h:159
bool empty() const
Function empty.
Definition: lib_id.h:198
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
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
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.
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

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 Load(), and ~CMP_READER().


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