From d7da6083e4c0d55966dd8801678649cb36af4125 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sat, 11 Feb 2012 10:04:26 +0100 Subject: [PATCH] CvPcb: serious code cleaning. More comments. Remove useless files and some files renamed with a better name. --- cvpcb/CMakeLists.txt | 5 +- cvpcb/cvframe.cpp | 12 +- cvpcb/cvpcb.cpp | 7 +- cvpcb/cvpcb.h | 1 + cvpcb/cvpcb_mainframe.h | 78 +++++++---- cvpcb/genequiv.cpp | 52 ------- cvpcb/init.cpp | 166 ---------------------- cvpcb/read_write_cmpfile.cpp | 180 ++++++++++++++++++++++++ cvpcb/readwrite_dlgs.cpp | 257 +++++++++++++++++++++++++++++++++++ cvpcb/savecmp.cpp | 174 ------------------------ cvpcb/writenetlistpcbnew.cpp | 102 -------------- pcbnew/editmod.cpp | 26 ++-- 12 files changed, 513 insertions(+), 547 deletions(-) delete mode 100644 cvpcb/genequiv.cpp delete mode 100644 cvpcb/init.cpp create mode 100644 cvpcb/read_write_cmpfile.cpp create mode 100644 cvpcb/readwrite_dlgs.cpp delete mode 100644 cvpcb/savecmp.cpp delete mode 100644 cvpcb/writenetlistpcbnew.cpp diff --git a/cvpcb/CMakeLists.txt b/cvpcb/CMakeLists.txt index fd727a0cff..6fff56f0ed 100644 --- a/cvpcb/CMakeLists.txt +++ b/cvpcb/CMakeLists.txt @@ -36,13 +36,12 @@ set(CVPCB_SRCS class_footprints_listbox.cpp cvframe.cpp cvpcb.cpp - genequiv.cpp - init.cpp listboxes.cpp loadcmp.cpp menubar.cpp readschematicnetlist.cpp - savecmp.cpp + read_write_cmpfile.cpp + readwrite_dlgs.cpp setvisu.cpp tool_cvpcb.cpp ) diff --git a/cvpcb/cvframe.cpp b/cvpcb/cvframe.cpp index 5a58933306..521e2bfad7 100644 --- a/cvpcb/cvframe.cpp +++ b/cvpcb/cvframe.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com + * Copyright (C) 2009 Jean-Pierre Charras, jean-pierre.charras * Copyright (C) 2011 Wayne Stambaugh * Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors. * @@ -242,7 +242,7 @@ void CVPCB_MAINFRAME::OnCloseWindow( wxCloseEvent& Event ) { unsigned ii; wxMessageDialog dialog( this, - _( "Net and component list modified.\nSave before exit ?" ), + _( "Component to Footprint links modified.\nSave before exit ?" ), _( "Confirmation" ), wxYES_NO | wxCANCEL | wxICON_EXCLAMATION | wxYES_DEFAULT ); @@ -259,7 +259,7 @@ void CVPCB_MAINFRAME::OnCloseWindow( wxCloseEvent& Event ) case wxID_OK: case wxID_YES: - diag = SaveNetList( m_NetlistFileName.GetFullPath() ); + diag = SaveCmpLinkFile( m_NetlistFileName.GetFullPath() ); if( diag > 0 ) { @@ -267,7 +267,7 @@ void CVPCB_MAINFRAME::OnCloseWindow( wxCloseEvent& Event ) } else if( diag == 0 ) { - if( !IsOK( this, _( "Problem when saving files, exit anyway ?" ) ) ) + if( !IsOK( this, _( "Problem when saving file, exit anyway ?" ) ) ) { Event.Veto(); return; @@ -385,7 +385,7 @@ void CVPCB_MAINFRAME::SaveQuitCvpcb( wxCommandEvent& aEvent ) if( aEvent.GetId() == wxID_SAVEAS ) m_NetlistFileName.Clear(); - if( SaveNetList( m_NetlistFileName.GetFullPath() ) > 0 ) + if( SaveCmpLinkFile( m_NetlistFileName.GetFullPath() ) > 0 ) { m_modified = false; @@ -451,7 +451,7 @@ void CVPCB_MAINFRAME::LoadNetList( wxCommandEvent& event ) wxGetApp().GetLibraryPathList().Insert( newFileName.GetPath(), 0 ); m_NetlistFileName = newFileName; - ReadNetList(); + ReadNetListAndLinkFiles(); } diff --git a/cvpcb/cvpcb.cpp b/cvpcb/cvpcb.cpp index bc430ee813..fae9eb762b 100644 --- a/cvpcb/cvpcb.cpp +++ b/cvpcb/cvpcb.cpp @@ -31,6 +31,9 @@ const wxString FootprintAliasFileExtension( wxT( "equ" ) ); const wxString RetroFileWildcard( _( "KiCad retroannotation files (*.stf)|*.stf" ) ); const wxString FootprintAliasFileWildcard( _( "KiCad footprint alias files (*.equ)|*.equ" ) ); +// Wildcard for cvpcb component to footprint link file ( normal output file ) +const wxString ComponentFileWildcard( _( "KiCad cmp/footprint link files (*.cmp)|*.cmp" ) ); + const wxString titleLibLoadError( _( "Library Load Error" ) ); @@ -57,7 +60,7 @@ void EDA_APP::MacOpenFile(const wxString &fileName) wxGetApp().GetLibraryPathList().Insert( filename.GetPath(), 0 ); frame->m_NetlistFileName = filename; - frame->ReadNetList(); + frame->ReadNetListAndLinkFiles(); } // Create a new application object @@ -108,7 +111,7 @@ bool EDA_APP::OnInit() { frame->m_NetlistFileName = filename; - if( frame->ReadNetList() ) + if( frame->ReadNetListAndLinkFiles() ) { frame->m_NetlistFileExtension = filename.GetExt(); return true; diff --git a/cvpcb/cvpcb.h b/cvpcb/cvpcb.h index 325b6e7928..201a61c598 100644 --- a/cvpcb/cvpcb.h +++ b/cvpcb/cvpcb.h @@ -29,6 +29,7 @@ extern const wxString ComponentFileExtension; extern const wxString RetroFileWildcard; extern const wxString FootprintAliasFileWildcard; +extern const wxString ComponentFileWildcard; extern const wxString titleLibLoadError; diff --git a/cvpcb/cvpcb_mainframe.h b/cvpcb/cvpcb_mainframe.h index e509159059..f0d7528c2c 100644 --- a/cvpcb/cvpcb_mainframe.h +++ b/cvpcb/cvpcb_mainframe.h @@ -110,7 +110,15 @@ public: */ void AssocieModule( wxCommandEvent& event ); + /** + * Function WriteStuffList + * Creates a file for Eeschema, import footprint selections + * in schematic + * the file format is + * comp = "" module = " + */ void WriteStuffList( wxCommandEvent& event ); + void DisplayDocFile( wxCommandEvent& event ); /** @@ -123,37 +131,64 @@ public: /** * Function SetNewPkg - * set the module to the selected component and selects the next component. + * links the footprint to the current selected component + * and selects the next component. + * @param aFootprintName = the selected footprint */ - void SetNewPkg( const wxString& package ); + void SetNewPkg( const wxString& aFootprintName ); void BuildCmpListBox(); void BuildFOOTPRINTS_LISTBOX(); void CreateScreenCmp(); /** - * Function SaveNetList - * backup and save netlist (.net) file to \a aFullFileName. + * Function SaveCmpLinkFile + * Saves the component - footprint link file (.cmp file) to \a aFullFileName. * - * @param aFullFileName A reference wxString object containing the full path and - * file name of the netlist to save. - * @return 0 if an error occurred saving the netlist 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 cancelled + * 1 if OK */ - int SaveNetList( const wxString& aFullFileName ); + int SaveCmpLinkFile( const wxString& aFullFileName ); + /** - * Function SaveComponentList - * backup modules to file \a aFullFileName. + * Function LoadComponentFile + * loads the .cmp link file \a aCmpFileName which stores + * the component/footprint association. * - * @param aFullFileName Name of net list file to save. - * @returns 1 if OK, 0 if error. + * @param aFileName The full filename of .cmp file to load + * If empty, a filename will be asked to the user */ - int SaveComponentList( const wxString& aFullFileName ); + bool LoadComponentLinkFile( const wxString& aFileName ); + + /** + * 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 ReadComponentLinkFile + * Reads the component footprint link file \a aFullFileName. + * + * @param aFile = the opened the opened file to read. + * ReadComponentLinkFile will close the file + * @return true if OK, false if error. + */ + bool ReadComponentLinkFile( FILE * aFile ); /** * Function ReadNetList * reads the netlist (.net) file defined by #m_NetlistFileName. + * and the corresponding cmp to footprint (.cmp) link file */ - bool ReadNetList(); + bool ReadNetListAndLinkFiles(); int ReadSchematicNetlist(); @@ -200,21 +235,6 @@ public: */ bool LoadFootprintFiles(); - /** - * function GenNetlistPcbnew - * writes the output netlist file - * - */ - int GenNetlistPcbnew( FILE* f, bool isEESchemaNetlist = true ); - - /** - * Function LoadComponentFile - * loads the .cmp file \a aCmpFileName that stores the component/footprint association. - * - * @param aFileName The full filename of .cmp file to load - */ - bool LoadComponentFile( const wxString& aFileName ); - /** * Function GetProjectFileParameters * return project file parameter list for CvPcb. diff --git a/cvpcb/genequiv.cpp b/cvpcb/genequiv.cpp deleted file mode 100644 index 81c17bf7d5..0000000000 --- a/cvpcb/genequiv.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/*****************/ -/* genequiv.cpp */ -/*****************/ - -#include -#include -#include -#include - -#include -#include - - -void CVPCB_MAINFRAME::WriteStuffList( wxCommandEvent& event ) -{ - FILE* FileEquiv; - wxString Line; - wxFileName fn = m_NetlistFileName; - - if( m_components.empty() ) - return; - - fn.SetExt( RetroFileExtension ); - - wxFileDialog dlg( this, wxT( "Save Stuff File" ), fn.GetPath(), - fn.GetFullName(), RetroFileWildcard, - wxFD_SAVE | wxFD_OVERWRITE_PROMPT ); - - if( dlg.ShowModal() == wxID_CANCEL ) - return; - - FileEquiv = wxFopen( dlg.GetPath(), wxT( "wt" ) ); - - if( FileEquiv == 0 ) - { - Line = _( "Unable to create " ) + dlg.GetPath(); - DisplayError( this, Line, 30 ); - return; - } - - BOOST_FOREACH( COMPONENT_INFO& component, m_components ) - { - if( component.m_Footprint.empty() ) - continue; - - fprintf( FileEquiv, "comp = %s module = %s\n", - EscapedUTF8( component.m_Reference ).c_str(), - EscapedUTF8( component.m_Footprint ).c_str() ); - } - - fclose( FileEquiv ); -} diff --git a/cvpcb/init.cpp b/cvpcb/init.cpp deleted file mode 100644 index b4c413f7b8..0000000000 --- a/cvpcb/init.cpp +++ /dev/null @@ -1,166 +0,0 @@ -/** - * @file init.cpp - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - - -void CVPCB_MAINFRAME::SetNewPkg( const wxString& package ) -{ - COMPONENT_INFO* Component; - bool isUndefined = false; - int NumCmp; - wxString msg; - - if( m_components.empty() ) - return; - - NumCmp = m_ListCmp->GetSelection(); - - if( NumCmp < 0 ) - { - NumCmp = 0; - m_ListCmp->SetSelection( NumCmp, true ); - } - - Component = &m_components[ NumCmp ]; - - if( Component == NULL ) - return; - - isUndefined = Component->m_Footprint.IsEmpty(); - - Component->m_Footprint = package; - - msg.Printf( CMP_FORMAT, NumCmp + 1, - GetChars( Component->m_Reference ), - GetChars( Component->m_Value ), - GetChars( Component->m_Footprint ) ); - m_modified = true; - - if( isUndefined ) - m_undefinedComponentCnt -= 1; - - m_ListCmp->SetString( NumCmp, msg ); - m_ListCmp->SetSelection( NumCmp, false ); - - // We activate next component: - if( NumCmp < (m_ListCmp->GetCount() - 1) ) - NumCmp++; - - m_ListCmp->SetSelection( NumCmp, true ); - - DisplayStatus(); -} - - -bool CVPCB_MAINFRAME::ReadNetList() -{ - wxString msg; - int error_level; - - error_level = ReadSchematicNetlist(); - - if( error_level < 0 ) - { - msg.Printf( _( "File <%s> does not appear to be a valid KiCad net list file." ), - GetChars( m_NetlistFileName.GetFullPath() ) ); - ::wxMessageBox( msg, _( "File Error" ), wxOK | wxICON_ERROR, this ); - m_NetlistFileName.Clear(); - UpdateTitle(); - return false; - } - - LoadComponentFile( m_NetlistFileName.GetFullPath() ); - - if( m_ListCmp == NULL ) - return false; - - LoadProjectFile( m_NetlistFileName.GetFullPath() ); - LoadFootprintFiles(); - BuildFOOTPRINTS_LISTBOX(); - - m_ListCmp->Clear(); - m_undefinedComponentCnt = 0; - - BOOST_FOREACH( COMPONENT_INFO& component, m_components ) - { - msg.Printf( CMP_FORMAT, m_ListCmp->GetCount() + 1, - GetChars( component.m_Reference ), - GetChars( component.m_Value ), - GetChars( component.m_Footprint ) ); - m_ListCmp->AppendLine( msg ); - - if( component.m_Footprint.IsEmpty() ) - m_undefinedComponentCnt += 1; - } - - if( !m_components.empty() ) - m_ListCmp->SetSelection( 0, true ); - - DisplayStatus(); - - UpdateTitle(); - - UpdateFileHistory( m_NetlistFileName.GetFullPath() ); - - return true; -} - - -int CVPCB_MAINFRAME::SaveNetList( const wxString& aFullFileName ) -{ - wxFileName fn; - - if( !aFullFileName.IsEmpty() && m_NetlistFileName.IsOk() ) - { - fn = m_NetlistFileName; - } - else - { - wxFileDialog dlg( this, _( "Save Net and Component List" ), wxGetCwd(), - wxEmptyString, NetlistFileWildcard, wxFD_SAVE ); - - if( dlg.ShowModal() == wxID_CANCEL ) - return -1; - - fn = dlg.GetPath(); - - if( !fn.HasExt() ) - fn.SetExt( NetlistFileExtension ); - - m_NetlistFileName = fn; - } - - if( !IsWritable( fn.GetFullPath() ) ) - return 0; - - if( SaveComponentList( fn.GetFullPath() ) == 0 ) - { - DisplayError( this, _( "Unable to create component file (.cmp)" ) ); - return 0; - } -#if 0 - FILE* netlist = wxFopen( fn.GetFullPath(), wxT( "wt" ) ); - - if( netlist == 0 ) - { - DisplayError( this, _( "Unable to create net list file" ) ); - return 0; - } - - GenNetlistPcbnew( netlist, m_isEESchemaNetlist ); -#endif - return 1; -} diff --git a/cvpcb/read_write_cmpfile.cpp b/cvpcb/read_write_cmpfile.cpp new file mode 100644 index 0000000000..c527b09f51 --- /dev/null +++ b/cvpcb/read_write_cmpfile.cpp @@ -0,0 +1,180 @@ +/** + * @file cvpcb/read_write_cmpfile.cpp + */ + +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras + * Copyright (C) 2011 Wayne Stambaugh + * Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include +#include +#include + +#include +#include + +#include + + +/* File header. */ +static char HeaderLinkFile[] = { "Cmp-Mod V01" }; + +/* Write the link file: + * 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 + */ + +bool CVPCB_MAINFRAME::WriteComponentLinkFile( const wxString& aFullFileName ) +{ + FILE* outputFile; + wxFileName fn( aFullFileName ); + wxString Title = wxGetApp().GetTitle() + wxT( " " ) + GetBuildVersion(); + + outputFile = wxFopen( fn.GetFullPath(), wxT( "wt" ) ); + + if( outputFile == NULL ) + return false; + + int retval = 0; + + retval |= fprintf( outputFile, "%s", HeaderLinkFile ); + retval |= fprintf( outputFile, " Created by %s", TO_UTF8( Title ) ); + retval |= fprintf( outputFile, " date = %s\n", TO_UTF8( DateAndTime() ) ); + + BOOST_FOREACH( COMPONENT_INFO& component, m_components ) + { + retval |= fprintf( outputFile, "\nBeginCmp\n" ); + retval |= fprintf( outputFile, "TimeStamp = %s;\n", TO_UTF8( component.m_TimeStamp ) ); + retval |= fprintf( outputFile, "Reference = %s;\n", TO_UTF8( component.m_Reference ) ); + retval |= fprintf( outputFile, "ValeurCmp = %s;\n", TO_UTF8( component.m_Value ) ); + retval |= fprintf( outputFile, "IdModule = %s;\n", TO_UTF8( component.m_Footprint ) ); + retval |= fprintf( outputFile, "EndCmp\n" ); + } + + retval |= fprintf( outputFile, "\nEndListe\n" ); + fclose( outputFile ); + return retval >= 0; +} + +bool CVPCB_MAINFRAME::ReadComponentLinkFile( FILE * aFile ) +{ + wxString timestamp, valeur, ilib, namecmp, msg; + bool read_cmp_data = false, eof = false; + char Line[1024], * ident, * data; + + // Identification of the type of link file + if( fgets( Line, sizeof(Line), aFile ) == 0 || + strnicmp( Line, HeaderLinkFile, 11 ) != 0 ) + { + fclose( aFile ); + return false; + } + + while( !eof && fgets( Line, sizeof(Line), aFile ) != 0 ) + { + if( strnicmp( Line, "EndListe", 8 ) == 0 ) + break; + + /* Search the beginning of the component description. */ + if( strnicmp( Line, "BeginCmp", 8 ) != 0 ) + continue; + + timestamp.Empty(); + valeur.Empty(); + ilib.Empty(); + namecmp.Empty(); + read_cmp_data = true; + + while( !eof && read_cmp_data ) + { + if( fgets( Line, 1024, aFile ) == 0 ) + { + eof = true; + break; + } + + if( strnicmp( Line, "EndCmp", 6 ) == 0 ) + { + read_cmp_data = true; + break; + } + + ident = strtok( Line, "=;\n\r" ); + data = strtok( NULL, ";\n\r" ); + + if( strnicmp( ident, "TimeStamp", 9 ) == 0 ) + { + timestamp = FROM_UTF8( data ); + timestamp.Trim( true ); + timestamp.Trim( false ); + continue; + } + + if( strnicmp( ident, "Reference", 9 ) == 0 ) + { + namecmp = FROM_UTF8( data ); + namecmp.Trim( true ); + namecmp.Trim( false ); + continue; + } + + if( strnicmp( ident, "ValeurCmp", 9 ) == 0 ) + { + valeur = FROM_UTF8( data ); + valeur.Trim( true ); + valeur.Trim( false ); + continue; + } + + if( strnicmp( ident, "IdModule", 8 ) == 0 ) + { + ilib = FROM_UTF8( data ); + ilib.Trim( true ); + ilib.Trim( false ); + continue; + } + } // End reading one component link block. + + // Search corresponding component info in list and update its parameters. + BOOST_FOREACH( COMPONENT_INFO& component, m_components ) + { + if( namecmp != component.m_Reference ) + continue; + + /* Copy the name of the corresponding module. */ + component.m_Footprint = ilib; + } + } + + fclose( aFile ); + return true; +} + diff --git a/cvpcb/readwrite_dlgs.cpp b/cvpcb/readwrite_dlgs.cpp new file mode 100644 index 0000000000..e618efae97 --- /dev/null +++ b/cvpcb/readwrite_dlgs.cpp @@ -0,0 +1,257 @@ +/** + * @file cvpcb/readwrite_dlgs.cpp + */ + +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras + * Copyright (C) 2011 Wayne Stambaugh + * Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include +#include +#include +#include + +#include +#include +#include + +#define titleComponentLibErr _( "Component Library Error" ) + + +void CVPCB_MAINFRAME::SetNewPkg( const wxString& aFootprintName ) +{ + COMPONENT_INFO* Component; + bool isUndefined = false; + int NumCmp; + wxString msg; + + if( m_components.empty() ) + return; + + NumCmp = m_ListCmp->GetSelection(); + + if( NumCmp < 0 ) + { + NumCmp = 0; + m_ListCmp->SetSelection( NumCmp, true ); + } + + Component = &m_components[ NumCmp ]; + + if( Component == NULL ) + return; + + isUndefined = Component->m_Footprint.IsEmpty(); + + Component->m_Footprint = aFootprintName; + + msg.Printf( CMP_FORMAT, NumCmp + 1, + GetChars( Component->m_Reference ), + GetChars( Component->m_Value ), + GetChars( Component->m_Footprint ) ); + m_modified = true; + + if( isUndefined ) + m_undefinedComponentCnt -= 1; + + m_ListCmp->SetString( NumCmp, msg ); + m_ListCmp->SetSelection( NumCmp, false ); + + // We activate next component: + if( NumCmp < (m_ListCmp->GetCount() - 1) ) + NumCmp++; + + m_ListCmp->SetSelection( NumCmp, true ); + + DisplayStatus(); +} + + +bool CVPCB_MAINFRAME::ReadNetListAndLinkFiles() +{ + wxString msg; + int error_level; + + error_level = ReadSchematicNetlist(); + + if( error_level < 0 ) + { + msg.Printf( _( "File <%s> does not appear to be a valid KiCad net list file." ), + GetChars( m_NetlistFileName.GetFullPath() ) ); + wxMessageBox( msg, _( "File Error" ), wxOK | wxICON_ERROR, this ); + m_NetlistFileName.Clear(); + UpdateTitle(); + return false; + } + + LoadComponentLinkFile( m_NetlistFileName.GetFullPath() ); + + if( m_ListCmp == NULL ) + return false; + + LoadProjectFile( m_NetlistFileName.GetFullPath() ); + LoadFootprintFiles(); + BuildFOOTPRINTS_LISTBOX(); + + m_ListCmp->Clear(); + m_undefinedComponentCnt = 0; + + BOOST_FOREACH( COMPONENT_INFO& component, m_components ) + { + msg.Printf( CMP_FORMAT, m_ListCmp->GetCount() + 1, + GetChars( component.m_Reference ), + GetChars( component.m_Value ), + GetChars( component.m_Footprint ) ); + m_ListCmp->AppendLine( msg ); + + if( component.m_Footprint.IsEmpty() ) + m_undefinedComponentCnt += 1; + } + + if( !m_components.empty() ) + m_ListCmp->SetSelection( 0, true ); + + DisplayStatus(); + + UpdateTitle(); + + UpdateFileHistory( m_NetlistFileName.GetFullPath() ); + + return true; +} + + +bool CVPCB_MAINFRAME::LoadComponentLinkFile( const wxString& aFileName ) +{ + FILE* linkfile; + wxFileName fn = aFileName; + + fn.SetExt( ComponentFileExtension ); + + linkfile = wxFopen( fn.GetFullPath(), wxT( "rt" ) ); + if( linkfile == NULL ) + { + wxString msg; + msg.Printf( _( "Cannot open CvPcb component file <%s>." ), + GetChars( fn.GetFullPath() ) ); + msg << wxT( "\n" ) << _( "This is normal if you are opening a new netlist file" ); + wxMessageBox( msg, titleComponentLibErr, wxOK | wxICON_ERROR ); + return false; + } + + // read and close the file + if( ! ReadComponentLinkFile( linkfile ) ) + { + wxString msg; + msg.Printf( _( " <%s> does not appear to be a valid KiCad component link file." ), + GetChars( fn.GetFullPath() ) ); + wxMessageBox( msg, titleComponentLibErr, wxOK | wxICON_ERROR ); + return false; + } + + return true; +} + +int CVPCB_MAINFRAME::SaveCmpLinkFile( const wxString& aFullFileName ) +{ + wxFileName fn; + + if( !aFullFileName.IsEmpty() ) + { + fn = m_NetlistFileName; + fn.SetExt( ComponentFileExtension ); + } + else + { + wxFileDialog dlg( this, _( "Save Component/Footprint Link File" ), wxGetCwd(), + wxEmptyString, ComponentFileWildcard, wxFD_SAVE ); + + if( dlg.ShowModal() == wxID_CANCEL ) + return -1; + + fn = dlg.GetPath(); + + if( !fn.HasExt() ) + fn.SetExt( ComponentFileExtension ); + } + + if( !IsWritable( fn.GetFullPath() ) ) + return 0; + + if( WriteComponentLinkFile( fn.GetFullPath() ) == 0 ) + { + DisplayError( this, _( "Unable to create component file (.cmp)" ) ); + return 0; + } + + wxString msg; + msg.Printf( _("File %s saved"), fn.GetFullPath() ); + SetStatusText( msg ); + return 1; +} + +/* Creates a file for Eeschema, import footprint selections in schematic + * the file format is + * comp = "" module = " + */ + +void CVPCB_MAINFRAME::WriteStuffList( wxCommandEvent& event ) +{ + FILE* FileEquiv; + wxString Line; + wxFileName fn = m_NetlistFileName; + + if( m_components.empty() ) + return; + + fn.SetExt( RetroFileExtension ); + + wxFileDialog dlg( this, wxT( "Save Stuff File" ), fn.GetPath(), + fn.GetFullName(), RetroFileWildcard, + wxFD_SAVE | wxFD_OVERWRITE_PROMPT ); + + if( dlg.ShowModal() == wxID_CANCEL ) + return; + + FileEquiv = wxFopen( dlg.GetPath(), wxT( "wt" ) ); + + if( FileEquiv == 0 ) + { + Line = _( "Unable to create " ) + dlg.GetPath(); + DisplayError( this, Line, 30 ); + return; + } + + BOOST_FOREACH( COMPONENT_INFO& component, m_components ) + { + if( component.m_Footprint.empty() ) + continue; + + fprintf( FileEquiv, "comp = %s module = %s\n", + EscapedUTF8( component.m_Reference ).c_str(), + EscapedUTF8( component.m_Footprint ).c_str() ); + } + + fclose( FileEquiv ); +} diff --git a/cvpcb/savecmp.cpp b/cvpcb/savecmp.cpp deleted file mode 100644 index c22ef3e158..0000000000 --- a/cvpcb/savecmp.cpp +++ /dev/null @@ -1,174 +0,0 @@ -/****************/ -/* savecmp.cpp */ -/****************/ - -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include - - -/* File header. */ -char EnteteCmpMod[] = { "Cmp-Mod V01" }; - -#define titleComponentLibErr _( "Component Library Error" ) - - -int CVPCB_MAINFRAME::SaveComponentList( const wxString& aFullFileName ) -{ - FILE* dest; - wxFileName fn( aFullFileName ); - wxString Title = wxGetApp().GetTitle() + wxT( " " ) + GetBuildVersion(); - - fn.SetExt( ComponentFileExtension ); - - dest = wxFopen( fn.GetFullPath(), wxT( "wt" ) ); - - if( dest == NULL ) - return 0; - - fprintf( dest, "%s", EnteteCmpMod ); - fprintf( dest, " Created by %s", TO_UTF8( Title ) ); - fprintf( dest, " date = %s\n", TO_UTF8( DateAndTime() ) ); - - BOOST_FOREACH( COMPONENT_INFO& component, m_components ) - { - fprintf( dest, "\nBeginCmp\n" ); - fprintf( dest, "TimeStamp = %s;\n", TO_UTF8( component.m_TimeStamp ) ); - fprintf( dest, "Reference = %s;\n", TO_UTF8( component.m_Reference ) ); - fprintf( dest, "ValeurCmp = %s;\n", TO_UTF8( component.m_Value ) ); - fprintf( dest, "IdModule = %s;\n", TO_UTF8( component.m_Footprint ) ); - fprintf( dest, "EndCmp\n" ); - } - - fprintf( dest, "\nEndListe\n" ); - fclose( dest ); - return 1; -} - - -bool CVPCB_MAINFRAME::LoadComponentFile( const wxString& aFileName ) -{ - wxString timestamp, valeur, ilib, namecmp, msg; - bool read_cmp_data = false, eof = false; - char Line[1024], * ident, * data; - FILE* source; - wxFileName fn = aFileName; - - fn.SetExt( ComponentFileExtension ); - - source = wxFopen( fn.GetFullPath(), wxT( "rt" ) ); - if( source == NULL ) - { - msg.Printf( _( "Cannot open CvPcb component file <%s>." ), - GetChars( fn.GetFullPath() ) ); - msg << wxT( "\n" ) << _( "This is normal if you are opening a new netlist file" ); - wxMessageBox( msg, titleComponentLibErr, wxOK | wxICON_ERROR ); - return false; - } - - /* Identification of the type of file CmpMod */ - if( fgets( Line, 79, source ) == 0 ) - { - msg.Printf( _( " <%s> does not appear to be a valid KiCad component library." ), - GetChars( fn.GetFullPath() ) ); - wxMessageBox( msg, titleComponentLibErr, wxOK | wxICON_ERROR ); - fclose( source ); - return false; - } - - if( strnicmp( Line, EnteteCmpMod, 11 ) != 0 ) /* old file version*/ - { - msg.Printf( _( "<%s> is an old version component file." ) ); - wxMessageBox( msg, titleComponentLibErr, wxOK | wxICON_ERROR ); - fclose( source ); - return false; - } - - while( !eof && fgets( Line, 79, source ) != 0 ) - { - if( strnicmp( Line, "EndListe", 8 ) == 0 ) - break; - - /* Search the beginning of the component description. */ - if( strnicmp( Line, "BeginCmp", 8 ) != 0 ) - continue; - - timestamp.Empty(); - valeur.Empty(); - ilib.Empty(); - namecmp.Empty(); - read_cmp_data = true; - - while( !eof && read_cmp_data ) - { - if( fgets( Line, 1024, source ) == 0 ) - { - eof = true; - break; - } - - if( strnicmp( Line, "EndCmp", 6 ) == 0 ) - { - read_cmp_data = true; - break; - } - - ident = strtok( Line, "=;\n\r" ); - data = strtok( NULL, ";\n\r" ); - - if( strnicmp( ident, "TimeStamp", 9 ) == 0 ) - { - timestamp = FROM_UTF8( data ); - timestamp.Trim( true ); - timestamp.Trim( false ); - continue; - } - - if( strnicmp( ident, "Reference", 9 ) == 0 ) - { - namecmp = FROM_UTF8( data ); - namecmp.Trim( true ); - namecmp.Trim( false ); - continue; - } - - if( strnicmp( ident, "ValeurCmp", 9 ) == 0 ) - { - valeur = FROM_UTF8( data ); - valeur.Trim( true ); - valeur.Trim( false ); - continue; - } - - if( strnicmp( ident, "IdModule", 8 ) == 0 ) - { - ilib = FROM_UTF8( data ); - ilib.Trim( true ); - ilib.Trim( false ); - continue; - } - } /* End reading component description. */ - - /* Search corresponding component and NetList Update its parameters. */ - BOOST_FOREACH( COMPONENT_INFO& component, m_components ) - { - if( namecmp != component.m_Reference ) - continue; - - /* Copy the name of the corresponding module. */ - component.m_Footprint = ilib; - } - } - - fclose( source ); - return true; -} diff --git a/cvpcb/writenetlistpcbnew.cpp b/cvpcb/writenetlistpcbnew.cpp deleted file mode 100644 index 0155794989..0000000000 --- a/cvpcb/writenetlistpcbnew.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/***************************/ -/* writenetlistpcbnew.cpp */ -/***************************/ - - -#include -#include -#include -#include -#include -#include - -#include -#include - -static void WriteFootprintFilterInfos( FILE* dest, COMPONENT_LIST& list ); - -/** - * Create KiCad net list file. - * - * @todo: None of the printf() call return values are checked for failure, - * a value less than zero. Check all printf() return values and - * return a true(pass) or false(fail) to the caller. - */ -int CVPCB_MAINFRAME::GenNetlistPcbnew( FILE* file,bool isEESchemaNetlist ) -{ -#define NETLIST_HEAD_STRING "EESchema Netlist Version 1.1" - - if( isEESchemaNetlist ) - fprintf( file, "# %s created %s\n(\n", NETLIST_HEAD_STRING, TO_UTF8( DateAndTime() ) ); - else - fprintf( file, "( { netlist created %s }\n", TO_UTF8( DateAndTime() ) ); - - - BOOST_FOREACH( COMPONENT_INFO& component, m_components ) - { - fprintf( file, " ( %s ", TO_UTF8( component.m_TimeStamp ) ); - - if( !component.m_Footprint.IsEmpty() ) - fprintf( file, "%s", TO_UTF8( component.m_Footprint ) ); - else - fprintf( file, "$noname$" ); - - fprintf( file, " %s ", TO_UTF8( component.m_Reference ) ); - - fprintf( file, "%s\n", TO_UTF8( component.m_Value ) ); - - component.m_Pins.sort(); - - BOOST_FOREACH( PIN& pin, component.m_Pins ) - { - if( !pin.m_Net.IsEmpty() ) - fprintf( file, " ( %s %s )\n", TO_UTF8( pin.m_Number ), TO_UTF8( pin.m_Net ) ); - else - fprintf( file, " ( %s ? )\n", TO_UTF8( pin.m_Number ) ); - } - - fprintf( file, " )\n" ); - } - - fprintf( file, ")\n*\n" ); - - if( isEESchemaNetlist ) - WriteFootprintFilterInfos( file, m_components ); - - fclose( file ); - return 0; -} - -/* - * Write the allowed footprint list for each component - */ -void WriteFootprintFilterInfos( FILE* file, COMPONENT_LIST& list ) -{ - bool WriteHeader = false; - - BOOST_FOREACH( COMPONENT_INFO& component, list ) - { - unsigned int FilterCount; - FilterCount = component.m_FootprintFilter.GetCount(); - if( FilterCount == 0 ) - continue; - if( !WriteHeader ) - { - fprintf( file, "{ Allowed footprints by component:\n" ); - WriteHeader = true; - } - fprintf( file, "$component %s\n", - TO_UTF8( component.m_Reference ) ); - /* Write the footprint list */ - for( unsigned int jj = 0; jj < FilterCount; jj++ ) - { - fprintf( file, " %s\n", - TO_UTF8( component.m_FootprintFilter[jj] ) ); - } - - fprintf( file, "$endlist\n" ); - } - - if( WriteHeader ) - fprintf( file, "$endfootprintlist\n}\n" ); -} diff --git a/pcbnew/editmod.cpp b/pcbnew/editmod.cpp index a2fb529fd3..8cbe6a9c07 100644 --- a/pcbnew/editmod.cpp +++ b/pcbnew/editmod.cpp @@ -57,13 +57,13 @@ void PCB_EDIT_FRAME::InstallModuleOptionsFrame( MODULE* Module, wxDC* DC ) /* - * Position anchor under the cursor. + * Move the footprint anchor position to the current cursor position. */ void FOOTPRINT_EDIT_FRAME::Place_Ancre( MODULE* pt_mod ) { wxPoint moveVector; - EDA_ITEM* PtStruct; - D_PAD* pt_pad; + EDA_ITEM* item; + D_PAD* pad; if( pt_mod == NULL ) return; @@ -78,30 +78,30 @@ void FOOTPRINT_EDIT_FRAME::Place_Ancre( MODULE* pt_mod ) RotatePoint( &moveVector, -pt_mod->m_Orient ); /* Update the pad coordinates. */ - pt_pad = (D_PAD*) pt_mod->m_Pads; + pad = (D_PAD*) pt_mod->m_Pads; - for( ; pt_pad != NULL; pt_pad = pt_pad->Next() ) + for( ; pad != NULL; pad = pad->Next() ) { - pt_pad->m_Pos0 += moveVector; + pad->m_Pos0 += moveVector; } /* Update the draw element coordinates. */ - PtStruct = pt_mod->m_Drawings; + item = pt_mod->m_Drawings; - for( ; PtStruct != NULL; PtStruct = PtStruct->Next() ) + for( ; item != NULL; item = item->Next() ) { - switch( PtStruct->Type() ) + switch( item->Type() ) { case PCB_MODULE_EDGE_T: - #undef STRUCT - #define STRUCT ( (EDGE_MODULE*) PtStruct ) + #undef STRUCT + #define STRUCT ( (EDGE_MODULE*) item ) STRUCT->m_Start0 += moveVector; STRUCT->m_End0 += moveVector; break; case PCB_MODULE_TEXT_T: - #undef STRUCT - #define STRUCT ( (TEXTE_MODULE*) PtStruct ) + #undef STRUCT + #define STRUCT ( (TEXTE_MODULE*) item ) STRUCT->SetPos0( STRUCT->GetPos0() + moveVector ); break;