2012-02-01 19:49:37 +00:00
|
|
|
/**
|
|
|
|
* @file cvpcb/readschematicnetlist.cpp
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Jean-Pierre Charras.
|
|
|
|
* Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-02-01 19:49:37 +00:00
|
|
|
/* Read a nelist type Eeschema (New and Old format)
|
|
|
|
* or OrcadPCB2 and build the component list
|
2007-12-17 20:18:04 +00:00
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <wxstruct.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <kicad_string.h>
|
|
|
|
#include <macros.h>
|
|
|
|
|
|
|
|
#include <cvpcb_mainframe.h>
|
|
|
|
#include <richio.h>
|
2010-04-13 16:38:20 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-02-01 19:49:37 +00:00
|
|
|
#include <netlist_reader.h>
|
2009-11-05 19:26:52 +00:00
|
|
|
|
2012-02-01 19:49:37 +00:00
|
|
|
// COMPONENT_INFO object list sort function:
|
|
|
|
bool operator < ( const COMPONENT_INFO& item1, const COMPONENT_INFO& item2 )
|
|
|
|
{
|
|
|
|
return StrNumCmp( item1.m_Reference, item2.m_Reference, INT_MAX, true ) < 0;
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2008-08-01 17:41:51 +00:00
|
|
|
|
2011-02-05 16:15:48 +00:00
|
|
|
int CVPCB_MAINFRAME::ReadSchematicNetlist()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2012-02-01 19:49:37 +00:00
|
|
|
FILE* netfile = wxFopen( m_NetlistFileName.GetFullPath(), wxT( "rt" ) );
|
2007-12-17 20:18:04 +00:00
|
|
|
|
2012-02-01 19:49:37 +00:00
|
|
|
if( netfile == NULL )
|
2009-04-23 15:02:18 +00:00
|
|
|
{
|
2012-02-01 19:49:37 +00:00
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Could not open file <%>" ),
|
|
|
|
GetChars( m_NetlistFileName.GetFullPath() ) );
|
|
|
|
wxMessageBox( msg );
|
2009-04-05 20:49:15 +00:00
|
|
|
return -1;
|
2007-12-17 20:18:04 +00:00
|
|
|
}
|
|
|
|
|
2012-02-01 19:49:37 +00:00
|
|
|
NETLIST_READER netList_Reader( NULL, NULL );
|
|
|
|
netList_Reader.m_UseTimeStamp = false;
|
|
|
|
netList_Reader.m_ChangeFootprints = false;
|
|
|
|
netList_Reader.m_UseCmpFile = false;
|
|
|
|
netList_Reader.SetFilesnames( m_NetlistFileName.GetFullPath(), wxEmptyString );
|
2010-04-13 16:38:20 +00:00
|
|
|
|
2012-02-01 19:49:37 +00:00
|
|
|
// True to read footprint filters section: true for CvPcb, false pro Pcbnew
|
|
|
|
netList_Reader.ReadLibpartSectionSetOpt( true );
|
2007-12-17 20:18:04 +00:00
|
|
|
|
2012-02-01 19:49:37 +00:00
|
|
|
bool success = netList_Reader.ReadNetList( netfile );
|
|
|
|
if( !success )
|
2007-12-17 20:18:04 +00:00
|
|
|
{
|
2012-02-01 19:49:37 +00:00
|
|
|
wxMessageBox( _("Netlist read error") );
|
|
|
|
return false;
|
2007-12-17 20:18:04 +00:00
|
|
|
}
|
|
|
|
|
2012-02-01 19:49:37 +00:00
|
|
|
// Now copy footprints info into Cvpcb list:
|
|
|
|
COMPONENT_INFO_LIST& cmpInfo = netList_Reader.GetComponentInfoList();
|
|
|
|
for( unsigned ii = 0; ii < cmpInfo.size(); ii++ )
|
|
|
|
m_components.push_back( cmpInfo[ii] );
|
|
|
|
cmpInfo.clear(); // cmpInfo is no more owner of the list.
|
2007-12-17 20:18:04 +00:00
|
|
|
|
2012-02-01 19:49:37 +00:00
|
|
|
// Sort components by reference:
|
|
|
|
sort( m_components.begin(), m_components.end() );
|
2007-12-17 20:18:04 +00:00
|
|
|
|
2012-02-01 19:49:37 +00:00
|
|
|
// Now copy filters in m_components, if netlist type is KICAD
|
|
|
|
// ( when the format is the "old" PCBNEW format, filters are already in
|
|
|
|
// m_component list
|
|
|
|
if( NETLIST_TYPE_KICAD == netList_Reader.GetNetlistType() )
|
2007-12-17 20:18:04 +00:00
|
|
|
{
|
2012-02-01 19:49:37 +00:00
|
|
|
for( unsigned ii = 0; ii < m_components.size(); ii++ )
|
2007-12-17 20:18:04 +00:00
|
|
|
{
|
2012-02-01 19:49:37 +00:00
|
|
|
LIPBART_INFO* libpart = netList_Reader.GetLibpart(m_components[ii].m_Libpart);
|
|
|
|
if( libpart == NULL )
|
|
|
|
continue;
|
2007-12-17 20:18:04 +00:00
|
|
|
|
2012-02-01 19:49:37 +00:00
|
|
|
// now copy filter list
|
|
|
|
m_components[ii].m_FootprintFilter = libpart->m_FootprintFilter;
|
2007-12-17 20:18:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|