KiCad PCB EDA Suite
pcbnew/files.cpp File Reference
#include <confirm.h>
#include <core/arraydim.h>
#include <gestfich.h>
#include <pcb_edit_frame.h>
#include <board_design_settings.h>
#include <3d_viewer/eda_3d_viewer_frame.h>
#include <widgets/msgpanel.h>
#include <fp_lib_table.h>
#include <kiface_base.h>
#include <macros.h>
#include <trace_helpers.h>
#include <lockfile.cpp>
#include <netlist_reader/pcb_netlist.h>
#include <pcbnew_id.h>
#include <io_mgr.h>
#include <wildcards_and_files_ext.h>
#include <tool/tool_manager.h>
#include <board.h>
#include <wx/checkbox.h>
#include <wx/stdpaths.h>
#include <ratsnest/ratsnest_data.h>
#include <kiplatform/app.h>
#include <widgets/appearance_controls.h>
#include <widgets/infobar.h>
#include <widgets/wx_progress_reporters.h>
#include <settings/settings_manager.h>
#include <paths.h>
#include <project/project_file.h>
#include <project/project_local_settings.h>
#include <project/net_settings.h>
#include <plugins/cadstar/cadstar_pcb_archive_plugin.h>
#include <plugins/kicad/kicad_plugin.h>
#include <dialogs/dialog_imported_layers.h>
#include <tools/pcb_actions.h>
#include "footprint_info_impl.h"
#include <wx_filename.h>
#include <wx/wupdlock.h>
#include <wx/filedlg.h>

Go to the source code of this file.

Classes

class  CREATE_PROJECT_CHECKBOX
 < Helper widget to select whether a new project should be created for a file when saving More...
 

Macros

#define USE_INSTRUMENTATION   0
 

Functions

bool AskLoadBoardFileName (PCB_EDIT_FRAME *aParent, int *aCtl, wxString *aFileName, bool aKicadFilesOnly)
 Show a wxFileDialog asking for a BOARD filename to open. More...
 
bool AskSaveBoardFileName (PCB_EDIT_FRAME *aParent, wxString *aFileName, bool *aCreateProject)
 Put 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 69 of file pcbnew/files.cpp.

Function Documentation

◆ AskLoadBoardFileName()

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

Show 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 KiCad pcb files plugins only, false to list import plugins.
Returns
true if chosen, else false if user aborted.Helper widget to select whether a new project should be created for a file when saving

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

References _, AddFileExtListToFilter(), IO_MGR::ALTIUM_CIRCUIT_MAKER, IO_MGR::ALTIUM_CIRCUIT_STUDIO, IO_MGR::ALTIUM_DESIGNER, AltiumCircuitMakerPcbFileWildcard(), AltiumCircuitStudioPcbFileWildcard(), AltiumDesignerPcbFileWildcard(), arrayDim(), IO_MGR::CADSTAR_PCB_ARCHIVE, CadstarPcbArchiveFileWildcard(), IO_MGR::EAGLE, EaglePcbFileWildcard(), IO_MGR::FABMASTER, FabmasterPcbFileWildcard(), filter, formatWildcardExt(), PATHS::GetDefaultUserProjectsPath(), EDA_BASE_FRAME::GetMruPath(), IO_MGR::KICAD_SEXP, KICTL_EAGLE_BRD, IO_MGR::LEGACY, LegacyPcbFileWildcard(), name, path, IO_MGR::PCAD, PCadPcbFileWildcard(), PcbFileWildcard(), IO_MGR::PluginFind(), and EDA_BASE_FRAME::SetMruPath().

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

◆ AskSaveBoardFileName()

bool AskSaveBoardFileName ( PCB_EDIT_FRAME aParent,
wxString *  aFileName,
bool *  aCreateProject 
)

Put 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).
aCreateProjectwill be filled with the state of the Create Project? checkbox if relevant.
Returns
true if chosen, else false if user aborted.

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

250 {
251  wxString wildcard = PcbFileWildcard();
252  wxFileName fn = *aFileName;
253 
254  fn.SetExt( KiCadPcbFileExtension );
255 
256  wxFileDialog dlg( aParent, _( "Save Board File As" ), fn.GetPath(), fn.GetFullName(), wildcard,
257  wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
258 
259  // Add a "Create a project" checkbox in standalone mode and one isn't loaded
260  if( Kiface().IsSingle() && aParent->Prj().IsNullProject() )
261  dlg.SetExtraControlCreator( &CREATE_PROJECT_CHECKBOX::Create );
262 
263  if( dlg.ShowModal() != wxID_OK )
264  return false;
265 
266  fn = dlg.GetPath();
267 
268  // always enforce filename extension, user may not have entered it.
269  fn.SetExt( KiCadPcbFileExtension );
270 
271  *aFileName = fn.GetFullPath();
272 
273  if( wxWindow* extraControl = dlg.GetExtraControl() )
274  *aCreateProject = static_cast<CREATE_PROJECT_CHECKBOX*>( extraControl )->GetValue();
275  else if( !aParent->Prj().IsNullProject() )
276  *aCreateProject = true;
277 
278  return true;
279 }
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
const std::string KiCadPcbFileExtension
static wxWindow * Create(wxWindow *aParent)
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
#define _(s)
virtual bool IsNullProject() const
Check if this project is a null project (i.e.
Definition: project.cpp:134
wxString PcbFileWildcard()
bool IsSingle() const
Is this KIFACE running under single_top?
Definition: kiface_base.h:104

References _, CREATE_PROJECT_CHECKBOX::Create(), PROJECT::IsNullProject(), KIFACE_BASE::IsSingle(), KiCadPcbFileExtension, Kiface(), PcbFileWildcard(), and KIWAY_HOLDER::Prj().

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 465 of file pcbnew/files.cpp.

466 {
467  IO_MGR::PCB_FILE_T pluginType;
468 
469  wxFileName fn = aFileName;
470 
471  // Note: file extensions are expected to be in lower case.
472  // This is not always true, especially when importing files, so the string
473  // comparisons are case insensitive to try to find the suitable plugin.
474 
475  if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::LEGACY ) ) == 0 )
476  {
477  // both legacy and eagle share a common file extension.
478  pluginType = ( aCtl & KICTL_EAGLE_BRD ) ? IO_MGR::EAGLE : IO_MGR::LEGACY;
479  }
480  else if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::PCAD ) ) == 0 )
481  {
482  pluginType = IO_MGR::PCAD;
483  }
484  else if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::ALTIUM_DESIGNER ) ) == 0 )
485  {
486  pluginType = IO_MGR::ALTIUM_DESIGNER;
487  }
488  else if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::ALTIUM_CIRCUIT_STUDIO ) ) == 0 )
489  {
490  pluginType = IO_MGR::ALTIUM_CIRCUIT_STUDIO;
491  }
492  else if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::ALTIUM_CIRCUIT_MAKER ) ) == 0 )
493  {
494  pluginType = IO_MGR::ALTIUM_CIRCUIT_MAKER;
495  }
496  else if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::CADSTAR_PCB_ARCHIVE ) ) == 0 )
497  {
498  pluginType = IO_MGR::CADSTAR_PCB_ARCHIVE;
499  }
500  else if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::FABMASTER ) ) == 0 )
501  {
502  pluginType = IO_MGR::FABMASTER;
503  }
504  else
505  {
506  pluginType = IO_MGR::KICAD_SEXP;
507  }
508 
509  return pluginType;
510 }
#define KICTL_EAGLE_BRD
chosen *.brd file is Eagle according to user.
Definition: kiway_player.h:81
Legacy Pcbnew file formats prior to s-expression.
Definition: io_mgr.h:55
PCB_FILE_T
The set of file types that the IO_MGR knows about, and for which there has been a plugin written.
Definition: io_mgr.h:53
S-expression Pcbnew file format.
Definition: io_mgr.h:56
static const wxString GetFileExtension(PCB_FILE_T aFileType)
Return the file extension for aFileType.
Definition: io_mgr.cpp:109

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

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