44 #include <wx/stdpaths.h> 49 #include <wx/wupdlock.h> 64 #define USE_INSTRUMENTATION 0 77 bool aKicadFilesOnly )
87 const wxString& filter;
120 wxFileName fileName( *aFileName );
121 wxString fileFilters;
123 if( aKicadFilesOnly )
125 std::vector<std::string> fileExtensions;
127 for(
unsigned ii = 0; ii < 2; ++ii )
129 if( !fileFilters.IsEmpty() )
130 fileFilters += wxChar(
'|' );
132 fileFilters += wxGetTranslation( loaders[ii].filter );
135 wxCHECK( plugin,
false );
136 fileExtensions.push_back( plugin->GetFileExtension().ToStdString() );
144 wxString allWildcards;
146 for(
unsigned ii = 2; ii <
arrayDim( loaders ); ++ii )
148 if( !fileFilters.IsEmpty() )
149 fileFilters += wxChar(
'|' );
151 fileFilters += wxGetTranslation( loaders[ii].filter );
154 wxCHECK( plugin,
false );
158 fileFilters =
_(
"All supported formats|" ) + allWildcards +
"|" + fileFilters;
165 if( fileName.FileExists() )
167 path = fileName.GetPath();
168 name = fileName.GetFullName();
179 wxFileDialog dlg( aParent,
180 aKicadFilesOnly ?
_(
"Open Board File" ) :
_(
"Import Non KiCad Board File" ),
181 path,
name, fileFilters,
182 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
184 if( dlg.ShowModal() == wxID_OK )
190 *aFileName = dlg.GetPath();
191 aParent->
SetMruPath( wxFileName( dlg.GetPath() ).GetPath() );
207 _(
"Create a new project for this board" ) );
210 "design rules, net classes, and layer presets" ) );
212 wxBoxSizer* sizer =
new wxBoxSizer( wxHORIZONTAL );
215 SetSizerAndFit( sizer );
223 static wxWindow*
Create( wxWindow* aParent )
245 wxFileName fn = *aFileName;
249 wxFileDialog dlg( aParent,
_(
"Save Board File As" ), fn.GetPath(), fn.GetFullName(), wildcard,
250 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
256 if( dlg.ShowModal() != wxID_OK )
264 *aFileName = fn.GetFullPath();
266 if( wxWindow* extraControl = dlg.GetExtraControl() )
267 *aCreateProject = static_cast<CREATE_PROJECT_CHECKBOX*>( extraControl )->GetValue();
269 *aCreateProject =
true;
283 if( !wxFileName::IsFileReadable( fn ) )
302 int id =
event.GetId();
334 wxFileName fn = currfn;
337 fn.SetName( rec_name );
339 if( !fn.FileExists() )
341 msg.Printf(
_(
"Recovery file \"%s\" not found." ), fn.GetFullPath() );
346 msg.Printf(
_(
"OK to load recovery file \"%s\"" ), fn.GetFullPath() );
348 if( !
IsOK(
this, msg ) )
369 wxString saveMsg =
_(
"Current board will be closed, save changes to '%s' before " 383 if( !
IsOK(
this,
_(
"Current Board will be closed. Continue?" ) ) )
408 if( !
GetBoard()->GetFileName().IsEmpty() )
416 bool addToHistory =
false;
418 wxFileName::SplitPath(
GetBoard()->GetFileName(),
nullptr,
nullptr, &orig_name,
nullptr );
420 if( orig_name.IsEmpty() )
423 orig_name =
_(
"noname" );
426 wxFileName savePath(
Prj().GetProjectFullName() );
428 if( !savePath.IsOk() || !savePath.IsDirWritable() )
432 if( !savePath.IsOk() || !savePath.IsDirWritable() )
437 wxString filename = fn.GetFullPath();
439 bool createProject =
false;
446 return SavePcbFile( filename, addToHistory, createProject );
465 wxFileName fn = aFileName;
519 for(
int i = 0; i < collector.
GetCount(); i++ )
523 int itemWidth = static_cast<PCB_SHAPE*>( collector[i] )->GetWidth();
525 if( edgeWidth != -1 && edgeWidth != itemWidth )
528 edgeWidth = std::max( edgeWidth, itemWidth );
532 edgeWidth = itemWidth;
540 wxMessageBox(
_(
"If the zones on this board are refilled the Copper Edge Clearance " 541 "setting will be used (see Board Setup > Design Rules > Constraints).\n" 542 "This may result in different fills from previous KiCad versions which " 543 "used the line thicknesses of the board boundary on the Edge Cuts " 545 _(
"Edge Clearance Warning" ), wxOK | wxICON_WARNING,
this );
548 return std::max( 0, edgeWidth / 2 );
555 if( aFileSet.size() != 1 )
557 UTF8 msg =
StrPrintf(
"Pcbnew:%s() takes only a single filename", __func__ );
562 wxString fullFileName( aFileSet[0] );
570 wxASSERT_MSG( wxFileName( fullFileName ).IsAbsolute(), wxT(
"Path is not absolute!" ) );
572 std::unique_ptr<wxSingleInstanceChecker> lockFile =
::LockFile( fullFileName );
576 wxString msg =
wxString::Format(
_(
"PCB file \"%s\" is already open." ), fullFileName );
593 wxFileName pro = fullFileName;
596 bool is_new = !wxFileName::IsFileReadable( fullFileName );
605 if( !
IsOK(
this, ask ) )
644 if( !pro.Exists() && !converted )
662 BOARD* loadedBoard = 0;
667 dynamic_cast< LAYER_REMAPPABLE_PLUGIN* >( (
PLUGIN*) pi );
668 if ( layerRemappable )
670 using namespace std::placeholders;
688 props[
"page_width"] = xbuf;
689 props[
"page_height"] = ybuf;
691 #if USE_INSTRUMENTATION 696 loadedBoard = pi->
Load( fullFileName,
NULL, &props, &
Prj() );
698 #if USE_INSTRUMENTATION 700 printf(
"PLUGIN::Load(): %u usecs\n", stopTime - startTime );
705 if( ioe.
Problem() != wxT(
"CANCEL" ) )
772 "It will be converted to the new format when saved." ),
782 wxFileName loadedBoardFn( fullFileName );
783 wxString libNickName = loadedBoardFn.GetName();
794 if( newLibPath.Length() > 0 )
798 for(
FOOTPRINT* footprint : loadedFootprints )
802 if( !footprint->GetFPID().GetLibItemName().empty() )
804 footprint->SetReference(
"REF**" );
805 piSexpr->FootprintSave( newLibPath, footprint );
812 "'%s' to the project specific footprint " 814 footprint->GetFPID().GetUniStringLibItemName(),
821 wxString rel_path, env_path;
823 wxASSERT_MSG( wxGetEnv( project_env, &env_path ),
"There is no project variable?" );
825 wxString result( newLibPath );
826 rel_path = result.Replace( env_path, wxString(
"$(" + project_env +
")" ) ) ? result
830 wxT(
"KiCad" ), wxEmptyString );
842 "footprint library table: %s" ),
849 LIB_ID libId = footprint->GetFPID();
855 footprint->SetFPID( libId );
862 wxFileName fn = fullFileName;
867 wxString fname = fn.GetFullPath();
896 #if 0 && defined(DEBUG) 920 bool aChangeProject )
923 wxFileName pcbFileName = aFileName;
931 "No access rights to write to file \"%s\"" ),
932 pcbFileName.GetFullPath() );
939 wxFileName projectFile( pcbFileName );
940 bool projectFileExists =
false;
943 projectFileExists = projectFile.FileExists();
945 if( aChangeProject && !projectFileExists )
958 if( !mgr->
LoadProject( projectFile.GetFullPath() ) )
965 if( projectFileExists )
968 wxFileName tempFile( aFileName );
969 tempFile.SetName( wxT(
"." ) + tempFile.GetName() );
970 tempFile.SetExt( tempFile.GetExt() + wxT(
"$" ) );
988 wxASSERT( tempFile.IsAbsolute() );
995 "Error saving board file \"%s\".\n%s" ),
996 pcbFileName.GetFullPath(), ioe.
What()
1000 lowerTxt.Printf(
_(
"Failed to create temporary file \"%s\"" ), tempFile.GetFullPath() );
1005 wxRemoveFile( tempFile.GetFullPath() );
1011 if( !wxRenameFile( tempFile.GetFullPath(), pcbFileName.GetFullPath() ) )
1014 "Failed to rename temporary file \"%s\"" ),
1015 pcbFileName.GetFullPath(),
1016 tempFile.GetFullPath() );
1019 lowerTxt.Printf(
_(
"Failed to rename temporary file \"%s\"" ),
1020 tempFile.GetFullPath() );
1027 if( !
Kiface().IsSingle() )
1043 wxFileName autoSaveFileName = pcbFileName;
1047 if( autoSaveFileName.FileExists() )
1048 wxRemoveFile( autoSaveFileName.GetFullPath() );
1050 lowerTxt.Printf(
_(
"File \"%s\" saved." ), pcbFileName.GetFullPath() );
1052 SetStatusText( lowerTxt, 0 );
1069 wxFileName pcbFileName = aFileName;
1077 "No access rights to write to file \"%s\"" ),
1078 pcbFileName.GetFullPath() );
1090 wxASSERT( pcbFileName.IsAbsolute() );
1092 pi->Save( pcbFileName.GetFullPath(),
GetBoard(),
NULL );
1097 pcbFileName.GetFullPath(), ioe.
What() );
1103 if( aCreateProject )
1105 wxFileName projectFile( pcbFileName );
1108 if( !projectFile.FileExists() )
1134 pcbFileName.GetFullPath() ) );
1142 wxFileName tmpFileName;
1144 if(
GetBoard()->GetFileName().IsEmpty() )
1155 wxFileName autoSaveFileName = tmpFileName;
1160 if( !autoSaveFileName.IsOk() )
1165 if( !autoSaveFileName.IsDirWritable() )
1167 autoSaveFileName.SetPath( wxFileName::GetTempDir() );
1169 if( !autoSaveFileName.IsOk() || !autoSaveFileName.IsDirWritable() )
1173 wxLogTrace(
traceAutoSave,
"Creating auto save file <" + autoSaveFileName.GetFullPath() +
">" );
1175 if(
SavePcbFile( autoSaveFileName.GetFullPath(),
false, false ) )
1182 if( !
Kiface().IsSingle() &&
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
void UpdateTitle()
Set the main window title bar text.
Plugin class for import plugins that support remappable layers.
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
LSET m_VisibleLayers
Board settings.
void ShowMessage(const wxString &aMessage, int aFlags=wxICON_INFORMATION) override
Show the info bar with the provided message and icon.
void OnModify() override
Must be called after a board change to set the modified flag.
bool HandleUnsavedChanges(wxWindow *aParent, const wxString &aMessage, const std::function< bool()> &aSaveFunction)
Display a dialog with Save, Cancel and Discard Changes buttons.
void SetCopperEdgeClearance(int aDistance)
virtual std::map< wxString, wxString > & GetTextVars() const
const UTF8 & GetLibItemName() const
#define WIN_STRING_DIR_SEP
#define KICTL_IMPORT_LIB
import all footprints into a project library.
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
wxString EaglePcbFileWildcard()
Pcbnew PLUGIN for CADSTAR PCB Archive (*.cpa) format: an ASCII format based on S-expressions.
static const KICAD_T AllBoardItems[]
A scan list for all editable board items.
bool m_LegacyDesignSettingsLoaded
True if the legacy board design settings were loaded from a file.
void SetMruPath(const wxString &aPath)
bool importFile(const wxString &aFileName, int aFileType)
Load the given filename but sets the path to the current project path.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
This file is part of the common library TODO brief description.
IO_MGR::PCB_FILE_T plugin_type(const wxString &aFileName, int aCtl)
SETTINGS_MANAGER * GetSettingsManager() const
const wxChar *const traceAutoSave
Flag to enable auto save feature debug tracing.
Hold a record identifying a library accessed by the appropriate footprint library PLUGIN object in th...
void Compile_Ratsnest(bool aDisplayStatus)
Create the entire board ratsnest.
bool InsertRow(LIB_TABLE_ROW *aRow, bool doReplace=false)
Adds aRow if it does not already exist or if doReplace is true.
This file is part of the common library.
const std::string ProjectFileExtension
const std::string LegacyPcbFileExtension
#define UNIX_STRING_DIR_SEP
bool doAutoSave() override
Perform auto save when the board has been modified and not saved within the auto save interval.
virtual PROJECT_FILE & GetProjectFile() const
#define KICTL_CREATE
caller thinks requested project files may not exist.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
Class that computes missing connections on a PCB.
void ResolveDRCExclusions()
Update markers to match recorded exclusions.
#define PROJECT_VAR_NAME
A variable name whose value holds the current project directory.
bool LoadProjectSettings()
Load the current project's file configuration settings which are pertinent to this PCB_EDIT_FRAME ins...
void ReleaseFile()
Release the current file marked in use.
void Collect(BOARD_ITEM *aBoard, const KICAD_T aScanList[])
Tests a BOARD_ITEM using this class's Inspector method, which does the collection.
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
CREATE_PROJECT_CHECKBOX(wxWindow *aParent)
NET_SETTINGS & NetSettings()
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
bool SavePcbCopy(const wxString &aFileName, bool aCreateProject=false)
Write the board data structures to aFileName.
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
#define KICTL_EAGLE_BRD
chosen *.brd file is Eagle according to user.
This is the end of the layers used for visibility bit masks in Pcbnew.
int inferLegacyEdgeClearance(BOARD *aBoard)
wxString AltiumCircuitMakerPcbFileWildcard()
Collect all BOARD_ITEM objects on a given layer.
const std::string KiCadPcbFileExtension
bool IsWritable(const wxFileName &aFileName)
Checks if aFileName can be written.
A logical library item identifier and consists of various portions much like a URI.
A name/value tuple with unique names and optional values.
const wxString & GetFileName() const
virtual const wxString Problem() const
what was the problem?
std::unique_ptr< wxSingleInstanceChecker > m_file_checker
void UpdateFileHistory(const wxString &FullFileName, FILE_HISTORY *aFileHistory=nullptr)
Update the list of recently opened files.
void SetLayerId(PCB_LAYER_ID aLayerId)
virtual BOARD * Load(const wxString &aFileName, BOARD *aAppendToMe, const PROPERTIES *aProperties=nullptr, PROJECT *aProject=nullptr)
Load information from some input file format that this PLUGIN implementation knows about into either ...
virtual void RegisterLayerMappingCallback(LAYER_MAPPING_HANDLER aLayerMappingHandler)
Register a different handler to be called when mapping of input layers to KiCad layers occurs.
virtual const wxString AbsolutePath(const wxString &aFileName) const
Fix up aFileName if it is relative to the project's directory to be an absolute path and filename.
virtual PROJECT_LOCAL_SETTINGS & GetLocalSettings() const
wxString GetFileFromHistory(int cmdId, const wxString &type, FILE_HISTORY *aFileHistory=nullptr)
Fetches the file name from the file history list.
bool HasCloseButton() const
int StrPrintf(std::string *result, const char *format,...)
This is like sprintf() but the output is appended to a std::string instead of to a character array.
bool m_LegacyCopperEdgeClearanceLoaded
Releases a PLUGIN in the context of a potential thrown exception through its destructor.
const std::map< wxString, wxString > & GetProperties() const
wxString FabmasterPcbFileWildcard()
int GetCount() const
Return the number of objects in the list.
void SynchronizeNetsAndNetClasses()
Copy NETCLASS info to each NET, based on NET membership in a NETCLASS.
void OnClearFileHistory(wxCommandEvent &aEvent)
wxString GetMruPath() const
virtual std::vector< FOOTPRINT * > GetImportedCachedLibraryFootprints()
Return a container with the cached library footprints generated in the last call to Load.
bool AskSaveBoardFileName(PCB_EDIT_FRAME *aParent, wxString *aFileName, bool *aCreateProject)
Put up a wxFileDialog asking for a BOARD filename to save.
wxString LegacyPcbFileWildcard()
void Dismiss() override
Dismisses the infobar and updates the containing layout and AUI manager (if one is provided).
GAL_SET m_VisibleItems
The GAL layers (aka items) that are turned on for viewing (.
void CheckForAutoSaveFile(const wxFileName &aFileName)
Check if an auto save file exists for aFileName and takes the appropriate action depending on the use...
bool AskLoadBoardFileName(PCB_EDIT_FRAME *aParent, int *aCtl, wxString *aFileName, bool aKicadFilesOnly)
Show a wxFileDialog asking for a BOARD filename to open.
bool IsSingle() const
Is this KIFACE_I running under single_top?
bool IsContentModified() override
Get if the current board has been modified but not saved.
virtual const wxString What() const
A composite of Problem() and Where()
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
bool OpenProjectFiles(const std::vector< wxString > &aFileSet, int aCtl=0) override
Load a KiCad board (.kicad_pcb) from aFileName.
static wxWindow * Create(wxWindow *aParent)
#define GAL_LAYER_INDEX(x)
Use this macro to convert a GAL layer to a 0-indexed offset from LAYER_VIAS.
void onBoardLoaded()
Update the state of the GUI after a new board is loaded or created.
bool TriggerBackupIfNeeded(REPORTER &aReporter) const
Calls BackupProject if a new backup is needed according to the current backup policy.
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
void ResolveNetClassAssignments(bool aRebuildFromScratch=false)
Explodes the list of netclass assignments to include atomic members of composite labels (buses).
wxString CreateNewLibrary(const wxString &aLibName=wxEmptyString, const wxString &aProposedName=wxEmptyString)
If a library name is given, creates a new footprint library in the project folder with the given name...
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
void SaveProjectSettings() override
Save changes to the project settings to the project (.pro) file.
void SynchronizeProperties()
Copy the current project's text variables into the boards property cache.
Definition of file extensions used in Kicad.
wxString formatWildcardExt(const wxString &aWildcard)
Format wildcard extension to support case sensitive file dialogs.
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Returns # of elements in an array.
wxLogTrace helper definitions.
virtual void SetFocus() override
void BuildConnectivity()
Builds or rebuilds the board connectivity database for the board, especially the list of connected it...
void SetFileName(const wxString &aFileName)
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
virtual bool IsNullProject() const
Check if this project is a null project (i.e.
void RemoveAllButtons()
Remove all the buttons that have been added by the user.
wxString AltiumDesignerPcbFileWildcard()
wxCheckBox * m_cbCreateProject
int GetFileFormatVersionAtLoad() const
A wrapper for reporting to a wxString object.
void DismissOutdatedSave()
Dismisses the infobar for outdated save warnings and updates the containing layout and AUI manager (i...
virtual FP_LIB_TABLE * PcbFootprintLibs(KIWAY &aKiway)
Return the table of footprint libraries.
int SetLibNickname(const UTF8 &aNickname)
Override the logical library name portion of the LIB_ID to aNickname.
void ClearFileHistory(FILE_HISTORY *aFileHistory=nullptr)
Removes all files from the file history.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
static wxString GetAutoSaveFilePrefix()
wxString AltiumCircuitStudioPcbFileWildcard()
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Loads a project or sets up a new project with a specified path.
void SetProject(PROJECT *aProject)
Links a board to a given project.
static wxString GetDefaultUserProjectsPath()
Gets the default path we point users to create projects.
static std::map< wxString, PCB_LAYER_ID > GetMapModal(wxWindow *aParent, const std::vector< INPUT_LAYER_DESC > &aLayerDesc)
Creates and shows a dialog (modal) and returns the data from it after completion.
void OnFileHistory(wxCommandEvent &event)
virtual void SetReadOnly(bool aReadOnly=true)
Legacy Pcbnew file formats prior to s-expression.
bool SavePcbFile(const wxString &aFileName, bool addToHistory=true, bool aChangeProject=true)
Writes the board data structures to a aFileName.
void SetBoard(BOARD *aBoard) override
Declaration of the eda_3d_viewer class.
Information pertinent to a Pcbnew printed circuit board.
#define SEXPR_BOARD_FILE_VERSION
Current s-expression file format version. 2 was the last legacy format version.
void Files_io(wxCommandEvent &event)
Call Files_io_from_id with the wxCommandEvent id.
unsigned GetRunningMicroSecs()
An alternate way to calculate an elapset time (in microsecondes) to class PROF_COUNTER.
static PLUGIN * PluginFind(PCB_FILE_T aFileType)
Return a PLUGIN which the caller can use to import, export, save, or load design documents.
bool UnloadProject(PROJECT *aProject, bool aSave=true)
Saves, unloads and unregisters the given PROJECT.
A base class that BOARD loading and saving plugins should derive from.
bool SaveProject(const wxString &aFullPath=wxEmptyString)
Saves a loaded project.
The main frame for Pcbnew.
wxString PcbFileWildcard()
void Save(const wxString &aFileName) const
Write this library table to aFileName in s-expression form.
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
OUTDATED_SAVE Messages that should be cleared on save.
const wxSize GetPageSizeIU() const override
Works off of GetPageSettings() to return the size of the paper page in the internal units of this par...
bool Files_io_from_id(int aId)
Read and write board files according to aId.
WX_INFOBAR * GetInfoBar()
Create and handle a window for the 3d viewer connected to a Kiway and a pcbboard.
static REPORTER & GetInstance()
wxString CadstarPcbArchiveFileWildcard()
Message panel definition file.
PCB_FILE_T
The set of file types that the IO_MGR knows about, and for which there has been a plugin written.
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
void NewDisplay(bool aForceImmediateRedraw=false)
Reload and refresh (rebuild) the 3D scene.
class PCB_SHAPE, a segment not on copper layers
wxString PCadPcbFileWildcard()
EDA_3D_VIEWER * Get3DViewerFrame()
bool Clear_Pcb(bool aQuery, bool aFinal=false)
Delete all and reinitialize the current board.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
LSET m_LegacyVisibleLayers
Visibility settings stored in board prior to 6.0, only used for loading legacy files.
virtual const wxString FootprintLibTblName() const
Returns the path and filename of this project's footprint library table.
bool LockFile(const wxString &aFileName)
Mark a schematic file as being in use.
wxString AddFileExtListToFilter(const std::vector< std::string > &aExts)
Build the wildcard extension file dialog wildcard filter to add to the base message dialog.
S-expression Pcbnew file format.
static const wxString GetFileExtension(PCB_FILE_T aFileType)
Return the file extension for aFileType.
void AddCloseButton(const wxString &aTooltip=_("Hide this message."))
Add the default close button to the infobar on the right side.
GAL_SET m_LegacyVisibleItems