2018-04-18 09:31:33 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1992-2018 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 <confirm.h>
|
|
|
|
#include <kicad_string.h>
|
2021-03-20 15:35:37 +00:00
|
|
|
#include <macros.h>
|
2018-04-18 09:31:33 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
|
|
|
#include <footprint.h>
|
2018-04-18 09:31:33 +00:00
|
|
|
#include <project.h>
|
|
|
|
#include <wildcards_and_files_ext.h>
|
|
|
|
|
|
|
|
|
|
|
|
bool RecreateCmpFile( BOARD * aBrd, const wxString& aFullCmpFileName )
|
|
|
|
{
|
|
|
|
FILE* cmpFile = wxFopen( aFullCmpFileName, wxT( "wt" ) );
|
|
|
|
|
|
|
|
if( cmpFile == NULL )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
fprintf( cmpFile, "Cmp-Mod V01 Created by PcbNew date = %s\n", TO_UTF8( DateAndTime() ) );
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* fp : aBrd->Footprints() )
|
2018-04-18 09:31:33 +00:00
|
|
|
{
|
|
|
|
fprintf( cmpFile, "\nBeginCmp\n" );
|
2020-11-12 23:50:33 +00:00
|
|
|
fprintf( cmpFile, "TimeStamp = %s\n", TO_UTF8( fp->m_Uuid.AsString() ) );
|
|
|
|
fprintf( cmpFile, "Path = %s\n", TO_UTF8( fp->GetPath().AsString() ) );
|
2018-04-18 09:31:33 +00:00
|
|
|
fprintf( cmpFile, "Reference = %s;\n",
|
2020-11-12 23:50:33 +00:00
|
|
|
!fp->GetReference().IsEmpty() ? TO_UTF8( fp->GetReference() ) : "[NoRef]" );
|
2018-04-18 09:31:33 +00:00
|
|
|
fprintf( cmpFile, "ValeurCmp = %s;\n",
|
2020-11-12 23:50:33 +00:00
|
|
|
!fp->GetValue().IsEmpty() ? TO_UTF8( fp->GetValue() ) : "[NoVal]" );
|
|
|
|
fprintf( cmpFile, "IdModule = %s;\n", fp->GetFPID().Format().c_str() );
|
2018-04-18 09:31:33 +00:00
|
|
|
fprintf( cmpFile, "EndCmp\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf( cmpFile, "\nEndListe\n" );
|
|
|
|
fclose( cmpFile );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PCB_EDIT_FRAME::RecreateCmpFileFromBoard( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
// Build the .cmp file name from the board name
|
|
|
|
wxString projectDir = wxPathOnly( Prj().GetProjectFullName() );
|
|
|
|
wxFileName fn = GetBoard()->GetFileName();
|
|
|
|
|
|
|
|
fn.SetExt( ComponentFileExtension );
|
|
|
|
|
|
|
|
wxFileDialog dlg( this, _( "Save Footprint Association File" ),
|
|
|
|
projectDir, fn.GetFullName(), ComponentFileWildcard(),
|
|
|
|
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
wxString path = dlg.GetPath();
|
|
|
|
|
|
|
|
if( !RecreateCmpFile( GetBoard(), path ) )
|
|
|
|
DisplayError( this, wxString::Format( _( "Could not create file \"%s\"." ), path ) );
|
|
|
|
}
|
|
|
|
|