KiCad PCB EDA Suite
PROJECT Class Reference

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 ()
 
VTBL_ENTRY ~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 GetSheetName (const KIID &aSheetID)
 Return the name of the sheet identified by the given UUID. 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 std::vector< PARAM_CFG * > &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 std::vector< PARAM_CFG * > &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
 
std::map< KIID, wxString > m_sheetNames
 
wxString m_rstrings [RSTRING_COUNT]
 
_ELEMm_elems [ELEM_COUNT]
 

Detailed Description

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 59 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 213 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 172 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:346

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 413 of file project.cpp.

414 {
415  wxFileName fn = aFileName;
416 
417  if( !fn.IsAbsolute() )
418  {
419  wxString pro_dir = wxPathOnly( GetProjectFullName() );
420  fn.Normalize( wxPATH_NORM_ALL, pro_dir );
421  }
422 
423  return fn.GetFullPath();
424 }
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(), PCB_EDIT_FRAME::Files_io_from_id(), SCH_EDIT_FRAME::OnCloseWindow(), DIALOG_GENDRILL::OnGenReportFile(), SCH_EDIT_FRAME::OnOpenCvpcb(), SCH_EDIT_FRAME::OnOpenPcbnew(), DIALOG_EXPORT_SVG::OnOutputDirectoryBrowseClicked(), DIALOG_PLOT::OnOutputDirectoryBrowseClicked(), DIALOG_PLOT_SCHEMATIC::OnOutputDirectoryBrowseClicked(), DIALOG_GEN_FOOTPRINT_POSITION::OnOutputDirectoryBrowseClicked(), DIALOG_GENDRILL::OnOutputDirectoryBrowseClicked(), SCH_EDIT_FRAME::OnUpdatePCB(), SCH_EDIT_FRAME::Print(), 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 247 of file project.h.

248  {
249  ElemsClear();
250 
251  for( unsigned i = 0; i<RSTRING_COUNT; ++i )
252  SetRString( RSTRING_T( i ), wxEmptyString );
253  }
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:198
RSTRING_T
Retain a number of project specific wxStrings, enumerated here:
Definition: project.h:172

References ElemsClear(), 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 318 of file project.cpp.

320 {
321  wxConfigBase* cfg = 0;
322  wxString cur_pro_fn = !aProjectFileName ? GetProjectFullName() : aProjectFileName;
323 
324  // If we do not have a project name or specified name, choose an empty file to store the
325  // temporary configuration data in.
326  if( cur_pro_fn.IsEmpty() )
327  cur_pro_fn = wxFileName::CreateTempFileName( GetProjectPath() );
328 
329  if( wxFileName( cur_pro_fn ).IsFileReadable() )
330  {
331  // Note: currently, aGroupName is not used.
332  // Previoulsy, the version of aGroupName was tested, but it
333  // was useless, and if the version is important,
334  // this is not the right place here, because configCreate does know anything
335  // about info stored in this config file.
336  cfg = new wxFileConfig( wxEmptyString, wxEmptyString, cur_pro_fn, wxEmptyString );
337  return cfg;
338  }
339 
340  // No suitable pro file was found, either does not exist, or not readable.
341  // Use the template kicad.pro file. Find it by using caller's SEARCH_STACK.
342  copy_pro_file_template( aSList, cur_pro_fn );
343 
344  cfg = new wxFileConfig( wxEmptyString, wxEmptyString, cur_pro_fn, wxEmptyString );
345 
346  return cfg;
347 }
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:262

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

Referenced by ConfigLoad(), ConfigSave(), and GetSheetName().

◆ ConfigLoad()

bool PROJECT::ConfigLoad ( const SEARCH_STACK aSearchS,
const wxString &  aGroupName,
const std::vector< PARAM_CFG * > &  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 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 385 of file project.cpp.

388 {
389  std::unique_ptr<wxConfigBase> cfg( configCreate( aSList, aGroupName,
390  aForeignProjectFileName ) );
391 
392  if( !cfg.get() )
393  {
394  // could not find template
395  return false;
396  }
397 
398  // We do not want expansion of env var values when reading our project config file
399  cfg.get()->SetExpandEnvVars( false );
400 
401  cfg->SetPath( wxCONFIG_PATH_SEPARATOR );
402 
403  wxString timestamp = cfg->Read( wxT( "update" ) );
404 
405  m_pro_date_and_time = timestamp;
406 
407  wxConfigLoadParams( cfg.get(), aParams, aGroupName );
408 
409  return true;
410 }
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:318
void wxConfigLoadParams(wxConfigBase *aCfg, const std::vector< PARAM_CFG * > &aList, const wxString &aGroup)
Function wxConfigLoadParams uses aList of PARAM_CFG to load configuration values from aCfg.
wxString m_pro_date_and_time
Definition: project.h:338

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

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

◆ ConfigSave()

void PROJECT::ConfigSave ( const SEARCH_STACK aSList,
const wxString &  aGroupName,
const std::vector< PARAM_CFG * > &  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 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 350 of file project.cpp.

352 {
353  std::unique_ptr<wxConfigBase> cfg( configCreate( aSList, aGroupName, aFileName ) );
354 
355  if( !cfg.get() )
356  {
357  // could not find template
358  return;
359  }
360 
361  cfg->SetPath( wxT( "/" ) );
362 
363  cfg->Write( wxT( "update" ), DateAndTime() );
364 
365  // @todo: pass in aLastClient wxString:
366  cfg->Write( wxT( "last_client" ), Pgm().App().GetAppName() );
367 
368  // Save parameters
369  cfg->DeleteGroup( aGroupName ); // Erase all data
370  cfg->Flush();
371 
372  cfg->SetPath( aGroupName );
373  cfg->Write( wxT( "version" ), CONFIG_VERSION );
374 
375  cfg->SetPath( wxT( "/" ) );
376 
377  wxConfigSaveParams( cfg.get(), aParams, aGroupName );
378 
379  cfg->SetPath( wxT( "/" ) );
380 
381  cfg->Flush();
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:318
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:103
void wxConfigSaveParams(wxConfigBase *aCfg, const std::vector< PARAM_CFG * > &aList, const wxString &aGroup)
Function wxConfigSaveParams writes aList of PARAM_CFG to save configuration values to aCfg.
#define CONFIG_VERSION
Definition: config_params.h:54
wxString DateAndTime()
Definition: string.cpp:345

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

Referenced by KICAD_MANAGER_FRAME::CreateNewProject(), PART_LIBS::LibNamesAndPaths(), SCH_EDIT_FRAME::Print(), LIB_TREE_MODEL_ADAPTER::SavePinnedItems(), 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:346
VTBL_ENTRY void SetElem(ELEM_T aIndex, _ELEM *aElem)
Definition: project.cpp:244
#define NULL
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Definition: macros.h:108
ELEM_T
Enum ELEM_T is the set of _ELEMs that a PROJECT can hold.
Definition: project.h:213

References arrayDim(), m_elems, NULL, 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 232 of file project.cpp.

233 {
234  // This is virtual, so implement it out of line
235 
236  if( unsigned( aIndex ) < arrayDim( m_elems ) )
237  {
238  return m_elems[aIndex];
239  }
240  return NULL;
241 }
_ELEM * m_elems[ELEM_COUNT]
Definition: project.h:346
#define NULL
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Definition: macros.h:108

References arrayDim(), m_elems, and NULL.

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

◆ GetProjectFullName()

◆ 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:337

References m_project_name.

Referenced by KICAD_MANAGER_CONTROL::SaveProjectAs(), and DIALOG_BOARD_STATISTICS::saveReportClicked().

◆ 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 213 of file project.cpp.

214 {
215  unsigned ndx = unsigned( aIndex );
216 
217  if( ndx < arrayDim( m_rstrings ) )
218  {
219  return m_rstrings[ndx];
220  }
221  else
222  {
223  static wxString no_cookie_for_you;
224 
225  wxASSERT( 0 ); // bad index
226 
227  return no_cookie_for_you;
228  }
229 }
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Definition: macros.h:108
wxString m_rstrings[RSTRING_COUNT]
Definition: project.h:343

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 LIB_EDIT_FRAME::SelectLibraryFromList().

◆ GetSheetName()

const wxString PROJECT::GetSheetName ( const KIID aSheetID)

Return the name of the sheet identified by the given UUID.

Definition at line 171 of file project.cpp.

172 {
173  if( m_sheetNames.empty() )
174  {
175  std::unique_ptr<wxConfigBase> config( configCreate( SEARCH_STACK(), GROUP_SHEET_NAMES ) );
176 
177  config->SetPath( GROUP_SHEET_NAMES );
178 
179  int index = 1;
180  wxString entry;
181 
182  while( config->Read( wxString::Format( "%d", index++ ), &entry ) )
183  {
184  wxArrayString tokens = wxSplit( entry, ':' );
185 
186  if( tokens.size() == 2 )
187  m_sheetNames[ KIID( tokens[0] ) ] = tokens[1];
188  }
189  }
190 
191  if( m_sheetNames.count( aSheetID ) )
192  return m_sheetNames.at( aSheetID );
193  else
194  return aSheetID.AsString();
195 }
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:318
wxString AsString() const
Definition: common.cpp:170
#define GROUP_SHEET_NAMES
Definition: config_params.h:52
SEARCH_STACK looks for files in a number of places.
Definition: search_stack.h:41
Definition: common.h:65
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
std::map< KIID, wxString > m_sheetNames
Definition: project.h:340

References KIID::AsString(), configCreate(), Format(), GROUP_SHEET_NAMES, and m_sheetNames.

Referenced by DIALOG_FOOTPRINT_BOARD_EDITOR::TransferDataToWindow().

◆ 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 427 of file project.cpp.

428 {
429  // This is a lazy loading function, it loads the project specific table when
430  // that table is asked for, not before.
431 
433 
434  // its gotta be NULL or a FP_LIB_TABLE, or a bug.
435  wxASSERT( !tbl || tbl->Type() == FP_LIB_TABLE_T );
436 
437  if( !tbl )
438  {
439  // Build a new project specific FP_LIB_TABLE with the global table as a fallback.
440  // ~FP_LIB_TABLE() will not touch the fallback table, so multiple projects may
441  // stack this way, all using the same global fallback table.
442  KIFACE* kiface = aKiway.KiFACE( KIWAY::FACE_PCB );
443 
444  if( kiface )
445  tbl = (FP_LIB_TABLE*) kiface->IfaceOrAddress( KIFACE_NEW_FOOTPRINT_TABLE );
446 
447  wxASSERT( tbl );
448  SetElem( ELEM_FPTBL, tbl );
449 
450  wxString projectFpLibTableFileName = FootprintLibTblName();
451 
452  try
453  {
454  tbl->Load( projectFpLibTableFileName );
455  }
456  catch( const IO_ERROR& ioe )
457  {
458  DisplayErrorMessage( NULL, _( "Error loading project footprint library table" ),
459  ioe.What() );
460  }
461  catch( ... )
462  {
463  DisplayErrorMessage( NULL, _( "Error loading project footprint library table" ) );
464  }
465  }
466 
467  return tbl;
468 }
BITMAP2CMP_SETTINGS kiface
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:252
VTBL_ENTRY _ELEM * GetElem(ELEM_T aIndex)
Typically wrapped somewhere else in a more meaningful function wrapper.
Definition: project.cpp:232
VTBL_ENTRY void SetElem(ELEM_T aIndex, _ELEM *aElem)
Definition: project.cpp:244
#define NULL
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
pcbnew DSO
Definition: kiway.h:282
Return a new FP_LIB_TABLE with the global table installed as a fallback.
Definition: kiface_ids.h:46
VTBL_ENTRY KIFACE * KiFACE(FACE_T aFaceId, bool doLoad=true)
Function KiFACE returns the KIFACE* given a FACE_T.
Definition: kiway.cpp:177
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
#define _(s)
Definition: 3d_actions.cpp:33
KIFACE is used by a participant in the KIWAY alchemy.
Definition: kiway.h:150
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, KIWAY::FACE_PCB, FootprintLibTblName(), FP_LIB_TABLE_T, GetElem(), kiface, KIWAY::KiFACE(), KIFACE_NEW_FOOTPRINT_TABLE, LIB_TABLE::Load(), NULL, 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(), CVPCB_MAINFRAME::DisplayStatus(), 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(), MODULE_EDITOR_TOOLS::PasteFootprint(), 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 244 of file project.cpp.

245 {
246  // This is virtual, so implement it out of line
247 
248  if( unsigned( aIndex ) < arrayDim( m_elems ) )
249  {
250 #if defined(DEBUG) && 0
251  if( aIndex == ELEM_SCH_PART_LIBS )
252  {
253  printf( "%s: &m_elems[%i]:%p aElem:%p\n", __func__, aIndex, &m_elems[aIndex], aElem );
254  }
255 #endif
256  delete m_elems[aIndex];
257  m_elems[aIndex] = aElem;
258  }
259 }
_ELEM * m_elems[ELEM_COUNT]
Definition: project.h:346
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Definition: macros.h:108

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:247
const std::string ProjectFileExtension
#define PROJECT_VAR_NAME
A variable name whose value holds the current project directory.
Definition: project.h:38
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:48
wxFileName m_project_name
<fullpath>/<basename>.pro
Definition: project.h:337
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 198 of file project.cpp.

199 {
200  unsigned ndx = unsigned( aIndex );
201 
202  if( ndx < arrayDim( m_rstrings ) )
203  {
204  m_rstrings[ndx] = aString;
205  }
206  else
207  {
208  wxASSERT( 0 ); // bad index
209  }
210 }
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Definition: macros.h:108
wxString m_rstrings[RSTRING_COUNT]
Definition: project.h:343

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(), LIB_EDIT_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 346 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 338 of file project.h.

Referenced by ConfigLoad().

◆ m_project_name

wxFileName PROJECT::m_project_name
private

<fullpath>/<basename>.pro

Definition at line 337 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 343 of file project.h.

Referenced by GetRString(), and SetRString().

◆ m_sheetNames

std::map<KIID, wxString> PROJECT::m_sheetNames
private

Definition at line 340 of file project.h.

Referenced by GetSheetName().


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