KiCad PCB EDA Suite
Loading...
Searching...
No Matches
export_footprint_associations.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include <confirm.h>
25#include <string_utils.h>
26#include <macros.h>
27#include <pcb_edit_frame.h>
28#include <board.h>
29#include <footprint.h>
30#include <project.h>
33#include <wx/filedlg.h>
34
35
36
37bool RecreateCmpFile( BOARD * aBrd, const wxString& aFullCmpFileName )
38{
39 FILE* cmpFile = wxFopen( aFullCmpFileName, wxT( "wt" ) );
40
41 if( cmpFile == nullptr )
42 return false;
43
44 fprintf( cmpFile, "Cmp-Mod V01 Created by PcbNew date = %s\n", TO_UTF8( GetISO8601CurrentDateTime() ) );
45
46 for( FOOTPRINT* fp : aBrd->Footprints() )
47 {
48 fprintf( cmpFile, "\nBeginCmp\n" );
49 fprintf( cmpFile, "TimeStamp = %s\n", TO_UTF8( fp->m_Uuid.AsString() ) );
50 fprintf( cmpFile, "Path = %s\n", TO_UTF8( fp->GetPath().AsString() ) );
51 fprintf( cmpFile, "Reference = %s;\n",
52 !fp->GetReference().IsEmpty() ? TO_UTF8( fp->GetReference() ) : "[NoRef]" );
53 fprintf( cmpFile, "ValeurCmp = %s;\n",
54 !fp->GetValue().IsEmpty() ? TO_UTF8( fp->GetValue() ) : "[NoVal]" );
55 fprintf( cmpFile, "IdModule = %s;\n", fp->GetFPID().Format().c_str() );
56 fprintf( cmpFile, "EndCmp\n" );
57 }
58
59 fprintf( cmpFile, "\nEndListe\n" );
60 fclose( cmpFile );
61
62 return true;
63}
64
65
67{
68 // Build the .cmp file name from the board name
70 wxString projectDir = wxPathOnly( m_frame->Prj().GetProjectFullName() );
71 wxFileName fn = board->GetFileName();
72
74
75 wxFileDialog dlg( m_frame, _( "Save Footprint Association File" ), projectDir, fn.GetFullName(),
77 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
78
79 if( dlg.ShowModal() == wxID_CANCEL )
80 return 0;
81
82 wxString path = dlg.GetPath();
83
84 if( !RecreateCmpFile( board, path ) )
85 DisplayError( m_frame, wxString::Format( _( "Failed to create file '%s'." ), path ) );
86
87 return 0;
88}
89
int ExportCmpFile(const TOOL_EVENT &aEvent)
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:317
const FOOTPRINTS & Footprints() const
Definition: board.h:358
const wxString & GetFileName() const
Definition: board.h:354
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
BOARD * GetBoard() const
BOARD * board() const
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
Definition: project.cpp:142
Generic, UI-independent tool event.
Definition: tool_event.h:168
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:169
This file is part of the common library.
#define _(s)
bool RecreateCmpFile(BOARD *aBrd, const wxString &aFullCmpFileName)
static const std::string FootprintAssignmentFileExtension
static wxString FootprintAssignmentFileWildcard()
This file contains miscellaneous commonly used macros and functions.
wxString GetISO8601CurrentDateTime()
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: string_utils.h:429
Definition of file extensions used in Kicad.