KiCad PCB EDA Suite
PROJECT Class Reference

Class PROJECT holds project specific data. More...

#include <project.h>

Classes

class  _ELEM
 A PROJECT can hold stuff it knows nothing about, in the form of _ELEM derivatives. More...
 

Public Types

enum  RSTRING_T {
  DOC_PATH, SCH_LIB_PATH, SCH_LIB_SELECT, SCH_LIBEDIT_CUR_LIB,
  SCH_LIBEDIT_CUR_PART, VIEWER_3D_PATH, VIEWER_3D_FILTER_INDEX, PCB_LIB_NICKNAME,
  PCB_FOOTPRINT, PCB_FOOTPRINT_EDITOR_FPNAME, PCB_FOOTPRINT_EDITOR_NICKNAME, PCB_FOOTPRINT_VIEWER_FPNAME,
  PCB_FOOTPRINT_VIEWER_NICKNAME, RSTRING_COUNT
}
 Retain a number of project specific wxStrings, enumerated here: More...
 
enum  ELEM_T {
  ELEM_FPTBL, ELEM_SCH_PART_LIBS, ELEM_SCH_SEARCH_STACK, ELEM_3DCACHE,
  ELEM_SYMBOL_LIB_TABLE, ELEM_COUNT
}
 Enum ELEM_T is the set of _ELEMs that a PROJECT can hold. More...
 

Public Member Functions

 PROJECT ()
 
 ~PROJECT ()
 
VTBL_ENTRY void SetProjectFullName (const wxString &aFullPathAndName)
 Function SetProjectFullName sets the: 1) full directory, 2) basename, and 3) extension of the project. More...
 
VTBL_ENTRY const wxString GetProjectFullName () const
 Function GetProjectFullName returns the full path and name of the project. More...
 
VTBL_ENTRY const wxString GetProjectPath () const
 Function GetProjectPath returns the full path of the project. More...
 
VTBL_ENTRY const wxString GetProjectName () const
 Function GetProjectName returns the short name of the project. More...
 
VTBL_ENTRY const wxString FootprintLibTblName () const
 Function FootprintLibTblName returns the path and filename of this project's fp-lib-table, i.e. More...
 
VTBL_ENTRY const wxString SymbolLibTableName () const
 Return the path and file name of this projects symbol library table. More...
 
VTBL_ENTRY void ConfigSave (const SEARCH_STACK &aSList, const wxString &aGroupName, const PARAM_CFG_ARRAY &aParams, const wxString &aFileName=wxEmptyString)
 Function ConfigSave saves the current "project" parameters into the wxConfigBase* derivative. More...
 
VTBL_ENTRY bool ConfigLoad (const SEARCH_STACK &aSearchS, const wxString &aGroupName, const PARAM_CFG_ARRAY &aParams, const wxString &aForeignConfigFileName=wxEmptyString)
 Function ConfigLoad reads a subset of parameters from the "project" file. More...
 
VTBL_ENTRY const wxString & GetRString (RSTRING_T aStringId)
 Function GetRString returns a "retained string", which is any session and project specific string identified in enum RSTRING_T. More...
 
VTBL_ENTRY void SetRString (RSTRING_T aStringId, const wxString &aString)
 Function SetRString stores a "retained string", which is any session and project specific string identified in enum RSTRING_T. More...
 
VTBL_ENTRY _ELEMGetElem (ELEM_T aIndex)
 Typically wrapped somewhere else in a more meaningful function wrapper. More...
 
VTBL_ENTRY void SetElem (ELEM_T aIndex, _ELEM *aElem)
 
VTBL_ENTRY void ElemsClear ()
 Function ElemsClear deletes all the _ELEMs and set their pointers to NULL. More...
 
void Clear ()
 Function Clear clears the _ELEMs and RSTRINGs. More...
 
VTBL_ENTRY const wxString AbsolutePath (const wxString &aFileName) const
 Function AbsolutePath fixes up aFileName if it is relative to the project's directory to be an absolute path and filename. More...
 
VTBL_ENTRY FP_LIB_TABLEPcbFootprintLibs (KIWAY &aKiway)
 Return the table of footprint libraries. More...
 

Private Member Functions

wxConfigBase * configCreate (const SEARCH_STACK &aSList, const wxString &aGroupName, const wxString &aProjectFileName=wxEmptyString)
 Function configCreate loads a *.pro file and returns a wxConfigBase. More...
 
const wxString libTableName (const wxString &aLibTableName) const
 Return the full path and file name of the project specific library table aLibTableName. More...
 

Private Attributes

wxFileName m_project_name
 <fullpath>/<basename>.pro More...
 
wxString m_pro_date_and_time
 
wxString m_rstrings [RSTRING_COUNT]
 
_ELEMm_elems [ELEM_COUNT]
 

Detailed Description

Class PROJECT holds project specific data.

Because it is in the neutral program top, which is not linked to by subsidiarly DSOs, any functions in this interface must be VTBL_ENTRYs.

Definition at line 57 of file project.h.

Member Enumeration Documentation

◆ ELEM_T

Enum ELEM_T is the set of _ELEMs that a PROJECT can hold.

Enumerator
ELEM_FPTBL 
ELEM_SCH_PART_LIBS 
ELEM_SCH_SEARCH_STACK 
ELEM_3DCACHE 
ELEM_SYMBOL_LIB_TABLE 
ELEM_COUNT 

Definition at line 204 of file project.h.

◆ RSTRING_T

Retain a number of project specific wxStrings, enumerated here:

Enumerator
DOC_PATH 
SCH_LIB_PATH 
SCH_LIB_SELECT 
SCH_LIBEDIT_CUR_LIB 
SCH_LIBEDIT_CUR_PART 
VIEWER_3D_PATH 
VIEWER_3D_FILTER_INDEX 
PCB_LIB_NICKNAME 
PCB_FOOTPRINT 
PCB_FOOTPRINT_EDITOR_FPNAME 
PCB_FOOTPRINT_EDITOR_NICKNAME 
PCB_FOOTPRINT_VIEWER_FPNAME 
PCB_FOOTPRINT_VIEWER_NICKNAME 
RSTRING_COUNT 

Definition at line 163 of file project.h.

Constructor & Destructor Documentation

◆ PROJECT()

PROJECT::PROJECT ( )

Definition at line 41 of file project.cpp.

42 {
43  memset( m_elems, 0, sizeof(m_elems) );
44 }
_ELEM * m_elems[ELEM_COUNT]
Definition: project.h:329

References m_elems.

◆ ~PROJECT()

PROJECT::~PROJECT ( )

Definition at line 58 of file project.cpp.

59 {
60  ElemsClear();
61 }
VTBL_ENTRY void ElemsClear()
Function ElemsClear deletes all the _ELEMs and set their pointers to NULL.
Definition: project.cpp:47

References ElemsClear().

Member Function Documentation

◆ AbsolutePath()

const wxString PROJECT::AbsolutePath ( const wxString &  aFileName) const

Function AbsolutePath fixes up aFileName if it is relative to the project's directory to be an absolute path and filename.

This intends to overcome the now missing chdir() into the project directory.

Definition at line 385 of file project.cpp.

386 {
387  wxFileName fn = aFileName;
388 
389  if( !fn.IsAbsolute() )
390  {
391  wxString pro_dir = wxPathOnly( GetProjectFullName() );
392  fn.Normalize( wxPATH_NORM_ALL, pro_dir );
393  }
394 
395  return fn.GetFullPath();
396 }
VTBL_ENTRY const wxString GetProjectFullName() const
Function GetProjectFullName returns the full path and name of the project.
Definition: project.cpp:96

References GetProjectFullName().

Referenced by DIALOG_PLOT_SCHEMATIC::createPlotFileName(), PCB_EDIT_FRAME::doAutoSave(), SCH_EDIT_FRAME::doUpdatePcb(), PCB_EDIT_FRAME::Files_io_from_id(), PCB_EDIT_FRAME::InstallNetlistFrame(), SCH_EDIT_FRAME::OnCloseWindow(), DIALOG_GENDRILL::OnGenReportFile(), SCH_EDIT_FRAME::OnOpenCvpcb(), SCH_EDIT_FRAME::OnOpenPcbModuleEditor(), SCH_EDIT_FRAME::OnOpenPcbnew(), DIALOG_EXPORT_SVG::OnOutputDirectoryBrowseClicked(), DIALOG_PLOT::OnOutputDirectoryBrowseClicked(), DIALOG_PLOT_SCHEMATIC::OnOutputDirectoryBrowseClicked(), DIALOG_GENDRILL::OnOutputDirectoryBrowseClicked(), DIALOG_GEN_FOOTPRINT_POSITION::OnOutputDirectoryBrowseClicked(), SCH_EDIT_FRAME::OnPrint(), SCH_EDIT_FRAME::PrintPage(), SCH_EDIT_FRAME::SaveEEFile(), SCH_EDIT_FRAME::SaveProject(), and SCH_EDIT_FRAME::UpdateTitle().

◆ Clear()

void PROJECT::Clear ( )
inline

Function Clear clears the _ELEMs and RSTRINGs.

Definition at line 238 of file project.h.

239  {
240  ElemsClear();
241 
242  for( unsigned i = 0; i<RSTRING_COUNT; ++i )
243  SetRString( RSTRING_T( i ), wxEmptyString );
244  }
VTBL_ENTRY void ElemsClear()
Function ElemsClear deletes all the _ELEMs and set their pointers to NULL.
Definition: project.cpp:47
VTBL_ENTRY void SetRString(RSTRING_T aStringId, const wxString &aString)
Function SetRString stores a "retained string", which is any session and project specific string iden...
Definition: project.cpp:171
RSTRING_T
Retain a number of project specific wxStrings, enumerated here:
Definition: project.h:163
size_t i
Definition: json11.cpp:597

References ElemsClear(), i, RSTRING_COUNT, and SetRString().

Referenced by SetProjectFullName().

◆ configCreate()

wxConfigBase * PROJECT::configCreate ( const SEARCH_STACK aSList,
const wxString &  aGroupName,
const wxString &  aProjectFileName = wxEmptyString 
)
private

Function configCreate loads a *.pro file and returns a wxConfigBase.

Parameters
aSListis the KIFACE or PGM's SEARCH_STACK
aGroupNameis the default config file subset to use.
aProjectFileNameis the *.pro file to open.

Definition at line 291 of file project.cpp.

293 {
294  wxConfigBase* cfg = 0;
295  wxString cur_pro_fn = !aProjectFileName ? GetProjectFullName() : aProjectFileName;
296 
297  // If we do not have a project name or specified name, choose an empty file to store the
298  // temporary configuration data in.
299  if( cur_pro_fn.IsEmpty() )
300  cur_pro_fn = wxFileName::CreateTempFileName( GetProjectPath() );
301 
302  if( wxFileName( cur_pro_fn ).IsFileReadable() )
303  {
304  // Note: currently, aGroupName is not used.
305  // Previoulsy, the version of aGroupName was tested, but it
306  // was useless, and if the version is important,
307  // this is not the right place here, because configCreate does know anything
308  // about info stored in this config file.
309  cfg = new wxFileConfig( wxEmptyString, wxEmptyString, cur_pro_fn, wxEmptyString );
310  return cfg;
311  }
312 
313  // No suitable pro file was found, either does not exist, or not readable.
314  // Use the template kicad.pro file. Find it by using caller's SEARCH_STACK.
315  copy_pro_file_template( aSList, cur_pro_fn );
316 
317  cfg = new wxFileConfig( wxEmptyString, wxEmptyString, cur_pro_fn, wxEmptyString );
318 
319  return cfg;
320 }
VTBL_ENTRY const wxString GetProjectPath() const
Function GetProjectPath returns the full path of the project.
Definition: project.cpp:102
VTBL_ENTRY const wxString GetProjectFullName() const
Function GetProjectFullName returns the full path and name of the project.
Definition: project.cpp:96
static bool copy_pro_file_template(const SEARCH_STACK &aSearchS, const wxString &aDestination)
Definition: project.cpp:235

References copy_pro_file_template(), GetProjectFullName(), and GetProjectPath().

Referenced by ConfigLoad(), and ConfigSave().

◆ ConfigLoad()

bool PROJECT::ConfigLoad ( const SEARCH_STACK aSearchS,
const wxString &  aGroupName,
const PARAM_CFG_ARRAY aParams,
const wxString &  aForeignConfigFileName = wxEmptyString 
)

Function ConfigLoad reads a subset of parameters from the "project" file.

Parameters are the subset of variables given in aParams array which have the .m_Setup member set to false. The file which is read in and then extracted from is the '*.pro' file for the project.

set: m_pro_date_and_time

Parameters
aSearchSa SEARCH_STACK where a kicad.pro template file may be found.
aGroupName
aParamsis ptr vector of PARAM_CFG_BASE derivatives.
aForeignConfigFileNamewhen NULL means load the *.pro filename given in this PROJECT's m_project_name field, otherwise load the provided filename.
Returns
bool - true if loaded OK.

Definition at line 358 of file project.cpp.

360 {
361  std::unique_ptr<wxConfigBase> cfg( configCreate( aSList, aGroupName,
362  aForeignProjectFileName ) );
363 
364  if( !cfg.get() )
365  {
366  // could not find template
367  return false;
368  }
369 
370  // We do not want expansion of env var values when reading our project config file
371  cfg.get()->SetExpandEnvVars( false );
372 
373  cfg->SetPath( wxCONFIG_PATH_SEPARATOR );
374 
375  wxString timestamp = cfg->Read( wxT( "update" ) );
376 
377  m_pro_date_and_time = timestamp;
378 
379  wxConfigLoadParams( cfg.get(), aParams, aGroupName );
380 
381  return true;
382 }
wxConfigBase * configCreate(const SEARCH_STACK &aSList, const wxString &aGroupName, const wxString &aProjectFileName=wxEmptyString)
Function configCreate loads a *.pro file and returns a wxConfigBase.
Definition: project.cpp:291
void wxConfigLoadParams(wxConfigBase *aCfg, const PARAM_CFG_ARRAY &aList, const wxString &aGroup)
Function wxConfigLoadParams uses aList of PARAM_CFG_ARRAY elements to load configuration values from ...
wxString m_pro_date_and_time
Definition: project.h:323

References configCreate(), m_pro_date_and_time, and wxConfigLoadParams().

Referenced by PART_LIBS::LibNamesAndPaths(), KICAD_MANAGER_FRAME::LoadProject(), CVPCB_MAINFRAME::LoadProjectFile(), SCH_EDIT_FRAME::LoadProjectFile(), PCB_EDIT_FRAME::LoadProjectSettings(), and SCH_EDIT_FRAME::Process_Config().

◆ ConfigSave()

void PROJECT::ConfigSave ( const SEARCH_STACK aSList,
const wxString &  aGroupName,
const PARAM_CFG_ARRAY aParams,
const wxString &  aFileName = wxEmptyString 
)

Function ConfigSave saves the current "project" parameters into the wxConfigBase* derivative.

Then the wxConfigBase derivative is written to the *.pro file for the project.

Parameters
aSLista SEARCH_STACK
aGroupNameis the name of the group inside the config which contains parameters
aParamsis a ptr vector of PARAM_CFG_BASE derivatives. Saved parameters are the subset in this array having the .m_Setup member set to false.
aFileNameis where to save the *.pro file and if NULL means use this PROJECT's m_project_name.

Definition at line 323 of file project.cpp.

325 {
326  std::unique_ptr<wxConfigBase> cfg( configCreate( aSList, aGroupName, aFileName ) );
327 
328  if( !cfg.get() )
329  {
330  // could not find template
331  return;
332  }
333 
334  cfg->SetPath( wxT( "/" ) );
335 
336  cfg->Write( wxT( "update" ), DateAndTime() );
337 
338  // @todo: pass in aLastClient wxString:
339  cfg->Write( wxT( "last_client" ), Pgm().App().GetAppName() );
340 
341  // Save parameters
342  cfg->DeleteGroup( aGroupName ); // Erase all data
343  cfg->Flush();
344 
345  cfg->SetPath( aGroupName );
346  cfg->Write( wxT( "version" ), CONFIG_VERSION );
347 
348  cfg->SetPath( wxT( "/" ) );
349 
350  wxConfigSaveParams( cfg.get(), aParams, aGroupName );
351 
352  cfg->SetPath( wxT( "/" ) );
353 
354  // cfg is deleted here by std::unique_ptr, that saves the *.pro file to disk
355 }
wxConfigBase * configCreate(const SEARCH_STACK &aSList, const wxString &aGroupName, const wxString &aProjectFileName=wxEmptyString)
Function configCreate loads a *.pro file and returns a wxConfigBase.
Definition: project.cpp:291
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:66
void wxConfigSaveParams(wxConfigBase *aCfg, const PARAM_CFG_ARRAY &aList, const wxString &aGroup)
Function wxConfigSaveParams writes aList of PARAM_CFG_ARRAY elements to save configuration values to ...
#define CONFIG_VERSION
Definition: config_params.h:56
wxString DateAndTime()
Definition: string.cpp:304

References CONFIG_VERSION, configCreate(), DateAndTime(), Pgm(), and wxConfigSaveParams().

Referenced by KICAD_MANAGER_FRAME::CreateNewProject(), PCB_EDIT_FRAME::DoShowBoardSetupDialog(), PCB_EDIT_FRAME::InstallNetlistFrame(), PART_LIBS::LibNamesAndPaths(), SCH_EDIT_FRAME::OnPrint(), KICAD_MANAGER_FRAME::OnSaveProject(), CVPCB_MAINFRAME::SaveProjectFile(), SCH_EDIT_FRAME::SaveProjectSettings(), and PCB_EDIT_FRAME::SaveProjectSettings().

◆ ElemsClear()

void PROJECT::ElemsClear ( )

Function ElemsClear deletes all the _ELEMs and set their pointers to NULL.

Definition at line 47 of file project.cpp.

48 {
49  // careful here, this should work, but the virtual destructor may not
50  // be in the same link image as PROJECT.
51  for( unsigned i = 0; i < arrayDim( m_elems ); ++i )
52  {
53  SetElem( ELEM_T( i ), NULL );
54  }
55 }
_ELEM * m_elems[ELEM_COUNT]
Definition: project.h:329
VTBL_ENTRY void SetElem(ELEM_T aIndex, _ELEM *aElem)
Definition: project.cpp:217
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Definition: macros.h:99
ELEM_T
Enum ELEM_T is the set of _ELEMs that a PROJECT can hold.
Definition: project.h:204
size_t i
Definition: json11.cpp:597

References arrayDim(), i, m_elems, and SetElem().

Referenced by Clear(), and ~PROJECT().

◆ FootprintLibTblName()

const wxString PROJECT::FootprintLibTblName ( ) const

Function FootprintLibTblName returns the path and filename of this project's fp-lib-table, i.e.

the project specific one, not the global one.

Definition at line 120 of file project.cpp.

121 {
122  return libTableName( "fp-lib-table" );
123 }
const wxString libTableName(const wxString &aLibTableName) const
Return the full path and file name of the project specific library table aLibTableName.
Definition: project.cpp:126

References libTableName().

Referenced by PCB_EDIT_FRAME::importFile(), InvokePcbLibTableEditor(), and PcbFootprintLibs().

◆ GetElem()

PROJECT::_ELEM * PROJECT::GetElem ( ELEM_T  aIndex)

Typically wrapped somewhere else in a more meaningful function wrapper.

This is a cross module API, therefore the _ELEM destructor is virtual and can point to a destructor function in another link image. Be careful that that program module is resident at time of destruction.

Summary: 1) cross module API, 2) PROJECT knows nothing about _ELEM objects, except how to delete them and set and get pointers to them.

Definition at line 205 of file project.cpp.

206 {
207  // This is virtual, so implement it out of line
208 
209  if( unsigned( aIndex ) < arrayDim( m_elems ) )
210  {
211  return m_elems[aIndex];
212  }
213  return NULL;
214 }
_ELEM * m_elems[ELEM_COUNT]
Definition: project.h:329
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Definition: macros.h:99

References arrayDim(), and m_elems.

Referenced by SCH_EDIT_FRAME::OpenProjectFiles(), PcbFootprintLibs(), and LEGACY_RESCUER::WriteRescueLibrary().

◆ GetProjectFullName()

const wxString PROJECT::GetProjectFullName ( ) const

Function GetProjectFullName returns the full path and name of the project.

This is the same as the name of the *.pro file and will always be an absolute path.

Definition at line 96 of file project.cpp.

97 {
98  return m_project_name.GetFullPath();
99 }
wxFileName m_project_name
<fullpath>/<basename>.pro
Definition: project.h:322

References m_project_name.

Referenced by AbsolutePath(), DIALOG_SYMBOL_REMAP::backupProject(), configCreate(), DIALOG_CONFIG_EQUFILES::DIALOG_CONFIG_EQUFILES(), KICAD_MANAGER_FRAME::GetProjectFileName(), PART_LIBS::LibNamesAndPaths(), libTableName(), PART_LIBS::LoadAllLibraries(), SCH_EDIT_FRAME::OnImportProject(), SCH_EDIT_FRAME::OpenProjectFiles(), CVPCB_MAINFRAME::SaveProjectFile(), PCB_EDIT_FRAME::SaveProjectSettings(), SetProjectFullName(), and EDA_3D_VIEWER::takeScreenshot().

◆ GetProjectName()

const wxString PROJECT::GetProjectName ( ) const

Function GetProjectName returns the short name of the project.

This is the file name without extension or path.

Definition at line 108 of file project.cpp.

109 {
110  return m_project_name.GetName();
111 }
wxFileName m_project_name
<fullpath>/<basename>.pro
Definition: project.h:322

References m_project_name.

Referenced by FOOTPRINT_EDIT_FRAME::updateTitle().

◆ GetProjectPath()

◆ GetRString()

const wxString & PROJECT::GetRString ( RSTRING_T  aStringId)

Function GetRString returns a "retained string", which is any session and project specific string identified in enum RSTRING_T.

Retained strings are not written to disk, and are therefore good only for the current session.

Definition at line 186 of file project.cpp.

187 {
188  unsigned ndx = unsigned( aIndex );
189 
190  if( ndx < arrayDim( m_rstrings ) )
191  {
192  return m_rstrings[ndx];
193  }
194  else
195  {
196  static wxString no_cookie_for_you;
197 
198  wxASSERT( 0 ); // bad index
199 
200  return no_cookie_for_you;
201  }
202 }
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Definition: macros.h:99
wxString m_rstrings[RSTRING_COUNT]
Definition: project.h:326

References arrayDim(), and m_rstrings.

Referenced by PCB_EDIT_FRAME::ArchiveModulesOnBoard(), FOOTPRINT_VIEWER_FRAME::getCurFootprintName(), LIB_EDIT_FRAME::GetCurLib(), FOOTPRINT_VIEWER_FRAME::getCurNickname(), LIB_EDIT_FRAME::LoadOneSymbol(), DIALOG_FOOTPRINT_FP_EDITOR::OnAdd3DModel(), DIALOG_FOOTPRINT_BOARD_EDITOR::OnAdd3DModel(), FOOTPRINT_EDIT_FRAME::restoreLastFootprint(), LIB_EDIT_FRAME::saveLibrary(), LIB_EDIT_FRAME::SaveOneSymbol(), and SCH_BASE_FRAME::SelectLibraryFromList().

◆ libTableName()

const wxString PROJECT::libTableName ( const wxString &  aLibTableName) const
private

Return the full path and file name of the project specific library table aLibTableName.

Definition at line 126 of file project.cpp.

127 {
128  wxFileName fn = GetProjectFullName();
129  wxString path = fn.GetPath();
130 
131  // if there's no path to the project name, or the name as a whole is bogus or its not
132  // write-able then use a template file.
133  if( !fn.GetDirCount() || !fn.IsOk() || !wxFileName::IsDirWritable( path ) )
134  {
135  // return a template filename now.
136 
137  // this next line is likely a problem now, since it relies on an
138  // application title which is no longer constant or known. This next line needs
139  // to be re-thought out.
140 
141 #ifndef __WXMAC__
142  fn.AssignDir( wxStandardPaths::Get().GetUserConfigDir() );
143 #else
144  // don't pollute home folder, temp folder seems to be more appropriate
145  fn.AssignDir( wxStandardPaths::Get().GetTempDir() );
146 #endif
147 
148 #if defined( __WINDOWS__ )
149  fn.AppendDir( wxT( "kicad" ) );
150 #endif
151 
152  /*
153  * The library table name used when no project file is passed to the appropriate
154  * code. This is used temporarily to store the project specific library table
155  * until the project file being edited is saved. It is then moved to the correct
156  * file in the folder where the project file is saved.
157  */
158  fn.SetName( "prj-" + aLibTableName );
159  }
160  else // normal path.
161  {
162  fn.SetName( aLibTableName );
163  }
164 
165  fn.ClearExt();
166 
167  return fn.GetFullPath();
168 }
VTBL_ENTRY const wxString GetProjectFullName() const
Function GetProjectFullName returns the full path and name of the project.
Definition: project.cpp:96

References GetProjectFullName().

Referenced by FootprintLibTblName(), and SymbolLibTableName().

◆ PcbFootprintLibs()

FP_LIB_TABLE * PROJECT::PcbFootprintLibs ( KIWAY aKiway)

Return the table of footprint libraries.

Requires an active Kiway as this is fetched from pcbnew.

Definition at line 178 of file pcb_base_frame.cpp.

179 {
180  // This is a lazy loading function, it loads the project specific table when
181  // that table is asked for, not before.
182 
184 
185  // its gotta be NULL or a FP_LIB_TABLE, or a bug.
186  wxASSERT( !tbl || tbl->Type() == FP_LIB_TABLE_T );
187 
188  if( !tbl )
189  {
190  // Stack the project specific FP_LIB_TABLE overlay on top of the global table.
191  // ~FP_LIB_TABLE() will not touch the fallback table, so multiple projects may
192  // stack this way, all using the same global fallback table.
193  tbl = new FP_LIB_TABLE( &GFootprintTable );
194 
195  SetElem( ELEM_FPTBL, tbl );
196 
197  wxString projectFpLibTableFileName = FootprintLibTblName();
198 
199  try
200  {
201  tbl->Load( projectFpLibTableFileName );
202  }
203  catch( const IO_ERROR& ioe )
204  {
205  DisplayErrorMessage( nullptr,
206  _( "Error loading project footprint libraries" ),
207  ioe.What() );
208  }
209  }
210 
211  return tbl;
212 }
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Function DisplayErrorMessage displays an error message with aMessage.
Definition: confirm.cpp:257
VTBL_ENTRY _ELEM * GetElem(ELEM_T aIndex)
Typically wrapped somewhere else in a more meaningful function wrapper.
Definition: project.cpp:205
FP_LIB_TABLE GFootprintTable
The global footprint library table.
Definition: pcbnew.cpp:326
VTBL_ENTRY void SetElem(ELEM_T aIndex, _ELEM *aElem)
Definition: project.cpp:217
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
void Load(const wxString &aFileName)
Load the library table using the path defined by aFileName aFallBackTable.
KICAD_T Type() override
Definition: fp_lib_table.h:108
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76
VTBL_ENTRY const wxString FootprintLibTblName() const
Function FootprintLibTblName returns the path and filename of this project's fp-lib-table,...
Definition: project.cpp:120

References DisplayErrorMessage(), ELEM_FPTBL, FootprintLibTblName(), FP_LIB_TABLE_T, GetElem(), GFootprintTable, LIB_TABLE::Load(), SetElem(), FP_LIB_TABLE::Type(), and IO_ERROR::What().

Referenced by PCB_BASE_EDIT_FRAME::AddLibrary(), PCB_EDIT_FRAME::ArchiveModulesOnBoard(), CVPCB_MAINFRAME::BuildLIBRARY_LISTBOX(), FOOTPRINT_EDIT_FRAME::DeleteModuleFromLibrary(), DISPLAY_FOOTPRINTS_FRAME::Get_Module(), FP_THREAD_IFACE::GetTable(), PCB_EDIT_FRAME::importFile(), FOOTPRINT_EDIT_FRAME::initLibraryTree(), InvokePcbLibTableEditor(), FOOTPRINT_EDIT_FRAME::KiwayMailIn(), FOOTPRINT_SELECT_WIDGET::Load(), PCB_BASE_FRAME::loadFootprint(), CVPCB_MAINFRAME::LoadFootprintFiles(), PCB_EDIT_FRAME::LoadFootprints(), FOOTPRINT_VIEWER_FRAME::OnActivate(), FOOTPRINT_EDIT_FRAME::Process_Special_Functions(), CVPCB_MAINFRAME::ReadNetListAndFpFiles(), FOOTPRINT_VIEWER_FRAME::ReCreateLibraryList(), FOOTPRINT_EDIT_FRAME::SaveFootprint(), FOOTPRINT_EDIT_FRAME::SaveFootprintAs(), FOOTPRINT_EDIT_FRAME::saveFootprintInLibrary(), FOOTPRINT_VIEWER_FRAME::SelectAndViewFootprint(), PCB_BASE_FRAME::SelectFootprintFromLibTree(), PCB_BASE_FRAME::SelectLibrary(), FOOTPRINT_VIEWER_FRAME::ShowModal(), FOOTPRINT_EDIT_FRAME::SyncLibraryTree(), FOOTPRINT_VIEWER_FRAME::UpdateTitle(), and FOOTPRINT_EDIT_FRAME::updateTitle().

◆ SetElem()

void PROJECT::SetElem ( ELEM_T  aIndex,
_ELEM aElem 
)

Definition at line 217 of file project.cpp.

218 {
219  // This is virtual, so implement it out of line
220 
221  if( unsigned( aIndex ) < arrayDim( m_elems ) )
222  {
223 #if defined(DEBUG) && 0
224  if( aIndex == ELEM_SCH_PART_LIBS )
225  {
226  printf( "%s: &m_elems[%i]:%p aElem:%p\n", __func__, aIndex, &m_elems[aIndex], aElem );
227  }
228 #endif
229  delete m_elems[aIndex];
230  m_elems[aIndex] = aElem;
231  }
232 }
_ELEM * m_elems[ELEM_COUNT]
Definition: project.h:329
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Definition: macros.h:99

References arrayDim(), ELEM_SCH_PART_LIBS, and m_elems.

Referenced by ElemsClear(), DIALOG_SYMBOL_REMAP::OnRemapSymbols(), SCH_EDIT_FRAME::OpenProjectFiles(), PcbFootprintLibs(), LEGACY_RESCUER::WriteRescueLibrary(), and SYMBOL_LIB_TABLE_RESCUER::WriteRescueLibrary().

◆ SetProjectFullName()

void PROJECT::SetProjectFullName ( const wxString &  aFullPathAndName)

Function SetProjectFullName sets the: 1) full directory, 2) basename, and 3) extension of the project.

This is the name of the *.pro file with full absolute path and it also defines the name of the project. The project name and the *.pro file names are exactly the same, providing the *.pro filename is absolute.

Definition at line 64 of file project.cpp.

65 {
66  // Compare paths, rather than inodes, to be less surprising to the user.
67  // Create a temporary wxFileName to normalize the path
68  wxFileName candidate_path( aFullPathAndName );
69 
70  // Edge transitions only. This is what clears the project
71  // data using the Clear() function.
72  if( m_project_name.GetFullPath() != candidate_path.GetFullPath() )
73  {
74  Clear(); // clear the data when the project changes.
75 
76  wxLogTrace( tracePathsAndFiles, "%s: old:'%s' new:'%s'", __func__,
77  TO_UTF8( GetProjectFullName() ), TO_UTF8( aFullPathAndName ) );
78 
79  m_project_name = aFullPathAndName;
80 
81  wxASSERT( m_project_name.IsAbsolute() );
82 
83  wxASSERT( m_project_name.GetExt() == ProjectFileExtension );
84 
85  // until multiple projects are in play, set an environment variable for the
86  // the project pointer.
87  {
88  wxString path = m_project_name.GetPath();
89 
90  wxSetEnv( PROJECT_VAR_NAME, path );
91  }
92  }
93 }
void Clear()
Function Clear clears the _ELEMs and RSTRINGs.
Definition: project.h:238
const std::string ProjectFileExtension
#define PROJECT_VAR_NAME
A variable name whose value holds the current project directory.
Definition: project.h:37
const wxChar *const tracePathsAndFiles
Flag to enable path and file name debug output.
#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
wxFileName m_project_name
<fullpath>/<basename>.pro
Definition: project.h:322
VTBL_ENTRY const wxString GetProjectFullName() const
Function GetProjectFullName returns the full path and name of the project.
Definition: project.cpp:96

References Clear(), GetProjectFullName(), m_project_name, PROJECT_VAR_NAME, ProjectFileExtension, TO_UTF8, and tracePathsAndFiles.

Referenced by PCB_EDIT_FRAME::Files_io_from_id(), SCH_EDIT_FRAME::OnImportProject(), SCH_EDIT_FRAME::OpenProjectFiles(), PCB_EDIT_FRAME::OpenProjectFiles(), and KICAD_MANAGER_FRAME::SetProjectFileName().

◆ SetRString()

void PROJECT::SetRString ( RSTRING_T  aStringId,
const wxString &  aString 
)

Function SetRString stores a "retained string", which is any session and project specific string identified in enum RSTRING_T.

Retained strings are not written to disk, and are therefore good only for the current session.

Definition at line 171 of file project.cpp.

172 {
173  unsigned ndx = unsigned( aIndex );
174 
175  if( ndx < arrayDim( m_rstrings ) )
176  {
177  m_rstrings[ndx] = aString;
178  }
179  else
180  {
181  wxASSERT( 0 ); // bad index
182  }
183 }
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Definition: macros.h:99
wxString m_rstrings[RSTRING_COUNT]
Definition: project.h:326

References arrayDim(), and m_rstrings.

Referenced by PCB_EDIT_FRAME::ArchiveModulesOnBoard(), Clear(), LIB_EDIT_FRAME::GetCurLib(), LIB_EDIT_FRAME::LoadOneSymbol(), DIALOG_FOOTPRINT_FP_EDITOR::OnAdd3DModel(), DIALOG_FOOTPRINT_BOARD_EDITOR::OnAdd3DModel(), FOOTPRINT_EDIT_FRAME::retainLastFootprint(), LIB_EDIT_FRAME::SaveOneSymbol(), SCH_BASE_FRAME::SelectLibraryFromList(), FOOTPRINT_VIEWER_FRAME::setCurFootprintName(), LIB_EDIT_FRAME::SetCurLib(), FOOTPRINT_VIEWER_FRAME::setCurNickname(), and LIB_EDIT_FRAME::SetCurPart().

◆ SymbolLibTableName()

const wxString PROJECT::SymbolLibTableName ( ) const

Return the path and file name of this projects symbol library table.

Definition at line 114 of file project.cpp.

115 {
116  return libTableName( "sym-lib-table" );
117 }
const wxString libTableName(const wxString &aLibTableName) const
Return the full path and file name of the project specific library table aLibTableName.
Definition: project.cpp:126

References libTableName().

Member Data Documentation

◆ m_elems

_ELEM* PROJECT::m_elems[ELEM_COUNT]
private
See also
this::Elem() and enum ELEM_T.

Definition at line 329 of file project.h.

Referenced by ElemsClear(), GetElem(), PROJECT(), and SetElem().

◆ m_pro_date_and_time

wxString PROJECT::m_pro_date_and_time
private

Definition at line 323 of file project.h.

Referenced by ConfigLoad().

◆ m_project_name

wxFileName PROJECT::m_project_name
private

<fullpath>/<basename>.pro

Definition at line 322 of file project.h.

Referenced by GetProjectFullName(), GetProjectName(), GetProjectPath(), and SetProjectFullName().

◆ m_rstrings

wxString PROJECT::m_rstrings[RSTRING_COUNT]
private
See also
this::SetRString(), GetRString(), and enum RSTRING_T.

Definition at line 326 of file project.h.

Referenced by GetRString(), and SetRString().


The documentation for this class was generated from the following files: