KiCad PCB EDA Suite
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 (C) 1992-2018 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 <kicad_string.h>
26 #include <pcb_edit_frame.h>
27 #include <board.h>
28 #include <footprint.h>
29 #include <project.h>
31 
32 
33 bool RecreateCmpFile( BOARD * aBrd, const wxString& aFullCmpFileName )
34 {
35  FILE* cmpFile = wxFopen( aFullCmpFileName, wxT( "wt" ) );
36 
37  if( cmpFile == NULL )
38  return false;
39 
40  fprintf( cmpFile, "Cmp-Mod V01 Created by PcbNew date = %s\n", TO_UTF8( DateAndTime() ) );
41 
42  for( FOOTPRINT* fp : aBrd->Footprints() )
43  {
44  fprintf( cmpFile, "\nBeginCmp\n" );
45  fprintf( cmpFile, "TimeStamp = %s\n", TO_UTF8( fp->m_Uuid.AsString() ) );
46  fprintf( cmpFile, "Path = %s\n", TO_UTF8( fp->GetPath().AsString() ) );
47  fprintf( cmpFile, "Reference = %s;\n",
48  !fp->GetReference().IsEmpty() ? TO_UTF8( fp->GetReference() ) : "[NoRef]" );
49  fprintf( cmpFile, "ValeurCmp = %s;\n",
50  !fp->GetValue().IsEmpty() ? TO_UTF8( fp->GetValue() ) : "[NoVal]" );
51  fprintf( cmpFile, "IdModule = %s;\n", fp->GetFPID().Format().c_str() );
52  fprintf( cmpFile, "EndCmp\n" );
53  }
54 
55  fprintf( cmpFile, "\nEndListe\n" );
56  fclose( cmpFile );
57 
58  return true;
59 }
60 
61 
62 void PCB_EDIT_FRAME::RecreateCmpFileFromBoard( wxCommandEvent& aEvent )
63 {
64  // Build the .cmp file name from the board name
65  wxString projectDir = wxPathOnly( Prj().GetProjectFullName() );
66  wxFileName fn = GetBoard()->GetFileName();
67 
68  fn.SetExt( ComponentFileExtension );
69 
70  wxFileDialog dlg( this, _( "Save Footprint Association File" ),
71  projectDir, fn.GetFullName(), ComponentFileWildcard(),
72  wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
73 
74  if( dlg.ShowModal() == wxID_CANCEL )
75  return;
76 
77  wxString path = dlg.GetPath();
78 
79  if( !RecreateCmpFile( GetBoard(), path ) )
80  DisplayError( this, wxString::Format( _( "Could not create file \"%s\"." ), path ) );
81 }
82 
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:240
bool RecreateCmpFile(BOARD *aBrd, const wxString &aFullCmpFileName)
void RecreateCmpFileFromBoard(wxCommandEvent &aEvent)
Function RecreateBOMFileFromBoard Recreates a .cmp file from the current loaded board this is the sam...
This file is part of the common library.
wxString ComponentFileWildcard()
const std::string ComponentFileExtension
const wxString & GetFileName() const
Definition: board.h:278
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:95
#define NULL
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
FOOTPRINTS & Footprints()
Definition: board.h:283
Definition of file extensions used in Kicad.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:186
#define _(s)
Definition: 3d_actions.cpp:33
BOARD * GetBoard() const
wxString DateAndTime()
Definition: string.cpp:400