From 8fb520249e828259ec44b9aa20f7e6338782d05c Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Sun, 7 Jun 2015 14:18:45 -0400 Subject: [PATCH] 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 ) --- CMakeLists.txt | 2 +- cvpcb/CMakeLists.txt | 98 ++++----- cvpcb/cvframe.cpp | 191 ++++-------------- cvpcb/cvpcb.cpp | 30 --- cvpcb/cvpcb_mainframe.h | 32 +-- cvpcb/menubar.cpp | 37 +--- cvpcb/readwrite_dlgs.cpp | 53 +---- eeschema/class_netlist_object.cpp | 1 + eeschema/class_netlist_object.h | 45 ++--- eeschema/cross-probing.cpp | 6 +- eeschema/dialogs/dialog_erc.cpp | 6 +- eeschema/netform.cpp | 16 +- eeschema/netlist.cpp | 83 +++++--- .../netlist_exporters/netlist_exporter.cpp | 2 + eeschema/netlist_exporters/netlist_exporter.h | 26 ++- .../netlist_exporter_cadstar.cpp | 2 +- .../netlist_exporter_cadstar.h | 4 +- .../netlist_exporter_generic.cpp | 31 +-- .../netlist_exporter_generic.h | 45 +++-- .../netlist_exporter_kicad.cpp | 24 ++- .../netlist_exporter_kicad.h | 18 +- .../netlist_exporter_orcadpcb2.cpp | 2 +- .../netlist_exporter_orcadpcb2.h | 2 +- .../netlist_exporter_pspice.cpp | 2 +- .../netlist_exporter_pspice.h | 4 +- eeschema/schframe.cpp | 41 +++- eeschema/schframe.h | 22 +- eeschema/tool_sch.cpp | 10 +- include/mail_type.h | 2 +- include/richio.h | 2 +- kicad/class_treeproject_item.cpp | 3 + kicad/commandframe.cpp | 5 - kicad/kicad.h | 1 - kicad/mainframe.cpp | 3 + kicad/menubar.cpp | 2 - pcbnew/netlist.cpp | 8 +- pcbnew/netlist_reader.cpp | 43 +--- pcbnew/netlist_reader.h | 27 ++- 38 files changed, 410 insertions(+), 521 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 62467ce670..25c282bf9d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -752,7 +752,7 @@ add_subdirectory( qa ) # except perhaps bitmap lib. This allows a multi-threaded build to succeed. add_dependencies( pcbnew boost ) add_dependencies( eeschema boost ) -add_dependencies( cvpcb boost ) +add_dependencies( cvpcb_kiface boost ) add_dependencies( gal boost ) add_dependencies( common boost ) add_dependencies( pcbcommon boost ) diff --git a/cvpcb/CMakeLists.txt b/cvpcb/CMakeLists.txt index 72840f7d1a..efabc1e9ea 100644 --- a/cvpcb/CMakeLists.txt +++ b/cvpcb/CMakeLists.txt @@ -74,28 +74,59 @@ if( APPLE ) endif() -add_executable( cvpcb WIN32 MACOSX_BUNDLE - ../common/single_top.cpp - ../common/pgm_base.cpp - ${CVPCB_RESOURCES} - ) +if( false ) # no CVPCB exe any more, only the *.kiface + add_executable( cvpcb WIN32 MACOSX_BUNDLE + ../common/single_top.cpp + ../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 - COMPILE_DEFINITIONS "TOP_FRAME=FRAME_CVPCB;PGM_DATA_FILE_EXT=\"net\";BUILD_KIWAY_DLL" - ) + if( APPLE ) + set_target_properties( cvpcb PROPERTIES + MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist + ) -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} - ) + # 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() + 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. add_library( cvpcb_kiface MODULE @@ -143,42 +174,13 @@ if( MAKE_LINK_MAPS ) LINK_FLAGS "${TO_LINKER},-cref ${TO_LINKER},-Map=_cvpcb.kiface.map" ) 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: 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 set_target_properties( cvpcb_kiface PROPERTIES 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() - install( TARGETS cvpcb - DESTINATION ${KICAD_BIN} - COMPONENT binary - ) install( TARGETS cvpcb_kiface DESTINATION ${KICAD_BIN} COMPONENT binary diff --git a/cvpcb/cvframe.cpp b/cvpcb/cvframe.cpp index d73367b39a..23d66e81f0 100644 --- a/cvpcb/cvframe.cpp +++ b/cvpcb/cvframe.cpp @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -58,13 +59,10 @@ static const wxString KeepCvpcbOpenEntry( wxT( "KeepCvpcbOpen" ) ); static const wxString FootprintDocFileEntry( wxT( "footprints_doc_file" ) ); -BEGIN_EVENT_TABLE( CVPCB_MAINFRAME, EDA_BASE_FRAME ) - EVT_MENU_RANGE( wxID_FILE1, wxID_FILE9, CVPCB_MAINFRAME::LoadNetList ) +BEGIN_EVENT_TABLE( CVPCB_MAINFRAME, KIWAY_PLAYER ) // Menu events - EVT_MENU( ID_LOAD_PROJECT, CVPCB_MAINFRAME::LoadNetList ) EVT_MENU( wxID_SAVE, CVPCB_MAINFRAME::SaveQuitCvpcb ) - EVT_MENU( wxID_SAVEAS, CVPCB_MAINFRAME::SaveQuitCvpcb ) EVT_MENU( wxID_EXIT, CVPCB_MAINFRAME::OnQuit ) EVT_MENU( wxID_HELP, CVPCB_MAINFRAME::GetKicadHelp ) EVT_MENU( wxID_ABOUT, CVPCB_MAINFRAME::GetKicadAbout ) @@ -75,7 +73,7 @@ BEGIN_EVENT_TABLE( CVPCB_MAINFRAME, EDA_BASE_FRAME ) // Toolbar events 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_CREATE_SCREENCMP, CVPCB_MAINFRAME::DisplayModule ) 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 ) { - int diag; - if( m_modified ) { wxString msg = _( "Component to Footprint links modified.\nSave before exit ?" ); @@ -260,29 +256,11 @@ void CVPCB_MAINFRAME::OnCloseWindow( wxCloseEvent& Event ) break; case wxID_YES: - diag = SaveCmpLinkFile( m_NetlistFileName.GetFullPath() ); - - if( diag > 0 ) - { - m_modified = false; - } - else if( diag == 0 ) - { - if( !IsOK( this, _( "Problem when saving file, exit anyway ?" ) ) ) - { - Event.Veto(); - return; - } - } + SaveEdits(); break; } } - if( m_NetlistFileName.IsOk() ) - { - UpdateFileHistory( m_NetlistFileName.GetFullPath() ); - } - // Close module display frame if( GetFpViewerFrame() ) GetFpViewerFrame()->Close( true ); @@ -370,18 +348,12 @@ void CVPCB_MAINFRAME::ToPreviousNA( wxCommandEvent& event ) void CVPCB_MAINFRAME::SaveQuitCvpcb( wxCommandEvent& aEvent ) { - wxString fullFilename; + SaveEdits(); - if( aEvent.GetId() != wxID_SAVEAS ) - fullFilename = m_NetlistFileName.GetFullPath(); + m_modified = false; - if( SaveCmpLinkFile( fullFilename ) > 0 ) - { - m_modified = false; - - if( !m_KeepCvpcbOpen ) - Close( true ); - } + 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 ) { int id = event.GetId(); @@ -437,43 +410,11 @@ void CVPCB_MAINFRAME::LoadNetList( wxCommandEvent& event ) OpenProjectFiles( std::vector( 1, newFileName.GetFullPath() ) ); } +*/ bool CVPCB_MAINFRAME::OpenProjectFiles( const std::vector& 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; } @@ -753,9 +694,8 @@ void CVPCB_MAINFRAME::UpdateTitle() if( fn.IsOk() && !prj.GetProjectFullName().IsEmpty() && fn.FileExists() ) { - title += wxString::Format( _("Project: '%s' (netlist: '%s')"), - GetChars( fn.GetFullPath() ), - GetChars( m_NetlistFileName.GetFullName() ) + title += wxString::Format( _("Project: '%s'"), + GetChars( fn.GetFullPath() ) ); 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; - wxString msg; - 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(); + STRING_LINE_READER* strrdr = new STRING_LINE_READER( aNetlist, "Eeschema via Kiway" ); + KICAD_NETLIST_READER netrdr( strrdr, &m_netlist ); m_netlist.Clear(); try { - netlistReader = NETLIST_READER::GetNetlistReader( &m_netlist, - 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 ); + netrdr.LoadNetlist(); } 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 ); 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() { DISPLAY_FOOTPRINTS_FRAME* fpframe = GetFpViewerFrame(); @@ -1040,3 +904,24 @@ void CVPCB_MAINFRAME::OnConfigurePaths( wxCommandEvent& aEvent ) { 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 + } +} diff --git a/cvpcb/cvpcb.cpp b/cvpcb/cvpcb.cpp index 1b8d5055eb..4680410fef 100644 --- a/cvpcb/cvpcb.cpp +++ b/cvpcb/cvpcb.cpp @@ -56,36 +56,6 @@ const wxString EquFileExtension( wxT( "equ" ) ); // Wildcard for schematic retroannotation (import footprint names in schematic): 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 { diff --git a/cvpcb/cvpcb_mainframe.h b/cvpcb/cvpcb_mainframe.h index aac37407cc..7ea861269e 100644 --- a/cvpcb/cvpcb_mainframe.h +++ b/cvpcb/cvpcb_mainframe.h @@ -65,7 +65,6 @@ public: LIBRARY_LISTBOX* m_libListBox; COMPONENTS_LISTBOX* m_compListBox; wxAuiToolBar* m_mainToolBar; - wxFileName m_NetlistFileName; wxArrayString m_ModuleLibNames; wxArrayString m_EquFilesNames; wxString m_NetlistFileExtension; @@ -88,6 +87,8 @@ public: bool OpenProjectFiles( const std::vector& 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 */ @@ -192,36 +193,21 @@ public: void CreateScreenCmp(); /** - * Function SaveCmpLinkFile - * Saves the component - footprint link file (.cmp file) to \a aFullFileName. - * - * @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 + * Function SaveEdits + * saves the edits that the user has done by sending them back to eeschema + * via the kiway. */ - int SaveCmpLinkFile( const wxString& aFullFileName ); - - - /** - * 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 ); + void SaveEdits(); /** * Function ReadNetList * reads the netlist (.net) file defined by #m_NetlistFileName. * 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 diff --git a/cvpcb/menubar.cpp b/cvpcb/menubar.cpp index 139643d6c0..d8ceb32d09 100644 --- a/cvpcb/menubar.cpp +++ b/cvpcb/menubar.cpp @@ -64,42 +64,9 @@ void CVPCB_MAINFRAME::ReCreateMenuBar() // Menu File: wxMenu* filesMenu = new wxMenu; - // Open files can be used only outside a project, because opening a netlist - // 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 + // Save the footprints back into eeschema AddMenuItem( filesMenu, wxID_SAVE, - _( "&Save Cmp File\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 ) ); + _( "&Save Edits\tCtrl+S" ), SAVE_HLP_MSG, KiBitmap( save_xpm ) ); // Separator filesMenu->AppendSeparator(); diff --git a/cvpcb/readwrite_dlgs.cpp b/cvpcb/readwrite_dlgs.cpp index f70fd2debd..0debf31f81 100644 --- a/cvpcb/readwrite_dlgs.cpp +++ b/cvpcb/readwrite_dlgs.cpp @@ -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; bool hasMissingNicks = false; - ReadSchematicNetlist(); + ReadSchematicNetlist( aNetlist ); if( m_compListBox == NULL ) return false; @@ -364,56 +364,17 @@ bool CVPCB_MAINFRAME::ReadNetListAndLinkFiles() DisplayStatus(); UpdateTitle(); - - UpdateFileHistory( m_NetlistFileName.GetFullPath() ); - return true; } -int CVPCB_MAINFRAME::SaveCmpLinkFile( const wxString& aFullFileName ) +void CVPCB_MAINFRAME::SaveEdits() { - wxFileName fn; + STRING_FORMATTER sf; - if( !aFullFileName.IsEmpty() ) - { - fn = m_NetlistFileName; - fn.SetExt( ComponentFileExtension ); - } - else - { - wxFileDialog dlg( this, _( "Save Component Footprint Link File" ), - Prj().GetProjectPath(), - wxT( "noname" ), ComponentFileWildcard, wxFD_SAVE ); + m_netlist.FormatBackAnnotation( &sf ); - if( dlg.ShowModal() == wxID_CANCEL ) - return -1; + Kiway().ExpressMail( FRAME_SCH, MAIL_BACKANNOTATE_FOOTPRINTS, sf.GetString() ); - fn = dlg.GetPath(); - - 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; + SetStatusText( _("Edits sent to Eeschema") ); } diff --git a/eeschema/class_netlist_object.cpp b/eeschema/class_netlist_object.cpp index 3a99199165..3052e59c10 100644 --- a/eeschema/class_netlist_object.cpp +++ b/eeschema/class_netlist_object.cpp @@ -201,6 +201,7 @@ NETLIST_OBJECT::~NETLIST_OBJECT() { } + // return true if the object is a label of any type bool NETLIST_OBJECT::IsLabelType() const { diff --git a/eeschema/class_netlist_object.h b/eeschema/class_netlist_object.h index 0b51714427..f97fe77de4 100644 --- a/eeschema/class_netlist_object.h +++ b/eeschema/class_netlist_object.h @@ -34,6 +34,7 @@ #include #include // LIB_PIN::PinStringNum( m_PinNum ) +#include class NETLIST_OBJECT_LIST; class SCH_COMPONENT; @@ -256,13 +257,21 @@ public: /** - * NETLIST_OBJECT_LIST is a class to handle the list of connected items - * in a full schematic hierarchy for netlist and erc calculations + * Type NETLIST_OBJECTS + * 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 +typedef std::vector 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_lastBusNetCode; // Used in intermediate calculation: // last net code created for bus members @@ -276,10 +285,8 @@ public: * @param aIsOwner true if the instance is the owner of item list * (default = false) */ - NETLIST_OBJECT_LIST( bool aIsOwner = false ) + NETLIST_OBJECT_LIST() { - m_isOwner = aIsOwner; - // Do not leave some members uninitialized: m_lastNetCode = 0; m_lastBusNetCode = 0; @@ -287,8 +294,6 @@ public: ~NETLIST_OBJECT_LIST(); - void SetOwner( bool aIsOwner ) { m_isOwner = aIsOwner; } - /** * Function BuildNetListInfo * the master function of tgis class. @@ -299,7 +304,7 @@ public: */ bool BuildNetListInfo( SCH_SHEET_LIST& aSheets ); - /* + /** * Acces to an item in list */ NETLIST_OBJECT* GetItem( unsigned aIdx ) const @@ -307,7 +312,7 @@ public: return *( this->begin() + aIdx ); } - /* + /** * Acces to an item type */ NETLIST_ITEM_T GetItemType( unsigned aIdx ) const @@ -315,7 +320,7 @@ public: return GetItem( aIdx )->m_Type; } - /* + /** * Acces to an item net code */ int GetItemNet( unsigned aIdx ) const @@ -340,17 +345,8 @@ public: GetItem( aIdx )->SetConnectionType( aFlg ); } - /* - * Delete all objects in list and clear list - * (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(); } + /** Delete all objects in list and clear list */ + void Clear(); /** * Reset the connection type of all items to UNCONNECTED type @@ -456,6 +452,7 @@ private: void findBestNetNameForEachNet(); }; + /** * Function IsBusLabel * test if \a aLabel has a bus notation. diff --git a/eeschema/cross-probing.cpp b/eeschema/cross-probing.cpp index d5f229b4cc..f9b67e7732 100644 --- a/eeschema/cross-probing.cpp +++ b/eeschema/cross-probing.cpp @@ -208,9 +208,7 @@ void SCH_EDIT_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail ) } break; - // many many others. - + default: + ; } } - - diff --git a/eeschema/dialogs/dialog_erc.cpp b/eeschema/dialogs/dialog_erc.cpp index c745ee6495..5674673a4f 100644 --- a/eeschema/dialogs/dialog_erc.cpp +++ b/eeschema/dialogs/dialog_erc.cpp @@ -466,7 +466,7 @@ void DIALOG_ERC::TestErc( wxArrayString* aMessagesList ) */ TestDuplicateSheetNames( true ); - NETLIST_OBJECT_LIST* objectsConnectedList = m_parent->BuildNetListBase(); + std::auto_ptr objectsConnectedList( m_parent->BuildNetListBase() ); // Reset the connection type indicator objectsConnectedList->ResetConnectionsType(); @@ -509,7 +509,7 @@ void DIALOG_ERC::TestErc( wxArrayString* aMessagesList ) // ERC problems when pin sheets do not match hierarchical labels. // Each pin sheet must match a hierarchical label // Each hierarchical label must match a pin sheet - TestLabel( objectsConnectedList, net, nextNet ); + TestLabel( objectsConnectedList.get(), net, nextNet ); break; case NET_NOCONNECT: @@ -525,7 +525,7 @@ void DIALOG_ERC::TestErc( wxArrayString* aMessagesList ) case NET_PIN: // Look for ERC problems between pins: - TestOthersItems( objectsConnectedList, net, nextNet, &NetNbItems, &MinConn ); + TestOthersItems( objectsConnectedList.get(), net, nextNet, &NetNbItems, &MinConn ); break; } diff --git a/eeschema/netform.cpp b/eeschema/netform.cpp index 87420046cb..e30836a7fc 100644 --- a/eeschema/netform.cpp +++ b/eeschema/netform.cpp @@ -42,7 +42,7 @@ #include #include -bool SCH_EDIT_FRAME::WriteNetListFile( NETLIST_OBJECT_LIST * aConnectedItemsList, +bool SCH_EDIT_FRAME::WriteNetListFile( NETLIST_OBJECT_LIST* aConnectedItemsList, int aFormat, const wxString& aFullFileName, unsigned aNetlistOptions ) { @@ -73,17 +73,17 @@ bool SCH_EDIT_FRAME::WriteNetListFile( NETLIST_OBJECT_LIST * aConnectedItemsList default: { - wxFileName tmpFile = fileName; - tmpFile.SetExt( GENERIC_INTERMEDIATE_NETLIST_EXT ); - fileName = tmpFile.GetFullPath(); + wxFileName tmpFile = fileName; + tmpFile.SetExt( GENERIC_INTERMEDIATE_NETLIST_EXT ); + fileName = tmpFile.GetFullPath(); - helper = new NETLIST_EXPORTER_GENERIC( aConnectedItemsList, Prj().SchLibs() ); - executeCommandLine = true; - break; + helper = new NETLIST_EXPORTER_GENERIC( aConnectedItemsList, Prj().SchLibs() ); + executeCommandLine = true; } + break; } - res = helper->Write( fileName, aNetlistOptions ); + res = helper->WriteNetlist( fileName, aNetlistOptions ); if( executeCommandLine ) { diff --git a/eeschema/netlist.cpp b/eeschema/netlist.cpp index 0565f20fbb..ee9751168b 100644 --- a/eeschema/netlist.cpp +++ b/eeschema/netlist.cpp @@ -30,6 +30,8 @@ #include #include #include +#include +#include #include #include @@ -51,8 +53,8 @@ //Imported function: 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; @@ -85,32 +87,55 @@ bool SCH_EDIT_FRAME::CreateNetlist( int aFormat, const wxString& aFullFileName, 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 connectedItemsList( BuildNetListBase() ); + + bool success = WriteNetListFile( connectedItemsList.release(), aFormat, aFullFileName, aNetlistOptions ); return success; } -// Buffer to build the list of items used in netlist and erc calculations -NETLIST_OBJECT_LIST s_NetObjectslist( true ); - //#define NETLIST_DEBUG NETLIST_OBJECT_LIST::~NETLIST_OBJECT_LIST() { - if( m_isOwner ) - FreeList(); - else - Clear(); + Clear(); } -void NETLIST_OBJECT_LIST::FreeList() +void NETLIST_OBJECT_LIST::Clear() { - std::vector::iterator iter; + NETLIST_OBJECTS::iterator 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 ret( new NETLIST_OBJECT_LIST() ); + // Creates the flattened sheet list: SCH_SHEET_LIST aSheets; // Build netlist info - bool success = s_NetObjectslist.BuildNetListInfo( aSheets ); + bool success = ret->BuildNetListInfo( aSheets ); if( !success ) { - SetStatusText( _("No Objects" ) ); - return &s_NetObjectslist; + SetStatusText( _( "No Objects" ) ); + return ret.release(); } - /* The new %zu specification is needed to properly format a size_t - * value (returned by size(), here) */ - wxString msg; + wxString msg = wxString::Format( _( "Net count = %zu" ), ret->size() ); - msg.Printf( _( "Net count = %zu" ), s_NetObjectslist.size() ); SetStatusText( msg ); - return &s_NetObjectslist; + return ret.release(); } bool NETLIST_OBJECT_LIST::BuildNetListInfo( SCH_SHEET_LIST& aSheets ) { - s_NetObjectslist.SetOwner( true ); - s_NetObjectslist.FreeList(); - SCH_SHEET_PATH* sheet; // 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 // the reference is kept) - // Build the list of items with no net names - NETLIST_OBJECT_LIST list; + // Build a list of items with no net names + NETLIST_OBJECTS list; // no ownership of elements being pointed at + for( unsigned ii = 0; ii < size(); ii++ ) { item = GetItem( ii ); @@ -505,12 +528,12 @@ void NETLIST_OBJECT_LIST::findBestNetNameForEachNet() idxstart = 0; candidate = NULL; - netcode = list.GetItemNet( 0 ); + netcode = list[0]->GetNet(); for( unsigned ii = 0; ii <= list.size(); ii++ ) { if( ii < list.size() ) - item = list.GetItem( ii ); + item = list[ii]; else item = NULL; @@ -520,7 +543,7 @@ void NETLIST_OBJECT_LIST::findBestNetNameForEachNet() { for (unsigned jj = idxstart; jj < ii; jj++ ) { - NETLIST_OBJECT* obj = list.GetItem( jj ); + NETLIST_OBJECT* obj = list[jj]; obj->SetNetNameCandidate( candidate ); } } diff --git a/eeschema/netlist_exporters/netlist_exporter.cpp b/eeschema/netlist_exporters/netlist_exporter.cpp index 041f8a0e14..fd38470526 100644 --- a/eeschema/netlist_exporters/netlist_exporter.cpp +++ b/eeschema/netlist_exporters/netlist_exporter.cpp @@ -45,6 +45,8 @@ #include #include + + wxString NETLIST_EXPORTER::MakeCommandLine( const wxString& aFormatString, const wxString& aTempfile, const wxString& aFinalFile, const wxString& aProjectPath ) { diff --git a/eeschema/netlist_exporters/netlist_exporter.h b/eeschema/netlist_exporters/netlist_exporter.h index 81848d6061..898d2673ac 100644 --- a/eeschema/netlist_exporters/netlist_exporter.h +++ b/eeschema/netlist_exporters/netlist_exporter.h @@ -73,13 +73,14 @@ public: class NETLIST_EXPORTER { 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 - /// when generating schematic component data in netlist (comp section) - NETLIST_OBJECT_LIST m_SortedComponentPinList; + /// when generating schematic component data in netlist (comp section). No ownership + /// of members. + NETLIST_OBJECTS m_SortedComponentPinList; /// Used for "multi parts per package" components, /// avoids processing a lib component more than once. @@ -91,7 +92,6 @@ protected: std::set m_Libraries; ///< unique libraries used - /** * Function sprintPinNetName * formats the net name for \a aPin using \a aNetNameFormat into \a aResult. @@ -155,21 +155,27 @@ protected: SCH_SHEET_PATH* aSheetPath ); 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() { + delete m_masterList; // I own the list itself in this instance. } /** - * Function Write + * Function WriteNetlist * writes to specified output file */ - virtual bool Write( const wxString& aOutFileName, unsigned aNetlistOptions ) + virtual bool WriteNetlist( const wxString& aOutFileName, unsigned aNetlistOptions ) { return false; } diff --git a/eeschema/netlist_exporters/netlist_exporter_cadstar.cpp b/eeschema/netlist_exporters/netlist_exporter_cadstar.cpp index 5692da8d93..1d175a94a3 100644 --- a/eeschema/netlist_exporters/netlist_exporter_cadstar.cpp +++ b/eeschema/netlist_exporters/netlist_exporter_cadstar.cpp @@ -36,7 +36,7 @@ /* Generate CADSTAR net list. */ 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 int ret = 0; diff --git a/eeschema/netlist_exporters/netlist_exporter_cadstar.h b/eeschema/netlist_exporters/netlist_exporter_cadstar.h index e91e9356de..909e1bdbb8 100644 --- a/eeschema/netlist_exporters/netlist_exporter_cadstar.h +++ b/eeschema/netlist_exporters/netlist_exporter_cadstar.h @@ -53,10 +53,10 @@ public: } /** - * Function Write + * Function WriteList * writes to specified output file */ - bool Write( const wxString& aOutFileName, unsigned aNetlistOptions ); + bool WriteNetlist( const wxString& aOutFileName, unsigned aNetlistOptions ); }; #endif diff --git a/eeschema/netlist_exporters/netlist_exporter_generic.cpp b/eeschema/netlist_exporters/netlist_exporter_generic.cpp index f95a3208de..9b9f6d5140 100644 --- a/eeschema/netlist_exporters/netlist_exporter_generic.cpp +++ b/eeschema/netlist_exporters/netlist_exporter_generic.cpp @@ -32,7 +32,7 @@ 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 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. wxXmlDocument xdoc; - xdoc.SetRoot( makeRoot() ); + xdoc.SetRoot( makeRoot( GNL_ALL ) ); 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" ) ); xroot->AddAttribute( wxT( "version" ), wxT( "D" ) ); - // add the "design" header - xroot->AddChild( makeDesignHeader() ); + if( aCtl & GNL_HEADER ) + // 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() - xroot->AddChild( makeLibraries() ); + if( aCtl & GNL_LIBRARIES ) + // must follow makeGenericLibParts() + xroot->AddChild( makeLibraries() ); - xroot->AddChild( makeListOfNets() ); + if( aCtl & GNL_NETS ) + xroot->AddChild( makeListOfNets() ); return xroot; } @@ -210,14 +215,14 @@ XNODE* NETLIST_EXPORTER_GENERIC::makeDesignHeader() for( SCH_SHEET_PATH* sheet = sheetList.GetFirst(); sheet; sheet = sheetList.GetNext() ) { - screen = sheet->LastScreen(); + screen = sheet->LastScreen(); xdesign->AddChild( xsheet = node( wxT( "sheet" ) ) ); // 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 // human readable - sheetTxt.Printf( wxT( "%d" ), ( sheetList.GetIndex() + 1 ) ); + sheetTxt.Printf( wxT( "%d" ), ( sheetList.GetIndex() + 1 ) ); xsheet->AddAttribute( wxT( "number" ), sheetTxt ); xsheet->AddAttribute( wxT( "name" ), sheet->PathHumanReadable() ); xsheet->AddAttribute( wxT( "tstamps" ), sheet->Path() ); @@ -251,7 +256,7 @@ XNODE* NETLIST_EXPORTER_GENERIC::makeDesignHeader() xtitleBlock->AddChild( xcomment = node( wxT( "comment" ) ) ); xcomment->AddAttribute( wxT("number"), wxT("4") ); xcomment->AddAttribute( wxT( "value" ), tb.GetComment4() ); - } + } return xdesign; } diff --git a/eeschema/netlist_exporters/netlist_exporter_generic.h b/eeschema/netlist_exporters/netlist_exporter_generic.h index 45ec79f097..89d57d57ae 100644 --- a/eeschema/netlist_exporters/netlist_exporter_generic.h +++ b/eeschema/netlist_exporters/netlist_exporter_generic.h @@ -32,6 +32,20 @@ #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 * 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 { +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: /** * Function node @@ -50,20 +78,23 @@ protected: * of the returned node, and has type wxXML_TEXT_NODE. */ XNODE* node( const wxString& aName, const wxString& aTextualContent = wxEmptyString ); + /** * Function writeGENERICListOfNets * writes out nets (ranked by Netcode), and elements that are * connected as part of that net. */ bool writeListOfNets( FILE* f, NETLIST_OBJECT_LIST& aObjectsList ); + /** * Function makeGenericRoot * 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 * 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 */ - XNODE* makeRoot(); + XNODE* makeRoot( int aCtl = GNL_ALL ); /** * Function makeComponents @@ -99,18 +130,6 @@ protected: * @return XNODE* - the library nodes */ 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 diff --git a/eeschema/netlist_exporters/netlist_exporter_kicad.cpp b/eeschema/netlist_exporters/netlist_exporter_kicad.cpp index dde4aa7d82..e4b624cd0e 100644 --- a/eeschema/netlist_exporters/netlist_exporter_kicad.cpp +++ b/eeschema/netlist_exporters/netlist_exporter_kicad.cpp @@ -31,8 +31,9 @@ #include #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 for( unsigned ii = 0; ii < m_masterList->size(); ii++ ) 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 ); } +#else + try + { + FILE_OUTPUTFORMATTER formatter( aOutFileName ); + + Format( &formatter, GNL_ALL ); + } +#endif + catch( const IO_ERROR& ioe ) { DisplayError( NULL, ioe.errorText ); @@ -53,3 +63,15 @@ bool NETLIST_EXPORTER_KICAD::Write( const wxString& aOutFileName, unsigned aNetl 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 xroot( makeRoot( aCtl ) ); + + xroot->Format( aOut, 0 ); +} diff --git a/eeschema/netlist_exporters/netlist_exporter_kicad.h b/eeschema/netlist_exporters/netlist_exporter_kicad.h index 654b8ba094..433d12c4f0 100644 --- a/eeschema/netlist_exporters/netlist_exporter_kicad.h +++ b/eeschema/netlist_exporters/netlist_exporter_kicad.h @@ -28,9 +28,11 @@ #include +class OUTPUTFORMATTER; + /** * 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. */ class NETLIST_EXPORTER_KICAD : public NETLIST_EXPORTER_GENERIC @@ -42,10 +44,20 @@ public: } /** - * Function Write + * Function WriteNetlist * 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 diff --git a/eeschema/netlist_exporters/netlist_exporter_orcadpcb2.cpp b/eeschema/netlist_exporters/netlist_exporter_orcadpcb2.cpp index 2eb67d1781..0aeaccc3d0 100644 --- a/eeschema/netlist_exporters/netlist_exporter_orcadpcb2.cpp +++ b/eeschema/netlist_exporters/netlist_exporter_orcadpcb2.cpp @@ -35,7 +35,7 @@ #include #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 FILE* f = NULL; diff --git a/eeschema/netlist_exporters/netlist_exporter_orcadpcb2.h b/eeschema/netlist_exporters/netlist_exporter_orcadpcb2.h index a1273e7368..06fcf10deb 100644 --- a/eeschema/netlist_exporters/netlist_exporter_orcadpcb2.h +++ b/eeschema/netlist_exporters/netlist_exporter_orcadpcb2.h @@ -40,7 +40,7 @@ public: { } - bool Write( const wxString& aOutFileName, unsigned aNetlistOptions ); + bool WriteNetlist( const wxString& aOutFileName, unsigned aNetlistOptions ); }; #endif diff --git a/eeschema/netlist_exporters/netlist_exporter_pspice.cpp b/eeschema/netlist_exporters/netlist_exporter_pspice.cpp index ddcd7e827c..1066dcdbbc 100644 --- a/eeschema/netlist_exporters/netlist_exporter_pspice.cpp +++ b/eeschema/netlist_exporters/netlist_exporter_pspice.cpp @@ -34,7 +34,7 @@ #include #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; bool aUsePrefix = aNetlistOptions & NET_USE_X_PREFIX; diff --git a/eeschema/netlist_exporters/netlist_exporter_pspice.h b/eeschema/netlist_exporters/netlist_exporter_pspice.h index e5bb95c3bd..c57938f69b 100644 --- a/eeschema/netlist_exporters/netlist_exporter_pspice.h +++ b/eeschema/netlist_exporters/netlist_exporter_pspice.h @@ -41,10 +41,10 @@ public: } /** - * Function Write + * Function WriteNetlist * writes to specified output file */ - bool Write( const wxString& aOutFileName, unsigned aNetlistOptions ); + bool WriteNetlist( const wxString& aOutFileName, unsigned aNetlistOptions ); }; #endif diff --git a/eeschema/schframe.cpp b/eeschema/schframe.cpp index a9c3290de4..22350ab91b 100644 --- a/eeschema/schframe.cpp +++ b/eeschema/schframe.cpp @@ -27,7 +27,6 @@ */ #include -#include #include #include #include @@ -186,6 +185,23 @@ PART_LIBS* PROJECT::SchLibs() return libs; } +/* +NETLIST_OBJECT_LIST* PROJECT::Netlist() +{ + NETLIST_OBJECT_LIST* netlist = (NETLIST_OBJECT_LIST*) GetElem( PROJECT::ELEM_SCH_NETLIST ); + + wxASSERT( !libs || dynamic_cast( netlist ) ); + + if( !netlist ) + { + netlist = new NETLIST_OBJECT_LIST(); + + // Make PROJECT the new NETLIST_OBJECT_LIST owner. + SetElem( PROJECT::ELEM_SCH_NETLIST, netlist ); + } +} +*/ + //----------------------------------------------- @@ -974,10 +990,16 @@ void SCH_EDIT_FRAME::OnOpenCvpcb( wxCommandEvent& event ) 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 ) ); + */ } else { +#if 0 KIWAY_PLAYER* player = Kiway().Player( FRAME_CVPCB, false ); // test open already. if( !player ) @@ -988,6 +1010,23 @@ void SCH_EDIT_FRAME::OnOpenCvpcb( wxCommandEvent& event ) } 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( 1, fn.GetFullPath() ) ); + } + + sendNetlist(); + + player->Raise(); + } +#endif } } diff --git a/eeschema/schframe.h b/eeschema/schframe.h index 2279e0e001..567e488a62 100644 --- a/eeschema/schframe.h +++ b/eeschema/schframe.h @@ -209,6 +209,20 @@ protected: void backAnnotateFootprints( const std::string& aChangedSetOfReferences ) 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: SCH_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ); ~SCH_EDIT_FRAME(); @@ -476,9 +490,9 @@ public: * netlist generation: * Creates a flat list which stores all connected objects, and mainly * 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 @@ -506,7 +520,7 @@ public: * Function WriteNetListFile * Create the netlist file. Netlist info must be existing * (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 aFullFileName = full netlist file name * @param aNetlistOptions = netlist options using OR'ed bits. @@ -518,7 +532,7 @@ public: *

* @return true if success. */ - bool WriteNetListFile( NETLIST_OBJECT_LIST * aConnectedItemsList, + bool WriteNetListFile( NETLIST_OBJECT_LIST* aConnectedItemsList, int aFormat, const wxString& aFullFileName, unsigned aNetlistOptions ); diff --git a/eeschema/tool_sch.cpp b/eeschema/tool_sch.cpp index 04a3d3ff42..f03faa8ff1 100644 --- a/eeschema/tool_sch.cpp +++ b/eeschema/tool_sch.cpp @@ -156,14 +156,16 @@ void SCH_EDIT_FRAME::ReCreateHToolbar() // The user must HAVE footprints before he can assign them. So put this before // 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 ), _( "Footprint Editor" ) ); - } - m_mainToolBar->AddTool( ID_RUN_CVPCB, wxEmptyString, KiBitmap( cvpcb_xpm ), - _( "Run CvPcb to associate components and footprints" ) ); + // CVPCB only reads from the kiway now, and the kiway is only implemented in the + // 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 ), _( "Run Pcbnew to layout printed circuit board" ) ); diff --git a/include/mail_type.h b/include/mail_type.h index 985ada08e2..dc9d03ed05 100644 --- a/include/mail_type.h +++ b/include/mail_type.h @@ -38,7 +38,7 @@ enum MAIL_T { MAIL_CROSS_PROBE, ///< PCB<->SCH, CVPCB->SCH cross-probing. MAIL_BACKANNOTATE_FOOTPRINTS, ///< CVPCB->SCH footprint stuffing at cvpcb termination - + MAIL_EESCHEMA_NETLIST, ///< EESCHEMA->CVPCB netlist immediately after launching CVPCB }; #endif // MAIL_TYPE_H_ diff --git a/include/richio.h b/include/richio.h index e3bf3bf104..4d344b9a86 100644 --- a/include/richio.h +++ b/include/richio.h @@ -605,7 +605,7 @@ public: */ void StripUseless(); - std::string GetString() + const std::string& GetString() { return mystring; } diff --git a/kicad/class_treeproject_item.cpp b/kicad/class_treeproject_item.cpp index e257b84a63..24a7aa194c 100644 --- a/kicad/class_treeproject_item.cpp +++ b/kicad/class_treeproject_item.cpp @@ -222,9 +222,12 @@ void TREEPROJECT_ITEM::Activate( TREE_PROJECT_FRAME* prjframe ) OpenPDF( fullFileName ); 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: frame->Execute( m_parent, CVPCB_EXE, fullFileName ); break; +*/ case TREE_TXT: { diff --git a/kicad/commandframe.cpp b/kicad/commandframe.cpp index 70d6d776bb..dca958027c 100644 --- a/kicad/commandframe.cpp +++ b/kicad/commandframe.cpp @@ -69,11 +69,6 @@ void LAUNCHER_PANEL::CreateCommandToolbar() btn = AddBitmapButton( ID_TO_SCH_LIB_EDITOR, KiBitmap( libedit_icon_xpm ) ); 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->SetToolTip( _( "Pcbnew - Printed circuit board editor" ) ); diff --git a/kicad/kicad.h b/kicad/kicad.h index 66b91d3da1..a9018a4b39 100644 --- a/kicad/kicad.h +++ b/kicad/kicad.h @@ -179,7 +179,6 @@ public: void OnRunSchLibEditor( wxCommandEvent& event ); void OnRunPcbNew( wxCommandEvent& event ); void OnRunPcbFpEditor( wxCommandEvent& event ); - void OnRunCvpcb( wxCommandEvent& event ); void OnRunGerbview( wxCommandEvent& event ); void OnRunBitmapConverter( wxCommandEvent& event ); void OnRunPcbCalculator( wxCommandEvent& event ); diff --git a/kicad/mainframe.cpp b/kicad/mainframe.cpp index 3abc510148..33a039bdf4 100644 --- a/kicad/mainframe.cpp +++ b/kicad/mainframe.cpp @@ -421,6 +421,7 @@ void KICAD_MANAGER_FRAME::OnRunPageLayoutEditor( wxCommandEvent& event ) // are now always set by Cvpcb. // ( The idea is to drop the .cmp files to avoid to have 2 places were // footprints are stored, but only one: the schematic ) +/* void KICAD_MANAGER_FRAME::OnRunCvpcb( wxCommandEvent& event ) { wxFileName fn( GetProjectFileName() ); @@ -437,6 +438,8 @@ void KICAD_MANAGER_FRAME::OnRunCvpcb( wxCommandEvent& event ) frame->Raise(); } +*/ + #include void KICAD_MANAGER_FRAME::OnRunGerbview( wxCommandEvent& event ) diff --git a/kicad/menubar.cpp b/kicad/menubar.cpp index a9e09559cd..fddb607c43 100644 --- a/kicad/menubar.cpp +++ b/kicad/menubar.cpp @@ -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_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_MENU( ID_TO_PCB, KICAD_MANAGER_FRAME::OnRunPcbNew ) diff --git a/pcbnew/netlist.cpp b/pcbnew/netlist.cpp index 9ede6c0ef3..3f309a0f73 100644 --- a/pcbnew/netlist.cpp +++ b/pcbnew/netlist.cpp @@ -64,7 +64,6 @@ void PCB_EDIT_FRAME::ReadPcbNetlist( const wxString& aNetlistFileName, { wxString msg; NETLIST netlist; - NETLIST_READER* netlistReader; KIGFX::VIEW* view = GetGalCanvas()->GetView(); BOARD* board = GetBoard(); @@ -75,17 +74,16 @@ void PCB_EDIT_FRAME::ReadPcbNetlist( const wxString& aNetlistFileName, try { - netlistReader = NETLIST_READER::GetNetlistReader( &netlist, aNetlistFileName, - aCmpFileName ); + std::auto_ptr netlistReader( NETLIST_READER::GetNetlistReader( + &netlist, aNetlistFileName, aCmpFileName ) ); - if( netlistReader == NULL ) + if( !netlistReader.get() ) { msg.Printf( _( "Cannot open netlist file \"%s\"." ), GetChars( aNetlistFileName ) ); wxMessageBox( msg, _( "Netlist Load Error." ), wxOK | wxICON_ERROR, this ); return; } - std::auto_ptr< NETLIST_READER > nlr( netlistReader ); SetLastNetListRead( aNetlistFileName ); netlistReader->LoadNetlist(); loadFootprints( netlist, aReporter ); diff --git a/pcbnew/netlist_reader.cpp b/pcbnew/netlist_reader.cpp index a7e278a035..73e71dc88c 100644 --- a/pcbnew/netlist_reader.cpp +++ b/pcbnew/netlist_reader.cpp @@ -40,17 +40,8 @@ NETLIST_READER::~NETLIST_READER() { - if( m_lineReader ) - { - delete m_lineReader; - m_lineReader = NULL; - } - - if( m_footprintReader ) - { - delete m_footprintReader; - m_footprintReader = NULL; - } + delete m_lineReader; + delete m_footprintReader; } @@ -92,43 +83,29 @@ NETLIST_READER* NETLIST_READER::GetNetlistReader( NETLIST* aNetlist, { 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 ) - { - 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(); + NETLIST_FILE_T type = GuessNetlistFileType( file_rdr.get() ); + file_rdr->Rewind(); // The component footprint link reader is NULL if no file name was specified. - CMP_READER* cmpFileReader = NULL; - - if( !aCompFootprintFileName.IsEmpty() ) - { - cmpFileReader = new CMP_READER( new FILE_LINE_READER( aCompFootprintFileName ) ); - } + std::auto_ptr cmp_rdr( aCompFootprintFileName.IsEmpty() ? + NULL : + new CMP_READER( new FILE_LINE_READER( aCompFootprintFileName ) ) ); switch( type ) { case LEGACY: 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: - return new KICAD_NETLIST_READER( r.release(), aNetlist, cmpFileReader ); + return new KICAD_NETLIST_READER( file_rdr.release(), aNetlist, cmp_rdr.release() ); default: // Unrecognized format: break; } - delete cmpFileReader; return NULL; } diff --git a/pcbnew/netlist_reader.h b/pcbnew/netlist_reader.h index f473aae006..0bdd6431cd 100644 --- a/pcbnew/netlist_reader.h +++ b/pcbnew/netlist_reader.h @@ -110,15 +110,6 @@ public: */ 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: enum NETLIST_FILE_T @@ -133,6 +124,12 @@ public: // 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* aNetlist, CMP_READER* aFootprintLinkReader = NULL ) @@ -190,6 +187,15 @@ public: * @return the #LINE_READER associated with the #NETLIST_READER. */ 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() { - if( m_parser ) - delete m_parser; + delete m_parser; } virtual void LoadNetlist() throw ( IO_ERROR, PARSE_ERROR, boost::bad_pointer );