From 61b4f8a9ebc4aaf5f4f5a59ea3cd791f06b6f02c Mon Sep 17 00:00:00 2001
From: Wayne Stambaugh
Date: Thu, 25 Apr 2013 12:29:35 -0400
Subject: [PATCH] Pcbnew NETLIST_READER improvements.
* Create separate NETLIST object to hold contents of netlist files.
* Read entire netlist and footprint link files before making applying
changes to board.
* Add BOARD::ReplaceNetlist() function to eliminate the calls between the
NETLIST_READER, PCB_EDIT_FRAME, and BOARD objects.
* Change placement of new components below the center of the current board
or in the center of the page if the BOARD is empty.
* Add dry run option to netlist dialog to print changes to message control
without making changes.
* Add button to netlist dialog to allow saving contents of message control
to a file.
* Eliminate the need to compile netlist_reader_*.cpp in both CvPcb and Pcbnew.
* Add netlist_reader_*.cpp to the pcbcommon library.
* Remove redundant load component link file code from CvPcb.
* Modify CvPcb new to work with the new NETLIST_READER object.
* Add compare() function and < and == operators to FPID object.
* Add REPORTER class to hide an underlying string writing implementation for
use in low level objects. Thank you Dick for the idea.
* Lots of minor coding policy, Doxygen comment, and missing license fixes.
---
3d-viewer/modelparsers.h | 3 +-
TODO.txt | 9 +-
common/CMakeLists.txt | 4 +
common/fpid.cpp | 20 +
common/reporter.cpp | 46 +
common/wildcards_and_files_ext.cpp | 3 +-
cvpcb/CMakeLists.txt | 3 -
cvpcb/autosel.cpp | 76 +-
cvpcb/class_footprints_listbox.cpp | 85 +-
cvpcb/cvframe.cpp | 39 +-
cvpcb/cvpcb.h | 4 -
cvpcb/cvpcb_mainframe.h | 65 +-
cvpcb/cvstruct.h | 63 +-
cvpcb/listboxes.cpp | 41 +-
cvpcb/loadcmp.cpp | 10 +-
cvpcb/read_write_cmpfile.cpp | 108 +--
cvpcb/readschematicnetlist.cpp | 92 +-
cvpcb/readwrite_dlgs.cpp | 95 +--
eeschema/class_library.cpp | 2 +-
include/appl_wxstruct.h | 4 +-
include/dialog_helpers.h | 25 +
include/fpid.h | 23 +
include/reporter.h | 89 ++
include/wildcards_and_files_ext.h | 1 +
include/wxBasePcbFrame.h | 13 +
include/wxPcbStruct.h | 77 +-
pcbnew/CMakeLists.txt | 3 -
pcbnew/class_board.cpp | 267 ++++++
pcbnew/class_board.h | 77 +-
pcbnew/class_module.cpp | 59 +-
pcbnew/class_module.h | 31 +-
pcbnew/class_netinfo.h | 31 +
pcbnew/class_netinfo_item.cpp | 7 -
pcbnew/class_pad.cpp | 50 +-
pcbnew/class_pad.h | 12 +
pcbnew/dialogs/dialog_edit_module_text.cpp | 4 +-
pcbnew/dialogs/dialog_netlist.cpp | 235 ++++-
pcbnew/dialogs/dialog_netlist.h | 51 +-
pcbnew/dialogs/dialog_netlist_fbp.cpp | 36 +-
pcbnew/dialogs/dialog_netlist_fbp.fbp | 207 ++++-
pcbnew/dialogs/dialog_netlist_fbp.h | 6 +
pcbnew/dialogs/dialog_orient_footprints.cpp | 43 +-
pcbnew/dialogs/dialog_pad_properties.cpp | 4 +-
pcbnew/loadcmp.cpp | 53 +-
pcbnew/muonde.cpp | 56 +-
pcbnew/netlist.cpp | 311 +++----
pcbnew/netlist_reader.h | 900 +++++++++++++-------
pcbnew/netlist_reader_common.cpp | 779 +++++++----------
pcbnew/netlist_reader_firstformat.cpp | 370 +++-----
pcbnew/netlist_reader_kicad.cpp | 448 ++++------
50 files changed, 2888 insertions(+), 2152 deletions(-)
create mode 100644 common/reporter.cpp
create mode 100644 include/reporter.h
diff --git a/3d-viewer/modelparsers.h b/3d-viewer/modelparsers.h
index 7153c21ba2..147a0fda16 100644
--- a/3d-viewer/modelparsers.h
+++ b/3d-viewer/modelparsers.h
@@ -112,7 +112,8 @@ public:
* Function GetNodeProperties
* Collects all node properties to map.
*
- * @param aProps contains map of found properties
+ * @param aNode is an XML node.
+ * @param aProps contains map of found properties.
*/
static void GetNodeProperties( wxXmlNode* aNode, PROPERTY_MAP& aProps );
diff --git a/TODO.txt b/TODO.txt
index 2dce8bed09..7a7a30ec34 100644
--- a/TODO.txt
+++ b/TODO.txt
@@ -10,7 +10,7 @@ WXMAC Platform
Common
------
* Grep for @TODO or TODO for sourcecode tasks
-* Use doxygen compatible comments on member functions (.h files)
+* Use Doxygen compatible comments on member functions (.h files)
* Add tooltip text to all non-obvious controls in every dialog window.
Use wxFormBuilder.
* Component and module search displays in which library the
@@ -113,9 +113,9 @@ const wxString FP_LIB_TABLE::ExpandSubtitutions( const wxString aString )
-EESchema
+Eeschema
--------
-* Drag and drop between two EESchema windows.
+* Drag and drop between two Eeschema windows.
Wayne:
E3) Hook up perform last library search hot key to replace search libraries for
@@ -159,5 +159,6 @@ PCBNew
of PLUGIN::Footprint*() functions. At least LEGACY and KICAD are both needed
concurrently.
-
+*) Add a hot key to toggle the 45 degree constraint on and off so that it can be
+ changed when drawing a trace.
diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt
index b0d61ebd8c..ffc0279f08 100644
--- a/common/CMakeLists.txt
+++ b/common/CMakeLists.txt
@@ -72,6 +72,7 @@ set(COMMON_SRCS
newstroke_font.cpp
projet_config.cpp
ptree.cpp
+ reporter.cpp
richio.cpp
selcolor.cpp
string.cpp
@@ -116,6 +117,9 @@ set(PCB_COMMON_SRCS
../pcbnew/class_zone_settings.cpp
../pcbnew/classpcb.cpp
../pcbnew/collectors.cpp
+ ../pcbnew/netlist_reader_common.cpp
+ ../pcbnew/netlist_reader_firstformat.cpp
+ ../pcbnew/netlist_reader_kicad.cpp
../pcbnew/sel_layer.cpp
../pcbnew/pcb_plot_params.cpp
../pcbnew/io_mgr.cpp
diff --git a/common/fpid.cpp b/common/fpid.cpp
index 48433985cd..984604d3cc 100644
--- a/common/fpid.cpp
+++ b/common/fpid.cpp
@@ -310,6 +310,26 @@ std::string FPID::Format( const std::string& aLogicalLib, const std::string& aFo
}
+int FPID::compare( const FPID& aFPID ) const
+{
+ // Don't bother comparing the same object.
+ if( this == &aFPID )
+ return 0;
+
+ int retv = nickname.compare( aFPID.nickname );
+
+ if( retv != 0 )
+ return retv;
+
+ retv = footprint.compare( aFPID.footprint );
+
+ if( retv != 0 )
+ return retv;
+
+ return revision.compare( aFPID.revision );
+}
+
+
#if 0 && defined(DEBUG)
// build this with Debug CMAKE_BUILD_TYPE
diff --git a/common/reporter.cpp b/common/reporter.cpp
new file mode 100644
index 0000000000..8402d0c2b8
--- /dev/null
+++ b/common/reporter.cpp
@@ -0,0 +1,46 @@
+/**
+ * @file reporter.h
+ */
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2013 Wayne Stambaugh
+ * Copyright (C) 1992-2013 KiCad Developers, see change_log.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
+ */
+
+#include
+#include
+
+
+REPORTER& REPORTER::Report( const char *aText )
+{
+ Report( FROM_UTF8( aText ) );
+ return *this;
+}
+
+
+REPORTER& WX_TEXT_CTRL_REPORTER::Report( const wxString& aText )
+{
+ wxCHECK_MSG( m_textCtrl != NULL, *this,
+ wxT( "No wxTextCtrl object defined in WX_TEXT_CTRL_REPORTER." ) );
+
+ m_textCtrl->AppendText( aText );
+ return *this;
+}
diff --git a/common/wildcards_and_files_ext.cpp b/common/wildcards_and_files_ext.cpp
index 2a09e046fb..9149ae229c 100644
--- a/common/wildcards_and_files_ext.cpp
+++ b/common/wildcards_and_files_ext.cpp
@@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
- * Copyright (C) 20012 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
+ * Copyright (C) 2012 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2012 Wayne Stambaugh
* Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
*
@@ -96,3 +96,4 @@ const wxString PSFileWildcard( _( "PostScript files (.ps)|*.ps" ) );
const wxString ReportFileWildcard = _( "Report files (*.rpt)|*.rpt" );
const wxString FootprintPlaceFileWildcard = _( "Footprint place files (*.pos)|*.pos" );
const wxString Shapes3DFileWildcard( _( "Vrml and x3d files (*.wrl *.x3d)|*.wrl;*.x3d" ) );
+const wxString TextWildcard( _( "Text files (*.txt)|*.txt" ) );
diff --git a/cvpcb/CMakeLists.txt b/cvpcb/CMakeLists.txt
index f154c169d4..ad48351d46 100644
--- a/cvpcb/CMakeLists.txt
+++ b/cvpcb/CMakeLists.txt
@@ -27,9 +27,6 @@ set(CVPCB_DIALOGS
set(CVPCB_SRCS
../common/base_units.cpp
- ../pcbnew/netlist_reader_common.cpp
- ../pcbnew/netlist_reader_kicad.cpp
- ../pcbnew/netlist_reader_firstformat.cpp
../pcbnew/class_drc_item.cpp
autosel.cpp
cfg.cpp
diff --git a/cvpcb/autosel.cpp b/cvpcb/autosel.cpp
index fd9fc906c4..0e96048b06 100644
--- a/cvpcb/autosel.cpp
+++ b/cvpcb/autosel.cpp
@@ -1,3 +1,26 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.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
+ */
+
/**
* @file autosel.cpp
*/
@@ -39,10 +62,16 @@ typedef boost::ptr_vector< FOOTPRINT_ALIAS > FOOTPRINT_ALIAS_LIST;
wxString GetQuotedText( wxString & text )
{
int i = text.Find( QUOTE );
- if( wxNOT_FOUND == i ) return wxT( "" );
+
+ if( wxNOT_FOUND == i )
+ return wxT( "" );
+
wxString shrt = text.Mid( i + 1 );
i = shrt.Find( QUOTE );
- if( wxNOT_FOUND == i ) return wxT( "" );
+
+ if( wxNOT_FOUND == i )
+ return wxT( "" );
+
text = shrt.Mid( i + 1 );
return shrt.Mid( 0, i );
}
@@ -52,13 +81,14 @@ void CVPCB_MAINFRAME::AssocieModule( wxCommandEvent& event )
{
FOOTPRINT_ALIAS_LIST aliases;
FOOTPRINT_ALIAS* alias;
+ COMPONENT* component;
wxFileName fn;
wxString msg, tmp;
char Line[1024];
FILE* file;
size_t ii;
- if( m_components.empty() )
+ if( m_netlist.IsEmpty() )
return;
/* Find equivalents in all available files. */
@@ -79,8 +109,8 @@ void CVPCB_MAINFRAME::AssocieModule( wxCommandEvent& event )
if( !tmp )
{
- msg.Printf( _( "Footprint alias library file <%s> could not be \
-found in the default search paths." ),
+ msg.Printf( _( "Footprint alias library file <%s> could not be found in the "
+ "default search paths." ),
GetChars( fn.GetFullName() ) );
wxMessageBox( msg, titleLibLoadError, wxOK | wxICON_ERROR );
continue;
@@ -127,18 +157,21 @@ found in the default search paths." ),
m_skipComponentSelect = true;
ii = 0;
- BOOST_FOREACH( COMPONENT_INFO& component, m_components )
+
+ for( unsigned kk = 0; kk < m_netlist.GetCount(); kk++ )
{
+ component = m_netlist.GetComponent( kk );
+
bool found = false;
m_ListCmp->SetSelection( ii++, true );
- if( !component.m_Footprint.IsEmpty() )
+ if( !component->GetFootprintLibName().IsEmpty() )
continue;
BOOST_FOREACH( FOOTPRINT_ALIAS& alias, aliases )
{
- if( alias.m_Name.CmpNoCase( component.m_Value ) != 0 )
+ if( alias.m_Name.CmpNoCase( component->GetValue() ) != 0 )
continue;
/* filter alias so one can use multiple aliases (for polar and nonpolar caps for
@@ -147,23 +180,23 @@ found in the default search paths." ),
if( module )
{
- size_t filtercount = component.m_FootprintFilter.GetCount();
+ size_t filtercount = component->GetFootprintFilters().GetCount();
found = ( 0 == filtercount ); // if no entries, do not filter
for( size_t jj = 0; jj < filtercount && !found; jj++ )
{
- found = module->m_Module.Matches( component.m_FootprintFilter[jj] );
+ found = module->m_Module.Matches( component->GetFootprintFilters()[jj] );
}
}
else
{
- msg.Printf( _( "Component %s: footprint %s not found in \
-any of the project footprint libraries." ),
- GetChars( component.m_Reference ),
+ msg.Printf( _( "Component %s: footprint %s not found in any of the project "
+ "footprint libraries." ),
+ GetChars( component->GetReference() ),
GetChars( alias.m_FootprintName ) );
- wxMessageBox( msg, _( "CvPcb Error" ), wxOK | wxICON_ERROR,
- this );
+ wxMessageBox( msg, _( "CvPcb Error" ), wxOK | wxICON_ERROR, this );
}
+
if( found )
{
SetNewPkg( alias.m_FootprintName );
@@ -171,15 +204,20 @@ any of the project footprint libraries." ),
}
}
+
/* obviously the last chance: there's only one filter matching one footprint */
- if( !found && 1 == component.m_FootprintFilter.GetCount() ) {
+ if( !found && 1 == component->GetFootprintFilters().GetCount() )
+ {
/* we do not need to analyse wildcards: single footprint do not contain them */
/* and if there are wildcards it just will not match any */
- FOOTPRINT_INFO *module = m_footprints.GetModuleInfo( component.m_FootprintFilter[0] );
- if( module ) {
- SetNewPkg( component.m_FootprintFilter[0] );
+ FOOTPRINT_INFO *module = m_footprints.GetModuleInfo( component->GetFootprintFilters()[0] );
+
+ if( module )
+ {
+ SetNewPkg( component->GetFootprintFilters()[0] );
}
}
}
+
m_skipComponentSelect = false;
}
diff --git a/cvpcb/class_footprints_listbox.cpp b/cvpcb/class_footprints_listbox.cpp
index a80c69c115..38421a34f7 100644
--- a/cvpcb/class_footprints_listbox.cpp
+++ b/cvpcb/class_footprints_listbox.cpp
@@ -1,6 +1,30 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
+ * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.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
+ */
+
/**
* @file class_footprints_listbox.cpp
- * class to display the list fo available footprints
+ * class to display the list of available footprints
*/
#include
@@ -132,7 +156,7 @@ void FOOTPRINTS_LISTBOX::SetFootprintFullList( FOOTPRINT_LIST& list )
}
-void FOOTPRINTS_LISTBOX::SetFootprintFilteredList( COMPONENT_INFO* Component,
+void FOOTPRINTS_LISTBOX::SetFootprintFilteredList( COMPONENT* aComponent,
FOOTPRINT_LIST& list )
{
wxString msg;
@@ -149,13 +173,16 @@ void FOOTPRINTS_LISTBOX::SetFootprintFilteredList( COMPONENT_INFO* Component,
// The search is case insensitive
wxString module = footprint.m_Module.Upper();
wxString candidate;
- for( jj = 0; jj < Component->m_FootprintFilter.GetCount(); jj++ )
+
+ for( jj = 0; jj < aComponent->GetFootprintFilters().GetCount(); jj++ )
{
- candidate = Component->m_FootprintFilter[jj].Upper();
+ candidate = aComponent->GetFootprintFilters()[jj].Upper();
+
if( !module.Matches( candidate ) )
continue;
+
msg.Printf( wxT( "%3zu %s" ), m_FilteredFootprintList.GetCount() + 1,
- footprint.m_Module.GetData() );
+ footprint.m_Module.GetData() );
m_FilteredFootprintList.Add( msg );
hasItem = true;
}
@@ -172,8 +199,10 @@ void FOOTPRINTS_LISTBOX::SetFootprintFilteredList( COMPONENT_INFO* Component,
Refresh();
}
-void FOOTPRINTS_LISTBOX::SetFootprintFilteredByPinCount( COMPONENT_INFO* Component,
- FOOTPRINT_LIST& list ) {
+
+void FOOTPRINTS_LISTBOX::SetFootprintFilteredByPinCount( COMPONENT* aComponent,
+ FOOTPRINT_LIST& list )
+{
wxString msg;
int oldSelection = GetSelection();
bool hasItem = false;
@@ -184,10 +213,10 @@ void FOOTPRINTS_LISTBOX::SetFootprintFilteredByPinCount( COMPONENT_INFO* Compone
{
FOOTPRINT_INFO& footprint = list.GetItem(ii);
- if( Component->m_pinCount == footprint.m_padCount )
+ if( aComponent->GetNetCount() == footprint.m_padCount )
{
msg.Printf( wxT( "%3zu %s" ), m_FilteredFootprintList.GetCount() + 1,
- footprint.m_Module.GetData() );
+ footprint.m_Module.GetData() );
m_FilteredFootprintList.Add( msg );
hasItem = true;
}
@@ -204,13 +233,7 @@ void FOOTPRINTS_LISTBOX::SetFootprintFilteredByPinCount( COMPONENT_INFO* Compone
Refresh();
}
-/** Set the footprint list. We can have 2 footprint list:
- * The full footprint list
- * The filtered footprint list (if the current selected component has a
- * filter for footprints)
- * @param FullList true = full footprint list, false = filtered footprint list
- * @param Redraw = true to redraw the window
- */
+
void FOOTPRINTS_LISTBOX::SetActiveFootprintList( bool FullList, bool Redraw )
{
bool old_selection = m_UseFootprintFullList;
@@ -226,10 +249,12 @@ void FOOTPRINTS_LISTBOX::SetActiveFootprintList( bool FullList, bool Redraw )
if( m_ActiveFootprintList )
{
bool new_selection;
+
if( FullList )
new_selection = true;
else
new_selection = false;
+
if( new_selection != old_selection )
SetSelection( 0, true );
}
@@ -264,14 +289,12 @@ void FOOTPRINTS_LISTBOX::SetActiveFootprintList( bool FullList, bool Redraw )
/**************************************/
BEGIN_EVENT_TABLE( FOOTPRINTS_LISTBOX, ITEMS_LISTBOX_BASE )
-EVT_SIZE( ITEMS_LISTBOX_BASE::OnSize )
-EVT_CHAR( FOOTPRINTS_LISTBOX::OnChar )
+ EVT_SIZE( ITEMS_LISTBOX_BASE::OnSize )
+ EVT_CHAR( FOOTPRINTS_LISTBOX::OnChar )
END_EVENT_TABLE()
-/********************************************************/
void FOOTPRINTS_LISTBOX::OnLeftClick( wxListEvent& event )
-/********************************************************/
{
FOOTPRINT_INFO* Module;
wxString footprintName = GetSelectedFootprint();
@@ -297,9 +320,7 @@ void FOOTPRINTS_LISTBOX::OnLeftClick( wxListEvent& event )
}
-/******************************************************/
void FOOTPRINTS_LISTBOX::OnLeftDClick( wxListEvent& event )
-/******************************************************/
{
wxString footprintName = GetSelectedFootprint();
@@ -307,21 +328,10 @@ void FOOTPRINTS_LISTBOX::OnLeftDClick( wxListEvent& event )
}
-/**
- * Function OnChar
- * called on a key pressed
- * Call default handler for some special keys,
- * and for "ascii" keys, select the first footprint
- * that the name starts by the letter.
- * This is the defaut behaviour of a listbox, but because we use
- * virtual lists, the listbox does not know anything to what is displayed,
- * we must handle this behaviour here.
- * Furthermore the footprint name is not at the beginning of
- * displayed lines (the first word is the line number)
- */
void FOOTPRINTS_LISTBOX::OnChar( wxKeyEvent& event )
{
int key = event.GetKeyCode();
+
switch( key )
{
case WXK_LEFT:
@@ -343,16 +353,20 @@ void FOOTPRINTS_LISTBOX::OnChar( wxKeyEvent& event )
default:
break;
}
+
// Search for an item name starting by the key code:
key = toupper(key);
+
for( unsigned ii = 0; ii < m_ActiveFootprintList->GetCount(); ii++ )
{
wxString text = m_ActiveFootprintList->Item(ii);
+
/* search for the start char of the footprint name.
* we must skip the line number
- */
+ */
text.Trim(false); // Remove leading spaces in line
unsigned jj = 0;
+
for( ; jj < text.Len(); jj++ )
{
// skip line number
@@ -367,6 +381,7 @@ void FOOTPRINTS_LISTBOX::OnChar( wxKeyEvent& event )
}
int start_char = toupper( text[jj] );
+
if( key == start_char )
{
Focus( ii );
diff --git a/cvpcb/cvframe.cpp b/cvpcb/cvframe.cpp
index c3c271c318..4098dc44f7 100644
--- a/cvpcb/cvframe.cpp
+++ b/cvpcb/cvframe.cpp
@@ -334,7 +334,7 @@ void CVPCB_MAINFRAME::ToFirstNA( wxCommandEvent& event )
int ii = 0;
int selection;
- if( m_components.empty() )
+ if( m_netlist.IsEmpty() )
return;
selection = m_ListCmp->GetSelection();
@@ -342,9 +342,9 @@ void CVPCB_MAINFRAME::ToFirstNA( wxCommandEvent& event )
if( selection < 0 )
selection = 0;
- BOOST_FOREACH( COMPONENT_INFO & component, m_components )
+ for( unsigned jj = 0; jj < m_netlist.GetCount(); jj++ )
{
- if( component.m_Footprint.IsEmpty() && ii > selection )
+ if( m_netlist.GetComponent( jj )->GetFootprintLibName().IsEmpty() && ii > selection )
{
m_ListCmp->SetSelection( ii );
SendMessageToEESCHEMA();
@@ -363,7 +363,7 @@ void CVPCB_MAINFRAME::ToPreviousNA( wxCommandEvent& event )
int ii;
int selection;
- if( m_components.empty() )
+ if( m_netlist.IsEmpty() )
return;
ii = m_ListCmp->GetCount() - 1;
@@ -372,9 +372,9 @@ void CVPCB_MAINFRAME::ToPreviousNA( wxCommandEvent& event )
if( selection < 0 )
selection = m_ListCmp->GetCount() - 1;
- BOOST_REVERSE_FOREACH( COMPONENT_INFO & component, m_components )
+ for( unsigned kk = m_netlist.GetCount() - 1; kk >= 0; kk-- )
{
- if( component.m_Footprint.IsEmpty() && ii < selection )
+ if( m_netlist.GetComponent( kk )->GetFootprintLibName().IsEmpty() && ii < selection )
{
m_ListCmp->SetSelection( ii );
SendMessageToEESCHEMA();
@@ -412,15 +412,15 @@ void CVPCB_MAINFRAME::DelAssociations( wxCommandEvent& event )
m_skipComponentSelect = true;
m_ListCmp->SetSelection( 0 );
- BOOST_FOREACH( COMPONENT_INFO & component, m_components )
+ for( unsigned i = 0; i < m_netlist.GetCount(); i++ )
{
- component.m_Footprint.Empty();
+ m_netlist.GetComponent( i )->SetFootprintLibName( wxEmptyString );
SetNewPkg( wxEmptyString );
}
m_skipComponentSelect = false;
m_ListCmp->SetSelection( 0 );
- m_undefinedComponentCnt = m_components.size();
+ m_undefinedComponentCnt = m_netlist.GetCount();
}
DisplayStatus();
@@ -538,18 +538,18 @@ void CVPCB_MAINFRAME::OnSelectComponent( wxListEvent& event )
else
{
- if( &m_components[ selection ] == NULL )
+ if( m_netlist.GetComponent( selection ) == NULL )
m_FootprintList->SetActiveFootprintList( SELECT_FULL_LIST, REDRAW_LIST );
else
{
if( m_mainToolBar->GetToolToggled( ID_CVPCB_FOOTPRINT_DISPLAY_PIN_FILTERED_LIST ) )
{
- m_FootprintList->SetFootprintFilteredByPinCount( &m_components[ selection ],
+ m_FootprintList->SetFootprintFilteredByPinCount( m_netlist.GetComponent( selection ),
m_footprints );
}
else
{
- m_FootprintList->SetFootprintFilteredList( &m_components[ selection ],
+ m_FootprintList->SetFootprintFilteredList( m_netlist.GetComponent( selection ),
m_footprints );
}
}
@@ -568,7 +568,7 @@ void CVPCB_MAINFRAME::OnSelectComponent( wxListEvent& event )
if( FindFocus() == m_ListCmp )
{
- wxString module = *(&m_components[ selection ].m_Footprint);
+ wxString module = m_netlist.GetComponent( selection )->GetFootprintLibName();
bool found = false;
for( int ii = 0; ii < m_FootprintList->GetCount(); ii++ )
@@ -642,7 +642,8 @@ void CVPCB_MAINFRAME::DisplayStatus()
{
wxString msg;
- msg.Printf( _( "Components: %d (free: %d)" ), (int) m_components.size(), m_undefinedComponentCnt );
+ msg.Printf( _( "Components: %d (free: %d)" ), (int) m_netlist.GetCount(),
+ m_undefinedComponentCnt );
SetStatusText( msg, 0 );
SetStatusText( wxEmptyString, 1 );
@@ -733,9 +734,9 @@ void CVPCB_MAINFRAME::SendMessageToEESCHEMA()
{
char cmd[1024];
int selection;
- COMPONENT_INFO* Component;
+ COMPONENT* Component;
- if( m_components.empty() )
+ if( m_netlist.IsEmpty() )
return;
selection = m_ListCmp->GetSelection();
@@ -743,12 +744,12 @@ void CVPCB_MAINFRAME::SendMessageToEESCHEMA()
if ( selection < 0 )
selection = 0;
- if( &m_components[ selection ] == NULL )
+ if( m_netlist.GetComponent( selection ) == NULL )
return;
- Component = &m_components[ selection ];
+ Component = m_netlist.GetComponent( selection );
- sprintf( cmd, "$PART: \"%s\"", TO_UTF8( Component->m_Reference ) );
+ sprintf( cmd, "$PART: \"%s\"", TO_UTF8( Component->GetReference() ) );
SendCommand( MSG_TO_SCH, cmd );
diff --git a/cvpcb/cvpcb.h b/cvpcb/cvpcb.h
index 08b8b6e209..c506ea41df 100644
--- a/cvpcb/cvpcb.h
+++ b/cvpcb/cvpcb.h
@@ -21,10 +21,6 @@
#define LISTB_STYLE (wxSUNKEN_BORDER | wxLC_NO_HEADER | wxLC_REPORT | wxLC_VIRTUAL)
-#include
-
-typedef boost::ptr_vector< COMPONENT_INFO > COMPONENT_LIST;
-
extern const wxString FootprintAliasFileExtension;
extern const wxString RetroFileExtension;
diff --git a/cvpcb/cvpcb_mainframe.h b/cvpcb/cvpcb_mainframe.h
index 7e3a665fd8..49d8fe0ac3 100644
--- a/cvpcb/cvpcb_mainframe.h
+++ b/cvpcb/cvpcb_mainframe.h
@@ -1,3 +1,27 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2011 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
+ * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.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
+ */
+
/**
* @file cvpcb_mainframe.h
*/
@@ -7,6 +31,7 @@
#include
#include
+#include
#include
#include
@@ -28,19 +53,19 @@ class CVPCB_MAINFRAME : public EDA_BASE_FRAME
{
public:
- bool m_KeepCvpcbOpen;
+ bool m_KeepCvpcbOpen;
FOOTPRINTS_LISTBOX* m_FootprintList;
COMPONENTS_LISTBOX* m_ListCmp;
DISPLAY_FOOTPRINTS_FRAME* m_DisplayFootprintFrame;
- wxAuiToolBar* m_mainToolBar;
- wxFileName m_NetlistFileName;
+ wxAuiToolBar* m_mainToolBar;
+ wxFileName m_NetlistFileName;
wxArrayString m_ModuleLibNames;
wxArrayString m_AliasLibNames;
- wxString m_UserLibraryPath;
- wxString m_NetlistFileExtension;
- wxString m_DocModulesFileName;
- FOOTPRINT_LIST m_footprints;
- COMPONENT_LIST m_components;
+ wxString m_UserLibraryPath;
+ wxString m_NetlistFileExtension;
+ wxString m_DocModulesFileName;
+ FOOTPRINT_LIST m_footprints;
+ NETLIST m_netlist;
protected:
int m_undefinedComponentCnt;
@@ -60,7 +85,7 @@ public:
/**
* Function OnSelectComponent
* Called when clicking on a component in component list window
- * * Updates the filtered foorprint list, if the filtered list option is selected
+ * * Updates the filtered footprint list, if the filtered list option is selected
* * Updates the current selected footprint in footprint list
* * Updates the footprint shown in footprint display window (if opened)
*/
@@ -141,22 +166,12 @@ public:
* file name of the netlist or cmp file.
* If aFullFileName is empty, a file name will be asked to the user
* @return 0 if an error occurred saving the link file to \a aFullFileName.
- * -1 if cancelled
+ * -1 if canceled
* 1 if OK
*/
int SaveCmpLinkFile( const wxString& aFullFileName );
- /**
- * Function LoadComponentFile
- * loads the .cmp link file \a aCmpFileName which stores
- * the component/footprint association.
- *
- * @param aFileName The full filename of .cmp file to load
- * If empty, a filename will be asked to the user
- */
- bool LoadComponentLinkFile( const wxString& aFileName );
-
/**
* Function WriteComponentLinkFile
* Writes the component footprint link file \a aFullFileName on disk.
@@ -166,16 +181,6 @@ public:
*/
bool WriteComponentLinkFile( const wxString& aFullFileName );
- /**
- * Function ReadComponentLinkFile
- * Reads the component footprint link file \a aFullFileName.
- *
- * @param aFile = the opened the opened file to read.
- * ReadComponentLinkFile will close the file
- * @return true if OK, false if error.
- */
- bool ReadComponentLinkFile( FILE * aFile );
-
/**
* Function ReadNetList
* reads the netlist (.net) file defined by #m_NetlistFileName.
diff --git a/cvpcb/cvstruct.h b/cvpcb/cvstruct.h
index 5d7ed48187..6bfbf3c445 100644
--- a/cvpcb/cvstruct.h
+++ b/cvpcb/cvstruct.h
@@ -1,6 +1,29 @@
-/*********************************************************/
-/* cvstruct.h */
-/*********************************************************/
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.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
+ */
+
+/**
+ * @file cvstruct.h
+ */
#ifndef CVSTRUCT_H
#define CVSTRUCT_H
@@ -10,6 +33,8 @@
/* Forward declarations of all top-level window classes. */
class CVPCB_MAINFRAME;
+class COMPONENT;
+
/*********************************************************************/
/* ListBox (base class) to display lists of components or footprints */
@@ -53,10 +78,19 @@ public:
void SetString( unsigned linecount, const wxString& text );
void AppendLine( const wxString& text );
void SetFootprintFullList( FOOTPRINT_LIST& list );
- void SetFootprintFilteredList( COMPONENT_INFO* Component,
- FOOTPRINT_LIST& list );
- void SetFootprintFilteredByPinCount( COMPONENT_INFO* Component,
- FOOTPRINT_LIST& list );
+ void SetFootprintFilteredList( COMPONENT* aComponent,
+ FOOTPRINT_LIST& aList );
+ void SetFootprintFilteredByPinCount( COMPONENT* aComponent,
+ FOOTPRINT_LIST& aList );
+
+ /**
+ * Set the footprint list. We can have 2 footprint list:
+ * The full footprint list
+ * The filtered footprint list (if the current selected component has a
+ * filter for footprints)
+ * @param FullList true = full footprint list, false = filtered footprint list
+ * @param Redraw = true to redraw the window
+ */
void SetActiveFootprintList( bool FullList, bool Redraw = false );
wxString GetSelectedFootprint();
@@ -65,6 +99,19 @@ public:
// Events functions:
void OnLeftClick( wxListEvent& event );
void OnLeftDClick( wxListEvent& event );
+
+ /**
+ * Function OnChar
+ * called on a key pressed
+ * Call default handler for some special keys,
+ * and for "ascii" keys, select the first footprint
+ * that the name starts by the letter.
+ * This is the default behavior of a listbox, but because we use
+ * virtual lists, the listbox does not know anything to what is displayed,
+ * we must handle this behavior here.
+ * Furthermore the footprint name is not at the beginning of
+ * displayed lines (the first word is the line number)
+ */
void OnChar( wxKeyEvent& event );
DECLARE_EVENT_TABLE()
@@ -78,7 +125,7 @@ class COMPONENTS_LISTBOX : public ITEMS_LISTBOX_BASE
{
public:
wxArrayString m_ComponentList;
- CVPCB_MAINFRAME* m_Parent;
+ CVPCB_MAINFRAME* m_Parent;
public:
diff --git a/cvpcb/listboxes.cpp b/cvpcb/listboxes.cpp
index c1e68a5910..b1fd0627b1 100644
--- a/cvpcb/listboxes.cpp
+++ b/cvpcb/listboxes.cpp
@@ -1,3 +1,26 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.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
+ */
+
/**
* @file listboxes.cpp
* @brief Implementation of class for displaying footprint list and component lists.
@@ -67,9 +90,10 @@ CVPCB_MAINFRAME* ITEMS_LISTBOX_BASE::GetParent()
*/
void CVPCB_MAINFRAME::BuildCmpListBox()
{
- wxString msg;
- wxSize size( 10, 10 );
- wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
+ COMPONENT* component;
+ wxString msg;
+ wxSize size( 10, 10 );
+ wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
if( m_ListCmp == NULL )
{
@@ -86,11 +110,14 @@ void CVPCB_MAINFRAME::BuildCmpListBox()
m_ListCmp->m_ComponentList.Clear();
- BOOST_FOREACH( COMPONENT_INFO & component, m_components ) {
+ for( unsigned i = 0; i < m_netlist.GetCount(); i++ )
+ {
+ component = m_netlist.GetComponent( i );
+
msg.Printf( CMP_FORMAT, m_ListCmp->GetCount() + 1,
- GetChars(component.m_Reference),
- GetChars(component.m_Value),
- GetChars(component.m_Footprint) );
+ GetChars( component->GetReference() ),
+ GetChars( component->GetValue() ),
+ GetChars( component->GetFootprintLibName() ) );
m_ListCmp->m_ComponentList.Add( msg );
}
diff --git a/cvpcb/loadcmp.cpp b/cvpcb/loadcmp.cpp
index d01699a8be..21cc0cc961 100644
--- a/cvpcb/loadcmp.cpp
+++ b/cvpcb/loadcmp.cpp
@@ -13,6 +13,7 @@
#include
#include
+#include
#include
#include
@@ -45,9 +46,9 @@ MODULE* DISPLAY_FOOTPRINTS_FRAME::Get_Module( const wxString& aFootprintName )
if( !libPath )
{
- wxString msg = wxString::Format(
- _("PCB foot print library file <%s> could not be found in the default search paths." ),
- fn.GetFullName().GetData() );
+ wxString msg = wxString::Format( _( "PCB footprint library file <%s> could not "
+ "be found in the default search paths." ),
+ fn.GetFullName().GetData() );
// @todo we should not be using wxMessageBox directly.
wxMessageBox( msg, titleLibLoadError, wxOK | wxICON_ERROR, this );
@@ -58,7 +59,7 @@ MODULE* DISPLAY_FOOTPRINTS_FRAME::Get_Module( const wxString& aFootprintName )
if( footprint )
{
- footprint->SetParent( GetBoard() );
+ footprint->SetParent( (EDA_ITEM*) GetBoard() );
footprint->SetPosition( wxPoint( 0, 0 ) );
return footprint;
}
@@ -74,4 +75,3 @@ MODULE* DISPLAY_FOOTPRINTS_FRAME::Get_Module( const wxString& aFootprintName )
DisplayError( this, msg );
return NULL;
}
-
diff --git a/cvpcb/read_write_cmpfile.cpp b/cvpcb/read_write_cmpfile.cpp
index c527b09f51..fc0a0bc23f 100644
--- a/cvpcb/read_write_cmpfile.cpp
+++ b/cvpcb/read_write_cmpfile.cpp
@@ -54,6 +54,7 @@ static char HeaderLinkFile[] = { "Cmp-Mod V01" };
bool CVPCB_MAINFRAME::WriteComponentLinkFile( const wxString& aFullFileName )
{
+ COMPONENT* component;
FILE* outputFile;
wxFileName fn( aFullFileName );
wxString Title = wxGetApp().GetTitle() + wxT( " " ) + GetBuildVersion();
@@ -69,13 +70,15 @@ bool CVPCB_MAINFRAME::WriteComponentLinkFile( const wxString& aFullFileName )
retval |= fprintf( outputFile, " Created by %s", TO_UTF8( Title ) );
retval |= fprintf( outputFile, " date = %s\n", TO_UTF8( DateAndTime() ) );
- BOOST_FOREACH( COMPONENT_INFO& component, m_components )
+ for( unsigned i = 0; i < m_netlist.GetCount(); i++ )
{
+ component = m_netlist.GetComponent( i );
retval |= fprintf( outputFile, "\nBeginCmp\n" );
- retval |= fprintf( outputFile, "TimeStamp = %s;\n", TO_UTF8( component.m_TimeStamp ) );
- retval |= fprintf( outputFile, "Reference = %s;\n", TO_UTF8( component.m_Reference ) );
- retval |= fprintf( outputFile, "ValeurCmp = %s;\n", TO_UTF8( component.m_Value ) );
- retval |= fprintf( outputFile, "IdModule = %s;\n", TO_UTF8( component.m_Footprint ) );
+ retval |= fprintf( outputFile, "TimeStamp = %s;\n", TO_UTF8( component->GetTimeStamp() ) );
+ retval |= fprintf( outputFile, "Reference = %s;\n", TO_UTF8( component->GetReference() ) );
+ retval |= fprintf( outputFile, "ValeurCmp = %s;\n", TO_UTF8( component->GetValue() ) );
+ retval |= fprintf( outputFile, "IdModule = %s;\n",
+ TO_UTF8( component->GetFootprintLibName() ) );
retval |= fprintf( outputFile, "EndCmp\n" );
}
@@ -83,98 +86,3 @@ bool CVPCB_MAINFRAME::WriteComponentLinkFile( const wxString& aFullFileName )
fclose( outputFile );
return retval >= 0;
}
-
-bool CVPCB_MAINFRAME::ReadComponentLinkFile( FILE * aFile )
-{
- wxString timestamp, valeur, ilib, namecmp, msg;
- bool read_cmp_data = false, eof = false;
- char Line[1024], * ident, * data;
-
- // Identification of the type of link file
- if( fgets( Line, sizeof(Line), aFile ) == 0 ||
- strnicmp( Line, HeaderLinkFile, 11 ) != 0 )
- {
- fclose( aFile );
- return false;
- }
-
- while( !eof && fgets( Line, sizeof(Line), aFile ) != 0 )
- {
- if( strnicmp( Line, "EndListe", 8 ) == 0 )
- break;
-
- /* Search the beginning of the component description. */
- if( strnicmp( Line, "BeginCmp", 8 ) != 0 )
- continue;
-
- timestamp.Empty();
- valeur.Empty();
- ilib.Empty();
- namecmp.Empty();
- read_cmp_data = true;
-
- while( !eof && read_cmp_data )
- {
- if( fgets( Line, 1024, aFile ) == 0 )
- {
- eof = true;
- break;
- }
-
- if( strnicmp( Line, "EndCmp", 6 ) == 0 )
- {
- read_cmp_data = true;
- break;
- }
-
- ident = strtok( Line, "=;\n\r" );
- data = strtok( NULL, ";\n\r" );
-
- if( strnicmp( ident, "TimeStamp", 9 ) == 0 )
- {
- timestamp = FROM_UTF8( data );
- timestamp.Trim( true );
- timestamp.Trim( false );
- continue;
- }
-
- if( strnicmp( ident, "Reference", 9 ) == 0 )
- {
- namecmp = FROM_UTF8( data );
- namecmp.Trim( true );
- namecmp.Trim( false );
- continue;
- }
-
- if( strnicmp( ident, "ValeurCmp", 9 ) == 0 )
- {
- valeur = FROM_UTF8( data );
- valeur.Trim( true );
- valeur.Trim( false );
- continue;
- }
-
- if( strnicmp( ident, "IdModule", 8 ) == 0 )
- {
- ilib = FROM_UTF8( data );
- ilib.Trim( true );
- ilib.Trim( false );
- continue;
- }
- } // End reading one component link block.
-
- // Search corresponding component info in list and update its parameters.
- BOOST_FOREACH( COMPONENT_INFO& component, m_components )
- {
- if( namecmp != component.m_Reference )
- continue;
-
- /* Copy the name of the corresponding module. */
- component.m_Footprint = ilib;
- }
- }
-
- fclose( aFile );
- return true;
-}
-
diff --git a/cvpcb/readschematicnetlist.cpp b/cvpcb/readschematicnetlist.cpp
index 06e0a36bbf..402443bb98 100644
--- a/cvpcb/readschematicnetlist.cpp
+++ b/cvpcb/readschematicnetlist.cpp
@@ -26,7 +26,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
-/* Read a nelist type Eeschema (New and Old format)
+/* Read a netlist type Eeschema (New and Old format)
* or OrcadPCB2 and build the component list
*/
@@ -35,82 +35,56 @@
#include
#include
#include
+#include
#include
#include
-
#include
-// 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;
-}
-
int CVPCB_MAINFRAME::ReadSchematicNetlist()
{
- FILE* netfile = wxFopen( m_NetlistFileName.GetFullPath(), wxT( "rt" ) );
+ wxBusyCursor dummy; // Shows an hourglass while loading.
+ NETLIST_READER* netlistReader;
+ wxString msg;
+ wxString compFootprintLinkFileName;
+ wxFileName fn = m_NetlistFileName;
- if( netfile == NULL )
+ // Load the footprint association file if it has already been created.
+ fn.SetExt( ComponentFileExtension );
+
+ if( fn.FileExists() && fn.IsFileReadable() )
+ compFootprintLinkFileName = fn.GetFullPath();
+
+ m_netlist.Clear();
+
+ try
{
- wxString msg;
- msg.Printf( _( "Could not open file <%>" ),
- GetChars( m_NetlistFileName.GetFullPath() ) );
- wxMessageBox( msg );
- return -1;
+ netlistReader = NETLIST_READER::GetNetlistReader( &m_netlist,
+ m_NetlistFileName.GetFullPath(),
+ compFootprintLinkFileName );
+ std::auto_ptr< NETLIST_READER > nlr( netlistReader );
+ netlistReader->LoadNetlist();
+ }
+ catch( IO_ERROR& ioe )
+ {
+ msg = wxString::Format( _( "Error loading netlist.\n%s" ), ioe.errorText.GetData() );
+ wxMessageBox( msg, _( "Netlist Load Error" ), wxOK | wxICON_ERROR );
+ return 1;
}
- 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 );
- // True to read footprint filters section: true for CvPcb, false for Pcbnew
- netList_Reader.ReadLibpartSectionSetOpt( true );
-
- // on OSX otherwise reloading a file you will see duplicates
- m_components.clear();
-
- bool success = netList_Reader.ReadNetList( netfile );
- if( !success )
+ // We also remove footprint name if it is "$noname" because this is a dummy name,
+ // not the actual name of the footprint.
+ for( unsigned ii = 0; ii < m_netlist.GetCount(); ii++ )
{
- wxMessageBox( _("Netlist read error") );
- return false;
+ if( m_netlist.GetComponent( ii )->GetFootprintLibName() == wxT( "$noname" ) )
+ m_netlist.GetComponent( ii )->SetFootprintLibName( wxEmptyString );
}
- // Now copy footprints info into Cvpcb list:
- // We also remove footprint name if it is "$noname"
- // because this is a dummy name,, not an actual name
- COMPONENT_INFO_LIST& cmpInfo = netList_Reader.GetComponentInfoList();
- for( unsigned ii = 0; ii < cmpInfo.size(); ii++ )
- {
- m_components.push_back( cmpInfo[ii] );
- if( cmpInfo[ii]->m_Footprint == wxT( "$noname" ) )
- cmpInfo[ii]->m_Footprint.Empty();
- }
- cmpInfo.clear(); // cmpInfo is no more owner of the list.
-
// Sort components by reference:
- sort( m_components.begin(), m_components.end() );
-
- // 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() )
- {
- for( unsigned ii = 0; ii < m_components.size(); ii++ )
- {
- LIPBART_INFO* libpart = netList_Reader.GetLibpart(m_components[ii].m_Libpart);
- if( libpart == NULL )
- continue;
-
- // now copy filter list
- m_components[ii].m_FootprintFilter = libpart->m_FootprintFilter;
- }
- }
+ m_netlist.SortByReference();
return 0;
}
diff --git a/cvpcb/readwrite_dlgs.cpp b/cvpcb/readwrite_dlgs.cpp
index 881b0fbef3..4027980809 100644
--- a/cvpcb/readwrite_dlgs.cpp
+++ b/cvpcb/readwrite_dlgs.cpp
@@ -41,17 +41,17 @@
void CVPCB_MAINFRAME::SetNewPkg( const wxString& aFootprintName )
{
- COMPONENT_INFO* component;
+ COMPONENT* component;
bool hasFootprint = false;
int componentIndex;
wxString description;
- if( m_components.empty() )
+ if( m_netlist.IsEmpty() )
return;
- // if no component is selected, select the first one
+ // If no component is selected, select the first one
- if(m_ListCmp->GetFirstSelected() < 0)
+ if( m_ListCmp->GetFirstSelected() < 0 )
{
componentIndex = 0;
m_ListCmp->SetSelection( componentIndex, true );
@@ -61,28 +61,28 @@ void CVPCB_MAINFRAME::SetNewPkg( const wxString& aFootprintName )
while( m_ListCmp->GetFirstSelected() != -1)
{
- // get the component for the current iteration
+ // Get the component for the current iteration
componentIndex = m_ListCmp->GetFirstSelected();
- component = &m_components[componentIndex];
+ component = m_netlist.GetComponent( componentIndex );
if( component == NULL )
return;
- // check to see if the component has allready a footprint set.
+ // Check to see if the component has already a footprint set.
- hasFootprint = !(component->m_Footprint.IsEmpty());
+ hasFootprint = !(component->GetFootprintLibName().IsEmpty());
- component->m_Footprint = aFootprintName;
+ component->SetFootprintLibName( aFootprintName );
// create the new component description
description.Printf( CMP_FORMAT, componentIndex + 1,
- GetChars( component->m_Reference ),
- GetChars( component->m_Value ),
- GetChars( component->m_Footprint ) );
+ GetChars( component->GetReference() ),
+ GetChars( component->GetValue() ),
+ GetChars( component->GetFootprintLibName() ) );
- // if the component hasn't had a footprint associated with it
+ // If the component hasn't had a footprint associated with it
// it now has, so we decrement the count of components without
// a footprint assigned.
@@ -92,12 +92,12 @@ void CVPCB_MAINFRAME::SetNewPkg( const wxString& aFootprintName )
m_undefinedComponentCnt -= 1;
}
- // set the new description and deselect the processed component
+ // Set the new description and deselect the processed component
m_ListCmp->SetString( componentIndex, description );
m_ListCmp->SetSelection( componentIndex, false );
}
- // mark this "session" as modified
+ // Mark this "session" as modified
m_modified = true;
// select the next component, if there is one
@@ -113,22 +113,10 @@ void CVPCB_MAINFRAME::SetNewPkg( const wxString& aFootprintName )
bool CVPCB_MAINFRAME::ReadNetListAndLinkFiles()
{
+ COMPONENT* component;
wxString msg;
- int error_level;
- error_level = ReadSchematicNetlist();
-
- if( error_level < 0 )
- {
- msg.Printf( _( "File <%s> does not appear to be a valid KiCad net list file." ),
- GetChars( m_NetlistFileName.GetFullPath() ) );
- wxMessageBox( msg, _( "File Error" ), wxOK | wxICON_ERROR, this );
- m_NetlistFileName.Clear();
- UpdateTitle();
- return false;
- }
-
- LoadComponentLinkFile( m_NetlistFileName.GetFullPath() );
+ ReadSchematicNetlist();
if( m_ListCmp == NULL )
return false;
@@ -140,19 +128,21 @@ bool CVPCB_MAINFRAME::ReadNetListAndLinkFiles()
m_ListCmp->Clear();
m_undefinedComponentCnt = 0;
- BOOST_FOREACH( COMPONENT_INFO& component, m_components )
+ for( unsigned i = 0; i < m_netlist.GetCount(); i++ )
{
+ component = m_netlist.GetComponent( i );
+
msg.Printf( CMP_FORMAT, m_ListCmp->GetCount() + 1,
- GetChars( component.m_Reference ),
- GetChars( component.m_Value ),
- GetChars( component.m_Footprint ) );
+ GetChars( component->GetReference() ),
+ GetChars( component->GetValue() ),
+ GetChars( component->GetFootprintLibName() ) );
m_ListCmp->AppendLine( msg );
- if( component.m_Footprint.IsEmpty() )
+ if( component->GetFootprintLibName().IsEmpty() )
m_undefinedComponentCnt += 1;
}
- if( !m_components.empty() )
+ if( !m_netlist.IsEmpty() )
m_ListCmp->SetSelection( 0, true );
DisplayStatus();
@@ -165,37 +155,6 @@ bool CVPCB_MAINFRAME::ReadNetListAndLinkFiles()
}
-bool CVPCB_MAINFRAME::LoadComponentLinkFile( const wxString& aFileName )
-{
- FILE* linkfile;
- wxFileName fn = aFileName;
-
- fn.SetExt( ComponentFileExtension );
-
- linkfile = wxFopen( fn.GetFullPath(), wxT( "rt" ) );
- if( linkfile == NULL )
- {
- wxString msg;
- msg.Printf( _( "Cannot open CvPcb component file <%s>." ),
- GetChars( fn.GetFullPath() ) );
- msg << wxT( "\n" ) << _( "This is normal if you are opening a new netlist file" );
- wxMessageBox( msg, titleComponentLibErr, wxOK | wxICON_ERROR );
- return false;
- }
-
- // read and close the file
- if( ! ReadComponentLinkFile( linkfile ) )
- {
- wxString msg;
- msg.Printf( _( " <%s> does not appear to be a valid KiCad component link file." ),
- GetChars( fn.GetFullPath() ) );
- wxMessageBox( msg, titleComponentLibErr, wxOK | wxICON_ERROR );
- return false;
- }
-
- return true;
-}
-
int CVPCB_MAINFRAME::SaveCmpLinkFile( const wxString& aFullFileName )
{
wxFileName fn;
@@ -207,7 +166,7 @@ int CVPCB_MAINFRAME::SaveCmpLinkFile( const wxString& aFullFileName )
}
else
{
- wxFileDialog dlg( this, _( "Save Component/Footprint Link File" ), wxGetCwd(),
+ wxFileDialog dlg( this, _( "Save Component Footprint Link File" ), wxGetCwd(),
wxEmptyString, ComponentFileWildcard, wxFD_SAVE );
if( dlg.ShowModal() == wxID_CANCEL )
@@ -224,7 +183,7 @@ int CVPCB_MAINFRAME::SaveCmpLinkFile( const wxString& aFullFileName )
if( WriteComponentLinkFile( fn.GetFullPath() ) == 0 )
{
- DisplayError( this, _( "Unable to create component file (.cmp)" ) );
+ DisplayError( this, _( "Unable to create component footprint link file (.cmp)" ) );
return 0;
}
diff --git a/eeschema/class_library.cpp b/eeschema/class_library.cpp
index d5ef45001a..53e69728d7 100644
--- a/eeschema/class_library.cpp
+++ b/eeschema/class_library.cpp
@@ -148,7 +148,7 @@ void CMP_LIBRARY::GetEntryNames( wxArrayString& aNames, bool aSort, bool aMakeUp
* simple function used as comparator to sort a std::vector&.
*
* @param aItem1 is the first comparison parameter.
- * @param aItem1 is the second.
+ * @param aItem2 is the second.
* @return bool - which item should be put first in the sorted list.
*/
bool sortFunction( wxArrayString aItem1, wxArrayString aItem2 )
diff --git a/include/appl_wxstruct.h b/include/appl_wxstruct.h
index e793795dd3..014de9a7e1 100644
--- a/include/appl_wxstruct.h
+++ b/include/appl_wxstruct.h
@@ -259,7 +259,7 @@ public:
* true.
* @param aList = array of PARAM_CFG_BASE pointers
*/
- void SaveCurrentSetupValues( const PARAM_CFG_ARRAY& List );
+ void SaveCurrentSetupValues( const PARAM_CFG_ARRAY& aList );
/**
* Function ReadCurrentSetupValues
@@ -268,7 +268,7 @@ public:
* true.
* @param aList = array of PARAM_CFG_BASE pointers
*/
- void ReadCurrentSetupValues( const PARAM_CFG_ARRAY& List );
+ void ReadCurrentSetupValues( const PARAM_CFG_ARRAY& aList );
/**
* Function ReadProjectConfig
diff --git a/include/dialog_helpers.h b/include/dialog_helpers.h
index 9f5bb90cd1..45e3ecfb13 100644
--- a/include/dialog_helpers.h
+++ b/include/dialog_helpers.h
@@ -1,3 +1,27 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2010 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
+ * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.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
+ */
+
/**
* @file dialog_helpers.h
* @brief Helper dialog and control classes.
@@ -38,6 +62,7 @@ public:
* Constructor:
* @param aParent Pointer to the parent window.
* @param aTitle = The title shown on top.
+ * @param aItemHeaders is an array containing the column header names for the dialog.
* @param aItemList = A wxArrayString of the list of elements.
* @param aRefText = An item name if an item must be preselected.
* @param aCallBackFunction = callback function to display comments
diff --git a/include/fpid.h b/include/fpid.h
index 221e9c6a1a..657a6a7101 100644
--- a/include/fpid.h
+++ b/include/fpid.h
@@ -133,8 +133,31 @@ public:
const std::string& aRevision )
throw( PARSE_ERROR );
+ /**
+ * Function clear
+ * clears the contents of the library nickname, footprint name, and revision strings.
+ */
void clear();
+ /**
+ * Function empty
+ * @return a boolean true value if the FPID is empty. Otherwise return false.
+ */
+ bool empty() const { return nickname.empty() && footprint.empty() && revision.empty(); }
+
+ /**
+ * Function Compare
+ * compares the contents of FPID objects by performing a std::string comparison of the
+ * library nickname, footprint name, and revision strings respectively.
+ *
+ * @param aFPID is the FPID to compare against.
+ * @return -1 if less than \a aFPID, 1 if greater than \a aFPID, and 0 if equal to \a aFPID.
+ */
+ int compare( const FPID& aFPID ) const;
+
+ bool operator <( const FPID& aFPID ) const { return this->compare( aFPID ) < 0; }
+ bool operator ==( const FPID& aFPID ) const { return this->compare( aFPID ) == 0; }
+
#if defined(DEBUG)
static void Test();
#endif
diff --git a/include/reporter.h b/include/reporter.h
new file mode 100644
index 0000000000..9f2081a8a6
--- /dev/null
+++ b/include/reporter.h
@@ -0,0 +1,89 @@
+#ifndef _REPORTER_H_
+#define _REPORTER_H_
+
+/**
+ * @file reporter.h
+ * @author Wayne Stambaugh
+ * @note A special thanks to Dick Hollenbeck who came up with the idea that inspired
+ * me to write this.
+ */
+
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2013 Wayne Stambaugh
+ * Copyright (C) 1992-2013 KiCad Developers, see change_log.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
+ */
+
+
+class wxString;
+class wxTextCtrl;
+
+
+/**
+ * Class REPORTER
+ * is a pure virtual class used to derive REPORTOR objects from.
+ *
+ * The purpose of the REPORTER object is to hide an object that take a string as an input
+ * from other objects. This prevents objects such as wxWidgets UI control internals from
+ * being exposed to low level KiCad objects dervice from #BOARD_ITEM and #SCH_ITEM.
+ */
+class REPORTER
+{
+public:
+ /**
+ * Function Report
+ * is a pure virtual function to override in the derived object.
+ *
+ * @param aText is the string to report.
+ */
+ virtual REPORTER& Report( const wxString& aText ) = 0;
+
+ REPORTER& Report( const char *aText );
+
+ REPORTER& operator <<( const wxString& aText ) { return Report( aText ); }
+
+ REPORTER& operator <<( const wxChar* aText ) { return Report( wxString( aText ) ); }
+
+ REPORTER& operator <<( wxChar aChar ) { return Report( wxString( aChar ) ); }
+
+ REPORTER& operator <<( const char* aText ) { return Report( aText ); }
+};
+
+
+/**
+ * Class WX_TEXT_CTRL_REPORTER
+ * is wrapper for reporting to a wxTextCtrl object.
+ */
+class WX_TEXT_CTRL_REPORTER : public REPORTER
+{
+ wxTextCtrl* m_textCtrl;
+
+public:
+ WX_TEXT_CTRL_REPORTER( wxTextCtrl* aTextCtrl ) :
+ REPORTER(),
+ m_textCtrl( aTextCtrl )
+ {
+ }
+
+ REPORTER& Report( const wxString& aText );
+};
+
+#endif // _REPORTER_H_
diff --git a/include/wildcards_and_files_ext.h b/include/wildcards_and_files_ext.h
index 9f1368eabb..39dc4f5165 100644
--- a/include/wildcards_and_files_ext.h
+++ b/include/wildcards_and_files_ext.h
@@ -98,6 +98,7 @@ extern const wxString KiCadFootprintLibFileWildcard;
extern const wxString KiCadFootprintLibPathWildcard;
extern const wxString GedaPcbFootprintLibFileWildcard;
extern const wxString EagleFootprintLibPathWildcard;
+extern const wxString TextWildcard;
#endif // INCLUDE_WILDCARDS_AND_FILES_EXT_H_
diff --git a/include/wxBasePcbFrame.h b/include/wxBasePcbFrame.h
index cdc7b19cf7..964b4163d4 100644
--- a/include/wxBasePcbFrame.h
+++ b/include/wxBasePcbFrame.h
@@ -91,6 +91,19 @@ protected:
void updateZoomSelectBox();
virtual void unitsChangeRefresh();
+ /**
+ * Function loadFootprint
+ * attempts to load \a aFootprintName from the list of libraries.
+ *
+ * @param aFootprintName is the name of component footprint to load.
+ * @return the #MODULE if found or NULL if \a aFootprintName not found in any of the
+ * libraries.
+ * @throw IO_ERROR if an I/O error occurs or a #PARSE_ERROR if a file parsing error
+ * occurs while reading footprint library files.
+ */
+ MODULE* loadFootprint( const wxString& aFootprintName )
+ throw( IO_ERROR, PARSE_ERROR );
+
public:
PCB_BASE_FRAME( wxWindow* aParent, ID_DRAWFRAME_TYPE aFrameType,
const wxString& aTitle,
diff --git a/include/wxPcbStruct.h b/include/wxPcbStruct.h
index 5ba16dc3e6..8a87869d7b 100644
--- a/include/wxPcbStruct.h
+++ b/include/wxPcbStruct.h
@@ -59,6 +59,10 @@ class PCB_LAYER_WIDGET;
class MARKER_PCB;
class BOARD_ITEM;
class PCB_LAYER_BOX_SELECTOR;
+class NETLIST;
+class REPORTER;
+class PARSE_ERROR;
+class IO_ERROR;
/**
@@ -80,6 +84,18 @@ class PCB_EDIT_FRAME : public PCB_BASE_FRAME
/// The auxiliary right vertical tool bar used to access the microwave tools.
wxAuiToolBar* m_microWaveToolBar;
+ /**
+ * Function loadFootprints
+ * loads the footprints for each #COMPONENT in \a aNetlist from the list of libraries.
+ *
+ * @param aNetlist is the netlist of components to load the footprints into.
+ * @param aReporter is the #REPORTER object to report to.
+ * @throw IO_ERROR if an I/O error occurs or a #PARSE_ERROR if a file parsing error
+ * occurs while reading footprint library files.
+ */
+ void loadFootprints( NETLIST& aNetlist, REPORTER* aReporter )
+ throw( IO_ERROR, PARSE_ERROR );
+
protected:
#ifdef KICAD_SCRIPTING_WXPYTHON
@@ -414,27 +430,6 @@ public:
m_useCmpFileForFpNames = aUseCmpfile;
}
- /**
- * 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 aFilename = the full filename netlist
- * @param aDuplicate = the list of duplicate modules to populate
- * @param aMissing = the list of missing module references and values
- * to populate. For each missing item, the first string is the ref,
- * the second is the value.
- * @param aNotInNetlist = the list of not-in-netlist modules to populate
- * @return true if the netlist was read, or false
- */
- bool Test_Duplicate_Missing_And_Extra_Footprints( const wxString& aFilename,
- std::vector & aDuplicate,
- wxArrayString& aMissing,
- std::vector & aNotInNetlist );
-
/**
* Function OnHotKey.
* ** Commands are case insensitive **
@@ -960,6 +955,11 @@ public:
*/
void Access_to_External_Tool( wxCommandEvent& event );
+ /**
+ * Function ListAndSelectModuleName
+ * builds and shows a list of existing modules on board that the user can select.
+ * @return a pointer to the selected module or NULL.
+ */
MODULE* ListAndSelectModuleName();
/**
@@ -1421,29 +1421,31 @@ public:
/**
* Function ReadPcbNetlist
- * Update footprints (load missing footprints and delete on demand extra
- * footprints)
+ * reads \a aNetlistFileName and ppdates the footprints (load missing footprints and
+ * delete on demand extra footprints) on the board.
* Update connectivity info, references, values and "TIME STAMP"
- * @param aNetlistFullFilename = netlist file name (*.net)
- * @param aCmpFullFileName = cmp/footprint link file name (*.cmp).
- * if not found or empty, only the netlist will be used
- * @param aMessageWindow = a reference to a wxTextCtrl where to display messages.
- * can be NULL
+ *
+ * @param aNetlistFileName = netlist file name (*.net)
+ * @param aCmpFileName = cmp/footprint link file name (*.cmp).
+ * if not found or empty, only the netlist will be used
+ * @param aReporter is a pointer to a #REPORTER object to write display messages.
+ * can be NULL.
* @param aChangeFootprint if true, footprints that have changed in netlist will be changed
* @param aDeleteBadTracks if true, erroneous tracks will be deleted
* @param aDeleteExtraFootprints if true, remove unlocked footprints that are not in netlist
- * @param aSelect_By_Timestamp if true, use timestamp instead of reference to identify
- * footprints from components (use after reannotation of the
- * schematic)
- * @return true if Ok
+ * @param aSelectByTimestamp if true, use timestamp instead of reference to identify
+ * footprints from components (use after reannotation of the
+ * schematic)
+ * @param aIsDryRun performs a dry run without making any changes if true.
*/
- bool ReadPcbNetlist( const wxString& aNetlistFullFilename,
- const wxString& aCmpFullFileName,
- wxTextCtrl* aMessageWindow,
+ void ReadPcbNetlist( const wxString& aNetlistFileName,
+ const wxString& aCmpFileName,
+ REPORTER* aReporter,
bool aChangeFootprint,
bool aDeleteBadTracks,
bool aDeleteExtraFootprints,
- bool aSelect_By_Timestamp );
+ bool aSelectByTimestamp,
+ bool aIsDryRun );
/**
* Function RemoveMisConnectedTracks
@@ -1480,8 +1482,7 @@ public:
* @param include_fixe = true to orient locked footprints
* @return true if some footprints modified, false if no change
*/
- bool ReOrientModules( const wxString& ModuleMask, int Orient,
- bool include_fixe );
+ bool ReOrientModules( const wxString& ModuleMask, int Orient, bool include_fixe );
void LockModule( MODULE* aModule, bool aLocked );
void AutoMoveModulesOnPcb( bool PlaceModulesHorsPcb );
diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt
index ba68add0c8..1c6bf153e4 100644
--- a/pcbnew/CMakeLists.txt
+++ b/pcbnew/CMakeLists.txt
@@ -181,9 +181,6 @@ set(PCBNEW_CLASS_SRCS
muonde.cpp
muwave_command.cpp
netlist.cpp
- netlist_reader_common.cpp
- netlist_reader_firstformat.cpp
- netlist_reader_kicad.cpp
onleftclick.cpp
onrightclick.cpp
pad_edition_functions.cpp
diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp
index eb7c6d540b..6d9fbd1d25 100644
--- a/pcbnew/class_board.cpp
+++ b/pcbnew/class_board.cpp
@@ -39,6 +39,8 @@
#include
#include
#include
+#include
+#include
#include
#include
@@ -1411,6 +1413,26 @@ MODULE* BOARD::FindModuleByReference( const wxString& aReference ) const
}
+MODULE* BOARD::FindModule( const wxString& aRefOrTimeStamp, bool aSearchByTimeStamp )
+{
+ for( MODULE* module = m_Modules; module != NULL; module = module->Next() )
+ {
+ if( aSearchByTimeStamp )
+ {
+ if( aRefOrTimeStamp.CmpNoCase( module->GetPath() ) == 0 )
+ return module;
+ }
+ else
+ {
+ if( aRefOrTimeStamp.CmpNoCase( module->GetReference() ) == 0 )
+ return module;
+ }
+ }
+
+ return NULL;
+}
+
+
// Sort nets by decreasing pad count
static bool s_SortByNodes( const NETINFO_ITEM* a, const NETINFO_ITEM* b )
{
@@ -2310,6 +2332,251 @@ bool BOARD::NormalizeAreaPolygon( PICKED_ITEMS_LIST * aNewZonesList, ZONE_CONTAI
}
+void BOARD::ReplaceNetlist( NETLIST& aNetlist, REPORTER* aReporter )
+{
+ unsigned i;
+ wxPoint bestPosition;
+ wxString msg;
+ D_PAD* pad;
+ MODULE* footprint;
+ COMPONENT* component;
+ COMPONENT_NET net;
+
+ if( !IsEmpty() )
+ {
+ // Position new components below any existing board features.
+ EDA_RECT bbbox = ComputeBoundingBox( true );
+
+ if( bbbox.GetWidth() || bbbox.GetHeight() )
+ {
+ bestPosition.x = bbbox.Centre().x;
+ bestPosition.y = bbbox.GetBottom() + DMils2iu( 5000 );
+ }
+ }
+ else
+ {
+ // Position new components in the center of the page when the board is empty.
+ wxSize pageSize = m_paper.GetSizeIU();
+
+ bestPosition.x = pageSize.GetWidth() / 2;
+ bestPosition.y = pageSize.GetHeight() / 2;
+ }
+
+ m_Status_Pcb = 0;
+
+ for( i = 0; i < aNetlist.GetCount(); i++ )
+ {
+ component = aNetlist.GetComponent( i );
+
+ if( aReporter )
+ {
+ msg.Printf( _( "Checking netlist component footprint \"%s:%s:%s\".\n" ),
+ GetChars( component->GetReference() ),
+ GetChars( component->GetTimeStamp() ),
+ GetChars( component->GetFootprintLibName() ) );
+ aReporter->Report( msg );
+ }
+
+ if( aNetlist.IsFindByTimeStamp() )
+ footprint = FindModule( aNetlist.GetComponent( i )->GetTimeStamp(), true );
+ else
+ footprint = FindModule( aNetlist.GetComponent( i )->GetReference() );
+
+ if( footprint == NULL ) // A new footprint.
+ {
+ if( aReporter )
+ {
+ msg.Printf( _( "Adding new component \"%s:%s\" footprint \"%s\".\n" ),
+ GetChars( component->GetReference() ),
+ GetChars( component->GetTimeStamp() ),
+ GetChars( component->GetFootprintLibName() ) );
+ aReporter->Report( msg );
+ }
+
+ // Owned by NETLIST, can only copy and read it.
+ footprint = component->GetModule();
+
+ wxCHECK2_MSG( footprint != NULL, continue,
+ wxString::Format( wxT( "No footprint loaded for component \"%s\"." ),
+ GetChars( component->GetReference() ) ) );
+
+ if( !aNetlist.IsDryRun() )
+ {
+ footprint = new MODULE( *footprint );
+ footprint->SetParent( this );
+ footprint->SetPosition( bestPosition );
+ footprint->SetTimeStamp( GetNewTimeStamp() );
+ Add( footprint, ADD_APPEND );
+ }
+ }
+ else // An existing footprint.
+ {
+ // Test for footprint change.
+ if( !component->GetFootprintLibName().IsEmpty() &&
+ footprint->GetLibRef() != component->GetFootprintLibName() )
+ {
+ if( aNetlist.GetReplaceFootprints() )
+ {
+ if( aReporter )
+ {
+ msg.Printf( _( "Replacing component \"%s:%s\" footprint \"%s\" with \"%s\".\n" ),
+ GetChars( footprint->GetReference() ),
+ GetChars( footprint->GetPath() ),
+ GetChars( footprint->GetLibRef() ),
+ GetChars( component->GetFootprintLibName() ) );
+ aReporter->Report( msg );
+ }
+
+ if( !aNetlist.IsDryRun() )
+ {
+ wxASSERT( footprint != NULL );
+ MODULE* newFootprint = new MODULE( *component->GetModule() );
+
+ if( aNetlist.IsFindByTimeStamp() )
+ newFootprint->SetReference( footprint->GetReference() );
+ else
+ newFootprint->SetPath( footprint->GetPath() );
+
+ footprint->CopyNetlistSettings( newFootprint );
+ Remove( footprint );
+ Add( newFootprint, ADD_APPEND );
+ footprint = newFootprint;
+ }
+ }
+ }
+
+ // Test for reference designator field change.
+ if( footprint->GetReference() != component->GetReference() )
+ {
+ if( aReporter )
+ {
+ msg.Printf( _( "Changing footprint \"%s:%s\" reference to \"%s\".\n" ),
+ GetChars( footprint->GetReference() ),
+ GetChars( footprint->GetPath() ),
+ GetChars( component->GetReference() ) );
+ aReporter->Report( msg );
+ }
+
+ if( !aNetlist.IsDryRun() )
+ footprint->SetReference( component->GetReference() );
+ }
+
+ // Test for value field change.
+ if( footprint->GetValue() != component->GetValue() )
+ {
+ if( aReporter )
+ {
+ msg.Printf( _( "Changing footprint \"%s:%s\" value from \"%s\" to \"%s\".\n" ),
+ GetChars( footprint->GetReference() ),
+ GetChars( footprint->GetPath() ),
+ GetChars( footprint->GetValue() ),
+ GetChars( component->GetValue() ) );
+ aReporter->Report( msg );
+ }
+
+ if( !aNetlist.IsDryRun() )
+ footprint->SetValue( component->GetValue() );
+ }
+
+ // Test for time stamp change.
+ if( footprint->GetPath() != component->GetTimeStamp() )
+ {
+ if( aReporter )
+ {
+ msg.Printf( _( "Changing footprint path \"%s:%s\" to \"%s\".\n" ),
+ GetChars( footprint->GetReference() ),
+ GetChars( footprint->GetPath() ),
+ GetChars( component->GetTimeStamp() ) );
+ aReporter->Report( msg );
+ }
+
+ if( !aNetlist.IsDryRun() )
+ footprint->SetPath( component->GetTimeStamp() );
+ }
+ }
+
+ wxASSERT( component != NULL );
+
+ // At this point, the component footprint is updated. Now update the nets.
+ for( pad = footprint->Pads(); pad; pad = pad->Next() )
+ {
+ net = component->GetNet( pad->GetPadName() );
+
+ if( !net.IsValid() ) // Footprint pad had no net.
+ {
+ if( !pad->GetNetname().IsEmpty() )
+ {
+ if( aReporter )
+ {
+ msg.Printf( _( "Clearing component \"%s:%s\" pin \"%s\" net name.\n" ),
+ GetChars( footprint->GetReference() ),
+ GetChars( footprint->GetPath() ),
+ GetChars( pad->GetPadName() ) );
+ aReporter->Report( msg );
+ }
+
+ if( !aNetlist.IsDryRun() )
+ pad->SetNetname( wxEmptyString );
+ }
+ }
+ else // Footprint pad has a net.
+ {
+ if( net.GetNetName() != pad->GetNetname() )
+ {
+ if( aReporter )
+ {
+ msg.Printf( _( "Changing component \"%s:%s\" pin \"%s\" net name from "
+ "\"%s\" to \"%s\".\n" ),
+ GetChars( footprint->GetReference() ),
+ GetChars( footprint->GetPath() ),
+ GetChars( pad->GetPadName() ),
+ GetChars( pad->GetNetname() ),
+ GetChars( net.GetNetName() ) );
+ aReporter->Report( msg );
+ }
+
+ if( !aNetlist.IsDryRun() )
+ pad->SetNetname( net.GetNetName() );
+ }
+ }
+ }
+ }
+
+ // Remove all components not in the netlist.
+ if( aNetlist.GetDeleteExtraFootprints() )
+ {
+ MODULE* nextModule;
+
+ for( MODULE* module = m_Modules; module != NULL; module = nextModule )
+ {
+ nextModule = module->Next();
+
+ if( module->IsLocked() )
+ continue;
+
+ if( aNetlist.IsFindByTimeStamp() )
+ component = aNetlist.GetComponentByTimeStamp( module->GetPath() );
+ else
+ component = aNetlist.GetComponentByReference( module->GetReference() );
+
+ if( component == NULL )
+ {
+ if( aReporter )
+ {
+ msg.Printf( _( "Removing footprint \"%s:%s\".\n" ),
+ GetChars( module->GetReference() ),
+ GetChars( module->GetPath() ) );
+ aReporter->Report( msg );
+ }
+
+ if( !aNetlist.IsDryRun() )
+ module->DeleteStructure();
+ }
+ }
+ }
+}
+
+
#if defined(DEBUG)
void BOARD::Show( int nestLevel, std::ostream& os ) const
diff --git a/pcbnew/class_board.h b/pcbnew/class_board.h
index bd0b33ea4e..6e28cb9028 100644
--- a/pcbnew/class_board.h
+++ b/pcbnew/class_board.h
@@ -1,3 +1,27 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2007 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
+ * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.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
+ */
+
/**
* @file class_board.h
* @brief Class BOARD to handle a board.
@@ -30,6 +54,8 @@ class TRACK;
class D_PAD;
class MARKER_PCB;
class MSG_PANEL_ITEM;
+class NETLIST;
+class REPORTER;
// non-owning container of item candidates when searching for items on the same track.
@@ -282,6 +308,12 @@ public:
BOARD();
~BOARD();
+ bool IsEmpty() const
+ {
+ return m_Drawings.GetCount() == 0 && m_Modules.GetCount() == 0 &&
+ m_Track.GetCount() == 0 && m_Zone.GetCount() == 0;
+ }
+
void Move( const wxPoint& aMoveVector ); // overload
void SetFileFormatVersionAtLoad( int aVersion ) { m_fileFormatVersionAtLoad = aVersion; }
@@ -849,6 +881,47 @@ public:
*/
MODULE* FindModuleByReference( const wxString& aReference ) const;
+ /**
+ * Function FindModule
+ * searches for a module matching \a aRefOrTimeStamp depending on the state of
+ * \a aSearchByTimeStamp.
+ * @param aRefOrTimeStamp is the search string.
+ * @param aSearchByTimeStamp searches by the module time stamp value if true. Otherwise
+ * search by reference designator.
+ * @return the module found or NULL if not module is found that meets the search criteria.
+ */
+ MODULE* FindModule( const wxString& aRefOrTimeStamp, bool aSearchByTimeStamp = false );
+
+ /**
+ * Function ReplaceNetlist
+ * updates the #BOARD according to \a aNetlist.
+ *
+ * The changes are made to the board are as follows they are not disabled in the status
+ * settings in the #NETLIST:
+ * - If a new component is found in the #NETLIST and not in the #BOARD, it is added
+ * to the #BOARD.
+ * - If a the component in the #NETLIST is already on the #BOARD, then one or more of the
+ * following actions can occur:
+ * + If the footprint name in the #NETLIST does not match the footprint name on the
+ * #BOARD, the footprint on the #BOARD is replaced with the footprint specified in
+ * the #NETLIST and the proper parameters are copied from the existing footprint.
+ * + If the reference designator in the #NETLIST does not match the reference designator
+ * on the #BOARD, the reference designator is updated from the #NETLIST.
+ * + If the value field in the #NETLIST does not match the value field on the #BOARD,
+ * the value field is updated from the #NETLIST.
+ * + If the time stamp in the #NETLIST does not match the time stamp on the #BOARD,
+ * the time stamp is updated from the #NETLIST.
+ * - After each footprint is added or update as described above, each footprint pad net
+ * name is compared and updated to the value defined in the #NETLIST.
+ * - After all of the footprints have been added, updated, and net names properly set,
+ * any extra unlock footprints are removed from the #BOARD.
+ *
+ * @param aNetlist is the new netlist to revise the contents of the #BOARD with.
+ * @param aReporter is a #REPORTER object to report the changes \a aNetlist makes to
+ * the #BOARD. If NULL, no change reporting occurs.
+ */
+ void ReplaceNetlist( NETLIST& aNetlist, REPORTER* aReporter = NULL );
+
/**
* Function ReturnSortedNetnamesList
* @param aNames An array string to fill with net names.
@@ -1229,12 +1302,12 @@ public:
/**
* Function GetPadFast
- * return pad found at \a aPosition on \a aLayer using the fast search method.
+ * return pad found at \a aPosition on \a aLayerMask using the fast search method.
*