2018-04-18 09:31:33 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2021-07-19 23:56:05 +00:00
|
|
|
* Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2018-04-18 09:31:33 +00:00
|
|
|
*
|
|
|
|
* 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>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.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>
|
2021-05-01 07:50:29 +00:00
|
|
|
#include <wx/filedlg.h>
|
|
|
|
|
2018-04-18 09:31:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool RecreateCmpFile( BOARD * aBrd, const wxString& aFullCmpFileName )
|
|
|
|
{
|
|
|
|
FILE* cmpFile = wxFopen( aFullCmpFileName, wxT( "wt" ) );
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
if( cmpFile == nullptr )
|
2018-04-18 09:31:33 +00:00
|
|
|
return false;
|
|
|
|
|
2023-07-15 03:23:42 +00:00
|
|
|
fprintf( cmpFile, "Cmp-Mod V01 Created by PcbNew date = %s\n", TO_UTF8( GetISO8601CurrentDateTime() ) );
|
2018-04-18 09:31:33 +00:00
|
|
|
|
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();
|
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
fn.SetExt( FootprintAssignmentFileExtension );
|
2018-04-18 09:31:33 +00:00
|
|
|
|
|
|
|
wxFileDialog dlg( this, _( "Save Footprint Association File" ),
|
2021-06-14 18:00:08 +00:00
|
|
|
projectDir, fn.GetFullName(), FootprintAssignmentFileWildcard(),
|
2018-04-18 09:31:33 +00:00
|
|
|
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
wxString path = dlg.GetPath();
|
|
|
|
|
|
|
|
if( !RecreateCmpFile( GetBoard(), path ) )
|
2021-06-28 23:44:07 +00:00
|
|
|
DisplayError( this, wxString::Format( _( "Failed to create file '%s'." ), path ) );
|
2018-04-18 09:31:33 +00:00
|
|
|
}
|
|
|
|
|