2009-04-24 07:36:36 +00:00
|
|
|
/***********************/
|
|
|
|
/* PCBNEW: netlist.cpp */
|
|
|
|
/***********************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
/*
|
2011-05-03 12:57:44 +00:00
|
|
|
* Functions to read a netlist. They are:
|
|
|
|
* - Load new footprints and nitialize net info
|
2009-04-24 07:36:36 +00:00
|
|
|
* - Test for missing or extra footprints
|
2011-05-03 12:57:44 +00:00
|
|
|
* - Recalculate full connectivity info
|
2008-02-19 00:28:42 +00:00
|
|
|
*
|
2009-04-24 07:36:36 +00:00
|
|
|
* Important remark:
|
2009-11-18 12:52:19 +00:00
|
|
|
* When reading a netlist Pcbnew must identify existing footprints (link
|
|
|
|
* between existing footprints an components in netlist)
|
2009-04-24 07:36:36 +00:00
|
|
|
* This identification can be from 2 fields:
|
|
|
|
* - The reference (U2, R5 ..): this is the normal mode
|
2009-11-18 12:52:19 +00:00
|
|
|
* - The Time Stamp (Signature Temporelle), useful after a full schematic
|
2011-05-03 12:57:44 +00:00
|
|
|
* reannotation because references can be changed for the same schematic.
|
|
|
|
* So when reading a netlist ReadPcbNetlist() can use references or time stamps
|
|
|
|
* to identify footprints on board and the corresponding component in schematic.
|
2009-04-24 07:36:36 +00:00
|
|
|
* If we want to fully reannotate a schematic this sequence must be used
|
2011-05-03 12:57:44 +00:00
|
|
|
* 1 - SAVE your board !!!
|
|
|
|
* 2 - Create and read the netlist (to ensure all info is correct, mainly
|
2009-11-18 12:52:19 +00:00
|
|
|
* references and time stamp)
|
2011-05-03 12:57:44 +00:00
|
|
|
* 3 - Reannotate the schematic (references will be changed, but not time stamps )
|
|
|
|
* 4 - Recreate and read the new netlist using the Time Stamp identification
|
2009-11-18 12:52:19 +00:00
|
|
|
* (that reinit the new references)
|
2007-08-20 19:33:15 +00:00
|
|
|
*/
|
2011-04-02 16:14:07 +00:00
|
|
|
|
|
|
|
#include "vector"
|
|
|
|
#include "algorithm"
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "fctsys.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
|
|
|
#include "confirm.h"
|
|
|
|
#include "kicad_string.h"
|
|
|
|
#include "gestfich.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "pcbnew.h"
|
2009-07-30 11:04:07 +00:00
|
|
|
#include "wxPcbStruct.h"
|
2010-04-16 16:28:35 +00:00
|
|
|
#include "richio.h"
|
2010-11-18 21:16:28 +00:00
|
|
|
#include "dialog_helpers.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-04-24 07:36:36 +00:00
|
|
|
#include "dialog_netlist.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-05-05 17:45:35 +00:00
|
|
|
// constants used by ReadNetlistModuleDescr():
|
2011-05-03 12:57:44 +00:00
|
|
|
#define TESTONLY true
|
|
|
|
#define READMODULE false
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
/*
|
|
|
|
* Helper class, to store new footprints info found in netlist.
|
|
|
|
* New footprints are footprints relative to new components found in netlist
|
|
|
|
*/
|
|
|
|
class MODULE_INFO
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
public:
|
2011-05-03 12:57:44 +00:00
|
|
|
wxString m_LibName;
|
|
|
|
wxString m_CmpName;
|
|
|
|
wxString m_TimeStampPath;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
public: MODULE_INFO( const wxString& libname,
|
|
|
|
const wxString& cmpname,
|
|
|
|
const wxString& timestamp_path )
|
2009-04-24 07:36:36 +00:00
|
|
|
{
|
|
|
|
m_LibName = libname;
|
|
|
|
m_CmpName = cmpname;
|
|
|
|
m_TimeStampPath = timestamp_path;
|
|
|
|
}
|
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
~MODULE_INFO() { };
|
2007-06-05 12:10:51 +00:00
|
|
|
};
|
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
/*
|
|
|
|
* Helper class, to read a netlist.
|
|
|
|
*/
|
|
|
|
class NETLIST_READER
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
PCB_EDIT_FRAME* m_pcbframe; // the main pcbnew frame
|
|
|
|
wxTextCtrl* m_messageWindow; // a textctrl to show messages (can be NULL)
|
|
|
|
wxString m_netlistFullName; // The full netlist filename
|
|
|
|
wxString m_cmplistFullName; // The full component/footprint association filename
|
|
|
|
MODULE* m_currModule; // The footprint currently being read in netlist
|
|
|
|
std::vector <MODULE_INFO*> m_newModulesList; // The list of new footprints,
|
|
|
|
// found in netlist, but not on board
|
|
|
|
// (must be loaded from libraries)
|
|
|
|
bool m_useCmpFile; // true to use .cmp files as component/footprint file link
|
|
|
|
// false to use netlist only to know component/footprint link
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool m_UseTimeStamp; // Set to true to identify footprits by time stamp
|
|
|
|
// false to use schematic reference
|
|
|
|
bool m_ChangeFootprints; // Set to true to change existing footprints to new ones
|
|
|
|
// when netlist gives a different footprint name
|
|
|
|
|
|
|
|
public: NETLIST_READER( PCB_EDIT_FRAME* aFrame, wxTextCtrl* aMessageWindow = NULL )
|
|
|
|
{
|
|
|
|
m_pcbframe = aFrame;
|
|
|
|
m_messageWindow = aMessageWindow;
|
|
|
|
m_UseTimeStamp = false;
|
|
|
|
m_ChangeFootprints = false;
|
|
|
|
m_useCmpFile = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
~NETLIST_READER()
|
|
|
|
{
|
|
|
|
// Free new modules list:
|
|
|
|
for( unsigned ii = 0; ii < m_newModulesList.size(); ii++ )
|
|
|
|
delete m_newModulesList[ii];
|
|
|
|
|
|
|
|
m_newModulesList.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function ReadNetList
|
|
|
|
* The main function to read a netlist, and update the board
|
|
|
|
* @param aFile = the already opened file (will be closed by ReadNetList)
|
|
|
|
* @param aNetlistFileName = the netlist full file name (*.net file)
|
|
|
|
* @param aCmplistFileName = the auxiliary component full file name (*.cmp file)
|
|
|
|
* If the aCmplistFileName file is not given or not found,
|
|
|
|
* the netlist is used to know the component/footprint link.
|
|
|
|
*/
|
|
|
|
bool ReadNetList( FILE* aFile, const wxString& aNetlistFileName,
|
|
|
|
const wxString& aCmplistFileName );
|
|
|
|
|
|
|
|
/**
|
2011-05-03 16:57:15 +00:00
|
|
|
* Function BuildComponentsListFromNetlist
|
|
|
|
* Fill aBufName with component references read from the netlist.
|
2011-05-03 12:57:44 +00:00
|
|
|
* @param aNetlistFilename = netlist full file name
|
2011-05-03 16:57:15 +00:00
|
|
|
* @param aBufName = wxArrayString to fill with component references
|
|
|
|
* @return the component count, or -1 if netlist file cannot opened
|
2011-05-03 12:57:44 +00:00
|
|
|
*/
|
2011-05-03 16:57:15 +00:00
|
|
|
int BuildComponentsListFromNetlist( const wxString& aNetlistFilename,
|
2011-05-03 12:57:44 +00:00
|
|
|
wxArrayString& aBufName );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* function RemoveExtraFootprints
|
|
|
|
* Remove (delete) not locked footprints found on board, but not in netlist
|
|
|
|
* @param aNetlistFileName = the netlist full file name (*.net file)
|
|
|
|
*/
|
|
|
|
void RemoveExtraFootprints( const wxString& aNetlistFileName );
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function SetPadNetName
|
|
|
|
* Update a pad netname using the current footprint
|
2011-06-07 15:29:01 +00:00
|
|
|
* from the netlist (line format: ( \<pad number\> \<net name\> ) )
|
2011-05-03 12:57:44 +00:00
|
|
|
* @param aText = current line read from netlist
|
|
|
|
*/
|
|
|
|
bool SetPadNetName( char* aText );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function ReadNetlistModuleDescr
|
|
|
|
* Read the full description of a footprint, from the netlist
|
|
|
|
* and update the corresponding module.
|
|
|
|
* @param aTstOnly bool to switch between 2 modes:
|
|
|
|
* aTstOnly = false:
|
|
|
|
* if the module does not exist, it is added to m_newModulesList
|
|
|
|
* aTstOnly = true:
|
|
|
|
* if the module does not exist, it is loaded and added to the board module list
|
|
|
|
* @param aText contains the first line of description
|
|
|
|
* This function uses m_useFichCmp as a flag to know the footprint name:
|
|
|
|
* If true: component file *.cmp is used
|
|
|
|
* If false: the netlist only is used
|
|
|
|
* This flag is reset to false if the .cmp file is not found
|
|
|
|
*/
|
|
|
|
MODULE* ReadNetlistModuleDescr( char* aText, bool aTstOnly );
|
2009-11-18 12:52:19 +00:00
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
/**
|
|
|
|
* Function loadNewModules
|
|
|
|
* Load from libraries new modules found in netlist and add them to the current Board.
|
2011-08-19 13:08:24 +00:00
|
|
|
* @return false if a footprint is not found, true if all footprints are loaded
|
2011-05-03 12:57:44 +00:00
|
|
|
*/
|
2011-08-19 13:08:24 +00:00
|
|
|
bool loadNewModules();
|
2011-05-03 12:57:44 +00:00
|
|
|
|
|
|
|
/**
|
2011-05-03 16:57:15 +00:00
|
|
|
* function readModuleComponentLinkfile
|
2011-05-03 12:57:44 +00:00
|
|
|
* read the *.cmp file ( filename in m_cmplistFullName )
|
2011-05-03 16:57:15 +00:00
|
|
|
* giving the equivalence between footprint names and components
|
|
|
|
* to find the footprint name corresponding to aCmpIdent
|
|
|
|
* @return true and the module name in aFootprintName, false if not found
|
2011-05-03 12:57:44 +00:00
|
|
|
*
|
|
|
|
* @param aCmpIdent = component identification: schematic reference or time stamp
|
2011-05-03 16:57:15 +00:00
|
|
|
* @param aFootprintName the footprint name corresponding to the component identification
|
2011-05-03 12:57:44 +00:00
|
|
|
*/
|
2011-05-03 16:57:15 +00:00
|
|
|
bool readModuleComponentLinkfile( const wxString* aCmpIdent, wxString& aFootprintName );
|
2011-05-03 12:57:44 +00:00
|
|
|
};
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function OpenNetlistFile
|
2009-04-24 07:36:36 +00:00
|
|
|
* used to open a netlist file
|
2007-08-20 19:33:15 +00:00
|
|
|
*/
|
2011-05-03 12:57:44 +00:00
|
|
|
static FILE* OpenNetlistFile( const wxString& aFullFileName )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-03-22 18:08:44 +00:00
|
|
|
if( aFullFileName.IsEmpty() )
|
2011-05-03 12:57:44 +00:00
|
|
|
return false; /* No filename: exit */
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
FILE* file = wxFopen( aFullFileName, wxT( "rt" ) );
|
|
|
|
if( file == NULL )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2008-03-22 18:08:44 +00:00
|
|
|
wxString msg;
|
2010-04-23 14:46:00 +00:00
|
|
|
msg.Printf( _( "Netlist file %s not found" ), GetChars( aFullFileName ) );
|
2011-05-03 12:57:44 +00:00
|
|
|
wxMessageBox( msg );
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
return file;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-02 16:14:07 +00:00
|
|
|
/* Function to sort the footprint list.
|
|
|
|
* the given list is sorted by name
|
2011-05-03 12:57:44 +00:00
|
|
|
*/
|
|
|
|
static bool SortByLibName( MODULE_INFO* ref, MODULE_INFO* cmp )
|
2011-04-02 16:14:07 +00:00
|
|
|
{
|
|
|
|
int ii = ref->m_LibName.CmpNoCase( cmp->m_LibName );
|
|
|
|
|
|
|
|
return ii > 0;
|
|
|
|
}
|
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function ReadPcbNetlist
|
2009-11-18 12:52:19 +00:00
|
|
|
* Update footprints (load missing footprints and delete on request extra
|
|
|
|
* footprints)
|
2009-04-24 07:36:36 +00:00
|
|
|
* Update connectivity info ( Net Name list )
|
|
|
|
* Update Reference, value and "TIME STAMP"
|
|
|
|
* @param aNetlistFullFilename = netlist file name (*.net)
|
2009-11-18 12:52:19 +00:00
|
|
|
* @param aCmpFullFileName = cmp/footprint list file name (*.cmp) if not found,
|
2011-05-03 12:57:44 +00:00
|
|
|
* @param aMessageWindow = a wxTextCtrl to print messages (can be NULL).
|
|
|
|
* @param aChangeFootprint = true to change existing footprints
|
|
|
|
* when the netlist gives a different footprint.
|
|
|
|
* false to keep existing footprints
|
|
|
|
* @param aDeleteBadTracks - true to erase erroneous tracks after updating connectivity info.
|
|
|
|
* @param aDeleteExtraFootprints - true to remove unlocked footprints found on board but not in netlist.
|
|
|
|
* @param aSelect_By_Timestamp - true to use schematic timestamps instead of schematic references
|
|
|
|
* to identify footprints on board
|
|
|
|
* (Must be used after a full reannotation in schematic).
|
2010-04-16 16:28:35 +00:00
|
|
|
* @return true if Ok
|
2007-08-20 19:33:15 +00:00
|
|
|
*/
|
2011-05-03 12:57:44 +00:00
|
|
|
bool PCB_EDIT_FRAME::ReadPcbNetlist( const wxString& aNetlistFullFilename,
|
|
|
|
const wxString& aCmpFullFileName,
|
|
|
|
wxTextCtrl* aMessageWindow,
|
|
|
|
bool aChangeFootprint,
|
|
|
|
bool aDeleteBadTracks,
|
|
|
|
bool aDeleteExtraFootprints,
|
|
|
|
bool aSelect_By_Timestamp )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-05-03 12:57:44 +00:00
|
|
|
FILE* netfile = OpenNetlistFile( aNetlistFullFilename );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2010-04-16 16:28:35 +00:00
|
|
|
if( !netfile )
|
|
|
|
return false;
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2010-04-23 14:46:00 +00:00
|
|
|
SetLastNetListRead( aNetlistFullFilename );
|
|
|
|
|
2008-03-22 18:08:44 +00:00
|
|
|
if( aMessageWindow )
|
2009-04-24 07:36:36 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
2010-04-23 14:46:00 +00:00
|
|
|
msg.Printf( _( "Reading Netlist \"%s\"" ), GetChars( aNetlistFullFilename ) );
|
2009-04-24 07:36:36 +00:00
|
|
|
aMessageWindow->AppendText( msg + wxT( "\n" ) );
|
2011-05-03 12:57:44 +00:00
|
|
|
if( ! aCmpFullFileName.IsEmpty() )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Using component/footprint link file \"%s\"" ), GetChars( aCmpFullFileName ) );
|
|
|
|
aMessageWindow->AppendText( msg + wxT( "\n" ) );
|
|
|
|
}
|
|
|
|
}
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2009-08-03 07:55:08 +00:00
|
|
|
// Clear undo and redo lists to avoid inconsistencies between lists
|
2010-04-16 16:28:35 +00:00
|
|
|
GetScreen()->ClearUndoRedoList();
|
2009-08-03 07:55:08 +00:00
|
|
|
|
2010-04-16 16:28:35 +00:00
|
|
|
OnModify();
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2011-01-20 11:26:10 +00:00
|
|
|
// Clear flags and pointeurs to avoid inconsistencies
|
2010-04-16 16:28:35 +00:00
|
|
|
GetBoard()->m_Status_Pcb = 0;
|
2011-01-20 11:26:10 +00:00
|
|
|
SetCurItem( NULL );
|
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
wxBusyCursor dummy; // Shows an hourglass while calculating
|
|
|
|
|
|
|
|
NETLIST_READER netList_Reader( this, aMessageWindow );
|
|
|
|
netList_Reader.m_UseTimeStamp = aSelect_By_Timestamp;
|
|
|
|
netList_Reader.m_ChangeFootprints = aChangeFootprint;
|
|
|
|
netList_Reader.ReadNetList( netfile, aNetlistFullFilename, aCmpFullFileName );
|
|
|
|
|
|
|
|
// Delete footprints not found in netlist:
|
|
|
|
if( aDeleteExtraFootprints )
|
|
|
|
{
|
|
|
|
netList_Reader.RemoveExtraFootprints( aNetlistFullFilename );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rebuild the board connectivity:
|
|
|
|
Compile_Ratsnest( NULL, true );
|
|
|
|
|
2011-05-03 16:57:15 +00:00
|
|
|
if( aDeleteBadTracks && GetBoard()->m_Track )
|
2011-05-03 12:57:44 +00:00
|
|
|
{
|
2011-05-03 16:57:15 +00:00
|
|
|
// Remove erroneous tracks
|
|
|
|
RemoveMisConnectedTracks( NULL );
|
|
|
|
Compile_Ratsnest( NULL, true );
|
2011-05-03 12:57:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GetBoard()->DisplayInfo( this );
|
|
|
|
DrawPanel->Refresh();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* function RemoveExtraFootprints
|
|
|
|
* Remove (delete) not locked footprints found on board, but not in netlist
|
|
|
|
*/
|
|
|
|
void NETLIST_READER::RemoveExtraFootprints( const wxString& aNetlistFileName )
|
|
|
|
{
|
2011-05-03 16:57:15 +00:00
|
|
|
wxArrayString componentsInNetlist;
|
2011-05-03 12:57:44 +00:00
|
|
|
|
|
|
|
// Build list of modules in the netlist
|
|
|
|
int modulesCount =
|
2011-05-03 16:57:15 +00:00
|
|
|
BuildComponentsListFromNetlist( aNetlistFileName, componentsInNetlist );
|
2011-05-03 12:57:44 +00:00
|
|
|
if( modulesCount == 0 )
|
|
|
|
return;
|
|
|
|
|
2011-05-03 16:57:15 +00:00
|
|
|
MODULE* nextModule;
|
|
|
|
MODULE* module = m_pcbframe->GetBoard()->m_Modules;
|
2011-05-03 12:57:44 +00:00
|
|
|
bool ask_user = true;
|
2011-05-03 16:57:15 +00:00
|
|
|
for( ; module != NULL; module = nextModule )
|
2011-05-03 12:57:44 +00:00
|
|
|
{
|
|
|
|
int ii;
|
2011-05-03 16:57:15 +00:00
|
|
|
nextModule = module->Next();
|
|
|
|
if( module->m_ModuleStatus & MODULE_is_LOCKED )
|
2011-05-03 12:57:44 +00:00
|
|
|
continue;
|
|
|
|
for( ii = 0; ii < modulesCount; ii++ )
|
|
|
|
{
|
2011-05-03 16:57:15 +00:00
|
|
|
if( module->m_Reference->m_Text.CmpNoCase( componentsInNetlist[ii] ) == 0 )
|
2011-05-03 12:57:44 +00:00
|
|
|
break; /* Module is found in net list. */
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ii == modulesCount ) // Module not found in netlist.
|
|
|
|
{
|
|
|
|
if( ask_user )
|
|
|
|
{
|
|
|
|
ask_user = false;
|
|
|
|
if( !IsOK( NULL,
|
|
|
|
_( "Ok to delete not locked footprints not found in netlist?" ) ) )
|
|
|
|
break;
|
|
|
|
}
|
2011-05-03 16:57:15 +00:00
|
|
|
module->DeleteStructure();
|
2011-05-03 12:57:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function ReadNetlist
|
|
|
|
* Update footprints (load missing footprints and delete on request extra
|
|
|
|
* footprints)
|
|
|
|
* Update References, values, "TIME STAMP" and connectivity data
|
|
|
|
* return true if Ok
|
|
|
|
*
|
|
|
|
* the format of the netlist is something like:
|
|
|
|
* # EESchema Netlist Version 1.0 generee le 18/5/2005-12:30:22
|
|
|
|
* (
|
|
|
|
* ( 40C08647 $noname R20 4,7K {Lib=R}
|
|
|
|
* ( 1 VCC )
|
|
|
|
* ( 2 MODB_1 )
|
|
|
|
* )
|
|
|
|
* ( 40C0863F $noname R18 4,7_k {Lib=R}
|
|
|
|
* ( 1 VCC )
|
|
|
|
* ( 2 MODA_1 )
|
|
|
|
* )
|
|
|
|
* }
|
|
|
|
* #End
|
|
|
|
*/
|
|
|
|
bool NETLIST_READER::ReadNetList( FILE* aFile,
|
|
|
|
const wxString& aNetlistFileName,
|
|
|
|
const wxString& aCmplistFileName )
|
|
|
|
{
|
2011-05-03 16:57:15 +00:00
|
|
|
int state = 0;
|
|
|
|
bool is_comment = false;
|
2011-05-03 12:57:44 +00:00
|
|
|
|
|
|
|
m_netlistFullName = aNetlistFileName;
|
|
|
|
m_cmplistFullName = aCmplistFileName;
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
m_useCmpFile = true;
|
2008-03-22 18:08:44 +00:00
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
/* First, read the netlist: Build the list of footprints to load (new
|
|
|
|
* footprints)
|
2007-08-20 19:33:15 +00:00
|
|
|
*/
|
2011-05-03 12:57:44 +00:00
|
|
|
FILE_LINE_READER netlineReader( aFile, m_netlistFullName ); // netlineReader dtor will close aFile
|
|
|
|
while( netlineReader.ReadLine() )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-05-03 12:57:44 +00:00
|
|
|
char* line = StrPurge( netlineReader.Line() );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2011-05-03 16:57:15 +00:00
|
|
|
if( is_comment ) /* Comments in progress */
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-04-02 16:14:07 +00:00
|
|
|
// Test for end of the current comment
|
2011-05-03 12:57:44 +00:00
|
|
|
if( ( line = strchr( line, '}' ) ) == NULL )
|
2007-08-20 19:33:15 +00:00
|
|
|
continue;
|
2011-05-03 16:57:15 +00:00
|
|
|
is_comment = false;
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
2011-05-03 12:57:44 +00:00
|
|
|
if( *line == '{' ) /* Start Comment */
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-05-03 16:57:15 +00:00
|
|
|
is_comment = true;
|
2011-05-03 12:57:44 +00:00
|
|
|
if( ( line = strchr( line, '}' ) ) == NULL )
|
2007-08-20 19:33:15 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
if( *line == '(' )
|
2011-05-03 16:57:15 +00:00
|
|
|
state++;
|
2008-02-19 00:28:42 +00:00
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
if( *line == ')' )
|
2011-05-03 16:57:15 +00:00
|
|
|
state--;
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2011-05-03 16:57:15 +00:00
|
|
|
if( state == 2 )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-05-03 12:57:44 +00:00
|
|
|
ReadNetlistModuleDescr( line, TESTONLY );
|
2007-08-20 19:33:15 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-05-03 16:57:15 +00:00
|
|
|
if( state >= 3 ) // First pass: pad descriptions are not read here.
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-05-03 16:57:15 +00:00
|
|
|
state--;
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-22 18:08:44 +00:00
|
|
|
/* Load new footprints */
|
2011-08-19 13:08:24 +00:00
|
|
|
bool success = loadNewModules();
|
|
|
|
if( ! success )
|
|
|
|
wxMessageBox( _("Some footprints are not found in libraries") );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2011-04-02 16:14:07 +00:00
|
|
|
/* Second read , All footprints are on board.
|
|
|
|
* One must update the schematic info (pad netnames)
|
|
|
|
*/
|
2011-05-03 12:57:44 +00:00
|
|
|
netlineReader.Rewind();
|
|
|
|
m_currModule = NULL;
|
2011-05-03 16:57:15 +00:00
|
|
|
state = 0;
|
|
|
|
is_comment = false;
|
2011-05-03 12:57:44 +00:00
|
|
|
while( netlineReader.ReadLine() )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-05-03 12:57:44 +00:00
|
|
|
char* line = StrPurge( netlineReader.Line() );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2011-05-03 16:57:15 +00:00
|
|
|
if( is_comment ) // we are reading a comment
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-04-02 16:14:07 +00:00
|
|
|
// Test for end of the current comment
|
2011-05-03 12:57:44 +00:00
|
|
|
if( ( line = strchr( line, '}' ) ) == NULL )
|
2007-08-20 19:33:15 +00:00
|
|
|
continue;
|
2011-05-03 16:57:15 +00:00
|
|
|
is_comment = false;
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
2011-05-03 12:57:44 +00:00
|
|
|
if( *line == '{' ) // this is the beginning of a comment
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-05-03 16:57:15 +00:00
|
|
|
is_comment = true;
|
2011-05-03 12:57:44 +00:00
|
|
|
if( ( line = strchr( line, '}' ) ) == NULL )
|
2007-08-20 19:33:15 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
if( *line == '(' )
|
2011-05-03 16:57:15 +00:00
|
|
|
state++;
|
2011-05-03 12:57:44 +00:00
|
|
|
if( *line == ')' )
|
2011-05-03 16:57:15 +00:00
|
|
|
state--;
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2011-05-03 16:57:15 +00:00
|
|
|
if( state == 2 )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-05-03 12:57:44 +00:00
|
|
|
m_currModule = ReadNetlistModuleDescr( line, READMODULE );
|
|
|
|
if( m_currModule == NULL ) // the module could not be created (perhaps
|
|
|
|
// footprint not found in library)
|
2007-08-20 19:33:15 +00:00
|
|
|
continue;
|
2009-04-24 07:36:36 +00:00
|
|
|
else /* clear pads netnames */
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-05-03 16:57:15 +00:00
|
|
|
D_PAD* pad = m_currModule->m_Pads;
|
|
|
|
for( ; pad != NULL; pad = pad->Next() )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-05-03 16:57:15 +00:00
|
|
|
pad->SetNetname( wxEmptyString );
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-05-03 16:57:15 +00:00
|
|
|
if( state >= 3 )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-05-03 12:57:44 +00:00
|
|
|
if( m_currModule )
|
|
|
|
SetPadNetName( line );
|
2011-05-03 16:57:15 +00:00
|
|
|
state--;
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-16 16:28:35 +00:00
|
|
|
return true;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
/* Function ReadNetlistModuleDescr
|
|
|
|
* Read the full description of a footprint, from the netlist
|
2009-11-18 12:52:19 +00:00
|
|
|
* and update the corresponding module.
|
2011-05-03 12:57:44 +00:00
|
|
|
* param aTstOnly bool to switch between 2 modes:
|
|
|
|
* If aTstOnly == false:
|
|
|
|
* if the module does not exist, it is added to m_newModulesList
|
|
|
|
* If aTstOnly = true:
|
|
|
|
* if the module does not exist, it is loaded and added to the board module list
|
|
|
|
* param aText contains the first line of description
|
|
|
|
* This function uses m_useFichCmp as a flag to know the footprint name:
|
|
|
|
* If true: component file *.cmp is used
|
|
|
|
* If false: the netlist only is used
|
|
|
|
* This flag is reset to false if the .cmp file is not found
|
2009-11-18 12:52:19 +00:00
|
|
|
* Analyze lines like:
|
2011-05-03 16:57:15 +00:00
|
|
|
* ( /40C08647 $noname R20 4.7K {Lib=R}
|
2009-11-18 12:52:19 +00:00
|
|
|
* (1 VCC)
|
|
|
|
* (2 MODB_1)
|
2011-05-03 16:57:15 +00:00
|
|
|
* )
|
2009-11-18 12:52:19 +00:00
|
|
|
*/
|
2011-05-03 12:57:44 +00:00
|
|
|
MODULE* NETLIST_READER::ReadNetlistModuleDescr( char* aText, bool aTstOnly )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-04-24 07:36:36 +00:00
|
|
|
char* text;
|
2011-05-03 16:57:15 +00:00
|
|
|
wxString timeStampPath; // the full time stamp read from netlist
|
|
|
|
wxString textFootprintName; // the footprint name read from netlist
|
|
|
|
wxString textValue; // the component value read from netlist
|
|
|
|
wxString textCmpReference; // the component schematic reference read from netlist
|
|
|
|
wxString cmpFootprintName; // the footprint name read from the *.cmp file
|
|
|
|
// giving the equivalence between footprint names and components
|
|
|
|
bool error = false;
|
|
|
|
char line[1024];
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2011-05-03 16:57:15 +00:00
|
|
|
strcpy( line, aText );
|
|
|
|
|
|
|
|
textValue = wxT( "~" );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2011-05-03 16:57:15 +00:00
|
|
|
// Read descr line like /40C08647 $noname R20 4.7K {Lib=R}
|
2008-02-19 00:28:42 +00:00
|
|
|
|
2011-05-03 16:57:15 +00:00
|
|
|
// Read time stamp (first word)
|
|
|
|
if( ( text = strtok( line, " ()\t\n" ) ) == NULL )
|
|
|
|
error = true;
|
2007-08-20 19:33:15 +00:00
|
|
|
else
|
2011-05-03 16:57:15 +00:00
|
|
|
timeStampPath = FROM_UTF8( text );
|
2008-02-19 00:28:42 +00:00
|
|
|
|
2011-05-03 16:57:15 +00:00
|
|
|
// Read footprint name (second word)
|
2007-08-20 19:33:15 +00:00
|
|
|
if( ( text = strtok( NULL, " ()\t\n" ) ) == NULL )
|
2011-05-03 16:57:15 +00:00
|
|
|
error = true;
|
2007-08-20 19:33:15 +00:00
|
|
|
else
|
2011-05-03 16:57:15 +00:00
|
|
|
textFootprintName = FROM_UTF8( text );
|
2008-02-19 00:28:42 +00:00
|
|
|
|
2011-05-03 16:57:15 +00:00
|
|
|
// Read schematic reference (third word)
|
2007-08-20 19:33:15 +00:00
|
|
|
if( ( text = strtok( NULL, " ()\t\n" ) ) == NULL )
|
2011-05-03 16:57:15 +00:00
|
|
|
error = true;
|
2007-08-20 19:33:15 +00:00
|
|
|
else
|
2011-05-03 16:57:15 +00:00
|
|
|
textCmpReference = FROM_UTF8( text );
|
2008-02-19 00:28:42 +00:00
|
|
|
|
2011-05-03 16:57:15 +00:00
|
|
|
// Read schematic value (forth word)
|
2007-08-20 19:33:15 +00:00
|
|
|
if( ( text = strtok( NULL, " ()\t\n" ) ) == NULL )
|
2011-05-03 16:57:15 +00:00
|
|
|
error = true;
|
2007-08-20 19:33:15 +00:00
|
|
|
else
|
2011-05-03 16:57:15 +00:00
|
|
|
textValue = FROM_UTF8( text );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2011-05-03 16:57:15 +00:00
|
|
|
if( error )
|
2007-08-20 19:33:15 +00:00
|
|
|
return NULL;
|
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
/* Test if module is already loaded. */
|
2011-05-03 16:57:15 +00:00
|
|
|
wxString * identMod = &textCmpReference;
|
2011-05-03 12:57:44 +00:00
|
|
|
if( m_UseTimeStamp )
|
2011-05-03 16:57:15 +00:00
|
|
|
identMod = &timeStampPath;
|
2009-04-24 07:36:36 +00:00
|
|
|
|
2011-05-03 16:57:15 +00:00
|
|
|
MODULE* module = m_pcbframe->GetBoard()->m_Modules;
|
|
|
|
MODULE* nextModule;
|
2011-05-03 12:57:44 +00:00
|
|
|
bool found = false;
|
2011-05-03 16:57:15 +00:00
|
|
|
for( ; module != NULL; module = nextModule )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-05-03 16:57:15 +00:00
|
|
|
nextModule = module->Next();
|
2011-05-03 12:57:44 +00:00
|
|
|
if( m_UseTimeStamp ) /* identification by time stamp */
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-05-03 16:57:15 +00:00
|
|
|
if( timeStampPath.CmpNoCase( module->m_Path ) == 0 )
|
2011-05-03 12:57:44 +00:00
|
|
|
found = true;
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
2009-04-24 07:36:36 +00:00
|
|
|
else /* identification by Reference */
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-05-03 16:57:15 +00:00
|
|
|
if( textCmpReference.CmpNoCase( module->m_Reference->m_Text ) == 0 )
|
2011-05-03 12:57:44 +00:00
|
|
|
found = true;
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
2011-05-03 16:57:15 +00:00
|
|
|
if( found ) // The footprint corresponding to the component is already on board
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-05-05 17:45:35 +00:00
|
|
|
// This footprint is already on board
|
|
|
|
// but if m_LibRef (existing footprint name) and the footprint name from netlist
|
|
|
|
// do not match, change this footprint on demand.
|
|
|
|
if( ! aTstOnly )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-05-03 16:57:15 +00:00
|
|
|
cmpFootprintName = textFootprintName; // Use footprint name from netlist
|
|
|
|
if( m_useCmpFile ) // Try to get footprint name from .cmp file
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-05-03 16:57:15 +00:00
|
|
|
m_useCmpFile = readModuleComponentLinkfile( identMod, cmpFootprintName );
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
2009-11-18 12:52:19 +00:00
|
|
|
|
2011-05-03 16:57:15 +00:00
|
|
|
/* Module mismatch: current fotprint and footprint specified in
|
|
|
|
* net list are different.
|
2009-11-18 12:52:19 +00:00
|
|
|
*/
|
2011-05-03 16:57:15 +00:00
|
|
|
if( module->m_LibRef.CmpNoCase( cmpFootprintName ) != 0 )
|
2009-04-24 07:36:36 +00:00
|
|
|
{
|
2011-05-03 12:57:44 +00:00
|
|
|
if( m_ChangeFootprints ) // footprint exchange allowed.
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-05-03 16:57:15 +00:00
|
|
|
MODULE* newModule =
|
2011-05-03 12:57:44 +00:00
|
|
|
m_pcbframe->Get_Librairie_Module( wxEmptyString,
|
2011-05-03 16:57:15 +00:00
|
|
|
cmpFootprintName,
|
2011-05-03 12:57:44 +00:00
|
|
|
true );
|
2011-05-03 16:57:15 +00:00
|
|
|
if( newModule )
|
2009-08-06 07:11:04 +00:00
|
|
|
{
|
2011-05-03 16:57:15 +00:00
|
|
|
// Change old module to the new module (and delete the old one)
|
|
|
|
m_pcbframe->Exchange_Module( module, newModule, NULL );
|
|
|
|
module = newModule;
|
2009-08-06 07:11:04 +00:00
|
|
|
}
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxString msg;
|
2011-05-03 12:57:44 +00:00
|
|
|
msg.Printf(
|
|
|
|
_(
|
|
|
|
"Component \"%s\": Mismatch! module is [%s] and netlist said [%s]\n" ),
|
2011-05-03 16:57:15 +00:00
|
|
|
GetChars( textCmpReference ),
|
|
|
|
GetChars( module->m_LibRef ),
|
|
|
|
GetChars( cmpFootprintName ) );
|
2011-05-03 12:57:44 +00:00
|
|
|
|
|
|
|
if( m_messageWindow )
|
|
|
|
m_messageWindow->AppendText( msg );
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-11-18 12:52:19 +00:00
|
|
|
|
2007-08-20 19:33:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-03 16:57:15 +00:00
|
|
|
if( module == NULL ) // a new module must be loaded from libs
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-05-03 16:57:15 +00:00
|
|
|
cmpFootprintName = textFootprintName; // Use footprint name from netlist
|
|
|
|
if( m_useCmpFile ) // Try to get footprint name from .cmp file
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-05-03 16:57:15 +00:00
|
|
|
m_useCmpFile = readModuleComponentLinkfile( identMod, cmpFootprintName );
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
|
2011-05-05 17:45:35 +00:00
|
|
|
if( aTstOnly )
|
2011-04-02 16:14:07 +00:00
|
|
|
{
|
2011-05-03 12:57:44 +00:00
|
|
|
MODULE_INFO* newMod;
|
2011-05-03 16:57:15 +00:00
|
|
|
newMod = new MODULE_INFO( cmpFootprintName, textCmpReference, timeStampPath );
|
2011-05-03 12:57:44 +00:00
|
|
|
m_newModulesList.push_back( newMod );
|
2011-04-02 16:14:07 +00:00
|
|
|
}
|
2007-08-20 19:33:15 +00:00
|
|
|
else
|
|
|
|
{
|
2011-05-03 12:57:44 +00:00
|
|
|
if( m_messageWindow )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2008-03-22 18:08:44 +00:00
|
|
|
wxString msg;
|
2009-11-18 12:52:19 +00:00
|
|
|
msg.Printf( _( "Component [%s] not found" ),
|
2011-05-03 16:57:15 +00:00
|
|
|
GetChars( textCmpReference ) );
|
2011-05-03 12:57:44 +00:00
|
|
|
m_messageWindow->AppendText( msg + wxT( "\n" ) );
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
}
|
2011-05-03 16:57:15 +00:00
|
|
|
return NULL; // The module could not be loaded.
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
|
2011-05-03 16:57:15 +00:00
|
|
|
// Update current module ( reference, value and "Time Stamp")
|
|
|
|
module->m_Reference->m_Text = textCmpReference;
|
|
|
|
module->m_Value->m_Text = textValue;
|
|
|
|
module->m_Path = timeStampPath;
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2011-05-03 16:57:15 +00:00
|
|
|
return module;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
/*
|
2010-11-12 16:36:43 +00:00
|
|
|
* Function SetPadNetName
|
2011-05-03 12:57:44 +00:00
|
|
|
* Update a pad netname using the current footprint
|
|
|
|
* Line format: ( <pad number> <net name> )
|
|
|
|
* Param aText = current line read from netlist
|
2007-08-20 19:33:15 +00:00
|
|
|
*/
|
2011-05-03 12:57:44 +00:00
|
|
|
bool NETLIST_READER::SetPadNetName( char* aText )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-05-03 12:57:44 +00:00
|
|
|
D_PAD* pad;
|
|
|
|
char* TextPinName, * TextNetName;
|
|
|
|
bool found;
|
|
|
|
bool error = false;
|
|
|
|
char Line[256];
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
if( m_currModule == NULL )
|
|
|
|
return false;
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
strcpy( Line, aText );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
|
|
|
if( ( TextPinName = strtok( Line, " ()\t\n" ) ) == NULL )
|
2011-05-03 12:57:44 +00:00
|
|
|
error = true;
|
2007-08-20 19:33:15 +00:00
|
|
|
if( ( TextNetName = strtok( NULL, " ()\t\n" ) ) == NULL )
|
2011-05-03 12:57:44 +00:00
|
|
|
error = true;
|
|
|
|
if( error )
|
2007-08-20 19:33:15 +00:00
|
|
|
return 0;
|
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
pad = m_currModule->m_Pads;
|
|
|
|
found = false;
|
|
|
|
for( ; pad != NULL; pad = pad->Next() )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2009-11-18 12:52:19 +00:00
|
|
|
if( strnicmp( TextPinName, pad->m_Padname, 4 ) == 0 )
|
2009-04-24 07:36:36 +00:00
|
|
|
{
|
2011-05-03 12:57:44 +00:00
|
|
|
found = true;
|
2007-08-20 19:33:15 +00:00
|
|
|
if( *TextNetName != '?' )
|
2011-02-28 18:36:19 +00:00
|
|
|
pad->SetNetname( FROM_UTF8( TextNetName ) );
|
2007-08-20 19:33:15 +00:00
|
|
|
else
|
2009-04-24 07:36:36 +00:00
|
|
|
pad->SetNetname( wxEmptyString );
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
if( !found )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-05-03 12:57:44 +00:00
|
|
|
if( m_messageWindow )
|
2009-04-24 07:36:36 +00:00
|
|
|
{
|
2011-05-03 12:57:44 +00:00
|
|
|
wxString msg;
|
2011-02-28 18:36:19 +00:00
|
|
|
wxString pin_name = FROM_UTF8( TextPinName );
|
2011-05-03 12:57:44 +00:00
|
|
|
msg.Printf( _( "Module [%s]: Pad [%s] not found" ),
|
|
|
|
GetChars( m_currModule->m_Reference->m_Text ),
|
|
|
|
GetChars( pin_name ) );
|
|
|
|
m_messageWindow->AppendText( msg + wxT( "\n" ) );
|
2009-04-24 07:36:36 +00:00
|
|
|
}
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
return found;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-24 07:36:36 +00:00
|
|
|
/**
|
|
|
|
* build and shows a list of existing modules on board
|
2009-11-18 12:52:19 +00:00
|
|
|
* The user can select a module from this list
|
2009-04-24 07:36:36 +00:00
|
|
|
* @return a pointer to the selected module or NULL
|
2007-08-20 19:33:15 +00:00
|
|
|
*/
|
2011-03-01 19:26:17 +00:00
|
|
|
MODULE* PCB_EDIT_FRAME::ListAndSelectModuleName( void )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-04-24 07:36:36 +00:00
|
|
|
MODULE* Module;
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
if( GetBoard()->m_Modules == NULL )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2010-11-19 18:50:23 +00:00
|
|
|
DisplayError( this, _( "No Modules" ) );
|
|
|
|
return 0;
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
|
2010-11-19 18:50:23 +00:00
|
|
|
wxArrayString listnames;
|
2009-04-24 07:36:36 +00:00
|
|
|
Module = (MODULE*) GetBoard()->m_Modules;
|
2008-11-24 06:53:43 +00:00
|
|
|
for( ; Module != NULL; Module = (MODULE*) Module->Next() )
|
2010-11-19 18:50:23 +00:00
|
|
|
listnames.Add( Module->m_Reference->m_Text );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2011-09-06 19:42:46 +00:00
|
|
|
EDA_LIST_DIALOG dlg( this, _( "Components" ), listnames, wxEmptyString );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2010-11-19 18:50:23 +00:00
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
wxString ref = dlg.GetTextSelection();
|
|
|
|
Module = (MODULE*) GetBoard()->m_Modules;
|
2011-09-06 19:42:46 +00:00
|
|
|
|
2010-11-19 18:50:23 +00:00
|
|
|
for( ; Module != NULL; Module = Module->Next() )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2010-11-19 18:50:23 +00:00
|
|
|
if( Module->m_Reference->m_Text == ref )
|
|
|
|
break;
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return Module;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
/*
|
|
|
|
* Function Test_Duplicate_Missing_And_Extra_Footprints
|
|
|
|
* Build a list of duplicate, missing and extra footprints
|
|
|
|
* from the current board and a netlist netlist :
|
|
|
|
* Shows 3 lists:
|
|
|
|
* 1 - duplicate footprints on board
|
|
|
|
* 2 - missing footprints (found in netlist but not on board)
|
|
|
|
* 3 - footprints not in netlist but on board
|
|
|
|
* @param aNetlistFullFilename = the full filename netlist
|
2007-08-20 19:33:15 +00:00
|
|
|
*/
|
2011-05-03 12:57:44 +00:00
|
|
|
void PCB_EDIT_FRAME::Test_Duplicate_Missing_And_Extra_Footprints(
|
|
|
|
const wxString& aNetlistFullFilename )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-05-03 12:57:44 +00:00
|
|
|
#define MAX_LEN_TXT 32
|
|
|
|
int ii;
|
|
|
|
int NbModulesNetListe, nberr = 0;
|
2011-04-19 14:28:34 +00:00
|
|
|
wxArrayString tmp;
|
|
|
|
wxArrayString list;
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
if( GetBoard()->m_Modules == NULL )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-05-03 12:57:44 +00:00
|
|
|
DisplayInfoMessage( this, _( "No modules" ) );
|
2009-11-18 12:52:19 +00:00
|
|
|
return;
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
/* Build the list of references of the net list modules. */
|
2011-05-03 12:57:44 +00:00
|
|
|
NETLIST_READER netList_Reader( this );
|
2011-05-03 16:57:15 +00:00
|
|
|
NbModulesNetListe = netList_Reader.BuildComponentsListFromNetlist( aNetlistFullFilename, tmp );
|
2011-04-19 14:28:34 +00:00
|
|
|
|
2007-08-20 19:33:15 +00:00
|
|
|
if( NbModulesNetListe < 0 )
|
2009-11-18 12:52:19 +00:00
|
|
|
return; /* File not found */
|
2007-08-20 19:33:15 +00:00
|
|
|
|
|
|
|
if( NbModulesNetListe == 0 )
|
|
|
|
{
|
2011-05-03 12:57:44 +00:00
|
|
|
wxMessageBox( _( "No modules in NetList" ) );
|
2009-11-18 12:52:19 +00:00
|
|
|
return;
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
/* Search for duplicate footprints. */
|
2011-04-19 14:28:34 +00:00
|
|
|
list.Add( _( "Duplicates" ) );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2011-05-05 17:45:35 +00:00
|
|
|
MODULE* module = GetBoard()->m_Modules;
|
|
|
|
for( ; module != NULL; module = module->Next() )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-05-05 17:45:35 +00:00
|
|
|
MODULE* altmodule = module->Next();
|
2011-04-19 14:28:34 +00:00
|
|
|
|
2011-05-05 17:45:35 +00:00
|
|
|
for( ; altmodule != NULL; altmodule = altmodule->Next() )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-05-05 17:45:35 +00:00
|
|
|
if( module->m_Reference->m_Text.CmpNoCase( altmodule->m_Reference->m_Text ) == 0 )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-05-05 17:45:35 +00:00
|
|
|
if( module->m_Reference->m_Text.IsEmpty() )
|
|
|
|
list.Add( wxT("<noref>") );
|
|
|
|
else
|
|
|
|
list.Add( module->m_Reference->m_Text );
|
2007-08-20 19:33:15 +00:00
|
|
|
nberr++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
/* Search for the missing module by the net list. */
|
2011-04-19 14:28:34 +00:00
|
|
|
list.Add( _( "Missing:" ) );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
|
|
|
for( ii = 0; ii < NbModulesNetListe; ii++ )
|
|
|
|
{
|
2011-05-05 17:45:35 +00:00
|
|
|
module = (MODULE*) GetBoard()->m_Modules;
|
2011-04-19 14:28:34 +00:00
|
|
|
|
2011-05-05 17:45:35 +00:00
|
|
|
for( ; module != NULL; module = module->Next() )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-05-05 17:45:35 +00:00
|
|
|
if( module->m_Reference->m_Text.CmpNoCase( tmp[ii] ) == 0 )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-05 17:45:35 +00:00
|
|
|
if( module == NULL ) // Module missing, not found in board
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-04-19 14:28:34 +00:00
|
|
|
list.Add( tmp[ii] );
|
2007-08-20 19:33:15 +00:00
|
|
|
nberr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
/* Search for modules not in net list. */
|
2011-04-19 14:28:34 +00:00
|
|
|
list.Add( _( "Not in Netlist:" ) );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2011-05-05 17:45:35 +00:00
|
|
|
module = GetBoard()->m_Modules;
|
|
|
|
for( ; module != NULL; module = module->Next() )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
|
|
|
for( ii = 0; ii < NbModulesNetListe; ii++ )
|
|
|
|
{
|
2011-05-05 17:45:35 +00:00
|
|
|
if( module->m_Reference->m_Text.CmpNoCase( tmp[ii] ) == 0 )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2009-11-18 12:52:19 +00:00
|
|
|
break; /* Module is in net list. */
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ii == NbModulesNetListe ) /* Module not found in netlist */
|
|
|
|
{
|
2011-05-05 17:45:35 +00:00
|
|
|
list.Add( module->m_Reference->m_Text );
|
2007-08-20 19:33:15 +00:00
|
|
|
nberr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
wxSingleChoiceDialog dlg( this, wxEmptyString, _( "Check Modules" ), list, NULL,
|
2011-04-19 14:28:34 +00:00
|
|
|
wxCHOICEDLG_STYLE & ~wxCANCEL );
|
|
|
|
|
|
|
|
dlg.ShowModal();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
2011-05-03 16:57:15 +00:00
|
|
|
* Function BuildComponentsListFromNetlist
|
|
|
|
* Fill aBufName with component references read from the netlist.
|
2011-05-03 12:57:44 +00:00
|
|
|
* @param aNetlistFilename = netlist full file name
|
2011-05-03 16:57:15 +00:00
|
|
|
* @param aBufName = wxArrayString to fill with component references
|
|
|
|
* @return component count, or -1 if netlist file cannot opened
|
2007-08-20 19:33:15 +00:00
|
|
|
*/
|
2011-05-03 16:57:15 +00:00
|
|
|
int NETLIST_READER::BuildComponentsListFromNetlist( const wxString& aNetlistFilename,
|
2011-05-13 13:15:28 +00:00
|
|
|
wxArrayString& aBufName )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-05-03 16:57:15 +00:00
|
|
|
int component_count;
|
|
|
|
int state;
|
|
|
|
bool is_comment;
|
|
|
|
char* text;
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
FILE* netfile = OpenNetlistFile( aNetlistFilename );
|
|
|
|
|
|
|
|
if( netfile == NULL )
|
2007-08-20 19:33:15 +00:00
|
|
|
return -1;
|
|
|
|
|
2011-05-03 16:57:15 +00:00
|
|
|
FILE_LINE_READER netlineReader( netfile, aNetlistFilename ); // ctor will close netfile
|
2011-05-03 12:57:44 +00:00
|
|
|
char* Line = netlineReader;
|
2010-04-16 16:28:35 +00:00
|
|
|
|
2011-05-03 16:57:15 +00:00
|
|
|
state = 0;
|
|
|
|
is_comment = false;
|
|
|
|
component_count = 0;
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
while( netlineReader.ReadLine() )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-05-03 16:57:15 +00:00
|
|
|
text = StrPurge( Line );
|
|
|
|
if( is_comment )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-05-03 16:57:15 +00:00
|
|
|
if( ( text = strchr( text, '}' ) ) == NULL )
|
2007-08-20 19:33:15 +00:00
|
|
|
continue;
|
2011-05-03 16:57:15 +00:00
|
|
|
is_comment = false;
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
2011-05-03 16:57:15 +00:00
|
|
|
if( *text == '{' ) /* Comments. */
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-05-03 16:57:15 +00:00
|
|
|
is_comment = true;
|
|
|
|
if( ( text = strchr( text, '}' ) ) == NULL )
|
2007-08-20 19:33:15 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-05-03 16:57:15 +00:00
|
|
|
if( *text == '(' )
|
|
|
|
state++;
|
|
|
|
if( *text == ')' )
|
|
|
|
state--;
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2011-05-03 16:57:15 +00:00
|
|
|
if( state == 2 )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-05-03 16:57:15 +00:00
|
|
|
// skip TimeStamp:
|
2011-05-13 13:15:28 +00:00
|
|
|
strtok( Line, " ()\t\n" );
|
|
|
|
|
2011-05-03 16:57:15 +00:00
|
|
|
// skip footprint name:
|
2011-05-13 13:15:28 +00:00
|
|
|
strtok( NULL, " ()\t\n" );
|
|
|
|
|
2011-05-03 16:57:15 +00:00
|
|
|
// Load the reference of the component:
|
2011-05-13 13:15:28 +00:00
|
|
|
text = strtok( NULL, " ()\t\n" );
|
2011-05-03 16:57:15 +00:00
|
|
|
component_count++;
|
|
|
|
aBufName.Add( FROM_UTF8( text ) );
|
2007-08-20 19:33:15 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-05-03 16:57:15 +00:00
|
|
|
if( state >= 3 )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-05-03 16:57:15 +00:00
|
|
|
state--;
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-03 16:57:15 +00:00
|
|
|
return component_count;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2011-05-03 16:57:15 +00:00
|
|
|
* function readModuleComponentLinkfile
|
2011-05-03 12:57:44 +00:00
|
|
|
* read the *.cmp file ( filename in m_cmplistFullName )
|
2011-05-03 16:57:15 +00:00
|
|
|
* giving the equivalence Footprint_names / components
|
|
|
|
* to find the footprint name corresponding to aCmpIdent
|
|
|
|
* return true and the module name in aFootprintName, false if not found
|
2008-02-19 00:28:42 +00:00
|
|
|
*
|
2011-05-03 12:57:44 +00:00
|
|
|
* param aCmpIdent = component identification: schematic reference or time stamp
|
2011-05-03 16:57:15 +00:00
|
|
|
* param aFootprintName the footprint name corresponding to the component identification
|
|
|
|
*
|
|
|
|
* Sample file:
|
2008-02-19 00:28:42 +00:00
|
|
|
*
|
2009-11-18 12:52:19 +00:00
|
|
|
* Cmp-Mod V01 Genere by Pcbnew 29/10/2003-13: 11:6 *
|
2007-08-20 19:33:15 +00:00
|
|
|
* BeginCmp
|
2009-04-24 07:36:36 +00:00
|
|
|
* TimeStamp = /322D3011;
|
2007-08-20 19:33:15 +00:00
|
|
|
* Reference = BUS1;
|
|
|
|
* ValeurCmp = BUSPC;
|
|
|
|
* IdModule = BUS_PC;
|
|
|
|
* EndCmp
|
2008-02-19 00:28:42 +00:00
|
|
|
*
|
2007-08-20 19:33:15 +00:00
|
|
|
* BeginCmp
|
2009-04-24 07:36:36 +00:00
|
|
|
* TimeStamp = /32307DE2/AA450F67;
|
2007-08-20 19:33:15 +00:00
|
|
|
* Reference = C1;
|
|
|
|
* ValeurCmp = 47uF;
|
|
|
|
* IdModule = CP6;
|
|
|
|
* EndCmp
|
2008-02-19 00:28:42 +00:00
|
|
|
*
|
2007-08-20 19:33:15 +00:00
|
|
|
*/
|
2011-05-03 16:57:15 +00:00
|
|
|
bool NETLIST_READER::readModuleComponentLinkfile( const wxString* aCmpIdent,
|
|
|
|
wxString& aFootprintName )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-05-03 12:57:44 +00:00
|
|
|
wxString refcurrcmp; // Stores value read from line like Reference = BUS1;
|
|
|
|
wxString timestamp; // Stores value read from line like TimeStamp = /32307DE2/AA450F67;
|
|
|
|
wxString idmod; // Stores value read from line like IdModule = CP6;
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
FILE* cmpFile = wxFopen( m_cmplistFullName, wxT( "rt" ) );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
if( cmpFile == NULL )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "File <%s> not found, use Netlist for lib module selection" ),
|
2011-05-03 12:57:44 +00:00
|
|
|
GetChars( m_cmplistFullName ) );
|
2008-03-22 18:08:44 +00:00
|
|
|
DisplayError( NULL, msg, 20 );
|
2011-05-03 12:57:44 +00:00
|
|
|
return false;
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
FILE_LINE_READER netlineReader( cmpFile, m_cmplistFullName ); // netlineReader dtor will close cmpFile
|
|
|
|
wxString buffer;
|
|
|
|
wxString value;
|
|
|
|
while( netlineReader.ReadLine() )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-05-03 12:57:44 +00:00
|
|
|
buffer = FROM_UTF8( netlineReader.Line() );
|
|
|
|
if( ! buffer.StartsWith( wxT("BeginCmp") ) )
|
2007-08-20 19:33:15 +00:00
|
|
|
continue;
|
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
/* Begin component description. */
|
2007-08-20 19:33:15 +00:00
|
|
|
refcurrcmp.Empty();
|
|
|
|
idmod.Empty();
|
2009-04-24 07:36:36 +00:00
|
|
|
timestamp.Empty();
|
2011-05-03 12:57:44 +00:00
|
|
|
while( netlineReader.ReadLine() )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-05-03 12:57:44 +00:00
|
|
|
buffer = FROM_UTF8( netlineReader.Line() );
|
|
|
|
if( buffer.StartsWith( wxT("EndCmp") ) )
|
2007-08-20 19:33:15 +00:00
|
|
|
break;
|
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
// store string value, stored between '=' and ';' delimiters.
|
|
|
|
value = buffer.AfterFirst( '=' );
|
|
|
|
value = value.BeforeLast( ';');
|
|
|
|
value.Trim(true);
|
|
|
|
value.Trim(false);
|
|
|
|
if( buffer.StartsWith( wxT("Reference") ) )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-05-03 12:57:44 +00:00
|
|
|
refcurrcmp = value;
|
2007-08-20 19:33:15 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
if( buffer.StartsWith( wxT("IdModule =" ) ) )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-05-03 12:57:44 +00:00
|
|
|
idmod = value;
|
2007-08-20 19:33:15 +00:00
|
|
|
continue;
|
|
|
|
}
|
2011-05-03 12:57:44 +00:00
|
|
|
|
|
|
|
if( buffer.StartsWith( wxT("TimeStamp =" ) ) )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-05-03 12:57:44 +00:00
|
|
|
timestamp = value;
|
|
|
|
continue;
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
// Check if this component is the right component:
|
|
|
|
if( m_UseTimeStamp ) // Use schematic timestamp to locate the footprint
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-05-03 12:57:44 +00:00
|
|
|
if( aCmpIdent->CmpNoCase( timestamp ) == 0 && !timestamp.IsEmpty() )
|
|
|
|
{ // Found
|
2011-05-03 16:57:15 +00:00
|
|
|
aFootprintName = idmod;
|
2011-05-03 12:57:44 +00:00
|
|
|
return true;
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
}
|
2011-05-03 12:57:44 +00:00
|
|
|
else // Use schematic reference to locate the footprint
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-05-03 12:57:44 +00:00
|
|
|
if( aCmpIdent->CmpNoCase( refcurrcmp ) == 0 ) // Found!
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-05-03 16:57:15 +00:00
|
|
|
aFootprintName = idmod;
|
2011-05-03 12:57:44 +00:00
|
|
|
return true;
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
return true;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
/* Load new modules from library.
|
2011-05-03 12:57:44 +00:00
|
|
|
* If a new module is already loaded it is duplicated, which avoids multiple
|
|
|
|
* unnecessary disk or net access to read libraries.
|
2011-08-19 13:08:24 +00:00
|
|
|
* return false if a footprint is not found, true if OK
|
2007-08-20 19:33:15 +00:00
|
|
|
*/
|
2011-08-19 13:08:24 +00:00
|
|
|
bool NETLIST_READER::loadNewModules()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-05-03 12:57:44 +00:00
|
|
|
MODULE_INFO* ref, * cmp;
|
|
|
|
MODULE* Module = NULL;
|
|
|
|
wxPoint ModuleBestPosition;
|
|
|
|
BOARD* pcb = m_pcbframe->GetBoard();
|
2011-08-19 13:08:24 +00:00
|
|
|
bool success = true;
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
if( m_newModulesList.size() == 0 )
|
2011-08-19 13:08:24 +00:00
|
|
|
return true;
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
sort( m_newModulesList.begin(), m_newModulesList.end(), SortByLibName );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2008-03-22 18:08:44 +00:00
|
|
|
// Calculate the footprint "best" position:
|
2011-05-03 12:57:44 +00:00
|
|
|
if( pcb->ComputeBoundingBox( true ) )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-05-03 12:57:44 +00:00
|
|
|
ModuleBestPosition = pcb->m_BoundaryBox.GetEnd();
|
|
|
|
ModuleBestPosition.y += 5000;
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
ref = cmp = m_newModulesList[0];
|
|
|
|
for( unsigned ii = 0; ii < m_newModulesList.size(); ii++ )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-05-03 12:57:44 +00:00
|
|
|
cmp = m_newModulesList[ii];
|
2007-08-20 19:33:15 +00:00
|
|
|
if( (ii == 0) || ( ref->m_LibName != cmp->m_LibName) )
|
2008-12-06 08:21:54 +00:00
|
|
|
{
|
|
|
|
/* New footprint : must be loaded from a library */
|
2011-05-03 12:57:44 +00:00
|
|
|
Module = m_pcbframe->Get_Librairie_Module( wxEmptyString,
|
|
|
|
cmp->m_LibName,
|
|
|
|
false );
|
|
|
|
ref = cmp;
|
2007-08-20 19:33:15 +00:00
|
|
|
if( Module == NULL )
|
|
|
|
{
|
2011-08-19 13:08:24 +00:00
|
|
|
success = false;
|
2007-08-20 19:33:15 +00:00
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Component [%s]: footprint <%s> not found" ),
|
2011-05-03 12:57:44 +00:00
|
|
|
GetChars( cmp->m_CmpName ),
|
|
|
|
GetChars( cmp->m_LibName ) );
|
2011-08-19 13:08:24 +00:00
|
|
|
if( m_messageWindow )
|
|
|
|
{
|
|
|
|
msg += wxT("\n");
|
|
|
|
m_messageWindow->AppendText( msg );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
DisplayError( NULL, msg );
|
2007-08-20 19:33:15 +00:00
|
|
|
continue;
|
|
|
|
}
|
2009-08-19 14:19:35 +00:00
|
|
|
Module->SetPosition( ModuleBestPosition );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
/* Update schematic links : reference "Time Stamp" and schematic
|
|
|
|
*hierarchical path */
|
2007-08-20 19:33:15 +00:00
|
|
|
Module->m_Reference->m_Text = cmp->m_CmpName;
|
2009-04-24 07:36:36 +00:00
|
|
|
Module->m_TimeStamp = GetTimeStamp();
|
|
|
|
Module->m_Path = cmp->m_TimeStampPath;
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-11-18 12:52:19 +00:00
|
|
|
/* Footprint already loaded from a library, duplicate it (faster)
|
|
|
|
*/
|
2007-08-20 19:33:15 +00:00
|
|
|
if( Module == NULL )
|
2009-11-18 12:52:19 +00:00
|
|
|
continue; /* Module does not exist in library. */
|
2008-12-06 08:21:54 +00:00
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
MODULE* newmodule = new MODULE( pcb );
|
2007-08-20 19:33:15 +00:00
|
|
|
newmodule->Copy( Module );
|
2008-12-06 08:21:54 +00:00
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
pcb->Add( newmodule, ADD_APPEND );
|
2008-12-06 08:21:54 +00:00
|
|
|
|
2007-08-20 19:33:15 +00:00
|
|
|
Module = newmodule;
|
|
|
|
Module->m_Reference->m_Text = cmp->m_CmpName;
|
2009-04-24 07:36:36 +00:00
|
|
|
Module->m_TimeStamp = GetTimeStamp();
|
|
|
|
Module->m_Path = cmp->m_TimeStampPath;
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
}
|
2011-08-19 13:08:24 +00:00
|
|
|
|
|
|
|
return success;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|