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, see <https://www.gnu.org/licenses/>.
18 */
19
20#include <confirm.h>
21#include <string_utils.h>
22#include <macros.h>
23#include <pcb_edit_frame.h>
24#include <board.h>
25#include <footprint.h>
26#include <project.h>
29#include <wx/filedlg.h>
30#include <kiplatform/ui.h>
31
32
33
34bool RecreateCmpFile( BOARD * aBrd, const wxString& aFullCmpFileName )
35{
36 FILE* cmpFile = wxFopen( aFullCmpFileName, wxT( "wt" ) );
37
38 if( cmpFile == nullptr )
39 return false;
40
41 fprintf( cmpFile, "Cmp-Mod V01 Created by PcbNew date = %s\n", TO_UTF8( GetISO8601CurrentDateTime() ) );
42
43 for( FOOTPRINT* fp : aBrd->Footprints() )
44 {
45 fprintf( cmpFile, "\nBeginCmp\n" );
46 fprintf( cmpFile, "TimeStamp = %s\n", TO_UTF8( fp->m_Uuid.AsString() ) );
47 fprintf( cmpFile, "Path = %s\n", TO_UTF8( fp->GetPath().AsString() ) );
48 fprintf( cmpFile, "Reference = %s;\n",
49 !fp->GetReference().IsEmpty() ? TO_UTF8( fp->GetReference() ) : "[NoRef]" );
50 fprintf( cmpFile, "ValeurCmp = %s;\n",
51 !fp->GetValue().IsEmpty() ? TO_UTF8( fp->GetValue() ) : "[NoVal]" );
52 fprintf( cmpFile, "IdModule = %s;\n", fp->GetFPID().Format().c_str() );
53 fprintf( cmpFile, "EndCmp\n" );
54 }
55
56 fprintf( cmpFile, "\nEndListe\n" );
57 fclose( cmpFile );
58
59 return true;
60}
61
62
64{
65 // Build the .cmp file name from the board name
66 BOARD* board = m_frame->GetBoard();
67 wxString projectDir = wxPathOnly( m_frame->Prj().GetProjectFullName() );
68 wxFileName fn = board->GetFileName();
69
71
72 wxFileDialog dlg( m_frame, _( "Save Footprint Association File" ), projectDir, fn.GetFullName(),
74 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
75
77
78 if( dlg.ShowModal() == wxID_CANCEL )
79 return 0;
80
81 wxString path = dlg.GetPath();
82
83 if( !RecreateCmpFile( board, path ) )
84 DisplayError( m_frame, wxString::Format( _( "Failed to create file '%s'." ), path ) );
85
86 return 0;
87}
88
int ExportCmpFile(const TOOL_EVENT &aEvent)
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:372
const FOOTPRINTS & Footprints() const
Definition board.h:420
BOARD * board() const
Generic, UI-independent tool event.
Definition tool_event.h:167
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
Definition confirm.cpp:192
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.
void AllowNetworkFileSystems(wxDialog *aDialog)
Configure a file dialog to show network and virtual file systems.
Definition wxgtk/ui.cpp:448
wxString GetISO8601CurrentDateTime()
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
std::string path
Definition of file extensions used in Kicad.