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 <fctsys.h>
25 #include <confirm.h>
26 #include <kicad_string.h>
27 #include <pcb_edit_frame.h>
28 #include <class_board.h>
29 #include <class_module.h>
30 #include <project.h>
32 
33 
34 bool RecreateCmpFile( BOARD * aBrd, const wxString& aFullCmpFileName )
35 {
36  FILE* cmpFile = wxFopen( aFullCmpFileName, wxT( "wt" ) );
37 
38  if( cmpFile == NULL )
39  return false;
40 
41  fprintf( cmpFile, "Cmp-Mod V01 Created by PcbNew date = %s\n", TO_UTF8( DateAndTime() ) );
42 
43  for( MODULE* module = aBrd->m_Modules; module != NULL; module = module->Next() )
44  {
45  fprintf( cmpFile, "\nBeginCmp\n" );
46  fprintf( cmpFile, "TimeStamp = %8.8lX\n", (unsigned long)module->GetTimeStamp() );
47  fprintf( cmpFile, "Path = %s\n", TO_UTF8( module->GetPath() ) );
48  fprintf( cmpFile, "Reference = %s;\n",
49  !module->GetReference().IsEmpty() ? TO_UTF8( module->GetReference() ) : "[NoRef]" );
50  fprintf( cmpFile, "ValeurCmp = %s;\n",
51  !module->GetValue().IsEmpty() ? TO_UTF8( module->GetValue() ) : "[NoVal]" );
52  fprintf( cmpFile, "IdModule = %s;\n", module->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 
63 void PCB_EDIT_FRAME::RecreateCmpFileFromBoard( wxCommandEvent& aEvent )
64 {
65  // Build the .cmp file name from the board name
66  wxString projectDir = wxPathOnly( Prj().GetProjectFullName() );
67  wxFileName fn = GetBoard()->GetFileName();
68 
69  fn.SetExt( ComponentFileExtension );
70 
71  wxFileDialog dlg( this, _( "Save Footprint Association File" ),
72  projectDir, fn.GetFullName(), ComponentFileWildcard(),
73  wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
74 
75  if( dlg.ShowModal() == wxID_CANCEL )
76  return;
77 
78  wxString path = dlg.GetPath();
79 
80  if( !RecreateCmpFile( GetBoard(), path ) )
81  DisplayError( this, wxString::Format( _( "Could not create file \"%s\"." ), path ) );
82 }
83 
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()
Class BOARD to handle a board.
MODULE * Next() const
Definition: class_module.h:123
BOARD * GetBoard() const
const std::string ComponentFileExtension
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
const wxString & GetFileName() const
Definition: class_board.h:237
The common library.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:170
DLIST< MODULE > m_Modules
Definition: class_board.h:248
Module description (excepted pads)
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:245
wxString DateAndTime()
Function DateAndTime.
Definition: string.cpp:306