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

References ElemsClear().

58 {
59  ElemsClear();
60 }
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 380 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().

381 {
382  wxFileName fn = aFileName;
383 
384  if( !fn.IsAbsolute() )
385  {
386  wxString pro_dir = wxPathOnly( GetProjectFullName() );
387  fn.Normalize( wxPATH_NORM_ALL, pro_dir );
388  }
389 
390  return fn.GetFullPath();
391 }
VTBL_ENTRY const wxString GetProjectFullName() const
Function GetProjectFullName returns the full path and name of the project.
Definition: project.cpp:94
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:171
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 289 of file project.cpp.

References copy_pro_file_template(), and GetProjectFullName().

Referenced by ConfigLoad(), and ConfigSave().

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

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

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

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

47 {
48  // careful here, this should work, but the virtual destructor may not
49  // be in the same link image as PROJECT.
50  for( unsigned i = 0; i < DIM( m_elems ); ++i )
51  {
52  SetElem( ELEM_T( i ), NULL );
53  }
54 }
_ELEM * m_elems[ELEM_COUNT]
Definition: project.h:324
#define DIM(x)
of elements in an array
Definition: macros.h:98
VTBL_ENTRY void SetElem(ELEM_T aIndex, _ELEM *aElem)
Definition: project.cpp:217
ELEM_T
Enum ELEM_T is the set of _ELEMs that a PROJECT can hold.
Definition: project.h:199
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 118 of file project.cpp.

References libTableName().

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

119 {
120  return libTableName( "fp-lib-table" );
121 }
const wxString libTableName(const wxString &aLibTableName) const
Return the full path and file name of the project specific library table aLibTableName.
Definition: project.cpp:124
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.

References DIM, and m_elems.

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

206 {
207  // This is virtual, so implement it out of line
208 
209  if( unsigned( aIndex ) < DIM( m_elems ) )
210  {
211  return m_elems[aIndex];
212  }
213  return NULL;
214 }
_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
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 106 of file project.cpp.

References m_project_name.

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

107 {
108  return m_project_name.GetName();
109 }
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 186 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::saveLibrary(), LIB_EDIT_FRAME::SaveOneSymbol(), and SCH_BASE_FRAME::SelectLibraryFromList().

187 {
188  unsigned ndx = unsigned( aIndex );
189 
190  if( ndx < DIM( 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 }
#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 124 of file project.cpp.

References GetProjectFullName().

Referenced by FootprintLibTblName(), and SymbolLibTableName().

125 {
126  wxFileName fn = GetProjectFullName();
127  wxString path = fn.GetPath();
128 
129  // DBG(printf( "path:'%s' fn:'%s'\n", TO_UTF8(path), TO_UTF8(fn.GetFullPath()) );)
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:94
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 }
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Function DisplayErrorMessage displays an error message with aMessage.
Definition: confirm.cpp:88
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:311
VTBL_ENTRY void SetElem(ELEM_T aIndex, _ELEM *aElem)
Definition: project.cpp:217
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:118
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 217 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().

218 {
219  // This is virtual, so implement it out of line
220 
221  if( unsigned( aIndex ) < DIM( 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: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 63 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::OnImportProject(), SCH_EDIT_FRAME::OpenProjectFiles(), PCB_EDIT_FRAME::OpenProjectFiles(), and KICAD_MANAGER_FRAME::SetProjectFileName().

64 {
65  // Compare paths, rather than inodes, to be less surprising to the user.
66  // Create a temporary wxFileName to normalize the path
67  wxFileName candidate_path( aFullPathAndName );
68 
69  // Edge transitions only. This is what clears the project
70  // data using the Clear() function.
71  if( m_project_name.GetFullPath() != candidate_path.GetFullPath() )
72  {
73  Clear(); // clear the data when the project changes.
74 
75  DBG(printf( "%s: old:'%s' new:'%s'\n", __func__, TO_UTF8( GetProjectFullName() ), TO_UTF8( aFullPathAndName ) );)
76 
77  m_project_name = aFullPathAndName;
78 
79  wxASSERT( m_project_name.IsAbsolute() );
80 
81  wxASSERT( m_project_name.GetExt() == ProjectFileExtension );
82 
83  // until multiple projects are in play, set an environment variable for the
84  // the project pointer.
85  {
86  wxString path = m_project_name.GetPath();
87 
88  wxSetEnv( PROJECT_VAR_NAME, path );
89  }
90  }
91 }
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:94
#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 171 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::SaveOneSymbol(), SCH_BASE_FRAME::SelectLibraryFromList(), FOOTPRINT_VIEWER_FRAME::setCurFootprintName(), LIB_EDIT_FRAME::SetCurLib(), FOOTPRINT_VIEWER_FRAME::setCurNickname(), and LIB_EDIT_FRAME::SetCurPart().

172 {
173  unsigned ndx = unsigned( aIndex );
174 
175  if( ndx < DIM( m_rstrings ) )
176  {
177  m_rstrings[ndx] = aString;
178  }
179  else
180  {
181  wxASSERT( 0 ); // bad index
182  }
183 }
#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 112 of file project.cpp.

References libTableName().

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

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: