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 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...
 

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 194 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 155 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:314
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 371 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(), PCB_EDIT_FRAME::InstallNetlistFrame(), SCH_EDIT_FRAME::LoadOneEEFile(), DIALOG_EESCHEMA_CONFIG::OnAddOrInsertLibClick(), 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(), PCB_EDIT_FRAME::OnUpdatePCBFromSch(), SCH_EDIT_FRAME::PrintPage(), SCH_EDIT_FRAME::SaveEEFile(), and SCH_EDIT_FRAME::UpdateTitle().

372 {
373  wxFileName fn = aFileName;
374 
375  if( !fn.IsAbsolute() )
376  {
377  wxString pro_dir = wxPathOnly( GetProjectFullName() );
378  fn.Normalize( wxPATH_NORM_ALL, pro_dir );
379  }
380 
381  return fn.GetFullPath();
382 }
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 228 of file project.h.

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

Referenced by SetProjectFullName().

229  {
230  ElemsClear();
231 
232  for( unsigned i = 0; i<RSTRING_COUNT; ++i )
233  SetRString( RSTRING_T( i ), wxEmptyString );
234  }
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:162
RSTRING_T
Retain a number of project specific wxStrings, enumerated here:
Definition: project.h:155
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 280 of file project.cpp.

References copy_pro_file_template(), and GetProjectFullName().

Referenced by ConfigLoad(), and ConfigSave().

282 {
283  wxConfigBase* cfg = 0;
284  wxString cur_pro_fn = !aProjectFileName ? GetProjectFullName() : aProjectFileName;
285 
286  if( wxFileName( cur_pro_fn ).IsFileReadable() )
287  {
288  // Note: currently, aGroupName is not used.
289  // Previoulsy, the version of aGroupName was tested, but it
290  // was useless, and if the version is important,
291  // this is not the right place here, because configCreate does know anything
292  // about info stored in this config file.
293  cfg = new wxFileConfig( wxEmptyString, wxEmptyString, cur_pro_fn, wxEmptyString );
294  return cfg;
295  }
296 
297  // No suitable pro file was found, either does not exist, or not readable.
298  // Use the template kicad.pro file. Find it by using caller's SEARCH_STACK.
299  copy_pro_file_template( aSList, cur_pro_fn );
300 
301  cfg = new wxFileConfig( wxEmptyString, wxEmptyString, cur_pro_fn, wxEmptyString );
302 
303  return cfg;
304 }
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:226
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 342 of file project.cpp.

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

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

344 {
345  std::unique_ptr<wxConfigBase> cfg( configCreate( aSList, aGroupName, aForeignProjectFileName ) );
346 
347  if( !cfg.get() )
348  {
349  // could not find template
350  return false;
351  }
352 
353  cfg->SetPath( wxCONFIG_PATH_SEPARATOR );
354 
355  wxString timestamp = cfg->Read( wxT( "update" ) );
356 
357  m_pro_date_and_time = timestamp;
358 
359  // We do not want expansion of env var values when reading our project config file
360  bool state = cfg.get()->IsExpandingEnvVars();
361  cfg.get()->SetExpandEnvVars( false );
362 
363  wxConfigLoadParams( cfg.get(), aParams, aGroupName );
364 
365  cfg.get()->SetExpandEnvVars( state );
366 
367  return true;
368 }
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:280
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:308
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 307 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().

309 {
310  std::unique_ptr<wxConfigBase> cfg( configCreate( aSList, aGroupName, aFileName ) );
311 
312  if( !cfg.get() )
313  {
314  // could not find template
315  return;
316  }
317 
318  cfg->SetPath( wxT( "/" ) );
319 
320  cfg->Write( wxT( "update" ), DateAndTime() );
321 
322  // @todo: pass in aLastClient wxString:
323  cfg->Write( wxT( "last_client" ), Pgm().App().GetAppName() );
324 
325  // Save parameters
326  cfg->DeleteGroup( aGroupName ); // Erase all data
327  cfg->Flush();
328 
329  cfg->SetPath( aGroupName );
330  cfg->Write( wxT( "version" ), CONFIG_VERSION );
331 
332  cfg->SetPath( wxT( "/" ) );
333 
334  wxConfigSaveParams( cfg.get(), aParams, aGroupName );
335 
336  cfg->SetPath( wxT( "/" ) );
337 
338  // cfg is deleted here by std::unique_ptr, that saves the *.pro file to disk
339 }
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:280
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:314
#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:208
#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:194
#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 114 of file project.cpp.

References GetProjectFullName().

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

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

References DIM, and m_elems.

Referenced by insert_library(), SCH_EDIT_FRAME::OpenProjectFiles(), and PcbFootprintLibs().

197 {
198  // This is virtual, so implement it out of line
199 
200  if( unsigned( aIndex ) < DIM( m_elems ) )
201  {
202  return m_elems[aIndex];
203  }
204  return NULL;
205 }
_ELEM * m_elems[ELEM_COUNT]
Definition: project.h:314
#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(), FootprintLibTblName(), KICAD_MANAGER_FRAME::GetProjectFileName(), PART_LIBS::LibNamesAndPaths(), 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:307
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 RESCUER::GetPartNameSuffix().

109 {
110  return m_project_name.GetName();
111 }
wxFileName m_project_name
/.pro
Definition: project.h:307
const wxString PROJECT::GetProjectPath ( ) const

Function GetProjectPath returns the full path of the project.

This is the path of the *.pro file and will always be an absolute path, ending by a dir separator.

Definition at line 102 of file project.cpp.

References m_project_name.

Referenced by DIALOG_PAGES_SETTINGS::DIALOG_PAGES_SETTINGS(), PCB_EDIT_FRAME::ExportVRML_File(), DIALOG_BOM::getPluginFileName(), DIALOG_DRC_CONTROL::makeValidFileNameReport(), DIALOG_DRC_CONTROL::OnButtonBrowseRptFileClick(), SCH_EDIT_FRAME::OnLoadProject(), KICAD_MANAGER_FRAME::OnOpenFileInTextEditor(), DIALOG_SPICE_MODEL::onSelectIcLib(), DIALOG_SPICE_MODEL::onSemiSelectLib(), SIM_PLOT_FRAME::SIM_PLOT_FRAME(), and SCH_EDIT_FRAME::WriteNetListFile().

103 {
104  return m_project_name.GetPathWithSep();
105 }
wxFileName m_project_name
/.pro
Definition: project.h:307
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 177 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(), LIB_EDIT_FRAME::GetCurPart(), FOOTPRINT_EDIT_FRAME::GetCurrentLib(), LIB_EDIT_FRAME::LoadOneSymbol(), DIALOG_EESCHEMA_CONFIG::OnAddOrInsertLibClick(), DIALOG_EESCHEMA_CONFIG::OnAddOrInsertPath(), FOOTPRINT_EDIT_FRAME::restoreLastFootprint(), LIB_EDIT_FRAME::SaveActiveLibrary(), LIB_EDIT_FRAME::SaveOneSymbol(), and SCH_BASE_FRAME::SelectLibraryFromList().

178 {
179  unsigned ndx = unsigned( aIndex );
180 
181  if( ndx < DIM( m_rstrings ) )
182  {
183  return m_rstrings[ndx];
184  }
185  else
186  {
187  static wxString no_cookie_for_you;
188 
189  wxASSERT( 0 ); // bad index
190 
191  return no_cookie_for_you;
192  }
193 }
#define DIM(x)
of elements in an array
Definition: macros.h:98
wxString m_rstrings[RSTRING_COUNT]
Definition: project.h:311
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 136 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().

137 {
138  // This is a lazy loading function, it loads the project specific table when
139  // that table is asked for, not before.
140 
142 
143  // its gotta be NULL or a FP_LIB_TABLE, or a bug.
144  wxASSERT( !tbl || dynamic_cast<FP_LIB_TABLE*>( tbl ) );
145 
146  if( !tbl )
147  {
148  // Stack the project specific FP_LIB_TABLE overlay on top of the global table.
149  // ~FP_LIB_TABLE() will not touch the fallback table, so multiple projects may
150  // stack this way, all using the same global fallback table.
151  tbl = new FP_LIB_TABLE( &GFootprintTable );
152 
153  SetElem( ELEM_FPTBL, tbl );
154 
155  wxString projectFpLibTableFileName = FootprintLibTblName();
156 
157  try
158  {
159  tbl->Load( projectFpLibTableFileName );
160  }
161  catch( const IO_ERROR& ioe )
162  {
163  DisplayErrorMessage( nullptr,
164  _( "Error loading project footprint libraries" ),
165  ioe.What() );
166  }
167  }
168 
169  return tbl;
170 }
VTBL_ENTRY _ELEM * GetElem(ELEM_T aIndex)
Typically wrapped somewhere else in a more meaningful function wrapper.
Definition: project.cpp:196
FP_LIB_TABLE GFootprintTable
The global footprint library table.
Definition: pcbnew.cpp:321
VTBL_ENTRY void SetElem(ELEM_T aIndex, _ELEM *aElem)
Definition: project.cpp:208
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:114
void Load(const wxString &aFileName)
Function Load.
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 208 of file project.cpp.

References DIM, ELEM_SCH_PART_LIBS, and m_elems.

Referenced by ElemsClear(), insert_library(), LIB_EDIT_FRAME::InstallConfigFrame(), SCH_EDIT_FRAME::InstallConfigFrame(), DIALOG_SYMBOL_REMAP::OnRemapSymbols(), SCH_EDIT_FRAME::OpenProjectFiles(), PcbFootprintLibs(), and SCH_EDIT_FRAME::RescueProject().

209 {
210  // This is virtual, so implement it out of line
211 
212  if( unsigned( aIndex ) < DIM( m_elems ) )
213  {
214 #if defined(DEBUG) && 0
215  if( aIndex == ELEM_SCH_PART_LIBS )
216  {
217  printf( "%s: &m_elems[%i]:%p aElem:%p\n", __func__, aIndex, &m_elems[aIndex], aElem );
218  }
219 #endif
220  delete m_elems[aIndex];
221  m_elems[aIndex] = aElem;
222  }
223 }
_ELEM * m_elems[ELEM_COUNT]
Definition: project.h:314
#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:228
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:307
#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 162 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::GetCurPart(), LIB_EDIT_FRAME::LoadOneSymbol(), DIALOG_EESCHEMA_CONFIG::OnAddOrInsertLibClick(), DIALOG_EESCHEMA_CONFIG::OnAddOrInsertPath(), 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().

163 {
164  unsigned ndx = unsigned( aIndex );
165 
166  if( ndx < DIM( m_rstrings ) )
167  {
168  m_rstrings[ndx] = aString;
169  }
170  else
171  {
172  wxASSERT( 0 ); // bad index
173  }
174 }
#define DIM(x)
of elements in an array
Definition: macros.h:98
wxString m_rstrings[RSTRING_COUNT]
Definition: project.h:311

Member Data Documentation

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

Definition at line 314 of file project.h.

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

wxString PROJECT::m_pro_date_and_time
private

Definition at line 308 of file project.h.

Referenced by ConfigLoad().

wxFileName PROJECT::m_project_name
private

<fullpath>/<basename>.pro

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

Referenced by GetRString(), and SetRString().


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