KiCad PCB EDA Suite
pcbnew/files.cpp File Reference
#include <fctsys.h>
#include <confirm.h>
#include <kicad_string.h>
#include <gestfich.h>
#include <pcb_edit_frame.h>
#include <macros.h>
#include <3d_viewer/eda_3d_viewer.h>
#include <richio.h>
#include <pgm_base.h>
#include <msgpanel.h>
#include <fp_lib_table.h>
#include <kiface_i.h>
#include <kiway.h>
#include <kiway_player.h>
#include <trace_helpers.h>
#include <lockfile.cpp>
#include <netlist_reader/pcb_netlist.h>
#include <pcbnew.h>
#include <pcbnew_id.h>
#include <io_mgr.h>
#include <wildcards_and_files_ext.h>
#include <tool/tool_manager.h>
#include <drc/drc.h>
#include <class_board.h>
#include <wx/stdpaths.h>
#include <pcb_layer_widget.h>
#include <ratsnest/ratsnest_data.h>
#include <kiplatform/app.h>
#include <wx/wupdlock.h>
#include <settings/common_settings.h>
#include <settings/settings_manager.h>
#include <project/project_file.h>
#include <project/project_local_settings.h>

Go to the source code of this file.

Macros

#define USE_INSTRUMENTATION   0
 

Functions

bool AskLoadBoardFileName (wxWindow *aParent, int *aCtl, wxString *aFileName, bool aKicadFilesOnly)
 Function AskLoadBoardFileName puts up a wxFileDialog asking for a BOARD filename to open. More...
 
bool AskSaveBoardFileName (wxWindow *aParent, wxString *aFileName)
 Function AskSaveBoardFileName puts up a wxFileDialog asking for a BOARD filename to save. More...
 
IO_MGR::PCB_FILE_T plugin_type (const wxString &aFileName, int aCtl)
 

Macro Definition Documentation

◆ USE_INSTRUMENTATION

#define USE_INSTRUMENTATION   0

Definition at line 63 of file pcbnew/files.cpp.

Function Documentation

◆ AskLoadBoardFileName()

bool AskLoadBoardFileName ( wxWindow *  aParent,
int *  aCtl,
wxString *  aFileName,
bool  aKicadFilesOnly 
)

Function AskLoadBoardFileName puts up a wxFileDialog asking for a BOARD filename to open.

Parameters
aParentis a wxFrame passed to wxFileDialog.
aCtlis where to put the OpenProjectFiles() control bits.
aFileNameon entry is a probable choice, on return is the chosen filename.
aKicadFilesOnlytrue to list kiacad pcb files plugins only, false to list import plugins.
Returns
bool - true if chosen, else false if user aborted.

Definition at line 78 of file pcbnew/files.cpp.

79 {
80  // This is a subset of all PLUGINs which are trusted to be able to
81  // load a BOARD. User may occasionally use the wrong plugin to load a
82  // *.brd file (since both legacy and eagle use *.brd extension),
83  // but eventually *.kicad_pcb will be more common than legacy *.brd files.
84 
85  // clang-format off
86  static const struct
87  {
88  const wxString& filter;
89  IO_MGR::PCB_FILE_T pluginType;
90  } loaders[] =
91  {
92  { PcbFileWildcard(), IO_MGR::KICAD_SEXP }, // Current Kicad board files
93  { LegacyPcbFileWildcard(), IO_MGR::LEGACY }, // Old Kicad board files
94  { EaglePcbFileWildcard(), IO_MGR::EAGLE }, // Import Eagle board files
95  { PCadPcbFileWildcard(), IO_MGR::PCAD }, // Import PCAD board files
96  { AltiumDesignerPcbFileWildcard(), IO_MGR::ALTIUM_DESIGNER }, // Import Altium Designer board files
97  { AltiumCircuitStudioPcbFileWildcard(), IO_MGR::ALTIUM_CIRCUIT_STUDIO }, // Import Altium Circuit Studio board files
98  { AltiumCircuitMakerPcbFileWildcard(), IO_MGR::ALTIUM_CIRCUIT_MAKER }, // Import Altium Circuit Maker board files
99  };
100  // clang-format on
101 
102  wxFileName fileName( *aFileName );
103  wxString fileFilters;
104 
105  if( aKicadFilesOnly )
106  {
107  for( unsigned ii = 0; ii < 2; ++ii )
108  {
109  if( !fileFilters.IsEmpty() )
110  fileFilters += wxChar( '|' );
111 
112  fileFilters += wxGetTranslation( loaders[ii].filter );
113  }
114  }
115  else
116  {
117  for( unsigned ii = 2; ii < arrayDim( loaders ); ++ii )
118  {
119  if( !fileFilters.IsEmpty() )
120  fileFilters += wxChar( '|' );
121 
122  fileFilters += wxGetTranslation( loaders[ii].filter );
123  }
124  }
125 
126  wxString path;
127  wxString name;
128 
129  if( fileName.FileExists() )
130  {
131  path = fileName.GetPath();
132  name = fileName.GetFullName();
133  }
134  else
135  {
136  path = wxStandardPaths::Get().GetDocumentsDir();
137  // leave name empty
138  }
139 
140  wxFileDialog dlg( aParent,
141  aKicadFilesOnly ? _( "Open Board File" ) : _( "Import Non KiCad Board File" ),
142  path, name, fileFilters,
143  wxFD_OPEN | wxFD_FILE_MUST_EXIST );
144 
145  if( dlg.ShowModal() == wxID_OK )
146  {
147  // For import option, if Eagle (*.brd files), tell OpenProjectFiles() to use Eagle plugin.
148  // It's the only special case because of the duplicate use of the *.brd file extension.
149  // Other cases are clear because of unique file extensions.
150  *aCtl = aKicadFilesOnly ? 0 : KICTL_EAGLE_BRD;
151  *aFileName = dlg.GetPath();
152  return true;
153  }
154  else
155  return false;
156 }
wxString EaglePcbFileWildcard()
#define KICTL_EAGLE_BRD
chosen *.brd file is Eagle according to user.
Definition: kiway_player.h:78
wxString AltiumCircuitMakerPcbFileWildcard()
wxString LegacyPcbFileWildcard()
wxString AltiumDesignerPcbFileWildcard()
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Definition: macros.h:160
wxString AltiumCircuitStudioPcbFileWildcard()
Legacy Pcbnew file formats prior to s-expression.
Definition: io_mgr.h:56
const char * name
Definition: DXF_plotter.cpp:60
#define _(s)
Definition: 3d_actions.cpp:33
wxString PcbFileWildcard()
PCB_FILE_T
Enum PCB_FILE_T is a set of file types that the IO_MGR knows about, and for which there has been a pl...
Definition: io_mgr.h:54
wxString PCadPcbFileWildcard()
S-expression Pcbnew file format.
Definition: io_mgr.h:57

References _, IO_MGR::ALTIUM_CIRCUIT_MAKER, IO_MGR::ALTIUM_CIRCUIT_STUDIO, IO_MGR::ALTIUM_DESIGNER, AltiumCircuitMakerPcbFileWildcard(), AltiumCircuitStudioPcbFileWildcard(), AltiumDesignerPcbFileWildcard(), arrayDim(), IO_MGR::EAGLE, EaglePcbFileWildcard(), IO_MGR::KICAD_SEXP, KICTL_EAGLE_BRD, IO_MGR::LEGACY, LegacyPcbFileWildcard(), name, IO_MGR::PCAD, PCadPcbFileWildcard(), and PcbFileWildcard().

Referenced by PCBNEW_CONTROL::AppendBoardFromFile(), PCB_EDIT_FRAME::Files_io_from_id(), and PCB_EDIT_FRAME::OnFileHistory().

◆ AskSaveBoardFileName()

bool AskSaveBoardFileName ( wxWindow *  aParent,
wxString *  aFileName 
)

Function AskSaveBoardFileName puts up a wxFileDialog asking for a BOARD filename to save.

Parameters
aParentis a wxFrame passed to wxFileDialog.
aFileNameon entry is a probable choice, on return is the chosen full filename (includes path).
Returns
bool - true if chosen, else false if user aborted.

Definition at line 169 of file pcbnew/files.cpp.

170 {
171  wxString wildcard = PcbFileWildcard();
172  wxFileName fn = *aFileName;
173 
174  fn.SetExt( KiCadPcbFileExtension );
175 
176  wxFileDialog dlg( aParent,
177  _( "Save Board File As" ),
178  fn.GetPath(),
179  fn.GetFullName(),
180  wildcard,
181  wxFD_SAVE | wxFD_OVERWRITE_PROMPT
182  );
183 
184  if( dlg.ShowModal() != wxID_OK )
185  return false;
186 
187  fn = dlg.GetPath();
188 
189  // always enforce filename extension, user may not have entered it.
190  fn.SetExt( KiCadPcbFileExtension );
191 
192  *aFileName = fn.GetFullPath();
193 
194  return true;
195 }
const std::string KiCadPcbFileExtension
#define _(s)
Definition: 3d_actions.cpp:33
wxString PcbFileWildcard()

References _, KiCadPcbFileExtension, and PcbFileWildcard().

Referenced by PCB_EDIT_FRAME::Files_io_from_id().

◆ plugin_type()

IO_MGR::PCB_FILE_T plugin_type ( const wxString &  aFileName,
int  aCtl 
)

Definition at line 371 of file pcbnew/files.cpp.

372 {
373  IO_MGR::PCB_FILE_T pluginType;
374 
375  wxFileName fn = aFileName;
376 
377  // Note: file extensions are expected to be in lower case.
378  // This is not always true, especially when importing files, so the string
379  // comparisons are case insensitive to try to find the suitable plugin.
380 
381  if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::LEGACY ) ) == 0 )
382  {
383  // both legacy and eagle share a common file extension.
384  pluginType = ( aCtl & KICTL_EAGLE_BRD ) ? IO_MGR::EAGLE : IO_MGR::LEGACY;
385  }
386  else if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::PCAD ) ) == 0 )
387  {
388  pluginType = IO_MGR::PCAD;
389  }
390  else if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::ALTIUM_DESIGNER ) ) == 0 )
391  {
392  pluginType = IO_MGR::ALTIUM_DESIGNER;
393  }
394  else if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::ALTIUM_CIRCUIT_STUDIO ) ) == 0 )
395  {
396  pluginType = IO_MGR::ALTIUM_CIRCUIT_STUDIO;
397  }
398  else if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::ALTIUM_CIRCUIT_MAKER ) ) == 0 )
399  {
400  pluginType = IO_MGR::ALTIUM_CIRCUIT_MAKER;
401  }
402  else
403  {
404  pluginType = IO_MGR::KICAD_SEXP;
405  }
406 
407  return pluginType;
408 }
#define KICTL_EAGLE_BRD
chosen *.brd file is Eagle according to user.
Definition: kiway_player.h:78
Legacy Pcbnew file formats prior to s-expression.
Definition: io_mgr.h:56
PCB_FILE_T
Enum PCB_FILE_T is a set of file types that the IO_MGR knows about, and for which there has been a pl...
Definition: io_mgr.h:54
S-expression Pcbnew file format.
Definition: io_mgr.h:57
static const wxString GetFileExtension(PCB_FILE_T aFileType)
Function GetFileExtension returns the file extension for aFileType.
Definition: io_mgr.cpp:112

References IO_MGR::ALTIUM_CIRCUIT_MAKER, IO_MGR::ALTIUM_CIRCUIT_STUDIO, IO_MGR::ALTIUM_DESIGNER, IO_MGR::EAGLE, IO_MGR::GetFileExtension(), IO_MGR::KICAD_SEXP, KICTL_EAGLE_BRD, IO_MGR::LEGACY, and IO_MGR::PCAD.

Referenced by PCBNEW_CONTROL::AppendBoardFromFile(), and PCB_EDIT_FRAME::OpenProjectFiles().