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_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 56 of file project.h.

Member Enumeration Documentation

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 199 of file project.h.

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_VIEWER_FPNAME 
PCB_FOOTPRINT_VIEWER_NICKNAME 
RSTRING_COUNT 

Definition at line 160 of file project.h.

Constructor & Destructor Documentation

PROJECT::PROJECT ( )

Definition at line 40 of file project.cpp.

References m_elems.

41 {
42  memset( m_elems, 0, sizeof(m_elems) );
43 }
_ELEM * m_elems[ELEM_COUNT]
Definition: project.h:324
PROJECT::~PROJECT ( )

Definition at line 59 of file project.cpp.

References ElemsClear().

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

Member Function Documentation

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

References GetProjectFullName().

Referenced by DIALOG_PLOT_SCHEMATIC::createPlotFileName(), PCB_EDIT_FRAME::doAutoSave(), SCH_EDIT_FRAME::EditSheet(), PCB_EDIT_FRAME::Files_io_from_id(), SCH_EDIT_FRAME::ImportFile(), PCB_EDIT_FRAME::ImportFile(), PCB_EDIT_FRAME::InstallNetlistFrame(), SCH_EDIT_FRAME::OnCloseWindow(), DIALOG_GENDRILL::OnGenReportFile(), SCH_EDIT_FRAME::OnOpenCvpcb(), SCH_EDIT_FRAME::OnOpenPcbModuleEditor(), SCH_EDIT_FRAME::OnOpenPcbnew(), DIALOG_PLOT::OnOutputDirectoryBrowseClicked(), DIALOG_SVG_PRINT::OnOutputDirectoryBrowseClicked(), DIALOG_GENDRILL::OnOutputDirectoryBrowseClicked(), DIALOG_PLOT_SCHEMATIC::OnOutputDirectoryBrowseClicked(), DIALOG_GEN_MODULE_POSITION::OnOutputDirectoryBrowseClicked(), SCH_EDIT_FRAME::OnPrint(), SCH_EDIT_FRAME::OnSaveProject(), SCH_EDIT_FRAME::OnUpdatePCB(), SCH_EDIT_FRAME::PrintPage(), SCH_EDIT_FRAME::SaveEEFile(), and SCH_EDIT_FRAME::UpdateTitle().

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

Function Clear clears the _ELEMs and RSTRINGs.

Definition at line 233 of file project.h.

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

Referenced by SetProjectFullName().

234  {
235  ElemsClear();
236 
237  for( unsigned i = 0; i<RSTRING_COUNT; ++i )
238  SetRString( RSTRING_T( i ), wxEmptyString );
239  }
VTBL_ENTRY void ElemsClear()
Function ElemsClear deletes all the _ELEMs and set their pointers to NULL.
Definition: project.cpp:46
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:173
RSTRING_T
Retain a number of project specific wxStrings, enumerated here:
Definition: project.h:160
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.

References copy_pro_file_template(), and GetProjectFullName().

Referenced by ConfigLoad(), and ConfigSave().

293 {
294  wxConfigBase* cfg = 0;
295  wxString cur_pro_fn = !aProjectFileName ? GetProjectFullName() : aProjectFileName;
296 
297  if( wxFileName( cur_pro_fn ).IsFileReadable() )
298  {
299  // Note: currently, aGroupName is not used.
300  // Previoulsy, the version of aGroupName was tested, but it
301  // was useless, and if the version is important,
302  // this is not the right place here, because configCreate does know anything
303  // about info stored in this config file.
304  cfg = new wxFileConfig( wxEmptyString, wxEmptyString, cur_pro_fn, wxEmptyString );
305  return cfg;
306  }
307 
308  // No suitable pro file was found, either does not exist, or not readable.
309  // Use the template kicad.pro file. Find it by using caller's SEARCH_STACK.
310  copy_pro_file_template( aSList, cur_pro_fn );
311 
312  cfg = new wxFileConfig( wxEmptyString, wxEmptyString, cur_pro_fn, wxEmptyString );
313 
314  return cfg;
315 }
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:237
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 353 of file project.cpp.

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(), SCH_EDIT_FRAME::Process_Config(), and PCB_EDIT_FRAME::Process_Config().

355 {
356  std::unique_ptr<wxConfigBase> cfg( configCreate( aSList, aGroupName, aForeignProjectFileName ) );
357 
358  if( !cfg.get() )
359  {
360  // could not find template
361  return false;
362  }
363 
364  cfg->SetPath( wxCONFIG_PATH_SEPARATOR );
365 
366  wxString timestamp = cfg->Read( wxT( "update" ) );
367 
368  m_pro_date_and_time = timestamp;
369 
370  // We do not want expansion of env var values when reading our project config file
371  bool state = cfg.get()->IsExpandingEnvVars();
372  cfg.get()->SetExpandEnvVars( false );
373 
374  wxConfigLoadParams( cfg.get(), aParams, aGroupName );
375 
376  cfg.get()->SetExpandEnvVars( state );
377 
378  return true;
379 }
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:318
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 318 of file project.cpp.

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

Referenced by KICAD_MANAGER_FRAME::CreateNewProject(), 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().

320 {
321  std::unique_ptr<wxConfigBase> cfg( configCreate( aSList, aGroupName, aFileName ) );
322 
323  if( !cfg.get() )
324  {
325  // could not find template
326  return;
327  }
328 
329  cfg->SetPath( wxT( "/" ) );
330 
331  cfg->Write( wxT( "update" ), DateAndTime() );
332 
333  // @todo: pass in aLastClient wxString:
334  cfg->Write( wxT( "last_client" ), Pgm().App().GetAppName() );
335 
336  // Save parameters
337  cfg->DeleteGroup( aGroupName ); // Erase all data
338  cfg->Flush();
339 
340  cfg->SetPath( aGroupName );
341  cfg->Write( wxT( "version" ), CONFIG_VERSION );
342 
343  cfg->SetPath( wxT( "/" ) );
344 
345  wxConfigSaveParams( cfg.get(), aParams, aGroupName );
346 
347  cfg->SetPath( wxT( "/" ) );
348 
349  // cfg is deleted here by std::unique_ptr, that saves the *.pro file to disk
350 }
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:65
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()
Function DateAndTime.
Definition: string.cpp:229
void PROJECT::ElemsClear ( )

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

Definition at line 46 of file project.cpp.

References DBG, DIM, GetProjectFullName(), m_elems, SetElem(), and TO_UTF8.

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

47 {
48  DBG( printf( "%s: clearing all _ELEMS for project %s\n", __func__, TO_UTF8( GetProjectFullName() ) );)
49 
50  // careful here, this should work, but the virtual destructor may not
51  // be in the same link image as PROJECT.
52  for( unsigned i = 0; i < DIM( m_elems ); ++i )
53  {
54  SetElem( ELEM_T( i ), NULL );
55  }
56 }
_ELEM * m_elems[ELEM_COUNT]
Definition: project.h:324
#define DIM(x)
of elements in an array
Definition: macros.h:98
VTBL_ENTRY const wxString GetProjectFullName() const
Function GetProjectFullName returns the full path and name of the project.
Definition: project.cpp:96
VTBL_ENTRY void SetElem(ELEM_T aIndex, _ELEM *aElem)
Definition: project.cpp:219
#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
ELEM_T
Enum ELEM_T is the set of _ELEMs that a PROJECT can hold.
Definition: project.h:199
#define DBG(x)
Definition: fctsys.h:33
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.

References libTableName().

Referenced by CVPCB_MAINFRAME::OnEditFootprintLibraryTable(), PcbFootprintLibs(), PCB_EDIT_FRAME::Process_Config(), and FOOTPRINT_EDIT_FRAME::ProcessPreferences().

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

References DIM, and m_elems.

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

208 {
209  // This is virtual, so implement it out of line
210 
211  if( unsigned( aIndex ) < DIM( m_elems ) )
212  {
213  return m_elems[aIndex];
214  }
215  return NULL;
216 }
_ELEM * m_elems[ELEM_COUNT]
Definition: project.h:324
#define DIM(x)
of elements in an array
Definition: macros.h:98
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.

References m_project_name.

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

97 {
98  return m_project_name.GetFullPath();
99 }
wxFileName m_project_name
/.pro
Definition: project.h:317
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.

References m_project_name.

Referenced by SCH_EAGLE_PLUGIN::getLibName(), and RESCUER::GetPartNameSuffix().

109 {
110  return m_project_name.GetName();
111 }
wxFileName m_project_name
/.pro
Definition: project.h:317
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 188 of file project.cpp.

References DIM, and m_rstrings.

Referenced by PCB_EDIT_FRAME::ArchiveModulesOnBoard(), DIALOG_MODULE_MODULE_EDITOR::BrowseAndAdd3DShapeFile(), DIALOG_MODULE_BOARD_EDITOR::BrowseAndAdd3DShapeFile(), DIALOG_EDIT_COMPONENT_IN_LIBRARY::BrowseAndSelectDocFile(), FOOTPRINT_VIEWER_FRAME::getCurFootprintName(), LIB_EDIT_FRAME::GetCurLib(), FOOTPRINT_VIEWER_FRAME::getCurNickname(), FOOTPRINT_EDIT_FRAME::GetCurrentLib(), LIB_EDIT_FRAME::LoadOneSymbol(), FOOTPRINT_EDIT_FRAME::restoreLastFootprint(), LIB_EDIT_FRAME::SaveActiveLibrary(), LIB_EDIT_FRAME::SaveOneSymbol(), and SCH_BASE_FRAME::SelectLibraryFromList().

189 {
190  unsigned ndx = unsigned( aIndex );
191 
192  if( ndx < DIM( m_rstrings ) )
193  {
194  return m_rstrings[ndx];
195  }
196  else
197  {
198  static wxString no_cookie_for_you;
199 
200  wxASSERT( 0 ); // bad index
201 
202  return no_cookie_for_you;
203  }
204 }
#define DIM(x)
of elements in an array
Definition: macros.h:98
wxString m_rstrings[RSTRING_COUNT]
Definition: project.h:321
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.

References GetProjectFullName().

Referenced by FootprintLibTblName(), and SymbolLibTableName().

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

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

Referenced by PCB_EDIT_FRAME::ArchiveModulesOnBoard(), CVPCB_MAINFRAME::BuildLIBRARY_LISTBOX(), FOOTPRINT_EDIT_FRAME::DeleteModuleFromCurrentLibrary(), DISPLAY_FOOTPRINTS_FRAME::Get_Module(), FOOTPRINT_EDIT_FRAME::getLibPath(), FP_THREAD_IFACE::GetTable(), FOOTPRINT_SELECT_WIDGET::Load(), PCB_BASE_FRAME::loadFootprint(), CVPCB_MAINFRAME::LoadFootprintFiles(), PCB_EDIT_FRAME::LoadFootprints(), FOOTPRINT_VIEWER_FRAME::OnActivate(), CVPCB_MAINFRAME::OnEditFootprintLibraryTable(), PCB_EDIT_FRAME::OnLeftClick(), FOOTPRINT_EDIT_FRAME::OnUpdateSelectCurrentLib(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDIT_FRAME::Process_Config(), FOOTPRINT_EDIT_FRAME::ProcessPreferences(), CVPCB_MAINFRAME::ReadNetListAndFpFiles(), FOOTPRINT_VIEWER_FRAME::ReCreateLibraryList(), FOOTPRINT_EDIT_FRAME::SaveFootprintInLibrary(), FOOTPRINT_VIEWER_FRAME::SelectAndViewFootprint(), PCB_BASE_FRAME::SelectLibrary(), FOOTPRINT_VIEWER_FRAME::UpdateTitle(), and FOOTPRINT_EDIT_FRAME::updateTitle().

138 {
139  // This is a lazy loading function, it loads the project specific table when
140  // that table is asked for, not before.
141 
143 
144  // its gotta be NULL or a FP_LIB_TABLE, or a bug.
145  wxASSERT( !tbl || dynamic_cast<FP_LIB_TABLE*>( tbl ) );
146 
147  if( !tbl )
148  {
149  // Stack the project specific FP_LIB_TABLE overlay on top of the global table.
150  // ~FP_LIB_TABLE() will not touch the fallback table, so multiple projects may
151  // stack this way, all using the same global fallback table.
152  tbl = new FP_LIB_TABLE( &GFootprintTable );
153 
154  SetElem( ELEM_FPTBL, tbl );
155 
156  wxString projectFpLibTableFileName = FootprintLibTblName();
157 
158  try
159  {
160  tbl->Load( projectFpLibTableFileName );
161  }
162  catch( const IO_ERROR& ioe )
163  {
164  DisplayErrorMessage( nullptr,
165  _( "Error loading project footprint libraries" ),
166  ioe.What() );
167  }
168  }
169 
170  return tbl;
171 }
VTBL_ENTRY _ELEM * GetElem(ELEM_T aIndex)
Typically wrapped somewhere else in a more meaningful function wrapper.
Definition: project.cpp:207
FP_LIB_TABLE GFootprintTable
The global footprint library table.
Definition: pcbnew.cpp:311
VTBL_ENTRY void SetElem(ELEM_T aIndex, _ELEM *aElem)
Definition: project.cpp:219
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString aExtraInfo)
Function DisplayErrorMessage displays an error message with aMessage.
Definition: confirm.cpp:85
VTBL_ENTRY const wxString FootprintLibTblName() const
Function FootprintLibTblName returns the path and filename of this project's fp-lib-table, i.e.
Definition: project.cpp:120
void Load(const wxString &aFileName)
Load the library table using the path defined by aFileName aFallBackTable.
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:47
void PROJECT::SetElem ( ELEM_T  aIndex,
_ELEM aElem 
)

Definition at line 219 of file project.cpp.

References DIM, ELEM_SCH_PART_LIBS, and m_elems.

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

220 {
221  // This is virtual, so implement it out of line
222 
223  if( unsigned( aIndex ) < DIM( m_elems ) )
224  {
225 #if defined(DEBUG) && 0
226  if( aIndex == ELEM_SCH_PART_LIBS )
227  {
228  printf( "%s: &m_elems[%i]:%p aElem:%p\n", __func__, aIndex, &m_elems[aIndex], aElem );
229  }
230 #endif
231  delete m_elems[aIndex];
232  m_elems[aIndex] = aElem;
233  }
234 }
_ELEM * m_elems[ELEM_COUNT]
Definition: project.h:324
#define DIM(x)
of elements in an array
Definition: macros.h:98
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 65 of file project.cpp.

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

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

66 {
67  // Compare paths, rather than inodes, to be less surprising to the user.
68  // Create a temporary wxFileName to normalize the path
69  wxFileName candidate_path( aFullPathAndName );
70 
71  // Edge transitions only. This is what clears the project
72  // data using the Clear() function.
73  if( m_project_name.GetFullPath() != candidate_path.GetFullPath() )
74  {
75  Clear(); // clear the data when the project changes.
76 
77  DBG(printf( "%s: old:'%s' new:'%s'\n", __func__, 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:233
const wxString ProjectFileExtension
#define PROJECT_VAR_NAME
A variable name whose value holds the current project directory.
Definition: project.h:36
VTBL_ENTRY const wxString GetProjectFullName() const
Function GetProjectFullName returns the full path and name of the project.
Definition: project.cpp:96
#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
/.pro
Definition: project.h:317
#define DBG(x)
Definition: fctsys.h:33
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 173 of file project.cpp.

References DIM, and m_rstrings.

Referenced by PCB_EDIT_FRAME::ArchiveModulesOnBoard(), DIALOG_MODULE_MODULE_EDITOR::BrowseAndAdd3DShapeFile(), DIALOG_MODULE_BOARD_EDITOR::BrowseAndAdd3DShapeFile(), DIALOG_EDIT_COMPONENT_IN_LIBRARY::BrowseAndSelectDocFile(), Clear(), LIB_EDIT_FRAME::GetCurLib(), LIB_EDIT_FRAME::LoadOneSymbol(), FOOTPRINT_EDIT_FRAME::Process_Special_Functions(), FOOTPRINT_EDIT_FRAME::retainLastFootprint(), LIB_EDIT_FRAME::SaveActiveLibrary(), 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().

174 {
175  unsigned ndx = unsigned( aIndex );
176 
177  if( ndx < DIM( m_rstrings ) )
178  {
179  m_rstrings[ndx] = aString;
180  }
181  else
182  {
183  wxASSERT( 0 ); // bad index
184  }
185 }
#define DIM(x)
of elements in an array
Definition: macros.h:98
wxString m_rstrings[RSTRING_COUNT]
Definition: project.h:321
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.

References libTableName().

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

Member Data Documentation

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

Definition at line 324 of file project.h.

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

wxString PROJECT::m_pro_date_and_time
private

Definition at line 318 of file project.h.

Referenced by ConfigLoad().

wxFileName PROJECT::m_project_name
private

<fullpath>/<basename>.pro

Definition at line 317 of file project.h.

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

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

Definition at line 321 of file project.h.

Referenced by GetRString(), and SetRString().


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