Use KiwayExpress messaging for CvPcb footprint assignment instead of *.cmp file.

* Remove global s_NetObjectslist.
* Separate out non-owning version of NETLIST_OBJECTS_LIST into NETLIST_OBJECTS.
* Fix double free pertaining to ~NETLIST_READER().
* Remove all file-io from CvPCB.
* Remove exe launcher cvpcb, retain only cvpcb.kiface, since cvpcb.kiface has no file i/o.
* Add void CVPCB_MAINFRAME::KiwayMailIn( KIWAY_EXPRESS& mail ) and teach it to use old
  netlist loading code with a STRING_LINE_READER LINE_READER.
* Fix BEGIN_EVENT_TABLE( CVPCB_MAINFRAME, KIWAY_PLAYER )
This commit is contained in:
Dick Hollenbeck 2015-06-07 14:18:45 -04:00 committed by Wayne Stambaugh
parent aadcd93ab5
commit 8fb520249e
38 changed files with 410 additions and 521 deletions

View File

@ -752,7 +752,7 @@ add_subdirectory( qa )
# except perhaps bitmap lib. This allows a multi-threaded build to succeed. # except perhaps bitmap lib. This allows a multi-threaded build to succeed.
add_dependencies( pcbnew boost ) add_dependencies( pcbnew boost )
add_dependencies( eeschema boost ) add_dependencies( eeschema boost )
add_dependencies( cvpcb boost ) add_dependencies( cvpcb_kiface boost )
add_dependencies( gal boost ) add_dependencies( gal boost )
add_dependencies( common boost ) add_dependencies( common boost )
add_dependencies( pcbcommon boost ) add_dependencies( pcbcommon boost )

View File

@ -74,28 +74,59 @@ if( APPLE )
endif() endif()
add_executable( cvpcb WIN32 MACOSX_BUNDLE if( false ) # no CVPCB exe any more, only the *.kiface
../common/single_top.cpp add_executable( cvpcb WIN32 MACOSX_BUNDLE
../common/pgm_base.cpp ../common/single_top.cpp
${CVPCB_RESOURCES} ../common/pgm_base.cpp
) ${CVPCB_RESOURCES}
)
set_source_files_properties( ../common/single_top.cpp PROPERTIES
COMPILE_DEFINITIONS "TOP_FRAME=FRAME_CVPCB;PGM_DATA_FILE_EXT=\"net\";BUILD_KIWAY_DLL"
)
target_link_libraries( cvpcb
#singletop # replaces common, giving us restrictive control and link warnings.
# There's way too much crap coming in from common yet.
common
bitmaps
${wxWidgets_LIBRARIES}
)
if( MAKE_LINK_MAPS )
set_target_properties( cvpcb PROPERTIES
LINK_FLAGS "${TO_LINKER},-cref ${TO_LINKER},-Map=cvpcb.map" )
endif()
set_source_files_properties( ../common/single_top.cpp PROPERTIES if( APPLE )
COMPILE_DEFINITIONS "TOP_FRAME=FRAME_CVPCB;PGM_DATA_FILE_EXT=\"net\";BUILD_KIWAY_DLL" set_target_properties( cvpcb PROPERTIES
) MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist
)
target_link_libraries( cvpcb # put individual bundle outside of main bundle as a first step
#singletop # replaces common, giving us restrictive control and link warnings. # will be pulled into the main bundle when creating main bundle
# There's way too much crap coming in from common yet. install( TARGETS cvpcb
common DESTINATION ${KICAD_BIN}
bitmaps COMPONENT binary
${wxWidgets_LIBRARIES} )
) install( CODE "
# override default embedded path settings
${OSX_BUNDLE_OVERRIDE_PATHS}
# do all the work
include( BundleUtilities )
fixup_bundle( ${KICAD_BIN}/cvpcb.app/Contents/MacOS/cvpcb
\"\"
\"\"
)
" COMPONENT Runtime
)
else()
install( TARGETS cvpcb
DESTINATION ${KICAD_BIN}
COMPONENT binary
)
endif()
endif() # no CVPCB exe
if( MAKE_LINK_MAPS )
set_target_properties( cvpcb PROPERTIES
LINK_FLAGS "${TO_LINKER},-cref ${TO_LINKER},-Map=cvpcb.map" )
endif()
# the main cvpcb program, in DSO form. # the main cvpcb program, in DSO form.
add_library( cvpcb_kiface MODULE add_library( cvpcb_kiface MODULE
@ -143,42 +174,13 @@ if( MAKE_LINK_MAPS )
LINK_FLAGS "${TO_LINKER},-cref ${TO_LINKER},-Map=_cvpcb.kiface.map" ) LINK_FLAGS "${TO_LINKER},-cref ${TO_LINKER},-Map=_cvpcb.kiface.map" )
endif() endif()
# if building cvpcb, then also build cvpcb_kiface if out of date.
add_dependencies( cvpcb cvpcb_kiface )
# these 2 binaries are a matched set, keep them together: # these 2 binaries are a matched set, keep them together:
if( APPLE ) if( APPLE )
set_target_properties( cvpcb PROPERTIES
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist
)
# puts binaries into the *.app bundle while linking # puts binaries into the *.app bundle while linking
set_target_properties( cvpcb_kiface PROPERTIES set_target_properties( cvpcb_kiface PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${OSX_BUNDLE_BUILD_KIFACE_DIR} LIBRARY_OUTPUT_DIRECTORY ${OSX_BUNDLE_BUILD_KIFACE_DIR}
) )
# put individual bundle outside of main bundle as a first step
# will be pulled into the main bundle when creating main bundle
install( TARGETS cvpcb
DESTINATION ${KICAD_BIN}
COMPONENT binary
)
install( CODE "
# override default embedded path settings
${OSX_BUNDLE_OVERRIDE_PATHS}
# do all the work
include( BundleUtilities )
fixup_bundle( ${KICAD_BIN}/cvpcb.app/Contents/MacOS/cvpcb
\"\"
\"\"
)
" COMPONENT Runtime
)
else() else()
install( TARGETS cvpcb
DESTINATION ${KICAD_BIN}
COMPONENT binary
)
install( TARGETS cvpcb_kiface install( TARGETS cvpcb_kiface
DESTINATION ${KICAD_BIN} DESTINATION ${KICAD_BIN}
COMPONENT binary COMPONENT binary

View File

@ -29,6 +29,7 @@
#include <fctsys.h> #include <fctsys.h>
#include <build_version.h> #include <build_version.h>
#include <kiway_express.h>
#include <pgm_base.h> #include <pgm_base.h>
#include <kiface_i.h> #include <kiface_i.h>
#include <macros.h> #include <macros.h>
@ -58,13 +59,10 @@ static const wxString KeepCvpcbOpenEntry( wxT( "KeepCvpcbOpen" ) );
static const wxString FootprintDocFileEntry( wxT( "footprints_doc_file" ) ); static const wxString FootprintDocFileEntry( wxT( "footprints_doc_file" ) );
BEGIN_EVENT_TABLE( CVPCB_MAINFRAME, EDA_BASE_FRAME ) BEGIN_EVENT_TABLE( CVPCB_MAINFRAME, KIWAY_PLAYER )
EVT_MENU_RANGE( wxID_FILE1, wxID_FILE9, CVPCB_MAINFRAME::LoadNetList )
// Menu events // Menu events
EVT_MENU( ID_LOAD_PROJECT, CVPCB_MAINFRAME::LoadNetList )
EVT_MENU( wxID_SAVE, CVPCB_MAINFRAME::SaveQuitCvpcb ) EVT_MENU( wxID_SAVE, CVPCB_MAINFRAME::SaveQuitCvpcb )
EVT_MENU( wxID_SAVEAS, CVPCB_MAINFRAME::SaveQuitCvpcb )
EVT_MENU( wxID_EXIT, CVPCB_MAINFRAME::OnQuit ) EVT_MENU( wxID_EXIT, CVPCB_MAINFRAME::OnQuit )
EVT_MENU( wxID_HELP, CVPCB_MAINFRAME::GetKicadHelp ) EVT_MENU( wxID_HELP, CVPCB_MAINFRAME::GetKicadHelp )
EVT_MENU( wxID_ABOUT, CVPCB_MAINFRAME::GetKicadAbout ) EVT_MENU( wxID_ABOUT, CVPCB_MAINFRAME::GetKicadAbout )
@ -75,7 +73,7 @@ BEGIN_EVENT_TABLE( CVPCB_MAINFRAME, EDA_BASE_FRAME )
// Toolbar events // Toolbar events
EVT_TOOL( ID_CVPCB_QUIT, CVPCB_MAINFRAME::OnQuit ) EVT_TOOL( ID_CVPCB_QUIT, CVPCB_MAINFRAME::OnQuit )
EVT_TOOL( ID_CVPCB_READ_INPUT_NETLIST, CVPCB_MAINFRAME::LoadNetList )
EVT_TOOL( ID_CVPCB_LIB_TABLE_EDIT, CVPCB_MAINFRAME::OnEditFootprintLibraryTable ) EVT_TOOL( ID_CVPCB_LIB_TABLE_EDIT, CVPCB_MAINFRAME::OnEditFootprintLibraryTable )
EVT_TOOL( ID_CVPCB_CREATE_SCREENCMP, CVPCB_MAINFRAME::DisplayModule ) EVT_TOOL( ID_CVPCB_CREATE_SCREENCMP, CVPCB_MAINFRAME::DisplayModule )
EVT_TOOL( ID_CVPCB_GOTO_FIRSTNA, CVPCB_MAINFRAME::ToFirstNA ) EVT_TOOL( ID_CVPCB_GOTO_FIRSTNA, CVPCB_MAINFRAME::ToFirstNA )
@ -243,8 +241,6 @@ void CVPCB_MAINFRAME::OnQuit( wxCommandEvent& event )
void CVPCB_MAINFRAME::OnCloseWindow( wxCloseEvent& Event ) void CVPCB_MAINFRAME::OnCloseWindow( wxCloseEvent& Event )
{ {
int diag;
if( m_modified ) if( m_modified )
{ {
wxString msg = _( "Component to Footprint links modified.\nSave before exit ?" ); wxString msg = _( "Component to Footprint links modified.\nSave before exit ?" );
@ -260,29 +256,11 @@ void CVPCB_MAINFRAME::OnCloseWindow( wxCloseEvent& Event )
break; break;
case wxID_YES: case wxID_YES:
diag = SaveCmpLinkFile( m_NetlistFileName.GetFullPath() ); SaveEdits();
if( diag > 0 )
{
m_modified = false;
}
else if( diag == 0 )
{
if( !IsOK( this, _( "Problem when saving file, exit anyway ?" ) ) )
{
Event.Veto();
return;
}
}
break; break;
} }
} }
if( m_NetlistFileName.IsOk() )
{
UpdateFileHistory( m_NetlistFileName.GetFullPath() );
}
// Close module display frame // Close module display frame
if( GetFpViewerFrame() ) if( GetFpViewerFrame() )
GetFpViewerFrame()->Close( true ); GetFpViewerFrame()->Close( true );
@ -370,18 +348,12 @@ void CVPCB_MAINFRAME::ToPreviousNA( wxCommandEvent& event )
void CVPCB_MAINFRAME::SaveQuitCvpcb( wxCommandEvent& aEvent ) void CVPCB_MAINFRAME::SaveQuitCvpcb( wxCommandEvent& aEvent )
{ {
wxString fullFilename; SaveEdits();
if( aEvent.GetId() != wxID_SAVEAS ) m_modified = false;
fullFilename = m_NetlistFileName.GetFullPath();
if( SaveCmpLinkFile( fullFilename ) > 0 ) if( !m_KeepCvpcbOpen )
{ Close( true );
m_modified = false;
if( !m_KeepCvpcbOpen )
Close( true );
}
} }
@ -411,6 +383,7 @@ void CVPCB_MAINFRAME::DelAssociations( wxCommandEvent& event )
} }
/* Remove in favor of Kiway messaging method of sending netlist
void CVPCB_MAINFRAME::LoadNetList( wxCommandEvent& event ) void CVPCB_MAINFRAME::LoadNetList( wxCommandEvent& event )
{ {
int id = event.GetId(); int id = event.GetId();
@ -437,43 +410,11 @@ void CVPCB_MAINFRAME::LoadNetList( wxCommandEvent& event )
OpenProjectFiles( std::vector<wxString>( 1, newFileName.GetFullPath() ) ); OpenProjectFiles( std::vector<wxString>( 1, newFileName.GetFullPath() ) );
} }
*/
bool CVPCB_MAINFRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, int aCtl ) bool CVPCB_MAINFRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, int aCtl )
{ {
if( aFileSet.size() != 1 ) // Unexpected comand
return false;
m_NetlistFileName = aFileSet[0];
if( Kiface().IsSingle() )
{
// PROJECT::SetProjectFullName() is an impactful function. It should only be
// called under carefully considered circumstances.
// The calling code should know not to ask me here to change projects unless
// it knows what consequences that will have on other KIFACEs running and using
// this same PROJECT. It can be very harmful if that calling code is stupid.
//
// In Cvpcb, we call SetProjectFullName only in Single mode, i.e. it is not
// called from a project
wxFileName pro = m_NetlistFileName;
pro.SetExt( ProjectFileExtension );
Prj().SetProjectFullName( pro.GetFullPath() );
}
ReadNetListAndLinkFiles();
UpdateTitle();
// Resize the components list box. This is needed in case the
// contents have shrunk compared to the previous netlist.
m_compListBox->UpdateWidth();
// OSX need it since some objects are "rebuild" just make aware AUI
// Fixes #1258081
m_auimgr.Update();
return true; return true;
} }
@ -753,9 +694,8 @@ void CVPCB_MAINFRAME::UpdateTitle()
if( fn.IsOk() && !prj.GetProjectFullName().IsEmpty() && fn.FileExists() ) if( fn.IsOk() && !prj.GetProjectFullName().IsEmpty() && fn.FileExists() )
{ {
title += wxString::Format( _("Project: '%s' (netlist: '%s')"), title += wxString::Format( _("Project: '%s'"),
GetChars( fn.GetFullPath() ), GetChars( fn.GetFullPath() )
GetChars( m_NetlistFileName.GetFullName() )
); );
if( !fn.IsFileWritable() ) if( !fn.IsFileWritable() )
@ -792,46 +732,20 @@ void CVPCB_MAINFRAME::SendMessageToEESCHEMA()
} }
int CVPCB_MAINFRAME::ReadSchematicNetlist() int CVPCB_MAINFRAME::ReadSchematicNetlist( const std::string& aNetlist )
{ {
NETLIST_READER* netlistReader; STRING_LINE_READER* strrdr = new STRING_LINE_READER( aNetlist, "Eeschema via Kiway" );
wxString msg; KICAD_NETLIST_READER netrdr( strrdr, &m_netlist );
wxString compFootprintLinkFileName;
wxFileName fn = m_NetlistFileName;
// Ensure the netlist file exists, and wran the user if not:
if( ! wxFileExists( m_NetlistFileName.GetFullPath() ) )
{
msg.Printf( _( "Unable to find netlist file:\n'%s'\n\nPlease, create it" ),
GetChars( m_NetlistFileName.GetFullPath() ) );
wxMessageBox( msg, _( "Netlist Load Error" ), wxOK | wxICON_ERROR );
return 1;
}
// 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(); m_netlist.Clear();
try try
{ {
netlistReader = NETLIST_READER::GetNetlistReader( &m_netlist, netrdr.LoadNetlist();
m_NetlistFileName.GetFullPath(),
compFootprintLinkFileName );
if( netlistReader != NULL )
{
std::auto_ptr< NETLIST_READER > nlr( netlistReader );
netlistReader->LoadNetlist();
}
else
wxMessageBox( _( "Unknown netlist format." ), wxEmptyString, wxOK | wxICON_ERROR );
} }
catch( const IO_ERROR& ioe ) catch( const IO_ERROR& ioe )
{ {
msg = wxString::Format( _( "Error loading netlist.\n%s" ), ioe.errorText.GetData() ); wxString msg = wxString::Format( _( "Error loading netlist.\n%s" ), ioe.errorText.GetData() );
wxMessageBox( msg, _( "Netlist Load Error" ), wxOK | wxICON_ERROR ); wxMessageBox( msg, _( "Netlist Load Error" ), wxOK | wxICON_ERROR );
return 1; return 1;
} }
@ -851,56 +765,6 @@ int CVPCB_MAINFRAME::ReadSchematicNetlist()
} }
// File header.
static char headerLinkFile[] = "Cmp-Mod V01";
bool CVPCB_MAINFRAME::WriteComponentLinkFile( const wxString& aFullFileName )
{
COMPONENT* component;
FILE* outputFile;
wxFileName fn( aFullFileName );
wxString title = wxString::Format( wxT( "Cvpcb %s " ), GetChars( GetBuildVersion() ) );
outputFile = wxFopen( fn.GetFullPath(), wxT( "wt" ) );
if( outputFile == NULL )
return false;
int retval = 0;
/*
* The header is:
* Cmp-Mod V01 Created by CvPcb (2012-02-08 BZR 3403)-testing date = 10/02/2012 20:45:59
* and write block per component like:
* BeginCmp
* TimeStamp = /322D3011;
* Reference = BUS1;
* ValeurCmp = BUSPC;
* IdModule = BUS_PC;
* EndCmp
*/
retval |= fprintf( outputFile, "%s", headerLinkFile );
retval |= fprintf( outputFile, " Created by %s", TO_UTF8( title ) );
retval |= fprintf( outputFile, " date = %s\n", TO_UTF8( DateAndTime() ) );
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->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", component->GetFPID().Format().c_str() );
retval |= fprintf( outputFile, "EndCmp\n" );
}
retval |= fprintf( outputFile, "\nEndListe\n" );
fclose( outputFile );
return retval >= 0;
}
void CVPCB_MAINFRAME::CreateScreenCmp() void CVPCB_MAINFRAME::CreateScreenCmp()
{ {
DISPLAY_FOOTPRINTS_FRAME* fpframe = GetFpViewerFrame(); DISPLAY_FOOTPRINTS_FRAME* fpframe = GetFpViewerFrame();
@ -1040,3 +904,24 @@ void CVPCB_MAINFRAME::OnConfigurePaths( wxCommandEvent& aEvent )
{ {
Pgm().ConfigurePaths( this ); Pgm().ConfigurePaths( this );
} }
void CVPCB_MAINFRAME::KiwayMailIn( KIWAY_EXPRESS& mail )
{
const std::string& payload = mail.GetPayload();
DBG(printf( "%s: %s\n", __func__, payload.c_str() );)
switch( mail.Command() )
{
case MAIL_EESCHEMA_NETLIST:
ReadNetListAndLinkFiles( payload );
/* @todo
Go into SCH_EDIT_FRAME::OnOpenCvpcb( wxCommandEvent& event ) and trim GNL_ALL down.
*/
break;
default:
; // ignore most
}
}

View File

@ -56,36 +56,6 @@ const wxString EquFileExtension( wxT( "equ" ) );
// Wildcard for schematic retroannotation (import footprint names in schematic): // Wildcard for schematic retroannotation (import footprint names in schematic):
const wxString EquFilesWildcard( _( "Component/footprint equ files (*.equ)|*.equ" ) ); const wxString EquFilesWildcard( _( "Component/footprint equ files (*.equ)|*.equ" ) );
#if 0 // add this logic to OpenProjectFiles()
/*
* MacOSX: Needed for file association
* http://wiki.wxwidgets.org/WxMac-specific_topics
*/
void PGM_BASE::MacOpenFile( const wxString& aFileName )
{
wxFileName filename = aFileName;
wxString oldPath;
CVPCB_MAINFRAME* frame = (CVPCB_MAINFRAME*) GetTopWindow();
if( !filename.FileExists() )
return;
if( frame->m_NetlistFileName.DirExists() )
oldPath = frame->m_NetlistFileName.GetPath();
// Update the library search path list.
if( Pgm().GetLibraryPathList().Index( oldPath ) != wxNOT_FOUND )
Pgm().GetLibraryPathList().Remove( oldPath );
Pgm().GetLibraryPathList().Insert( filename.GetPath(), 0 );
frame->m_NetlistFileName = filename;
frame->ReadNetListAndLinkFiles();
}
#endif
namespace CV { namespace CV {

View File

@ -65,7 +65,6 @@ public:
LIBRARY_LISTBOX* m_libListBox; LIBRARY_LISTBOX* m_libListBox;
COMPONENTS_LISTBOX* m_compListBox; COMPONENTS_LISTBOX* m_compListBox;
wxAuiToolBar* m_mainToolBar; wxAuiToolBar* m_mainToolBar;
wxFileName m_NetlistFileName;
wxArrayString m_ModuleLibNames; wxArrayString m_ModuleLibNames;
wxArrayString m_EquFilesNames; wxArrayString m_EquFilesNames;
wxString m_NetlistFileExtension; wxString m_NetlistFileExtension;
@ -88,6 +87,8 @@ public:
bool OpenProjectFiles( const std::vector<wxString>& aFileSet, int aCtl=0 ); // overload KIWAY_PLAYER bool OpenProjectFiles( const std::vector<wxString>& aFileSet, int aCtl=0 ); // overload KIWAY_PLAYER
void KiwayMailIn( KIWAY_EXPRESS& aEvent ); // override virtual from KIWAY_PLAYER
/** /**
* @return a pointer on the Footprint Viewer frame, if exists, or NULL * @return a pointer on the Footprint Viewer frame, if exists, or NULL
*/ */
@ -192,36 +193,21 @@ public:
void CreateScreenCmp(); void CreateScreenCmp();
/** /**
* Function SaveCmpLinkFile * Function SaveEdits
* Saves the component - footprint link file (.cmp file) to \a aFullFileName. * saves the edits that the user has done by sending them back to eeschema
* * via the kiway.
* @param aFullFileName A reference wxString object containing the full
* 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 canceled
* 1 if OK
*/ */
int SaveCmpLinkFile( const wxString& aFullFileName ); void SaveEdits();
/**
* Function WriteComponentLinkFile
* Writes the component footprint link file \a aFullFileName on disk.
*
* @param aFullFileName full filename of .cmp file to write.
* @return true if OK, false if error.
*/
bool WriteComponentLinkFile( const wxString& aFullFileName );
/** /**
* Function ReadNetList * Function ReadNetList
* reads the netlist (.net) file defined by #m_NetlistFileName. * reads the netlist (.net) file defined by #m_NetlistFileName.
* and the corresponding cmp to footprint (.cmp) link file * and the corresponding cmp to footprint (.cmp) link file
* @param aNetlist is the netlist from eeschema in kicad s-expr format.
*/ */
bool ReadNetListAndLinkFiles(); bool ReadNetListAndLinkFiles( const std::string& aNetlist );
int ReadSchematicNetlist(); int ReadSchematicNetlist( const std::string& aNetlist );
/** /**
* Function LoadProjectFile * Function LoadProjectFile

View File

@ -64,42 +64,9 @@ void CVPCB_MAINFRAME::ReCreateMenuBar()
// Menu File: // Menu File:
wxMenu* filesMenu = new wxMenu; wxMenu* filesMenu = new wxMenu;
// Open files can be used only outside a project, because opening a netlist // Save the footprints back into eeschema
// which is not the project netlist is a non sense.
if( Kiface().IsSingle() )
{
AddMenuItem( filesMenu, ID_LOAD_PROJECT,
_( "&Open Netlist" ), LOAD_FILE_HELP, KiBitmap( open_document_xpm ) );
// Open Recent submenu
static wxMenu* openRecentMenu;
// Add this menu to list menu managed by m_fileHistory
// (the file history will be updated when adding/removing files in history
if( openRecentMenu )
Kiface().GetFileHistory().RemoveMenu( openRecentMenu );
openRecentMenu = new wxMenu();
Kiface().GetFileHistory().UseMenu( openRecentMenu );
Kiface().GetFileHistory().AddFilesToMenu();
AddMenuItem( filesMenu, openRecentMenu, -1,
_( "Open &Recent" ),
_( "Open recent netlist" ),
KiBitmap( open_project_xpm ) );
// Separator
filesMenu->AppendSeparator();
}
// Save the .cmp file
AddMenuItem( filesMenu, wxID_SAVE, AddMenuItem( filesMenu, wxID_SAVE,
_( "&Save Cmp File\tCtrl+S" ), SAVE_HLP_MSG, KiBitmap( save_xpm ) ); _( "&Save Edits\tCtrl+S" ), SAVE_HLP_MSG, KiBitmap( save_xpm ) );
// Save as the .cmp file
AddMenuItem( filesMenu, wxID_SAVEAS,
_( "Save Cmp File &As...\tCtrl+Shift+S" ), SAVE_AS_HLP_MSG, KiBitmap( save_xpm ) );
// Separator // Separator
filesMenu->AppendSeparator(); filesMenu->AppendSeparator();

View File

@ -156,12 +156,12 @@ static int guessNickname( FP_LIB_TABLE* aTbl, FPID* aFootprintId )
} }
bool CVPCB_MAINFRAME::ReadNetListAndLinkFiles() bool CVPCB_MAINFRAME::ReadNetListAndLinkFiles( const std::string& aNetlist )
{ {
wxString msg; wxString msg;
bool hasMissingNicks = false; bool hasMissingNicks = false;
ReadSchematicNetlist(); ReadSchematicNetlist( aNetlist );
if( m_compListBox == NULL ) if( m_compListBox == NULL )
return false; return false;
@ -364,56 +364,17 @@ bool CVPCB_MAINFRAME::ReadNetListAndLinkFiles()
DisplayStatus(); DisplayStatus();
UpdateTitle(); UpdateTitle();
UpdateFileHistory( m_NetlistFileName.GetFullPath() );
return true; return true;
} }
int CVPCB_MAINFRAME::SaveCmpLinkFile( const wxString& aFullFileName ) void CVPCB_MAINFRAME::SaveEdits()
{ {
wxFileName fn; STRING_FORMATTER sf;
if( !aFullFileName.IsEmpty() ) m_netlist.FormatBackAnnotation( &sf );
{
fn = m_NetlistFileName;
fn.SetExt( ComponentFileExtension );
}
else
{
wxFileDialog dlg( this, _( "Save Component Footprint Link File" ),
Prj().GetProjectPath(),
wxT( "noname" ), ComponentFileWildcard, wxFD_SAVE );
if( dlg.ShowModal() == wxID_CANCEL ) Kiway().ExpressMail( FRAME_SCH, MAIL_BACKANNOTATE_FOOTPRINTS, sf.GetString() );
return -1;
fn = dlg.GetPath(); SetStatusText( _("Edits sent to Eeschema") );
if( !fn.HasExt() )
fn.SetExt( ComponentFileExtension );
}
if( !IsWritable( fn.GetFullPath() ) || WriteComponentLinkFile( fn.GetFullPath() ) == 0 )
{
DisplayError( this,
wxString::Format( _( "Unable to create component footprint link file '%s'" ),
fn.GetFullPath() ) );
return 0;
}
wxString msg = wxString::Format( _("File %s saved"), GetChars( fn.GetFullPath() ) );
// Perhaps this replaces all of the above someday.
{
STRING_FORMATTER sf;
m_netlist.FormatBackAnnotation( &sf );
Kiway().ExpressMail( FRAME_SCH, MAIL_BACKANNOTATE_FOOTPRINTS, sf.GetString() );
}
SetStatusText( msg );
return 1;
} }

View File

@ -201,6 +201,7 @@ NETLIST_OBJECT::~NETLIST_OBJECT()
{ {
} }
// return true if the object is a label of any type // return true if the object is a label of any type
bool NETLIST_OBJECT::IsLabelType() const bool NETLIST_OBJECT::IsLabelType() const
{ {

View File

@ -34,6 +34,7 @@
#include <sch_sheet_path.h> #include <sch_sheet_path.h>
#include <lib_pin.h> // LIB_PIN::PinStringNum( m_PinNum ) #include <lib_pin.h> // LIB_PIN::PinStringNum( m_PinNum )
#include <sch_item_struct.h>
class NETLIST_OBJECT_LIST; class NETLIST_OBJECT_LIST;
class SCH_COMPONENT; class SCH_COMPONENT;
@ -256,13 +257,21 @@ public:
/** /**
* NETLIST_OBJECT_LIST is a class to handle the list of connected items * Type NETLIST_OBJECTS
* in a full schematic hierarchy for netlist and erc calculations * is a container referring to (not owning) NETLIST_OBJECTs, which are connected items
* in a full schematic hierarchy. It is useful when referring to NETLIST_OBJECTs
* actually owned by some other container.
*/ */
class NETLIST_OBJECT_LIST : public std::vector <NETLIST_OBJECT*> typedef std::vector<NETLIST_OBJECT*> NETLIST_OBJECTS;
/**
* Class NETLIST_OBJECT_LIST
* is a container holding and _owning_ NETLIST_OBJECTs, which are connected items
* in a full schematic hierarchy. It is helpful for netlist and ERC calculations.
*/
class NETLIST_OBJECT_LIST : public NETLIST_OBJECTS
{ {
bool m_isOwner; // = true if the objects in list are owned my me, and therefore
// the memory should be freed by the destructor and the list cleared
int m_lastNetCode; // Used in intermediate calculation: last net code created int m_lastNetCode; // Used in intermediate calculation: last net code created
int m_lastBusNetCode; // Used in intermediate calculation: int m_lastBusNetCode; // Used in intermediate calculation:
// last net code created for bus members // last net code created for bus members
@ -276,10 +285,8 @@ public:
* @param aIsOwner true if the instance is the owner of item list * @param aIsOwner true if the instance is the owner of item list
* (default = false) * (default = false)
*/ */
NETLIST_OBJECT_LIST( bool aIsOwner = false ) NETLIST_OBJECT_LIST()
{ {
m_isOwner = aIsOwner;
// Do not leave some members uninitialized: // Do not leave some members uninitialized:
m_lastNetCode = 0; m_lastNetCode = 0;
m_lastBusNetCode = 0; m_lastBusNetCode = 0;
@ -287,8 +294,6 @@ public:
~NETLIST_OBJECT_LIST(); ~NETLIST_OBJECT_LIST();
void SetOwner( bool aIsOwner ) { m_isOwner = aIsOwner; }
/** /**
* Function BuildNetListInfo * Function BuildNetListInfo
* the master function of tgis class. * the master function of tgis class.
@ -299,7 +304,7 @@ public:
*/ */
bool BuildNetListInfo( SCH_SHEET_LIST& aSheets ); bool BuildNetListInfo( SCH_SHEET_LIST& aSheets );
/* /**
* Acces to an item in list * Acces to an item in list
*/ */
NETLIST_OBJECT* GetItem( unsigned aIdx ) const NETLIST_OBJECT* GetItem( unsigned aIdx ) const
@ -307,7 +312,7 @@ public:
return *( this->begin() + aIdx ); return *( this->begin() + aIdx );
} }
/* /**
* Acces to an item type * Acces to an item type
*/ */
NETLIST_ITEM_T GetItemType( unsigned aIdx ) const NETLIST_ITEM_T GetItemType( unsigned aIdx ) const
@ -315,7 +320,7 @@ public:
return GetItem( aIdx )->m_Type; return GetItem( aIdx )->m_Type;
} }
/* /**
* Acces to an item net code * Acces to an item net code
*/ */
int GetItemNet( unsigned aIdx ) const int GetItemNet( unsigned aIdx ) const
@ -340,17 +345,8 @@ public:
GetItem( aIdx )->SetConnectionType( aFlg ); GetItem( aIdx )->SetConnectionType( aFlg );
} }
/* /** Delete all objects in list and clear list */
* Delete all objects in list and clear list void Clear();
* (delete NETLIST_OBJECT items)
*/
void FreeList();
/*
* Clear list but do not delete NETLIST_OBJECT items
* (they can be deleted only if the instance is owner of the items
*/
void Clear() { this->clear(); }
/** /**
* Reset the connection type of all items to UNCONNECTED type * Reset the connection type of all items to UNCONNECTED type
@ -456,6 +452,7 @@ private:
void findBestNetNameForEachNet(); void findBestNetNameForEachNet();
}; };
/** /**
* Function IsBusLabel * Function IsBusLabel
* test if \a aLabel has a bus notation. * test if \a aLabel has a bus notation.

View File

@ -208,9 +208,7 @@ void SCH_EDIT_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail )
} }
break; break;
// many many others. default:
;
} }
} }

View File

@ -466,7 +466,7 @@ void DIALOG_ERC::TestErc( wxArrayString* aMessagesList )
*/ */
TestDuplicateSheetNames( true ); TestDuplicateSheetNames( true );
NETLIST_OBJECT_LIST* objectsConnectedList = m_parent->BuildNetListBase(); std::auto_ptr<NETLIST_OBJECT_LIST> objectsConnectedList( m_parent->BuildNetListBase() );
// Reset the connection type indicator // Reset the connection type indicator
objectsConnectedList->ResetConnectionsType(); objectsConnectedList->ResetConnectionsType();
@ -509,7 +509,7 @@ void DIALOG_ERC::TestErc( wxArrayString* aMessagesList )
// ERC problems when pin sheets do not match hierarchical labels. // ERC problems when pin sheets do not match hierarchical labels.
// Each pin sheet must match a hierarchical label // Each pin sheet must match a hierarchical label
// Each hierarchical label must match a pin sheet // Each hierarchical label must match a pin sheet
TestLabel( objectsConnectedList, net, nextNet ); TestLabel( objectsConnectedList.get(), net, nextNet );
break; break;
case NET_NOCONNECT: case NET_NOCONNECT:
@ -525,7 +525,7 @@ void DIALOG_ERC::TestErc( wxArrayString* aMessagesList )
case NET_PIN: case NET_PIN:
// Look for ERC problems between pins: // Look for ERC problems between pins:
TestOthersItems( objectsConnectedList, net, nextNet, &NetNbItems, &MinConn ); TestOthersItems( objectsConnectedList.get(), net, nextNet, &NetNbItems, &MinConn );
break; break;
} }

View File

@ -42,7 +42,7 @@
#include <netlist_exporter_kicad.h> #include <netlist_exporter_kicad.h>
#include <netlist_exporter_generic.h> #include <netlist_exporter_generic.h>
bool SCH_EDIT_FRAME::WriteNetListFile( NETLIST_OBJECT_LIST * aConnectedItemsList, bool SCH_EDIT_FRAME::WriteNetListFile( NETLIST_OBJECT_LIST* aConnectedItemsList,
int aFormat, const wxString& aFullFileName, int aFormat, const wxString& aFullFileName,
unsigned aNetlistOptions ) unsigned aNetlistOptions )
{ {
@ -73,17 +73,17 @@ bool SCH_EDIT_FRAME::WriteNetListFile( NETLIST_OBJECT_LIST * aConnectedItemsList
default: default:
{ {
wxFileName tmpFile = fileName; wxFileName tmpFile = fileName;
tmpFile.SetExt( GENERIC_INTERMEDIATE_NETLIST_EXT ); tmpFile.SetExt( GENERIC_INTERMEDIATE_NETLIST_EXT );
fileName = tmpFile.GetFullPath(); fileName = tmpFile.GetFullPath();
helper = new NETLIST_EXPORTER_GENERIC( aConnectedItemsList, Prj().SchLibs() ); helper = new NETLIST_EXPORTER_GENERIC( aConnectedItemsList, Prj().SchLibs() );
executeCommandLine = true; executeCommandLine = true;
break;
} }
break;
} }
res = helper->Write( fileName, aNetlistOptions ); res = helper->WriteNetlist( fileName, aNetlistOptions );
if( executeCommandLine ) if( executeCommandLine )
{ {

View File

@ -30,6 +30,8 @@
#include <fctsys.h> #include <fctsys.h>
#include <schframe.h> #include <schframe.h>
#include <confirm.h> #include <confirm.h>
#include <netlist_exporter_kicad.h>
#include <kiway.h>
#include <netlist.h> #include <netlist.h>
#include <class_netlist_object.h> #include <class_netlist_object.h>
@ -51,8 +53,8 @@
//Imported function: //Imported function:
int TestDuplicateSheetNames( bool aCreateMarker ); int TestDuplicateSheetNames( bool aCreateMarker );
bool SCH_EDIT_FRAME::CreateNetlist( int aFormat, const wxString& aFullFileName,
unsigned aNetlistOptions ) bool SCH_EDIT_FRAME::prepareForNetlist()
{ {
SCH_SHEET_LIST sheets; SCH_SHEET_LIST sheets;
@ -85,32 +87,55 @@ bool SCH_EDIT_FRAME::CreateNetlist( int aFormat, const wxString& aFullFileName,
screens.SchematicCleanUp(); screens.SchematicCleanUp();
NETLIST_OBJECT_LIST* connectedItemsList = BuildNetListBase(); return true;
}
bool success = WriteNetListFile( connectedItemsList, aFormat,
void SCH_EDIT_FRAME::sendNetlist()
{
NETLIST_OBJECT_LIST* net_atoms = BuildNetListBase();
NETLIST_EXPORTER_KICAD exporter( net_atoms, Prj().SchLibs() );
STRING_FORMATTER formatter;
// @todo : trim GNL_ALL down to minimum for CVPCB
exporter.Format( &formatter, GNL_ALL );
Kiway().ExpressMail( FRAME_CVPCB,
MAIL_EESCHEMA_NETLIST,
formatter.GetString(), // an abbreviated "kicad" (s-expr) netlist
this
);
}
bool SCH_EDIT_FRAME::CreateNetlist( int aFormat, const wxString& aFullFileName,
unsigned aNetlistOptions )
{
if( !prepareForNetlist() )
return false;
std::auto_ptr<NETLIST_OBJECT_LIST> connectedItemsList( BuildNetListBase() );
bool success = WriteNetListFile( connectedItemsList.release(), aFormat,
aFullFileName, aNetlistOptions ); aFullFileName, aNetlistOptions );
return success; return success;
} }
// Buffer to build the list of items used in netlist and erc calculations
NETLIST_OBJECT_LIST s_NetObjectslist( true );
//#define NETLIST_DEBUG //#define NETLIST_DEBUG
NETLIST_OBJECT_LIST::~NETLIST_OBJECT_LIST() NETLIST_OBJECT_LIST::~NETLIST_OBJECT_LIST()
{ {
if( m_isOwner ) Clear();
FreeList();
else
Clear();
} }
void NETLIST_OBJECT_LIST::FreeList() void NETLIST_OBJECT_LIST::Clear()
{ {
std::vector<NETLIST_OBJECT*>::iterator iter; NETLIST_OBJECTS::iterator iter;
for( iter = begin(); iter != end(); iter++ ) for( iter = begin(); iter != end(); iter++ )
{ {
@ -134,36 +159,33 @@ void NETLIST_OBJECT_LIST::SortListbySheet()
} }
NETLIST_OBJECT_LIST * SCH_EDIT_FRAME::BuildNetListBase() NETLIST_OBJECT_LIST* SCH_EDIT_FRAME::BuildNetListBase()
{ {
// I own this list until I return it to the new owner.
std::auto_ptr<NETLIST_OBJECT_LIST> ret( new NETLIST_OBJECT_LIST() );
// Creates the flattened sheet list: // Creates the flattened sheet list:
SCH_SHEET_LIST aSheets; SCH_SHEET_LIST aSheets;
// Build netlist info // Build netlist info
bool success = s_NetObjectslist.BuildNetListInfo( aSheets ); bool success = ret->BuildNetListInfo( aSheets );
if( !success ) if( !success )
{ {
SetStatusText( _("No Objects" ) ); SetStatusText( _( "No Objects" ) );
return &s_NetObjectslist; return ret.release();
} }
/* The new %zu specification is needed to properly format a size_t wxString msg = wxString::Format( _( "Net count = %zu" ), ret->size() );
* value (returned by size(), here) */
wxString msg;
msg.Printf( _( "Net count = %zu" ), s_NetObjectslist.size() );
SetStatusText( msg ); SetStatusText( msg );
return &s_NetObjectslist; return ret.release();
} }
bool NETLIST_OBJECT_LIST::BuildNetListInfo( SCH_SHEET_LIST& aSheets ) bool NETLIST_OBJECT_LIST::BuildNetListInfo( SCH_SHEET_LIST& aSheets )
{ {
s_NetObjectslist.SetOwner( true );
s_NetObjectslist.FreeList();
SCH_SHEET_PATH* sheet; SCH_SHEET_PATH* sheet;
// Fill list with connected items from the flattened sheet list // Fill list with connected items from the flattened sheet list
@ -491,8 +513,9 @@ void NETLIST_OBJECT_LIST::findBestNetNameForEachNet()
// even if components are moved or deleted and undelete or replaced, as long // even if components are moved or deleted and undelete or replaced, as long
// the reference is kept) // the reference is kept)
// Build the list of items with no net names // Build a list of items with no net names
NETLIST_OBJECT_LIST list; NETLIST_OBJECTS list; // no ownership of elements being pointed at
for( unsigned ii = 0; ii < size(); ii++ ) for( unsigned ii = 0; ii < size(); ii++ )
{ {
item = GetItem( ii ); item = GetItem( ii );
@ -505,12 +528,12 @@ void NETLIST_OBJECT_LIST::findBestNetNameForEachNet()
idxstart = 0; idxstart = 0;
candidate = NULL; candidate = NULL;
netcode = list.GetItemNet( 0 ); netcode = list[0]->GetNet();
for( unsigned ii = 0; ii <= list.size(); ii++ ) for( unsigned ii = 0; ii <= list.size(); ii++ )
{ {
if( ii < list.size() ) if( ii < list.size() )
item = list.GetItem( ii ); item = list[ii];
else else
item = NULL; item = NULL;
@ -520,7 +543,7 @@ void NETLIST_OBJECT_LIST::findBestNetNameForEachNet()
{ {
for (unsigned jj = idxstart; jj < ii; jj++ ) for (unsigned jj = idxstart; jj < ii; jj++ )
{ {
NETLIST_OBJECT* obj = list.GetItem( jj ); NETLIST_OBJECT* obj = list[jj];
obj->SetNetNameCandidate( candidate ); obj->SetNetNameCandidate( candidate );
} }
} }

View File

@ -45,6 +45,8 @@
#include <netlist.h> #include <netlist.h>
#include <netlist_exporter.h> #include <netlist_exporter.h>
wxString NETLIST_EXPORTER::MakeCommandLine( const wxString& aFormatString, wxString NETLIST_EXPORTER::MakeCommandLine( const wxString& aFormatString,
const wxString& aTempfile, const wxString& aFinalFile, const wxString& aProjectPath ) const wxString& aTempfile, const wxString& aFinalFile, const wxString& aProjectPath )
{ {

View File

@ -73,13 +73,14 @@ public:
class NETLIST_EXPORTER class NETLIST_EXPORTER
{ {
protected: protected:
NETLIST_OBJECT_LIST* m_masterList; /// The main connected items flat list NETLIST_OBJECT_LIST* m_masterList; /// yes ownership, connected items flat list
PART_LIBS* m_libs; /// no ownership PART_LIBS* m_libs; /// no ownership
/// Used to temporary store and filter the list of pins of a schematic component /// Used to temporary store and filter the list of pins of a schematic component
/// when generating schematic component data in netlist (comp section) /// when generating schematic component data in netlist (comp section). No ownership
NETLIST_OBJECT_LIST m_SortedComponentPinList; /// of members.
NETLIST_OBJECTS m_SortedComponentPinList;
/// Used for "multi parts per package" components, /// Used for "multi parts per package" components,
/// avoids processing a lib component more than once. /// avoids processing a lib component more than once.
@ -91,7 +92,6 @@ protected:
std::set<void*> m_Libraries; ///< unique libraries used std::set<void*> m_Libraries; ///< unique libraries used
/** /**
* Function sprintPinNetName * Function sprintPinNetName
* formats the net name for \a aPin using \a aNetNameFormat into \a aResult. * formats the net name for \a aPin using \a aNetNameFormat into \a aResult.
@ -155,21 +155,27 @@ protected:
SCH_SHEET_PATH* aSheetPath ); SCH_SHEET_PATH* aSheetPath );
public: public:
NETLIST_EXPORTER( NETLIST_OBJECT_LIST* aMasterList, PART_LIBS* aLibs )
/**
* Constructor
* @param aMasterList we take ownership of this here.
*/
NETLIST_EXPORTER( NETLIST_OBJECT_LIST* aMasterList, PART_LIBS* aLibs ) :
m_masterList( aMasterList ),
m_libs( aLibs )
{ {
m_masterList = aMasterList;
m_libs = aLibs;
} }
virtual ~NETLIST_EXPORTER() virtual ~NETLIST_EXPORTER()
{ {
delete m_masterList; // I own the list itself in this instance.
} }
/** /**
* Function Write * Function WriteNetlist
* writes to specified output file * writes to specified output file
*/ */
virtual bool Write( const wxString& aOutFileName, unsigned aNetlistOptions ) virtual bool WriteNetlist( const wxString& aOutFileName, unsigned aNetlistOptions )
{ {
return false; return false;
} }

View File

@ -36,7 +36,7 @@
/* Generate CADSTAR net list. */ /* Generate CADSTAR net list. */
static wxString StartLine( wxT( "." ) ); static wxString StartLine( wxT( "." ) );
bool NETLIST_EXPORTER_CADSTAR::Write( const wxString& aOutFileName, unsigned aNetlistOptions ) bool NETLIST_EXPORTER_CADSTAR::WriteNetlist( const wxString& aOutFileName, unsigned aNetlistOptions )
{ {
(void)aNetlistOptions; //unused (void)aNetlistOptions; //unused
int ret = 0; int ret = 0;

View File

@ -53,10 +53,10 @@ public:
} }
/** /**
* Function Write * Function WriteList
* writes to specified output file * writes to specified output file
*/ */
bool Write( const wxString& aOutFileName, unsigned aNetlistOptions ); bool WriteNetlist( const wxString& aOutFileName, unsigned aNetlistOptions );
}; };
#endif #endif

View File

@ -32,7 +32,7 @@
static bool sortPinsByNumber( LIB_PIN* aPin1, LIB_PIN* aPin2 ); static bool sortPinsByNumber( LIB_PIN* aPin1, LIB_PIN* aPin2 );
bool NETLIST_EXPORTER_GENERIC::Write( const wxString& aOutFileName, unsigned aNetlistOptions ) bool NETLIST_EXPORTER_GENERIC::WriteNetlist( const wxString& aOutFileName, unsigned aNetlistOptions )
{ {
// Prepare list of nets generation // Prepare list of nets generation
for( unsigned ii = 0; ii < m_masterList->size(); ii++ ) for( unsigned ii = 0; ii < m_masterList->size(); ii++ )
@ -41,29 +41,34 @@ bool NETLIST_EXPORTER_GENERIC::Write( const wxString& aOutFileName, unsigned aNe
// output the XML format netlist. // output the XML format netlist.
wxXmlDocument xdoc; wxXmlDocument xdoc;
xdoc.SetRoot( makeRoot() ); xdoc.SetRoot( makeRoot( GNL_ALL ) );
return xdoc.Save( aOutFileName, 2 /* indent bug, today was ignored by wxXml lib */ ); return xdoc.Save( aOutFileName, 2 /* indent bug, today was ignored by wxXml lib */ );
} }
XNODE* NETLIST_EXPORTER_GENERIC::makeRoot() XNODE* NETLIST_EXPORTER_GENERIC::makeRoot( int aCtl )
{ {
XNODE* xroot = node( wxT( "export" ) ); XNODE* xroot = node( wxT( "export" ) );
xroot->AddAttribute( wxT( "version" ), wxT( "D" ) ); xroot->AddAttribute( wxT( "version" ), wxT( "D" ) );
// add the "design" header if( aCtl & GNL_HEADER )
xroot->AddChild( makeDesignHeader() ); // add the "design" header
xroot->AddChild( makeDesignHeader() );
xroot->AddChild( makeComponents() ); if( aCtl & GNL_COMPONENTS )
xroot->AddChild( makeComponents() );
xroot->AddChild( makeLibParts() ); if( aCtl & GNL_PARTS )
xroot->AddChild( makeLibParts() );
// must follow makeGenericLibParts() if( aCtl & GNL_LIBRARIES )
xroot->AddChild( makeLibraries() ); // must follow makeGenericLibParts()
xroot->AddChild( makeLibraries() );
xroot->AddChild( makeListOfNets() ); if( aCtl & GNL_NETS )
xroot->AddChild( makeListOfNets() );
return xroot; return xroot;
} }
@ -210,14 +215,14 @@ XNODE* NETLIST_EXPORTER_GENERIC::makeDesignHeader()
for( SCH_SHEET_PATH* sheet = sheetList.GetFirst(); sheet; sheet = sheetList.GetNext() ) for( SCH_SHEET_PATH* sheet = sheetList.GetFirst(); sheet; sheet = sheetList.GetNext() )
{ {
screen = sheet->LastScreen(); screen = sheet->LastScreen();
xdesign->AddChild( xsheet = node( wxT( "sheet" ) ) ); xdesign->AddChild( xsheet = node( wxT( "sheet" ) ) );
// get the string representation of the sheet index number. // get the string representation of the sheet index number.
// Note that sheet->GetIndex() is zero index base and we need to increment the number by one to make // Note that sheet->GetIndex() is zero index base and we need to increment the number by one to make
// human readable // human readable
sheetTxt.Printf( wxT( "%d" ), ( sheetList.GetIndex() + 1 ) ); sheetTxt.Printf( wxT( "%d" ), ( sheetList.GetIndex() + 1 ) );
xsheet->AddAttribute( wxT( "number" ), sheetTxt ); xsheet->AddAttribute( wxT( "number" ), sheetTxt );
xsheet->AddAttribute( wxT( "name" ), sheet->PathHumanReadable() ); xsheet->AddAttribute( wxT( "name" ), sheet->PathHumanReadable() );
xsheet->AddAttribute( wxT( "tstamps" ), sheet->Path() ); xsheet->AddAttribute( wxT( "tstamps" ), sheet->Path() );
@ -251,7 +256,7 @@ XNODE* NETLIST_EXPORTER_GENERIC::makeDesignHeader()
xtitleBlock->AddChild( xcomment = node( wxT( "comment" ) ) ); xtitleBlock->AddChild( xcomment = node( wxT( "comment" ) ) );
xcomment->AddAttribute( wxT("number"), wxT("4") ); xcomment->AddAttribute( wxT("number"), wxT("4") );
xcomment->AddAttribute( wxT( "value" ), tb.GetComment4() ); xcomment->AddAttribute( wxT( "value" ), tb.GetComment4() );
} }
return xdesign; return xdesign;
} }

View File

@ -32,6 +32,20 @@
#define GENERIC_INTERMEDIATE_NETLIST_EXT wxT( "xml" ) #define GENERIC_INTERMEDIATE_NETLIST_EXT wxT( "xml" )
/**
* Enum GNL
* is a set of bit which control the totality of the tree built by makeRoot()
*/
enum GNL_T
{
GNL_LIBRARIES = 1 << 0,
GNL_COMPONENTS = 1 << 1,
GNL_PARTS = 1 << 2,
GNL_HEADER = 1 << 3,
GNL_NETS = 1 << 4,
};
/** /**
* Class NETLIST_EXPORTER_GENERIC * Class NETLIST_EXPORTER_GENERIC
* generates a generic XML based netlist file. This allows using XSLT or other methods to * generates a generic XML based netlist file. This allows using XSLT or other methods to
@ -39,6 +53,20 @@
*/ */
class NETLIST_EXPORTER_GENERIC : public NETLIST_EXPORTER class NETLIST_EXPORTER_GENERIC : public NETLIST_EXPORTER
{ {
public:
NETLIST_EXPORTER_GENERIC( NETLIST_OBJECT_LIST* aMasterList, PART_LIBS* aLibs ) :
NETLIST_EXPORTER( aMasterList, aLibs )
{
}
/**
* Function WriteNetlist
* writes to specified output file
*/
bool WriteNetlist( const wxString& aOutFileName, unsigned aNetlistOptions );
#define GNL_ALL ( GNL_LIBRARIES | GNL_COMPONENTS | GNL_PARTS | GNL_HEADER | GNL_NETS )
protected: protected:
/** /**
* Function node * Function node
@ -50,20 +78,23 @@ protected:
* of the returned node, and has type wxXML_TEXT_NODE. * of the returned node, and has type wxXML_TEXT_NODE.
*/ */
XNODE* node( const wxString& aName, const wxString& aTextualContent = wxEmptyString ); XNODE* node( const wxString& aName, const wxString& aTextualContent = wxEmptyString );
/** /**
* Function writeGENERICListOfNets * Function writeGENERICListOfNets
* writes out nets (ranked by Netcode), and elements that are * writes out nets (ranked by Netcode), and elements that are
* connected as part of that net. * connected as part of that net.
*/ */
bool writeListOfNets( FILE* f, NETLIST_OBJECT_LIST& aObjectsList ); bool writeListOfNets( FILE* f, NETLIST_OBJECT_LIST& aObjectsList );
/** /**
* Function makeGenericRoot * Function makeGenericRoot
* builds the entire document tree for the generic export. This is factored * builds the entire document tree for the generic export. This is factored
* out here so we can write the tree in either S-expression file format * out here so we can write the tree in either S-expression file format
* or in XML if we put the tree built here into a wxXmlDocument. * or in XML if we put the tree built here into a wxXmlDocument.
* @param aCtl - a bitset or-ed together from GNL_ENUM values
* @return XNODE* - the root nodes * @return XNODE* - the root nodes
*/ */
XNODE* makeRoot(); XNODE* makeRoot( int aCtl = GNL_ALL );
/** /**
* Function makeComponents * Function makeComponents
@ -99,18 +130,6 @@ protected:
* @return XNODE* - the library nodes * @return XNODE* - the library nodes
*/ */
XNODE* makeLibraries(); XNODE* makeLibraries();
public:
NETLIST_EXPORTER_GENERIC( NETLIST_OBJECT_LIST* aMasterList, PART_LIBS* aLibs ) :
NETLIST_EXPORTER( aMasterList, aLibs )
{
}
/**
* Function Write
* writes to specified output file
*/
bool Write( const wxString& aOutFileName, unsigned aNetlistOptions );
}; };
#endif #endif

View File

@ -31,8 +31,9 @@
#include <schframe.h> #include <schframe.h>
#include "netlist_exporter_kicad.h" #include "netlist_exporter_kicad.h"
bool NETLIST_EXPORTER_KICAD::Write( const wxString& aOutFileName, unsigned aNetlistOptions ) bool NETLIST_EXPORTER_KICAD::WriteNetlist( const wxString& aOutFileName, unsigned aNetlistOptions )
{ {
#if 0
// Prepare list of nets generation // Prepare list of nets generation
for( unsigned ii = 0; ii < m_masterList->size(); ii++ ) for( unsigned ii = 0; ii < m_masterList->size(); ii++ )
m_masterList->GetItem( ii )->m_Flag = 0; m_masterList->GetItem( ii )->m_Flag = 0;
@ -45,6 +46,15 @@ bool NETLIST_EXPORTER_KICAD::Write( const wxString& aOutFileName, unsigned aNetl
xroot->Format( &formatter, 0 ); xroot->Format( &formatter, 0 );
} }
#else
try
{
FILE_OUTPUTFORMATTER formatter( aOutFileName );
Format( &formatter, GNL_ALL );
}
#endif
catch( const IO_ERROR& ioe ) catch( const IO_ERROR& ioe )
{ {
DisplayError( NULL, ioe.errorText ); DisplayError( NULL, ioe.errorText );
@ -53,3 +63,15 @@ bool NETLIST_EXPORTER_KICAD::Write( const wxString& aOutFileName, unsigned aNetl
return true; return true;
} }
void NETLIST_EXPORTER_KICAD::Format( OUTPUTFORMATTER* aOut, int aCtl )
{
// Prepare list of nets generation
for( unsigned ii = 0; ii < m_masterList->size(); ii++ )
m_masterList->GetItem( ii )->m_Flag = 0;
std::auto_ptr<XNODE> xroot( makeRoot( aCtl ) );
xroot->Format( aOut, 0 );
}

View File

@ -28,9 +28,11 @@
#include <netlist_exporter_generic.h> #include <netlist_exporter_generic.h>
class OUTPUTFORMATTER;
/** /**
* Class NETLIST_EXPORTER_KICAD * Class NETLIST_EXPORTER_KICAD
* generates the kicad netlist format supported by pcbnew. It is basically * generates the kicad netlist format supported by pcbnew. It is basically
* the generic netlist format just formatted slightly different. * the generic netlist format just formatted slightly different.
*/ */
class NETLIST_EXPORTER_KICAD : public NETLIST_EXPORTER_GENERIC class NETLIST_EXPORTER_KICAD : public NETLIST_EXPORTER_GENERIC
@ -42,10 +44,20 @@ public:
} }
/** /**
* Function Write * Function WriteNetlist
* writes to specified output file * writes to specified output file
*/ */
bool Write( const wxString& aOutFileName, unsigned aNetlistOptions ); bool WriteNetlist( const wxString& aOutFileName, unsigned aNetlistOptions ); // OVERRIDE
/**
* Function Format
* outputs this s-expression netlist into @a aOutputFormatter.
* @param aOutputFormatter is the destination of the serialization to text.
* @param aCtl is bit set composed by OR-ing together enum GNL bits, it allows ouputting
* a subset of the full document model.
* @throw IO_ERROR if any problems.
*/
void Format( OUTPUTFORMATTER* aOutputFormatter, int aCtl );
}; };
#endif #endif

View File

@ -35,7 +35,7 @@
#include <netlist.h> #include <netlist.h>
#include "netlist_exporter_orcadpcb2.h" #include "netlist_exporter_orcadpcb2.h"
bool NETLIST_EXPORTER_ORCADPCB2::Write( const wxString& aOutFileName, unsigned aNetlistOptions ) bool NETLIST_EXPORTER_ORCADPCB2::WriteNetlist( const wxString& aOutFileName, unsigned aNetlistOptions )
{ {
(void)aNetlistOptions; //unused (void)aNetlistOptions; //unused
FILE* f = NULL; FILE* f = NULL;

View File

@ -40,7 +40,7 @@ public:
{ {
} }
bool Write( const wxString& aOutFileName, unsigned aNetlistOptions ); bool WriteNetlist( const wxString& aOutFileName, unsigned aNetlistOptions );
}; };
#endif #endif

View File

@ -34,7 +34,7 @@
#include <wx/tokenzr.h> #include <wx/tokenzr.h>
#include "netlist_exporter_pspice.h" #include "netlist_exporter_pspice.h"
bool NETLIST_EXPORTER_PSPICE::Write( const wxString& aOutFileName, unsigned aNetlistOptions ) bool NETLIST_EXPORTER_PSPICE::WriteNetlist( const wxString& aOutFileName, unsigned aNetlistOptions )
{ {
FILE* f = NULL; FILE* f = NULL;
bool aUsePrefix = aNetlistOptions & NET_USE_X_PREFIX; bool aUsePrefix = aNetlistOptions & NET_USE_X_PREFIX;

View File

@ -41,10 +41,10 @@ public:
} }
/** /**
* Function Write * Function WriteNetlist
* writes to specified output file * writes to specified output file
*/ */
bool Write( const wxString& aOutFileName, unsigned aNetlistOptions ); bool WriteNetlist( const wxString& aOutFileName, unsigned aNetlistOptions );
}; };
#endif #endif

View File

@ -27,7 +27,6 @@
*/ */
#include <fctsys.h> #include <fctsys.h>
#include <kiway.h>
#include <kiface_i.h> #include <kiface_i.h>
#include <pgm_base.h> #include <pgm_base.h>
#include <gr_basic.h> #include <gr_basic.h>
@ -186,6 +185,23 @@ PART_LIBS* PROJECT::SchLibs()
return libs; return libs;
} }
/*
NETLIST_OBJECT_LIST* PROJECT::Netlist()
{
NETLIST_OBJECT_LIST* netlist = (NETLIST_OBJECT_LIST*) GetElem( PROJECT::ELEM_SCH_NETLIST );
wxASSERT( !libs || dynamic_cast<NETLIST_OBJECT_LIST*>( netlist ) );
if( !netlist )
{
netlist = new NETLIST_OBJECT_LIST();
// Make PROJECT the new NETLIST_OBJECT_LIST owner.
SetElem( PROJECT::ELEM_SCH_NETLIST, netlist );
}
}
*/
//-----</SCH "data on demand" functions>------------------------------------------ //-----</SCH "data on demand" functions>------------------------------------------
@ -974,10 +990,16 @@ void SCH_EDIT_FRAME::OnOpenCvpcb( wxCommandEvent& event )
if( Kiface().IsSingle() ) if( Kiface().IsSingle() )
{ {
/* the CVPCB executable is now gone, only the *.kiface remains, that is because
* CVPCB can now read the netlist ONLY from the Kiway. This removes cvpcb's
* use of the *.cmp file altogether, and also its use of reading the *.net file
* from disk.
ExecuteFile( this, CVPCB_EXE, QuoteFullPath( fn ) ); ExecuteFile( this, CVPCB_EXE, QuoteFullPath( fn ) );
*/
} }
else else
{ {
#if 0
KIWAY_PLAYER* player = Kiway().Player( FRAME_CVPCB, false ); // test open already. KIWAY_PLAYER* player = Kiway().Player( FRAME_CVPCB, false ); // test open already.
if( !player ) if( !player )
@ -988,6 +1010,23 @@ void SCH_EDIT_FRAME::OnOpenCvpcb( wxCommandEvent& event )
} }
player->Raise(); player->Raise();
#else
if( prepareForNetlist() )
{
KIWAY_PLAYER* player = Kiway().Player( FRAME_CVPCB, false ); // test open already.
if( !player )
{
player = Kiway().Player( FRAME_CVPCB, true );
player->Show( true );
// player->OpenProjectFiles( std::vector<wxString>( 1, fn.GetFullPath() ) );
}
sendNetlist();
player->Raise();
}
#endif
} }
} }

View File

@ -209,6 +209,20 @@ protected:
void backAnnotateFootprints( const std::string& aChangedSetOfReferences ) void backAnnotateFootprints( const std::string& aChangedSetOfReferences )
throw( IO_ERROR, boost::bad_pointer ); throw( IO_ERROR, boost::bad_pointer );
/**
* Function prepareForNetlist
* verifies that annotation is complete so that a proper netlist is even
* possible. If not, asks the user if annotation should be done.
* @return bool - true if annotation is complete, else false.
*/
bool prepareForNetlist();
/**
* Function sendNetlist
* sends the kicad netlist over to CVPCB.
*/
void sendNetlist();
public: public:
SCH_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ); SCH_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent );
~SCH_EDIT_FRAME(); ~SCH_EDIT_FRAME();
@ -476,9 +490,9 @@ public:
* netlist generation: * netlist generation:
* Creates a flat list which stores all connected objects, and mainly * Creates a flat list which stores all connected objects, and mainly
* pins and labels. * pins and labels.
* @return a pointer to the list * @return NETLIST_OBJECT_LIST* - caller owns the object.
*/ */
NETLIST_OBJECT_LIST * BuildNetListBase(); NETLIST_OBJECT_LIST* BuildNetListBase();
/** /**
* Function CreateNetlist * Function CreateNetlist
@ -506,7 +520,7 @@ public:
* Function WriteNetListFile * Function WriteNetListFile
* Create the netlist file. Netlist info must be existing * Create the netlist file. Netlist info must be existing
* (BuildNetListBase() creates this info) * (BuildNetListBase() creates this info)
* @param aConnectedItemsList = the initialized list of connected items * @param aConnectedItemsList = the initialized list of connected items, take ownership.
* @param aFormat = netlist format (NET_TYPE_PCBNEW ...) * @param aFormat = netlist format (NET_TYPE_PCBNEW ...)
* @param aFullFileName = full netlist file name * @param aFullFileName = full netlist file name
* @param aNetlistOptions = netlist options using OR'ed bits. * @param aNetlistOptions = netlist options using OR'ed bits.
@ -518,7 +532,7 @@ public:
* </p> * </p>
* @return true if success. * @return true if success.
*/ */
bool WriteNetListFile( NETLIST_OBJECT_LIST * aConnectedItemsList, bool WriteNetListFile( NETLIST_OBJECT_LIST* aConnectedItemsList,
int aFormat, int aFormat,
const wxString& aFullFileName, const wxString& aFullFileName,
unsigned aNetlistOptions ); unsigned aNetlistOptions );

View File

@ -156,14 +156,16 @@ void SCH_EDIT_FRAME::ReCreateHToolbar()
// The user must HAVE footprints before he can assign them. So put this before // The user must HAVE footprints before he can assign them. So put this before
// the CVPCB. // the CVPCB.
if( !Kiface().IsSingle() ) // if pcbnew is not a separate process if( !Kiface().IsSingle() ) // if eeschema is not a separate process
{ {
m_mainToolBar->AddTool( ID_RUN_PCB_MODULE_EDITOR, wxEmptyString, KiBitmap( module_editor_xpm ), m_mainToolBar->AddTool( ID_RUN_PCB_MODULE_EDITOR, wxEmptyString, KiBitmap( module_editor_xpm ),
_( "Footprint Editor" ) ); _( "Footprint Editor" ) );
}
m_mainToolBar->AddTool( ID_RUN_CVPCB, wxEmptyString, KiBitmap( cvpcb_xpm ), // CVPCB only reads from the kiway now, and the kiway is only implemented in the
_( "Run CvPcb to associate components and footprints" ) ); // project manager, not single_top.
m_mainToolBar->AddTool( ID_RUN_CVPCB, wxEmptyString, KiBitmap( cvpcb_xpm ),
_( "Run CvPcb to associate components and footprints" ) );
}
m_mainToolBar->AddTool( ID_RUN_PCB, wxEmptyString, KiBitmap( pcbnew_xpm ), m_mainToolBar->AddTool( ID_RUN_PCB, wxEmptyString, KiBitmap( pcbnew_xpm ),
_( "Run Pcbnew to layout printed circuit board" ) ); _( "Run Pcbnew to layout printed circuit board" ) );

View File

@ -38,7 +38,7 @@ enum MAIL_T
{ {
MAIL_CROSS_PROBE, ///< PCB<->SCH, CVPCB->SCH cross-probing. MAIL_CROSS_PROBE, ///< PCB<->SCH, CVPCB->SCH cross-probing.
MAIL_BACKANNOTATE_FOOTPRINTS, ///< CVPCB->SCH footprint stuffing at cvpcb termination MAIL_BACKANNOTATE_FOOTPRINTS, ///< CVPCB->SCH footprint stuffing at cvpcb termination
MAIL_EESCHEMA_NETLIST, ///< EESCHEMA->CVPCB netlist immediately after launching CVPCB
}; };
#endif // MAIL_TYPE_H_ #endif // MAIL_TYPE_H_

View File

@ -605,7 +605,7 @@ public:
*/ */
void StripUseless(); void StripUseless();
std::string GetString() const std::string& GetString()
{ {
return mystring; return mystring;
} }

View File

@ -222,9 +222,12 @@ void TREEPROJECT_ITEM::Activate( TREE_PROJECT_FRAME* prjframe )
OpenPDF( fullFileName ); OpenPDF( fullFileName );
break; break;
/* No, use a text editor. Netlists can only be handled sanely now from within
eeschema's launcher for the *.kiface, NOT THE EXE which is now gone.
case TREE_NET: case TREE_NET:
frame->Execute( m_parent, CVPCB_EXE, fullFileName ); frame->Execute( m_parent, CVPCB_EXE, fullFileName );
break; break;
*/
case TREE_TXT: case TREE_TXT:
{ {

View File

@ -69,11 +69,6 @@ void LAUNCHER_PANEL::CreateCommandToolbar()
btn = AddBitmapButton( ID_TO_SCH_LIB_EDITOR, KiBitmap( libedit_icon_xpm ) ); btn = AddBitmapButton( ID_TO_SCH_LIB_EDITOR, KiBitmap( libedit_icon_xpm ) );
btn->SetToolTip( _( "Schematic library editor" ) ); btn->SetToolTip( _( "Schematic library editor" ) );
#if 0
btn = AddBitmapButton( ID_TO_CVPCB, KiBitmap( icon_cvpcb_xpm ) );
btn->SetToolTip( _( "CvPcb - Associate footprint to components" ) );
#endif
btn = AddBitmapButton( ID_TO_PCB, KiBitmap( icon_pcbnew_xpm ) ); btn = AddBitmapButton( ID_TO_PCB, KiBitmap( icon_pcbnew_xpm ) );
btn->SetToolTip( _( "Pcbnew - Printed circuit board editor" ) ); btn->SetToolTip( _( "Pcbnew - Printed circuit board editor" ) );

View File

@ -179,7 +179,6 @@ public:
void OnRunSchLibEditor( wxCommandEvent& event ); void OnRunSchLibEditor( wxCommandEvent& event );
void OnRunPcbNew( wxCommandEvent& event ); void OnRunPcbNew( wxCommandEvent& event );
void OnRunPcbFpEditor( wxCommandEvent& event ); void OnRunPcbFpEditor( wxCommandEvent& event );
void OnRunCvpcb( wxCommandEvent& event );
void OnRunGerbview( wxCommandEvent& event ); void OnRunGerbview( wxCommandEvent& event );
void OnRunBitmapConverter( wxCommandEvent& event ); void OnRunBitmapConverter( wxCommandEvent& event );
void OnRunPcbCalculator( wxCommandEvent& event ); void OnRunPcbCalculator( wxCommandEvent& event );

View File

@ -421,6 +421,7 @@ void KICAD_MANAGER_FRAME::OnRunPageLayoutEditor( wxCommandEvent& event )
// are now always set by Cvpcb. // are now always set by Cvpcb.
// ( The idea is to drop the .cmp files to avoid to have 2 places were // ( The idea is to drop the .cmp files to avoid to have 2 places were
// footprints are stored, but only one: the schematic ) // footprints are stored, but only one: the schematic )
/*
void KICAD_MANAGER_FRAME::OnRunCvpcb( wxCommandEvent& event ) void KICAD_MANAGER_FRAME::OnRunCvpcb( wxCommandEvent& event )
{ {
wxFileName fn( GetProjectFileName() ); wxFileName fn( GetProjectFileName() );
@ -437,6 +438,8 @@ void KICAD_MANAGER_FRAME::OnRunCvpcb( wxCommandEvent& event )
frame->Raise(); frame->Raise();
} }
*/
#include <wx/filefn.h> #include <wx/filefn.h>
void KICAD_MANAGER_FRAME::OnRunGerbview( wxCommandEvent& event ) void KICAD_MANAGER_FRAME::OnRunGerbview( wxCommandEvent& event )

View File

@ -85,8 +85,6 @@ BEGIN_EVENT_TABLE( KICAD_MANAGER_FRAME, EDA_BASE_FRAME )
EVT_BUTTON( ID_TO_SCH_LIB_EDITOR, KICAD_MANAGER_FRAME::OnRunSchLibEditor ) EVT_BUTTON( ID_TO_SCH_LIB_EDITOR, KICAD_MANAGER_FRAME::OnRunSchLibEditor )
EVT_MENU( ID_TO_SCH_LIB_EDITOR, KICAD_MANAGER_FRAME::OnRunSchLibEditor ) EVT_MENU( ID_TO_SCH_LIB_EDITOR, KICAD_MANAGER_FRAME::OnRunSchLibEditor )
EVT_BUTTON( ID_TO_CVPCB, KICAD_MANAGER_FRAME::OnRunCvpcb )
EVT_BUTTON( ID_TO_PCB, KICAD_MANAGER_FRAME::OnRunPcbNew ) EVT_BUTTON( ID_TO_PCB, KICAD_MANAGER_FRAME::OnRunPcbNew )
EVT_MENU( ID_TO_PCB, KICAD_MANAGER_FRAME::OnRunPcbNew ) EVT_MENU( ID_TO_PCB, KICAD_MANAGER_FRAME::OnRunPcbNew )

View File

@ -64,7 +64,6 @@ void PCB_EDIT_FRAME::ReadPcbNetlist( const wxString& aNetlistFileName,
{ {
wxString msg; wxString msg;
NETLIST netlist; NETLIST netlist;
NETLIST_READER* netlistReader;
KIGFX::VIEW* view = GetGalCanvas()->GetView(); KIGFX::VIEW* view = GetGalCanvas()->GetView();
BOARD* board = GetBoard(); BOARD* board = GetBoard();
@ -75,17 +74,16 @@ void PCB_EDIT_FRAME::ReadPcbNetlist( const wxString& aNetlistFileName,
try try
{ {
netlistReader = NETLIST_READER::GetNetlistReader( &netlist, aNetlistFileName, std::auto_ptr<NETLIST_READER> netlistReader( NETLIST_READER::GetNetlistReader(
aCmpFileName ); &netlist, aNetlistFileName, aCmpFileName ) );
if( netlistReader == NULL ) if( !netlistReader.get() )
{ {
msg.Printf( _( "Cannot open netlist file \"%s\"." ), GetChars( aNetlistFileName ) ); msg.Printf( _( "Cannot open netlist file \"%s\"." ), GetChars( aNetlistFileName ) );
wxMessageBox( msg, _( "Netlist Load Error." ), wxOK | wxICON_ERROR, this ); wxMessageBox( msg, _( "Netlist Load Error." ), wxOK | wxICON_ERROR, this );
return; return;
} }
std::auto_ptr< NETLIST_READER > nlr( netlistReader );
SetLastNetListRead( aNetlistFileName ); SetLastNetListRead( aNetlistFileName );
netlistReader->LoadNetlist(); netlistReader->LoadNetlist();
loadFootprints( netlist, aReporter ); loadFootprints( netlist, aReporter );

View File

@ -40,17 +40,8 @@
NETLIST_READER::~NETLIST_READER() NETLIST_READER::~NETLIST_READER()
{ {
if( m_lineReader ) delete m_lineReader;
{ delete m_footprintReader;
delete m_lineReader;
m_lineReader = NULL;
}
if( m_footprintReader )
{
delete m_footprintReader;
m_footprintReader = NULL;
}
} }
@ -92,43 +83,29 @@ NETLIST_READER* NETLIST_READER::GetNetlistReader( NETLIST* aNetlist,
{ {
wxASSERT( aNetlist != NULL ); wxASSERT( aNetlist != NULL );
FILE* file = wxFopen( aNetlistFileName, wxT( "rt" ) ); std::auto_ptr< FILE_LINE_READER > file_rdr(new FILE_LINE_READER( aNetlistFileName ) );
if( file == NULL ) NETLIST_FILE_T type = GuessNetlistFileType( file_rdr.get() );
{ file_rdr->Rewind();
wxString msg;
msg.Printf( _( "Cannot open file %s for reading." ), GetChars( aNetlistFileName ) );
THROW_IO_ERROR( msg );
}
FILE_LINE_READER* reader = new FILE_LINE_READER( file, aNetlistFileName );
std::auto_ptr< FILE_LINE_READER > r( reader );
NETLIST_FILE_T type = GuessNetlistFileType( reader );
reader->Rewind();
// The component footprint link reader is NULL if no file name was specified. // The component footprint link reader is NULL if no file name was specified.
CMP_READER* cmpFileReader = NULL; std::auto_ptr<CMP_READER> cmp_rdr( aCompFootprintFileName.IsEmpty() ?
NULL :
if( !aCompFootprintFileName.IsEmpty() ) new CMP_READER( new FILE_LINE_READER( aCompFootprintFileName ) ) );
{
cmpFileReader = new CMP_READER( new FILE_LINE_READER( aCompFootprintFileName ) );
}
switch( type ) switch( type )
{ {
case LEGACY: case LEGACY:
case ORCAD: case ORCAD:
return new LEGACY_NETLIST_READER( r.release(), aNetlist, cmpFileReader ); return new LEGACY_NETLIST_READER( file_rdr.release(), aNetlist, cmp_rdr.release() );
case KICAD: case KICAD:
return new KICAD_NETLIST_READER( r.release(), aNetlist, cmpFileReader ); return new KICAD_NETLIST_READER( file_rdr.release(), aNetlist, cmp_rdr.release() );
default: // Unrecognized format: default: // Unrecognized format:
break; break;
} }
delete cmpFileReader;
return NULL; return NULL;
} }

View File

@ -110,15 +110,6 @@ public:
*/ */
class NETLIST_READER class NETLIST_READER
{ {
protected:
NETLIST* m_netlist; ///< The net list to read the file(s) into.
bool m_loadFootprintFilters; ///< Load the component footprint filters section if true.
bool m_loadNets; ///< Load the nets section of the netlist file if true.
LINE_READER* m_lineReader; ///< The line reader of the netlist.
/// The reader used to load the footprint links. If NULL, footprint links are not read.
CMP_READER* m_footprintReader;
public: public:
enum NETLIST_FILE_T enum NETLIST_FILE_T
@ -133,6 +124,12 @@ public:
// function. // function.
}; };
/**
* Constructor
* @param aLineReader ownership is taken of this LINE_READER.
* @param aFootprintLinkReader ownership is taken of this CMP_READER.
*/
NETLIST_READER( LINE_READER* aLineReader, NETLIST_READER( LINE_READER* aLineReader,
NETLIST* aNetlist, NETLIST* aNetlist,
CMP_READER* aFootprintLinkReader = NULL ) CMP_READER* aFootprintLinkReader = NULL )
@ -190,6 +187,15 @@ public:
* @return the #LINE_READER associated with the #NETLIST_READER. * @return the #LINE_READER associated with the #NETLIST_READER.
*/ */
LINE_READER* GetLineReader(); LINE_READER* GetLineReader();
protected:
NETLIST* m_netlist; ///< The net list to read the file(s) into.
bool m_loadFootprintFilters; ///< Load the component footprint filters section if true.
bool m_loadNets; ///< Load the nets section of the netlist file if true.
LINE_READER* m_lineReader; ///< The line reader of the netlist.
/// The reader used to load the footprint links. If NULL, footprint links are not read.
CMP_READER* m_footprintReader;
}; };
@ -388,8 +394,7 @@ public:
virtual ~KICAD_NETLIST_READER() virtual ~KICAD_NETLIST_READER()
{ {
if( m_parser ) delete m_parser;
delete m_parser;
} }
virtual void LoadNetlist() throw ( IO_ERROR, PARSE_ERROR, boost::bad_pointer ); virtual void LoadNetlist() throw ( IO_ERROR, PARSE_ERROR, boost::bad_pointer );