7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-02 00:26:45 +00:00

Modular KiCad Blueprint Milestone B), major portions:

*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
     get disassociated from their true PROJECT.
  *) Allow loading eeschema library editor from kicad.exe
  *) Allow loading pcbnew library editor from kicad.exe
  *) Rename LIB_COMPONENT to LIB_PART.
  *) Add class PART_LIBS, and PART_LIB.
  *) Make PART_LIBS non-global, i.e. PROJECT specific.
  *) Implement "data on demand" for PART_LIBS
  *) Implement "data on demand" for schematic SEARCH_STACK.
  *) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
  *) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
     a weak pointer.
  *) Remove all chdir() calls so projects don't need to be CWD.
  *) Romove APPEND support from OpenProjectFiles().
  *) Make OpenProjectFiles() robust, even for creating new projects.
  *) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
     and save them in the .eeschema config file, not in the project file.
  *) Fix bug with wxDir() while accessing protected dirs in kicad.exe
  *) Consolidate template copying into PROJECT class, not in kicad.exe source.
  *) Generally untangle eeschema, making its libraries not global but rather
     held in the PROJECT.
This commit is contained in:
Dick Hollenbeck 2014-08-13 15:28:54 -05:00
parent c63459653a
commit 7e483f69bd
163 changed files with 5839 additions and 5589 deletions
TODO.txt
common
cvpcb
eeschema
annotate.cppbackanno.cppblock_libedit.cppclass_libentry.cppclass_libentry.hclass_library.cppclass_library.hcomponent_references_lister.cppcomponent_tree_search_container.cppcomponent_tree_search_container.hdatabase.cpp
dialogs
edit_component_in_schematic.cppeelibs_read_libraryfiles.cppeeschema.cppeeschema_config.cppfiles-io.cppgetpart.cppinvoke_sch_dialog.hlib_arc.cpplib_arc.hlib_bezier.cpplib_bezier.hlib_circle.cpplib_circle.hlib_draw_item.cpplib_draw_item.hlib_export.cpplib_field.cpplib_field.hlib_pin.cpplib_pin.hlib_polyline.cpplib_polyline.hlib_rectangle.cpplib_rectangle.hlib_text.cpplib_text.hlibarch.cpplibedit.cpplibedit_onleftclick.cpplibedit_onrightclick.cpplibedit_plot_component.cpplibedit_undo_redo.cpplibeditframe.cpplibeditframe.hlibfield.cppload_one_schematic_file.cppmenubar.cppnetform.cppnetlist.cppnetlist.honrightclick.cpppinedit.cppplot_schematic_DXF.cppplot_schematic_HPGL.cppplot_schematic_PDF.cppplot_schematic_PS.cppplot_schematic_SVG.cppprotos.hsch_collectors.cppsch_collectors.hsch_component.cppsch_component.hsch_field.cppsch_screen.cppsch_sheet.cppsch_sheet_path.cppsch_sheet_path.hschedit.cppschframe.cppselpart.cppsheet.cppsymbdraw.cppsymbedit.cpptemplate_fieldnames.htool_sch.cpptool_viewlib.cppviewlib_frame.cppviewlib_frame.hviewlibs.cpp
gerbview
include
kicad
pcbnew

View File

@ -64,18 +64,13 @@ PCBNew
Dick's Final TODO List:
======================
*) Milestone B of Modular KiCad Blueprint:
* Put SEARCH_STACK::LastVisitedPath() out of its misery.
* Combine CVPCB into PCBNEW.
*) Milestone C of Modular KiCad Blueprint
* SWIG class KIWAY, PROJECT, and KIWAY_MGR and fill out KIWAY_MGR as needed.
* Implement PROJECT::Substitute().
* Other stuff in blueprint milestone.
*) Get licensing cleaned up.
*) DLL-ization of pcbnew & eeschema
http://www.eevblog.com/forum/open-source-kicad-geda/seriously-irritated-with-the-library-editor!/
https://blueprints.launchpad.net/kicad/+spec/modular-kicad
Issues as a result of minimal testing:
* If eeschema launched from C++ project manager and does not find all libraries,
then the dialog showing the names of missing libraries is shown twice.
* Clear all/some? retained strings on project change.
* Clear the FP_LIB_TABLE when the last KIWAY_PLAYER using it is closed.
Fix export gencad

View File

@ -40,6 +40,40 @@
#include <boost/foreach.hpp>
void wxConfigLoadParams( wxConfigBase* aCfg,
const PARAM_CFG_ARRAY& aList, const wxString& aGroup )
{
wxASSERT( aCfg );
BOOST_FOREACH( const PARAM_CFG_BASE& param, aList )
{
if( !!param.m_Group )
aCfg->SetPath( param.m_Group );
else
aCfg->SetPath( aGroup );
if( param.m_Setup )
continue;
param.ReadParam( aCfg );
}
}
void wxConfigLoadSetups( wxConfigBase* aCfg, const PARAM_CFG_ARRAY& aList )
{
wxASSERT( aCfg );
BOOST_FOREACH( const PARAM_CFG_BASE& param, aList )
{
if( !param.m_Setup )
continue;
param.ReadParam( aCfg );
}
}
void wxConfigSaveParams( wxConfigBase* aCfg,
const PARAM_CFG_ARRAY& aList, const wxString& aGroup )
{
@ -68,26 +102,6 @@ void wxConfigSaveParams( wxConfigBase* aCfg,
}
void wxConfigLoadParams( wxConfigBase* aCfg,
const PARAM_CFG_ARRAY& aList, const wxString& aGroup )
{
wxASSERT( aCfg );
BOOST_FOREACH( const PARAM_CFG_BASE& param, aList )
{
if( !!param.m_Group )
aCfg->SetPath( param.m_Group );
else
aCfg->SetPath( aGroup );
if( param.m_Setup )
continue;
param.ReadParam( aCfg );
}
}
void wxConfigSaveSetups( wxConfigBase* aCfg, const PARAM_CFG_ARRAY& aList )
{
wxASSERT( aCfg );
@ -110,21 +124,6 @@ void wxConfigSaveSetups( wxConfigBase* aCfg, const PARAM_CFG_ARRAY& aList )
}
void wxConfigLoadSetups( wxConfigBase* aCfg, const PARAM_CFG_ARRAY& aList )
{
wxASSERT( aCfg );
BOOST_FOREACH( const PARAM_CFG_BASE& param, aList )
{
if( !param.m_Setup )
continue;
param.ReadParam( aCfg );
}
}
void ConfigBaseWriteDouble( wxConfigBase* aConfig, const wxString& aKey, double aValue )
{
// Use a single strategy, regardless of wx version.

View File

@ -62,8 +62,7 @@ DIALOG_SHIM::DIALOG_SHIM( wxWindow* aParent, wxWindowID id, const wxString& titl
// pray that aParent is either a KIWAY_PLAYER or DIALOG_SHIM derivation.
KIWAY_HOLDER* h = dynamic_cast<KIWAY_HOLDER*>( aParent );
wxASSERT_MSG( h,
wxT( "DIALOG_SHIM's parent is NULL or not derived from KIWAY_PLAYER nor DIALOG_SHIM" ) );
// wxASSERT_MSG( h, wxT( "DIALOG_SHIM's parent is NULL or not derived from KIWAY_PLAYER nor DIALOG_SHIM" ) );
if( h )
SetKiway( this, &h->Kiway() );

View File

@ -28,6 +28,7 @@
#include <fctsys.h>
#include <macros.h> // DIM()
#include <common.h>
#include <project.h>
#include <confirm.h>
#include <gr_basic.h>
#include <base_struct.h>
@ -781,9 +782,11 @@ void DIALOG_PAGES_SETTINGS::GetCustomSizeMilsFromDialog()
// Called on .kicad_wks file description selection change
void DIALOG_PAGES_SETTINGS::OnWksFileSelection( wxCommandEvent& event )
{
wxString pro_dir = wxPathOnly( Prj().GetProjectFullName() );
// Display a file picker dialog
wxFileDialog fileDialog( this, _( "Select Page Layout Descr File" ),
wxGetCwd(), GetWksFileName(),
pro_dir, GetWksFileName(),
PageLayoutDescrFileWildcard,
wxFD_DEFAULT_STYLE | wxFD_FILE_MUST_EXIST );
@ -800,11 +803,14 @@ void DIALOG_PAGES_SETTINGS::OnWksFileSelection( wxCommandEvent& event )
// For Win/Linux/macOS compatibility, a relative path is a good idea
if( fn.IsAbsolute() && fileName != GetWksFileName() )
{
fn.MakeRelativeTo( wxGetCwd() );
wxString msg;
msg.Printf( _( "The page layout descr filename has changed\n"
"Do you want to use the relative path:\n%s"),
fn.GetFullPath().GetData() );
fn.MakeRelativeTo( pro_dir );
wxString msg = wxString::Format( _(
"The page layout descr filename has changed.\n"
"Do you want to use the relative path:\n"
"'%s'" ),
GetChars( fn.GetFullPath() )
);
if( IsOK( this, msg ) )
shortFileName = fn.GetFullPath();
}

View File

@ -37,12 +37,14 @@ EDA_LIST_DIALOG::EDA_LIST_DIALOG( EDA_DRAW_FRAME* aParent, const wxString& aTitl
const wxArrayString& aItemHeaders,
const std::vector<wxArrayString>& aItemList,
const wxString& aSelection,
void( *aCallBackFunction )( wxString& ),
void( *aCallBackFunction )( wxString&, void* ),
void* aCallBackFunctionData,
bool aSortList ) :
EDA_LIST_DIALOG_BASE( aParent, wxID_ANY, aTitle )
{
m_sortList = aSortList;
m_callBackFct = aCallBackFunction;
m_cb_func = aCallBackFunction;
m_cb_data = aCallBackFunctionData;
m_itemsListCp = &aItemList;
for( unsigned i = 0; i < aItemHeaders.Count(); i++ )
@ -57,7 +59,7 @@ EDA_LIST_DIALOG::EDA_LIST_DIALOG( EDA_DRAW_FRAME* aParent, const wxString& aTitl
InsertItems( aItemList, 0 );
if( m_callBackFct == NULL )
if( m_cb_func == NULL )
{
m_messages->Show( false );
m_staticTextMsg->Show( false );
@ -231,12 +233,11 @@ void EDA_LIST_DIALOG::onCancelClick( wxCommandEvent& event )
void EDA_LIST_DIALOG::onListItemSelected( wxListEvent& event )
{
if( m_callBackFct )
if( m_cb_func )
{
m_messages->Clear();
wxString text = GetTextSelection();
m_callBackFct( text );
m_cb_func( text, m_cb_data );
m_messages->WriteText( text );
}
}

View File

@ -659,7 +659,7 @@ void EDA_DRAW_FRAME::AppendMsgPanel( const wxString& textUpper,
}
void EDA_DRAW_FRAME::ClearMsgPanel( void )
void EDA_DRAW_FRAME::ClearMsgPanel()
{
if( m_messagePanel == NULL )
return;

View File

@ -41,100 +41,6 @@
#include <wx/filename.h>
#include <wx/dir.h>
/* List of default paths used to locate help files and KiCad library files.
*
* Under windows, KiCad search its files from the binary path file (first
* argument when running "main") So for a standard install, default paths
* are not mandatory, but they exist, just in case.
* KiCad is often installed in c:/Program Files/kicad or c:/kicad (or d: or
* e: ... ) and the directory "share" has no meaning under windows.
*
* Under linux, the problem is more complex.
* In fact there are 3 cases:
* 1 - When released in a distribution:
* binaries are in /usr/bin, KiCad libs in /usr/share/kicad/ and doc in
* /usr/share/doc/kicad/
* 2 - When compiled by an user:
* binaries also can be in /usr/local/bin, KiCad libs in
* /usr/local/share/kicad/ and doc in /usr/local/share/doc/kicad/
* 3 - When in an "universal tarball" or build for a server:
* all files are in /usr/local/kicad
* This is mandatory when KiCad is installed on a server (in a school for
* instance) because one can export /usr/local/kicad and obviously the others
* paths cannot be used (cannot be mounted by the client, because they are
* already used).
*
* in cases 1 and 2 KiCad files cannot be found from the binary path.
* in case 3 KiCad files can be found from the binary path only if this is
* a KiCad binary file which is launched.
* But if an user creates a symbolic link to the actual binary file to run
* KiCad, the binary path is not good and the defaults paths must be used
*
* Note:
* KiCad uses first the bin path lo locate KiCad tree.
* if not found KiCad uses the environment variable KICAD to find its files
* and at last KiCad uses the default paths.
* So we can export (linux and windows) the variable KICAD:
* like export KICAD=/my_path/kicad if /my_path/kicad is not a default path
*/
wxString MakeReducedFileName( const wxString& fullfilename,
const wxString& default_path,
const wxString& default_ext )
{
wxString reduced_filename = fullfilename;
wxString Cwd, ext, path;
Cwd = default_path;
ext = default_ext;
path = wxPathOnly( reduced_filename ) + UNIX_STRING_DIR_SEP;
reduced_filename.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP );
Cwd.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP );
if( Cwd.Last() != '/' )
Cwd += UNIX_STRING_DIR_SEP;
path.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP );
#ifdef __WINDOWS__
// names are case insensitive under windows
path.MakeLower();
Cwd.MakeLower();
ext.MakeLower();
#endif
// if the path is "default_path" -> remove it
wxString root_path = path.Left( Cwd.Length() );
if( root_path == Cwd )
{
reduced_filename.Remove( 0, Cwd.Length() );
}
else // if the path is the current path -> change path to ./
{
Cwd = wxGetCwd() + UNIX_STRING_DIR_SEP;
#ifdef __WINDOWS__
Cwd.MakeLower();
#endif
Cwd.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP );
if( path == Cwd )
{ // the path is the current path -> path = "./"
reduced_filename.Remove( 0, Cwd.Length() );
wxString tmp = wxT( "./" ) + reduced_filename;
reduced_filename = tmp;
}
}
// remove extension if == default_ext:
if( !ext.IsEmpty() && reduced_filename.Contains( ext ) )
reduced_filename.Truncate( reduced_filename.Length() - ext.Length() );
return reduced_filename;
}
void AddDelimiterString( wxString& string )
{

View File

@ -676,16 +676,17 @@ void ParseHotkeyConfig( const wxString& data,
}
/**
* Function ImportHotkeyConfigFromFile
* Prompt the user for an old hotkey file to read, and read it.
* @param aDescList = current hotkey list descr. to initialize.
*/
void EDA_BASE_FRAME::ImportHotkeyConfigFromFile( struct EDA_HOTKEY_CONFIG* aDescList )
void EDA_BASE_FRAME::ImportHotkeyConfigFromFile( EDA_HOTKEY_CONFIG* aDescList )
{
wxString ext = DEFAULT_HOTKEY_FILENAME_EXT;
wxString mask = wxT( "*." ) + ext;
#if 0 // pass in the project dir as an argument
wxString path = wxPathOnly( Prj().GetProjectFullName() );
#else
wxString path = wxGetCwd();
#endif
wxString filename = Kiface().Name() + wxT( '.' ) + ext;
filename = EDA_FileSelector( _( "Read Hotkey Configuration File:" ),
@ -704,16 +705,17 @@ void EDA_BASE_FRAME::ImportHotkeyConfigFromFile( struct EDA_HOTKEY_CONFIG* aDesc
}
/**
* Function ExportHotkeyConfigToFile
* Prompt the user for an old hotkey file to read, and read it.
* @param aDescList = current hotkey list descr. to initialize.
*/
void EDA_BASE_FRAME::ExportHotkeyConfigToFile( struct EDA_HOTKEY_CONFIG* aDescList )
void EDA_BASE_FRAME::ExportHotkeyConfigToFile( EDA_HOTKEY_CONFIG* aDescList )
{
wxString ext = DEFAULT_HOTKEY_FILENAME_EXT;
wxString mask = wxT( "*." ) + ext;
#if 0
wxString path = wxPathOnly( Prj().GetProjectFullName() );
#else
wxString path = wxGetCwd();
#endif
wxString filename = Kiface().Name() + wxT( "." ) + ext;
filename = EDA_FileSelector( _( "Write Hotkey Configuration File:" ),

View File

@ -364,6 +364,8 @@ bool PGM_BASE::initPgm()
{
wxFileName pgm_name( App().argv[0] );
wxConfigBase::DontCreateOnDemand();
wxInitAllImageHandlers();
m_pgm_checker = new wxSingleInstanceChecker( pgm_name.GetName().Lower() + wxT( "-" ) + wxGetUserId() );
@ -536,7 +538,9 @@ void PGM_BASE::saveCommonSettings()
// process startup: initPgm(), so test before using:
if( m_common_settings )
{
m_common_settings->Write( workingDirKey, wxGetCwd() );
wxString cur_dir = wxGetCwd();
m_common_settings->Write( workingDirKey, cur_dir );
}
}

View File

@ -45,12 +45,13 @@ PROJECT::PROJECT()
void PROJECT::ElemsClear()
{
DBG( printf( "%s: clearing all _ELEMS for project %s\n", __func__, TO_UTF8( GetProjectFullName() ) );)
// careful here, this should work, but the virtual destructor may not
// be in the same link image as PROJECT.
for( unsigned i = 0; i<DIM(m_elems); ++i )
for( unsigned i = 0; i < DIM( m_elems ); ++i )
{
delete m_elems[i];
m_elems[i] = NULL;
SetElem( ELEM_T( i ), NULL );
}
}
@ -63,23 +64,27 @@ PROJECT::~PROJECT()
void PROJECT::SetProjectFullName( const wxString& aFullPathAndName )
{
m_project_name = aFullPathAndName;
wxASSERT( m_project_name.GetName() == NAMELESS_PROJECT || m_project_name.IsAbsolute() );
#if 0
wxASSERT( m_project_name.GetExt() == ProjectFileExtension )
#else
m_project_name.SetExt( ProjectFileExtension );
#endif
// until multiple projects are in play, set an environment variable for the
// the project pointer.
// Edge transitions only. This is what clears the project
// data using the Clear() function.
if( m_project_name != aFullPathAndName )
{
wxString path = m_project_name.GetPath();
Clear(); // clear the data when the project changes.
// wxLogDebug( wxT( "Setting env %s to '%s'." ), PROJECT_VAR_NAME, GetChars( path ) );
DBG(printf( "%s: old:'%s' new:'%s'\n", __func__, TO_UTF8( GetProjectFullName() ), TO_UTF8( aFullPathAndName ) );)
wxSetEnv( PROJECT_VAR_NAME, path );
m_project_name = aFullPathAndName;
wxASSERT( m_project_name.IsAbsolute() );
wxASSERT( m_project_name.GetExt() == ProjectFileExtension );
// until multiple projects are in play, set an environment variable for the
// the project pointer.
{
wxString path = m_project_name.GetPath();
wxSetEnv( PROJECT_VAR_NAME, path );
}
}
}
@ -185,90 +190,63 @@ void PROJECT::SetElem( ELEM_T aIndex, _ELEM* aElem )
if( unsigned( aIndex ) < DIM( m_elems ) )
{
#if defined(DEBUG) && 0
if( aIndex == ELEM_SCH_PART_LIBS )
{
printf( "%s: &m_elems[%i]:%p aElem:%p\n", __func__, aIndex, &m_elems[aIndex], aElem );
}
#endif
delete m_elems[aIndex];
m_elems[aIndex] = aElem;
}
}
// non-member so it can be moved easily, and kept REALLY private.
// Do NOT Clear() in here.
static void add_search_paths( SEARCH_STACK* aDst, wxConfigBase* aCfg, int aIndex )
static bool copy_pro_file_template( const SEARCH_STACK& aSearchS, const wxString& aDestination )
{
for( int i=1; true; ++i )
wxString templateFile = wxT( "kicad." ) + ProjectFileExtension;
wxString kicad_pro_template = aSearchS.FindValidPath( templateFile );
if( !kicad_pro_template )
{
wxString key = wxString::Format( wxT( "LibraryPath%d" ), i );
wxString upath = aCfg->Read( key, wxEmptyString );
DBG( printf( "%s: template file '%s' not found using search paths.\n", __func__, TO_UTF8( templateFile ) );)
if( !upath )
break;
wxFileName templ( wxStandardPaths::Get().GetDocumentsDir(),
wxT( "kicad" ), ProjectFileExtension );
aDst->AddPaths( upath, aIndex );
if( !templ.IsFileReadable() )
{
wxString msg = wxString::Format( _(
"Unable to find '%s' template config file." ),
GetChars( templateFile ) );
DisplayError( NULL, msg );
return false;
}
kicad_pro_template = templ.GetFullPath();
}
}
DBG( printf( "%s: using template file '%s' as project file.\n", __func__, TO_UTF8( kicad_pro_template ) );)
// non-member so it can be moved easily, and kept REALLY private.
// Do NOT Clear() in here.
static void add_search_paths( SEARCH_STACK* aDst, const SEARCH_STACK& aSrc, int aIndex )
{
for( unsigned i=0; i<aSrc.GetCount(); ++i )
aDst->AddPaths( aSrc[i], aIndex );
}
wxCopyFile( kicad_pro_template, aDestination );
/*
bool PROJECT::MaybeLoadProjectSettings( const std::vector<wxString>& aFileSet )
{
// @todo
return true;
}
*/
wxConfigBase* PROJECT::configCreate( const SEARCH_STACK& aSList, const wxString& aFileName,
const wxString& aGroupName, bool aForceUseLocalConfig )
wxConfigBase* PROJECT::configCreate( const SEARCH_STACK& aSList,
const wxString& aGroupName, const wxString& aFileName )
{
wxConfigBase* cfg = 0;
wxString cur_pro_fn = !aFileName ? GetProjectFullName() : aFileName;
wxFileName fn = aFileName;
fn.SetExt( ProjectFileExtension );
wxString cur_pro_fn = fn.GetFullPath();
// is there an edge transition, a change in m_project_filename?
if( m_project_name != cur_pro_fn )
{
m_sch_search.Clear();
// to the empty lists, add project dir as first
m_sch_search.AddPaths( fn.GetPath() );
// append all paths from aSList
add_search_paths( &m_sch_search, aSList, -1 );
// addLibrarySearchPaths( SEARCH_STACK* aSP, wxConfigBase* aCfg )
// This is undocumented, but somebody wanted to store !schematic!
// library search paths in the .kicad_common file?
add_search_paths( &m_sch_search, Pgm().CommonSettings(), -1 );
#if 1 && defined(DEBUG)
m_sch_search.Show( __func__ );
#endif
}
// Init local config filename
if( aForceUseLocalConfig || fn.FileExists() )
if( wxFileName( cur_pro_fn ).IsFileReadable() )
{
cfg = new wxFileConfig( wxEmptyString, wxEmptyString, cur_pro_fn, wxEmptyString );
cfg->DontCreateOnDemand();
if( aForceUseLocalConfig )
{
SetProjectFullName( cur_pro_fn );
return cfg;
}
/* Check the application version against the version saved in the
* project file.
*
@ -286,12 +264,11 @@ wxConfigBase* PROJECT::configCreate( const SEARCH_STACK& aSList, const wxString&
if( version > 0 )
{
cfg->SetPath( wxCONFIG_PATH_SEPARATOR );
SetProjectFullName( cur_pro_fn );
return cfg;
}
else // Version incorrect
{
wxLogDebug( wxT( "Project file version is zero, not using this old project file, going with template." ) );
DBG( printf( "%s: project file version is zero, not using this old project file, going with template.", __func__ );)
delete cfg;
cfg = 0;
}
@ -299,49 +276,18 @@ wxConfigBase* PROJECT::configCreate( const SEARCH_STACK& aSList, const wxString&
// No suitable pro file was found, either does not exist, or is too old.
// Use the template kicad.pro file. Find it by using caller's SEARCH_STACK.
wxString templateFile = wxT( "kicad." ) + ProjectFileExtension;
wxString kicad_pro_template = aSList.FindValidPath( templateFile );
if( !kicad_pro_template )
{
wxLogDebug( wxT( "Template file <%s> not found using search paths." ),
GetChars( templateFile ) );
wxFileName templ( wxStandardPaths::Get().GetDocumentsDir(),
wxT( "kicad" ), ProjectFileExtension );
if( !templ.IsFileReadable() )
{
wxString msg = wxString::Format( _( "Unable to find %s template config file." ),
GetChars( templateFile ) );
DisplayError( NULL, msg );
return NULL;
}
kicad_pro_template = templ.GetFullPath();
}
// The project config file is not found (happens for new projects,
// or if the schematic editor is run outside an existing project
// In this case the default template (kicad.pro) is used
cur_pro_fn = kicad_pro_template;
wxLogDebug( wxT( "Use template file '%s' as project file." ), GetChars( cur_pro_fn ) );
copy_pro_file_template( aSList, cur_pro_fn );
cfg = new wxFileConfig( wxEmptyString, wxEmptyString, cur_pro_fn, wxEmptyString );
cfg->DontCreateOnDemand();
SetProjectFullName( cur_pro_fn );
return cfg;
}
void PROJECT::ConfigSave( const SEARCH_STACK& aSList, const wxString& aFileName,
const wxString& aGroupName, const PARAM_CFG_ARRAY& aParams )
void PROJECT::ConfigSave( const SEARCH_STACK& aSList, const wxString& aGroupName,
const PARAM_CFG_ARRAY& aParams, const wxString& aFileName )
{
std::auto_ptr<wxConfigBase> cfg( configCreate( aSList, aFileName, aGroupName, true ) );
std::auto_ptr<wxConfigBase> cfg( configCreate( aSList, aGroupName, aFileName ) );
if( !cfg.get() )
{
@ -373,11 +319,10 @@ void PROJECT::ConfigSave( const SEARCH_STACK& aSList, const wxString& aFileName
}
bool PROJECT::ConfigLoad( const SEARCH_STACK& aSList, const wxString& aFileName,
const wxString& aGroupName, const PARAM_CFG_ARRAY& aParams,
bool doLoadOnlyIfNew )
bool PROJECT::ConfigLoad( const SEARCH_STACK& aSList, const wxString& aGroupName,
const PARAM_CFG_ARRAY& aParams, const wxString& aForeignProjectFileName )
{
std::auto_ptr<wxConfigBase> cfg( configCreate( aSList, aFileName, aGroupName, false ) );
std::auto_ptr<wxConfigBase> cfg( configCreate( aSList, aGroupName, aForeignProjectFileName ) );
if( !cfg.get() )
{
@ -389,11 +334,6 @@ bool PROJECT::ConfigLoad( const SEARCH_STACK& aSList, const wxString& aFileName,
wxString timestamp = cfg->Read( wxT( "update" ) );
if( doLoadOnlyIfNew && timestamp.size() && timestamp == m_pro_date_and_time )
{
return false;
}
m_pro_date_and_time = timestamp;
wxConfigLoadParams( cfg.get(), aParams, aGroupName );
@ -401,3 +341,17 @@ bool PROJECT::ConfigLoad( const SEARCH_STACK& aSList, const wxString& aFileName,
return true;
}
const wxString PROJECT::AbsolutePath( const wxString& aFileName ) const
{
wxFileName fn = aFileName;
if( !fn.IsAbsolute() )
{
wxString pro_dir = wxPathOnly( GetProjectFullName() );
fn.Normalize( wxPATH_NORM_ALL, pro_dir );
}
return fn.GetFullPath();
}

View File

@ -11,17 +11,39 @@
#endif
wxString SEARCH_STACK::FilenameWithRelativePathInSearchList( const wxString& aFullFilename )
int SEARCH_STACK::Split( wxArrayString* aResult, const wxString aPathString )
{
wxStringTokenizer tokenizer( aPathString, PATH_SEPS, wxTOKEN_STRTOK );
while( tokenizer.HasMoreTokens() )
{
wxString path = tokenizer.GetNextToken();
aResult->Add( path );
}
return aResult->GetCount();
}
// Convert aRelativePath to an absolute path based on aBaseDir
static wxString base_dir( const wxString& aRelativePath, const wxString& aBaseDir )
{
wxFileName fn = aRelativePath;
if( !fn.IsAbsolute() && !!aBaseDir )
{
wxASSERT_MSG( wxFileName( aBaseDir ).IsAbsolute(), wxT( "Must pass absolute path in aBaseDir" ) );
fn.MakeRelativeTo( aBaseDir );
}
return fn.GetFullPath();
}
wxString SEARCH_STACK::FilenameWithRelativePathInSearchList(
const wxString& aFullFilename, const wxString& aBaseDir )
{
/* If the library path is already in the library search paths
* list, just add the library name to the list. Otherwise, add
* the library name with the full or relative path.
* the relative path, when possible is preferable,
* because it preserve use of default libraries paths, when the path is a sub path of
* these default paths
* Note we accept only sub paths,
* not relative paths starting by ../ that are not subpaths and are outside kicad libs paths
*/
wxFileName fn = aFullFilename;
wxString filename = aFullFilename;
@ -33,7 +55,7 @@ wxString SEARCH_STACK::FilenameWithRelativePathInSearchList( const wxString& aFu
fn = aFullFilename;
// Search for the shortest subpath within 'this':
if( fn.MakeRelativeTo( (*this)[kk] ) )
if( fn.MakeRelativeTo( base_dir( (*this)[kk], aBaseDir ) ) )
{
if( fn.GetPathWithSep().StartsWith( wxT("..") ) ) // Path outside kicad libs paths
continue;
@ -52,13 +74,16 @@ wxString SEARCH_STACK::FilenameWithRelativePathInSearchList( const wxString& aFu
void SEARCH_STACK::RemovePaths( const wxString& aPaths )
{
wxStringTokenizer tokenizer( aPaths, PATH_SEPS, wxTOKEN_STRTOK );
bool isCS = wxFileName::IsCaseSensitive();
wxArrayString paths;
while( tokenizer.HasMoreTokens() )
Split( &paths, aPaths );
for( unsigned i=0; i<paths.GetCount(); ++i )
{
wxString path = tokenizer.GetNextToken();
wxString path = paths[i];
if( Index( path, wxFileName::IsCaseSensitive() ) != wxNOT_FOUND )
if( Index( path, isCS ) != wxNOT_FOUND )
{
Remove( path );
}
@ -68,15 +93,17 @@ void SEARCH_STACK::RemovePaths( const wxString& aPaths )
void SEARCH_STACK::AddPaths( const wxString& aPaths, int aIndex )
{
bool isCS = wxFileName::IsCaseSensitive();
wxStringTokenizer tokenizer( aPaths, PATH_SEPS, wxTOKEN_STRTOK );
bool isCS = wxFileName::IsCaseSensitive();
wxArrayString paths;
Split( &paths, aPaths );
// appending all of them, on large or negative aIndex
if( unsigned( aIndex ) >= GetCount() )
{
while( tokenizer.HasMoreTokens() )
for( unsigned i=0; i<paths.GetCount(); ++i )
{
wxString path = tokenizer.GetNextToken();
wxString path = paths[i];
if( wxFileName::IsDirReadable( path )
&& Index( path, isCS ) == wxNOT_FOUND )
@ -89,9 +116,9 @@ void SEARCH_STACK::AddPaths( const wxString& aPaths, int aIndex )
// inserting all of them:
else
{
while( tokenizer.HasMoreTokens() )
for( unsigned i=0; i<paths.GetCount(); ++i )
{
wxString path = tokenizer.GetNextToken();
wxString path = paths[i];
if( wxFileName::IsDirReadable( path )
&& Index( path, isCS ) == wxNOT_FOUND )
@ -104,6 +131,8 @@ void SEARCH_STACK::AddPaths( const wxString& aPaths, int aIndex )
}
#if 1 // this function is too convoluted for words.
const wxString SEARCH_STACK::LastVisitedPath( const wxString& aSubPathToSearch )
{
wxString path;
@ -142,6 +171,7 @@ const wxString SEARCH_STACK::LastVisitedPath( const wxString& aSubPathToSearch )
return path;
}
#endif
#if defined(DEBUG)

View File

@ -270,20 +270,6 @@ bool PGM_SINGLE_TOP::OnPgmInit( wxApp* aWxApp )
argv1.MakeAbsolute();
argSet[0] = argv1.GetFullPath();
if( !Pgm().LockFile( argSet[0] ) )
{
wxLogSysError( _( "This file is already open." ) );
return false;
}
}
// @todo: setting CWD is taboo in a multi-project environment, this
// will not be possible soon.
if( argv1.GetPath().size() ) // path only
{
// wxSetWorkingDirectory() does not like empty paths
wxSetWorkingDirectory( argv1.GetPath() );
}
// Use the KIWAY_PLAYER::OpenProjectFiles() API function:
@ -298,24 +284,6 @@ bool PGM_SINGLE_TOP::OnPgmInit( wxApp* aWxApp )
return false;
}
}
else
{
/*
The lean single_top program launcher has no access to program
settings, for if it did, it would not be lean. That kind of
functionality is in the KIFACE now, but it cannot assume that it is
the only KIFACE in memory. So this looks like a dead concept here,
or an expensive one in terms of code size.
wxString dir;
if( m_pgmSettings->Read( workingDirKey, &dir ) && wxDirExists( dir ) )
{
wxSetWorkingDirectory( dir );
}
*/
}
frame->Show();

View File

@ -29,6 +29,7 @@
#include <fctsys.h>
#include <common.h>
#include <kiface_i.h>
#include <project.h>
#include <confirm.h>
#include <gestfich.h>
@ -91,7 +92,8 @@ void CVPCB_MAINFRAME::AssocieModule( wxCommandEvent& event )
char Line[1024];
FILE* file;
size_t ii;
SEARCH_STACK& search = Prj().SchSearchS();
SEARCH_STACK& search = Kiface().KifaceSearch();
if( m_netlist.IsEmpty() )
return;

View File

@ -59,30 +59,25 @@ PARAM_CFG_ARRAY& CVPCB_MAINFRAME::GetProjectFileParameters()
}
void CVPCB_MAINFRAME::LoadProjectFile( const wxString& aFileName )
void CVPCB_MAINFRAME::LoadProjectFile()
{
wxFileName fn( aFileName );
PROJECT& prj = Prj();
PROJECT& prj = Prj();
m_ModuleLibNames.Clear();
m_AliasLibNames.Clear();
fn.SetExt( ProjectFileExtension );
// was: Pgm().ReadProjectConfig( fn.GetFullPath(), GROUP, GetProjectFileParameters(), false );
prj.ConfigLoad( Kiface().KifaceSearch(), fn.GetFullPath(), GROUP_CVP, GetProjectFileParameters(), false );
prj.ConfigLoad( Kiface().KifaceSearch(), GROUP_CVP, GetProjectFileParameters() );
if( m_NetlistFileExtension.IsEmpty() )
m_NetlistFileExtension = wxT( "net" );
// Force FP_LIB_TABLE to be loaded on demand.
prj.ElemClear( PROJECT::ELEM_FPTBL );
}
void CVPCB_MAINFRAME::SaveProjectFile( wxCommandEvent& aEvent )
{
wxFileName fn = m_NetlistFileName;
PROJECT& prj = Prj();
wxFileName fn = prj.AbsolutePath( m_NetlistFileName.GetFullPath() );
fn.SetExt( ProjectFileExtension );
@ -103,11 +98,8 @@ void CVPCB_MAINFRAME::SaveProjectFile( wxCommandEvent& aEvent )
if( !IsWritable( fn ) )
return;
// was:
// Pgm().WriteProjectConfig( fn.GetFullPath(), GROUP, GetProjectFileParameters() );
wxString pro_name = fn.GetFullPath();
PROJECT& prj = Prj();
prj.ConfigSave( Kiface().KifaceSearch(), fn.GetFullPath(), GROUP_CVP, GetProjectFileParameters() );
prj.ConfigSave( Kiface().KifaceSearch(), GROUP_CVP, GetProjectFileParameters(), pro_name );
}

View File

@ -217,7 +217,7 @@ public:
* Function LoadProjectFile
* reads the configuration parameter from the project (.pro) file \a aFileName
*/
void LoadProjectFile( const wxString& aFileName );
void LoadProjectFile();
void LoadSettings( wxConfigBase* aCfg ); // override virtual

View File

@ -169,7 +169,7 @@ bool CVPCB_MAINFRAME::ReadNetListAndLinkFiles()
if( m_compListBox == NULL )
return false;
LoadProjectFile( m_NetlistFileName.GetFullPath() );
LoadProjectFile();
LoadFootprintFiles();
BuildFOOTPRINTS_LISTBOX();

View File

@ -95,18 +95,18 @@ void SCH_EDIT_FRAME::AnnotateComponents( bool aAnnotateSchematic,
// Set sheet number and number of sheets.
SetSheetNumberAndCount();
/* Build component list */
// Build component list
if( aAnnotateSchematic )
{
sheets.GetComponents( references );
sheets.GetComponents( Prj().SchLibs(), references );
}
else
{
m_CurrentSheet->GetComponents( references );
m_CurrentSheet->GetComponents( Prj().SchLibs(), references );
}
/* Break full components reference in name (prefix) and number:
* example: IC1 become IC, and 1 */
// Break full components reference in name (prefix) and number:
// example: IC1 become IC, and 1
references.SplitReferences();
switch( aSortOption )
@ -172,15 +172,15 @@ void SCH_EDIT_FRAME::AnnotateComponents( bool aAnnotateSchematic,
int SCH_EDIT_FRAME::CheckAnnotate( wxArrayString* aMessageList, bool aOneSheetOnly )
{
/* build the screen list */
// build the screen list
SCH_SHEET_LIST SheetList;
SCH_REFERENCE_LIST ComponentsList;
/* Build the list of components */
// Build the list of components
if( !aOneSheetOnly )
SheetList.GetComponents( ComponentsList );
SheetList.GetComponents( Prj().SchLibs(), ComponentsList );
else
m_CurrentSheet->GetComponents( ComponentsList );
m_CurrentSheet->GetComponents( Prj().SchLibs(), ComponentsList );
return ComponentsList.CheckAnnotation( aMessageList );
}

View File

@ -54,7 +54,7 @@ void SCH_EDIT_FRAME::backAnnotateFootprints( const std::string& aChangedSetOfRef
SCH_SHEET_LIST sheets;
bool isChanged = false;
sheets.GetComponents( refs, false );
sheets.GetComponents( Prj().SchLibs(), refs, false );
DSNLEXER lexer( aChangedSetOfReferences, FROM_UTF8( __func__ ) );
PTREE doc;
@ -98,7 +98,7 @@ void SCH_EDIT_FRAME::backAnnotateFootprints( const std::string& aChangedSetOfRef
// We have found a candidate.
// Note: it can be not unique (multiple parts per package)
// So we *do not* stop the search here
SCH_COMPONENT* component = refs[ii].GetComponent();
SCH_COMPONENT* component = refs[ii].GetComp();
SCH_FIELD* fpfield = component->GetField( FOOTPRINT );
const wxString& oldfp = fpfield->GetText();
@ -133,9 +133,9 @@ bool SCH_EDIT_FRAME::ProcessCmpToFootprintLinkFile( const wxString& aFullFilenam
{
// Build a flat list of components in schematic:
SCH_REFERENCE_LIST referencesList;
SCH_SHEET_LIST SheetList;
SCH_SHEET_LIST sheetList;
SheetList.GetComponents( referencesList, false );
sheetList.GetComponents( Prj().SchLibs(), referencesList, false );
FILE* cmpFile = wxFopen( aFullFilename, wxT( "rt" ) );
if( cmpFile == NULL )
@ -196,9 +196,9 @@ bool SCH_EDIT_FRAME::ProcessCmpToFootprintLinkFile( const wxString& aFullFilenam
if( Cmp_KEEPCASE( reference, referencesList[ii].GetRef() ) == 0 )
{
// We have found a candidate.
// Note: it can be not unique (multiple parts per package)
// Note: it can be not unique (multiple units per part)
// So we *do not* stop the search here
SCH_COMPONENT* component = referencesList[ii].GetComponent();
SCH_COMPONENT* component = referencesList[ii].GetComp();
SCH_FIELD* fpfield = component->GetField( FOOTPRINT );
fpfield->SetText( footprint );
@ -218,7 +218,7 @@ bool SCH_EDIT_FRAME::ProcessCmpToFootprintLinkFile( const wxString& aFullFilenam
bool SCH_EDIT_FRAME::LoadCmpToFootprintLinkFile()
{
wxString path = wxGetCwd();
wxString path = wxPathOnly( Prj().GetProjectFullName() );
wxFileDialog dlg( this, _( "Load Component-Footprint Link File" ),
path, wxEmptyString,

View File

@ -109,12 +109,12 @@ bool LIB_EDIT_FRAME::HandleBlockEnd( wxDC* DC )
DisplayError( this, wxT( "Error in HandleBlockPLace" ) );
break;
case BLOCK_DRAG:
case BLOCK_DRAG: // Drag
case BLOCK_DRAG_ITEM:
case BLOCK_MOVE:
case BLOCK_COPY:
if ( m_component )
ItemCount = m_component->SelectItems( GetScreen()->m_BlockLocate,
case BLOCK_MOVE: // Move
case BLOCK_COPY: // Copy
if( GetCurPart() )
ItemCount = GetCurPart()->SelectItems( GetScreen()->m_BlockLocate,
m_unit, m_convert,
m_editPinsPerPartOrConvert );
if( ItemCount )
@ -139,57 +139,56 @@ bool LIB_EDIT_FRAME::HandleBlockEnd( wxDC* DC )
GetScreen()->m_BlockLocate.SetState( STATE_BLOCK_MOVE );
break;
case BLOCK_DELETE: /* Delete */
if ( m_component )
ItemCount = m_component->SelectItems( GetScreen()->m_BlockLocate,
case BLOCK_DELETE: // Delete
if( GetCurPart() )
ItemCount = GetCurPart()->SelectItems( GetScreen()->m_BlockLocate,
m_unit, m_convert,
m_editPinsPerPartOrConvert );
if( ItemCount )
SaveCopyInUndoList( m_component );
SaveCopyInUndoList( GetCurPart() );
if ( m_component )
if( GetCurPart() )
{
m_component->DeleteSelectedItems();
GetCurPart()->DeleteSelectedItems();
OnModify();
}
break;
case BLOCK_SAVE: /* Save */
case BLOCK_SAVE: // Save
case BLOCK_PASTE:
case BLOCK_FLIP:
break;
case BLOCK_ROTATE:
case BLOCK_MIRROR_X:
case BLOCK_MIRROR_Y:
if ( m_component )
ItemCount = m_component->SelectItems( GetScreen()->m_BlockLocate,
if( GetCurPart() )
ItemCount = GetCurPart()->SelectItems( GetScreen()->m_BlockLocate,
m_unit, m_convert,
m_editPinsPerPartOrConvert );
if( ItemCount )
SaveCopyInUndoList( m_component );
SaveCopyInUndoList( GetCurPart() );
pt = GetScreen()->m_BlockLocate.Centre();
pt = GetNearestGridPosition( pt );
NEGATE( pt.y );
if ( m_component )
if( GetCurPart() )
{
OnModify();
int block_cmd = GetScreen()->m_BlockLocate.GetCommand();
if( block_cmd == BLOCK_MIRROR_Y)
m_component->MirrorSelectedItemsH( pt );
GetCurPart()->MirrorSelectedItemsH( pt );
else if( block_cmd == BLOCK_MIRROR_X)
m_component->MirrorSelectedItemsV( pt );
GetCurPart()->MirrorSelectedItemsV( pt );
else if( block_cmd == BLOCK_ROTATE )
m_component->RotateSelectedItems( pt );
GetCurPart()->RotateSelectedItems( pt );
}
break;
case BLOCK_ZOOM: /* Window Zoom */
case BLOCK_ZOOM: // Window Zoom
Window_Zoom( GetScreen()->m_BlockLocate );
break;
@ -200,10 +199,10 @@ bool LIB_EDIT_FRAME::HandleBlockEnd( wxDC* DC )
break;
}
if( ! nextCmd )
if( !nextCmd )
{
if( GetScreen()->m_BlockLocate.GetCommand() != BLOCK_SELECT_ITEMS_ONLY && m_component )
m_component->ClearSelectedItems();
if( GetScreen()->m_BlockLocate.GetCommand() != BLOCK_SELECT_ITEMS_ONLY && GetCurPart() )
GetCurPart()->ClearSelectedItems();
GetScreen()->m_BlockLocate.SetState( STATE_NO_BLOCK );
GetScreen()->m_BlockLocate.SetCommand( BLOCK_IDLE );
@ -233,62 +232,62 @@ void LIB_EDIT_FRAME::HandleBlockPlace( wxDC* DC )
case BLOCK_IDLE:
break;
case BLOCK_DRAG:
case BLOCK_DRAG: // Drag
case BLOCK_DRAG_ITEM:
case BLOCK_MOVE:
case BLOCK_PRESELECT_MOVE: /* Move with preselection list*/
case BLOCK_MOVE: // Move
case BLOCK_PRESELECT_MOVE: // Move with preselection list
GetScreen()->m_BlockLocate.ClearItemsList();
if ( m_component )
SaveCopyInUndoList( m_component );
if( GetCurPart() )
SaveCopyInUndoList( GetCurPart() );
pt = GetScreen()->m_BlockLocate.GetMoveVector();
pt.y *= -1;
if ( m_component )
m_component->MoveSelectedItems( pt );
if( GetCurPart() )
GetCurPart()->MoveSelectedItems( pt );
m_canvas->Refresh( true );
break;
case BLOCK_COPY: /* Copy */
case BLOCK_COPY: // Copy
GetScreen()->m_BlockLocate.ClearItemsList();
if ( m_component )
SaveCopyInUndoList( m_component );
if( GetCurPart() )
SaveCopyInUndoList( GetCurPart() );
pt = GetScreen()->m_BlockLocate.GetMoveVector();
NEGATE( pt.y );
if ( m_component )
m_component->CopySelectedItems( pt );
if( GetCurPart() )
GetCurPart()->CopySelectedItems( pt );
break;
case BLOCK_PASTE: /* Paste (recopy the last block saved) */
case BLOCK_PASTE: // Paste (recopy the last block saved)
GetScreen()->m_BlockLocate.ClearItemsList();
break;
case BLOCK_ROTATE: // Invert by popup menu, from block move
case BLOCK_MIRROR_X: // Invert by popup menu, from block move
case BLOCK_MIRROR_Y: // Invert by popup menu, from block move
if ( m_component )
SaveCopyInUndoList( m_component );
if( GetCurPart() )
SaveCopyInUndoList( GetCurPart() );
pt = GetScreen()->m_BlockLocate.Centre();
pt = GetNearestGridPosition( pt );
NEGATE( pt.y );
if ( m_component )
if( GetCurPart() )
{
int block_cmd = GetScreen()->m_BlockLocate.GetCommand();
if( block_cmd == BLOCK_MIRROR_Y)
m_component->MirrorSelectedItemsH( pt );
GetCurPart()->MirrorSelectedItemsH( pt );
else if( block_cmd == BLOCK_MIRROR_X)
m_component->MirrorSelectedItemsV( pt );
GetCurPart()->MirrorSelectedItemsV( pt );
else if( block_cmd == BLOCK_ROTATE )
m_component->RotateSelectedItems( pt );
GetCurPart()->RotateSelectedItems( pt );
}
break;
@ -326,7 +325,7 @@ void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint&
LIB_EDIT_FRAME* parent = (LIB_EDIT_FRAME*) aPanel->GetParent();
wxASSERT( parent != NULL );
LIB_COMPONENT* component = parent->GetComponent();
LIB_PART* component = parent->GetCurPart();
if( component == NULL )
return;

View File

@ -51,36 +51,30 @@
#include <boost/foreach.hpp>
// Set this to 1 to print debugging output in alias and component destructors to verify
// objects get cleaned up properly.
#if defined( TRACE_DESTRUCTOR )
#undef TRACE_DESTRUCTOR
#endif
#define TRACE_DESTRUCTOR 0
// the separator char between the subpart id and the reference
// 0 (no separator) or '.' or some other character
int LIB_COMPONENT::m_subpartIdSeparator = 0;
int LIB_PART::m_subpartIdSeparator = 0;
// the ascii char value to calculate the subpart symbol id from the part number:
// 'A' or '1' usually. (to print U1.A or U1.1)
// if this a a digit, a number is used as id symbol
int LIB_COMPONENT::m_subpartFirstId = 'A';
int LIB_PART::m_subpartFirstId = 'A';
LIB_ALIAS::LIB_ALIAS( const wxString& aName, LIB_COMPONENT* aRootComponent ):
EDA_ITEM( LIB_ALIAS_T )
LIB_ALIAS::LIB_ALIAS( const wxString& aName, LIB_PART* aRootPart ):
EDA_ITEM( LIB_ALIAS_T ),
shared( aRootPart )
{
root = aRootComponent;
name = aName;
}
LIB_ALIAS::LIB_ALIAS( const LIB_ALIAS& aAlias, LIB_COMPONENT* aRootComponent ) :
EDA_ITEM( aAlias )
LIB_ALIAS::LIB_ALIAS( const LIB_ALIAS& aAlias, LIB_PART* aRootPart ) :
EDA_ITEM( aAlias ),
shared( aRootPart )
{
name = aAlias.name;
root = aRootComponent;
name = aAlias.name;
description = aAlias.description;
keyWords = aAlias.keyWords;
docFileName = aAlias.docFileName;
@ -89,17 +83,24 @@ LIB_ALIAS::LIB_ALIAS( const LIB_ALIAS& aAlias, LIB_COMPONENT* aRootComponent ) :
LIB_ALIAS::~LIB_ALIAS()
{
#if TRACE_DESTRUCTOR
wxLogDebug( wxT( "Destroying alias \"%s\" of component \"%s\" with alias list count %d." ),
GetChars( name ), GetChars( root->GetName() ), root->m_aliases.size() );
wxASSERT_MSG( shared, wxT( "~LIB_ALIAS() without a LIB_PART" ) );
#if defined(DEBUG) && 1
printf( "%s: destroying alias:'%s' of part:'%s' alias count:%zd.\n",
__func__, TO_UTF8( name ), TO_UTF8( shared->GetName() ), shared->m_aliases.size() );
#endif
if( shared )
shared->RemoveAlias( this );
}
wxString LIB_ALIAS::GetLibraryName()
const wxString LIB_ALIAS::GetLibraryName()
{
if( GetComponent() )
return GetComponent()->GetLibraryName();
wxASSERT_MSG( shared, wxT( "LIB_ALIAS without a LIB_PART" ) );
if( shared )
return shared->GetLibraryName();
return wxString( _( "none" ) );
}
@ -107,12 +108,13 @@ wxString LIB_ALIAS::GetLibraryName()
bool LIB_ALIAS::IsRoot() const
{
return name.CmpNoCase( root->GetName() ) == 0;
return Cmp_KEEPCASE( name, shared->GetName() ) == 0;
}
CMP_LIBRARY* LIB_ALIAS::GetLibrary()
PART_LIB* LIB_ALIAS::GetLib()
{
return root->GetLibrary();
return shared->GetLib();
}
@ -147,24 +149,34 @@ bool LIB_ALIAS::SaveDoc( OUTPUTFORMATTER& aFormatter )
bool LIB_ALIAS::operator==( const wxChar* aName ) const
{
return name.CmpNoCase( aName ) == 0;
return Cmp_KEEPCASE( name, aName ) == 0;
}
bool operator<( const LIB_ALIAS& aItem1, const LIB_ALIAS& aItem2 )
{
return aItem1.GetName().CmpNoCase( aItem2.GetName() ) < 0;
return Cmp_KEEPCASE( aItem1.GetName(), aItem2.GetName() ) < 0;
}
int LibraryEntryCompare( const LIB_ALIAS* aItem1, const LIB_ALIAS* aItem2 )
{
return aItem1->GetName().CmpNoCase( aItem2->GetName() );
return Cmp_KEEPCASE( aItem1->GetName(), aItem2->GetName() );
}
LIB_COMPONENT::LIB_COMPONENT( const wxString& aName, CMP_LIBRARY* aLibrary ) :
EDA_ITEM( LIB_COMPONENT_T )
/// http://www.boost.org/doc/libs/1_55_0/libs/smart_ptr/sp_techniques.html#weak_without_shared
struct null_deleter
{
void operator()(void const *) const
{
}
};
LIB_PART::LIB_PART( const wxString& aName, PART_LIB* aLibrary ) :
EDA_ITEM( LIB_PART_T ),
m_me( this, null_deleter() )
{
m_name = aName;
m_library = aLibrary;
@ -192,23 +204,24 @@ LIB_COMPONENT::LIB_COMPONENT( const wxString& aName, CMP_LIBRARY* aLibrary ) :
}
LIB_COMPONENT::LIB_COMPONENT( LIB_COMPONENT& aComponent, CMP_LIBRARY* aLibrary ) :
EDA_ITEM( aComponent )
LIB_PART::LIB_PART( LIB_PART& aPart, PART_LIB* aLibrary ) :
EDA_ITEM( aPart ),
m_me( this, null_deleter() )
{
LIB_ITEM* newItem;
m_library = aLibrary;
m_name = aComponent.m_name;
m_FootprintList = aComponent.m_FootprintList;
m_unitCount = aComponent.m_unitCount;
m_unitsLocked = aComponent.m_unitsLocked;
m_pinNameOffset = aComponent.m_pinNameOffset;
m_showPinNumbers = aComponent.m_showPinNumbers;
m_showPinNames = aComponent.m_showPinNames;
m_dateModified = aComponent.m_dateModified;
m_options = aComponent.m_options;
m_name = aPart.m_name;
m_FootprintList = aPart.m_FootprintList;
m_unitCount = aPart.m_unitCount;
m_unitsLocked = aPart.m_unitsLocked;
m_pinNameOffset = aPart.m_pinNameOffset;
m_showPinNumbers = aPart.m_showPinNumbers;
m_showPinNames = aPart.m_showPinNames;
m_dateModified = aPart.m_dateModified;
m_options = aPart.m_options;
BOOST_FOREACH( LIB_ITEM& oldItem, aComponent.GetDrawItemList() )
BOOST_FOREACH( LIB_ITEM& oldItem, aPart.GetDrawItemList() )
{
if( oldItem.IsNew() )
continue;
@ -218,47 +231,49 @@ LIB_COMPONENT::LIB_COMPONENT( LIB_COMPONENT& aComponent, CMP_LIBRARY* aLibrary )
drawings.push_back( newItem );
}
for( size_t i = 0; i < aComponent.m_aliases.size(); i++ )
for( size_t i = 0; i < aPart.m_aliases.size(); i++ )
{
LIB_ALIAS* alias = new LIB_ALIAS( *aComponent.m_aliases[i], this );
LIB_ALIAS* alias = new LIB_ALIAS( *aPart.m_aliases[i], this );
m_aliases.push_back( alias );
}
}
LIB_COMPONENT::~LIB_COMPONENT()
LIB_PART::~LIB_PART()
{
#if TRACE_DESTRUCTOR
wxLogDebug( wxT( "Destroying component <%s> with alias list count of %d" ),
GetChars( GetName() ), m_aliases.size() );
#if defined(DEBUG) && 1
if( m_aliases.size() )
{
int breakhere = 1;
(void) breakhere;
}
printf( "%s: destroying part '%s' with alias list count of %zd\n",
__func__, TO_UTF8( GetName() ), m_aliases.size() );
#endif
// If the component is being delete directly rather than trough the library, free all
// of the memory allocated by the aliases.
if( !m_aliases.empty() )
// If the part is being deleted directly rather than through the library,
// delete all of the aliases.
while( m_aliases.size() )
{
LIB_ALIAS* alias;
while( !m_aliases.empty() )
{
alias = m_aliases.back();
m_aliases.pop_back();
delete alias;
}
LIB_ALIAS* alias = m_aliases.back();
m_aliases.pop_back();
delete alias;
}
}
wxString LIB_COMPONENT::GetLibraryName()
const wxString LIB_PART::GetLibraryName()
{
if( m_library != NULL )
if( m_library )
return m_library->GetName();
return wxString( _( "none" ) );
}
wxString LIB_COMPONENT::SubReference( int aUnit, bool aAddSeparator )
wxString LIB_PART::SubReference( int aUnit, bool aAddSeparator )
{
wxString subRef;
@ -274,7 +289,7 @@ wxString LIB_COMPONENT::SubReference( int aUnit, bool aAddSeparator )
}
void LIB_COMPONENT::SetName( const wxString& aName )
void LIB_PART::SetName( const wxString& aName )
{
m_name = aName;
GetValueField().SetText( aName );
@ -282,7 +297,7 @@ void LIB_COMPONENT::SetName( const wxString& aName )
}
void LIB_COMPONENT::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDc, const wxPoint& aOffset, int aMulti,
void LIB_PART::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDc, const wxPoint& aOffset, int aMulti,
int aConvert, GR_DRAWMODE aDrawMode, EDA_COLOR_T aColor, const TRANSFORM& aTransform,
bool aShowPinText, bool aDrawFields, bool aOnlySelected )
{
@ -390,7 +405,7 @@ void LIB_COMPONENT::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDc, const wxPoint& aOff
}
void LIB_COMPONENT::Plot( PLOTTER* aPlotter, int aUnit, int aConvert,
void LIB_PART::Plot( PLOTTER* aPlotter, int aUnit, int aConvert,
const wxPoint& aOffset, const TRANSFORM& aTransform )
{
wxASSERT( aPlotter != NULL );
@ -415,7 +430,7 @@ void LIB_COMPONENT::Plot( PLOTTER* aPlotter, int aUnit, int aConvert,
}
}
void LIB_COMPONENT::PlotLibFields( PLOTTER* aPlotter, int aUnit, int aConvert,
void LIB_PART::PlotLibFields( PLOTTER* aPlotter, int aUnit, int aConvert,
const wxPoint& aOffset, const TRANSFORM& aTransform )
{
wxASSERT( aPlotter != NULL );
@ -449,7 +464,7 @@ void LIB_COMPONENT::PlotLibFields( PLOTTER* aPlotter, int aUnit, int aConvert,
}
void LIB_COMPONENT::RemoveDrawItem( LIB_ITEM* aItem, EDA_DRAW_PANEL* aPanel, wxDC* aDc )
void LIB_PART::RemoveDrawItem( LIB_ITEM* aItem, EDA_DRAW_PANEL* aPanel, wxDC* aDc )
{
wxASSERT( aItem != NULL );
@ -461,10 +476,10 @@ void LIB_COMPONENT::RemoveDrawItem( LIB_ITEM* aItem, EDA_DRAW_PANEL* aPanel, wxD
if( field->GetId() < MANDATORY_FIELDS )
{
wxLogWarning( _( "An attempt was made to remove the %s field \
from component %s in library %s." ),
GetChars( field->GetName() ), GetChars( GetName() ),
GetChars( GetLibraryName() ) );
wxLogWarning( _(
"An attempt was made to remove the %s field from component %s in library %s." ),
GetChars( field->GetName() ), GetChars( GetName() ),
GetChars( GetLibraryName() ) );
return;
}
}
@ -486,7 +501,7 @@ from component %s in library %s." ),
}
void LIB_COMPONENT::AddDrawItem( LIB_ITEM* aItem )
void LIB_PART::AddDrawItem( LIB_ITEM* aItem )
{
wxASSERT( aItem != NULL );
@ -495,7 +510,7 @@ void LIB_COMPONENT::AddDrawItem( LIB_ITEM* aItem )
}
LIB_ITEM* LIB_COMPONENT::GetNextDrawItem( LIB_ITEM* aItem, KICAD_T aType )
LIB_ITEM* LIB_PART::GetNextDrawItem( LIB_ITEM* aItem, KICAD_T aType )
{
/* Return the next draw object pointer.
* If item is NULL return the first item of type in the list.
@ -532,7 +547,7 @@ LIB_ITEM* LIB_COMPONENT::GetNextDrawItem( LIB_ITEM* aItem, KICAD_T aType )
}
void LIB_COMPONENT::GetPins( LIB_PINS& aList, int aUnit, int aConvert )
void LIB_PART::GetPins( LIB_PINS& aList, int aUnit, int aConvert )
{
/* Notes:
* when aUnit == 0: no unit filtering
@ -558,7 +573,7 @@ void LIB_COMPONENT::GetPins( LIB_PINS& aList, int aUnit, int aConvert )
}
LIB_PIN* LIB_COMPONENT::GetPin( const wxString& aNumber, int aUnit, int aConvert )
LIB_PIN* LIB_PART::GetPin( const wxString& aNumber, int aUnit, int aConvert )
{
wxString pNumber;
LIB_PINS pinList;
@ -579,7 +594,7 @@ LIB_PIN* LIB_COMPONENT::GetPin( const wxString& aNumber, int aUnit, int aConvert
}
bool LIB_COMPONENT::Save( OUTPUTFORMATTER& aFormatter )
bool LIB_PART::Save( OUTPUTFORMATTER& aFormatter )
{
LIB_FIELD& value = GetValueField();
@ -714,7 +729,7 @@ bool LIB_COMPONENT::Save( OUTPUTFORMATTER& aFormatter )
}
bool LIB_COMPONENT::Load( LINE_READER& aLineReader, wxString& aErrorMsg )
bool LIB_PART::Load( LINE_READER& aLineReader, wxString& aErrorMsg )
{
int unused;
char* p;
@ -866,7 +881,7 @@ ok:
}
bool LIB_COMPONENT::LoadDrawEntries( LINE_READER& aLineReader, wxString& aErrorMsg )
bool LIB_PART::LoadDrawEntries( LINE_READER& aLineReader, wxString& aErrorMsg )
{
char* line;
LIB_ITEM* newEntry = NULL;
@ -914,8 +929,8 @@ bool LIB_COMPONENT::LoadDrawEntries( LINE_READER& aLineReader, wxString& aErrorM
newEntry = ( LIB_ITEM* ) new LIB_BEZIER( this );
break;
case '#': // Comment
continue;
case '#': // Comment
continue;
default:
aErrorMsg.Printf( wxT( "undefined DRAW command %c" ), line[0] );
@ -924,7 +939,7 @@ bool LIB_COMPONENT::LoadDrawEntries( LINE_READER& aLineReader, wxString& aErrorM
if( !newEntry->Load( aLineReader, aErrorMsg ) )
{
aErrorMsg.Printf( wxT( "error <%s> in DRAW command %c" ),
aErrorMsg.Printf( wxT( "error '%s' in DRAW command %c" ),
GetChars( aErrorMsg ), line[0] );
delete newEntry;
@ -951,7 +966,7 @@ bool LIB_COMPONENT::LoadDrawEntries( LINE_READER& aLineReader, wxString& aErrorM
}
bool LIB_COMPONENT::LoadAliases( char* aLine, wxString& aErrorMsg )
bool LIB_PART::LoadAliases( char* aLine, wxString& aErrorMsg )
{
char* text = strtok( aLine, " \t\r\n" );
@ -965,7 +980,7 @@ bool LIB_COMPONENT::LoadAliases( char* aLine, wxString& aErrorMsg )
}
bool LIB_COMPONENT::LoadField( LINE_READER& aLineReader, wxString& aErrorMsg )
bool LIB_PART::LoadField( LINE_READER& aLineReader, wxString& aErrorMsg )
{
LIB_FIELD* field = new LIB_FIELD( this );
@ -1000,7 +1015,7 @@ bool LIB_COMPONENT::LoadField( LINE_READER& aLineReader, wxString& aErrorMsg )
}
bool LIB_COMPONENT::LoadFootprints( LINE_READER& aLineReader, wxString& aErrorMsg )
bool LIB_PART::LoadFootprints( LINE_READER& aLineReader, wxString& aErrorMsg )
{
char* line;
char* p;
@ -1025,7 +1040,7 @@ bool LIB_COMPONENT::LoadFootprints( LINE_READER& aLineReader, wxString& aErrorMs
}
EDA_RECT LIB_COMPONENT::GetBoundingBox( int aUnit, int aConvert ) const
EDA_RECT LIB_PART::GetBoundingBox( int aUnit, int aConvert ) const
{
EDA_RECT bBox( wxPoint( 0, 0 ), wxSize( 0, 0 ) );
@ -1050,7 +1065,7 @@ EDA_RECT LIB_COMPONENT::GetBoundingBox( int aUnit, int aConvert ) const
}
EDA_RECT LIB_COMPONENT::GetBodyBoundingBox( int aUnit, int aConvert ) const
EDA_RECT LIB_PART::GetBodyBoundingBox( int aUnit, int aConvert ) const
{
EDA_RECT bBox( wxPoint( 0, 0 ), wxSize( 0, 0 ) );
@ -1075,7 +1090,7 @@ EDA_RECT LIB_COMPONENT::GetBodyBoundingBox( int aUnit, int aConvert ) const
}
void LIB_COMPONENT::deleteAllFields()
void LIB_PART::deleteAllFields()
{
LIB_ITEMS::iterator it;
@ -1093,7 +1108,7 @@ void LIB_COMPONENT::deleteAllFields()
}
void LIB_COMPONENT::SetFields( const std::vector <LIB_FIELD>& aFields )
void LIB_PART::SetFields( const std::vector <LIB_FIELD>& aFields )
{
deleteAllFields();
@ -1111,7 +1126,7 @@ void LIB_COMPONENT::SetFields( const std::vector <LIB_FIELD>& aFields )
}
void LIB_COMPONENT::GetFields( LIB_FIELDS& aList )
void LIB_PART::GetFields( LIB_FIELDS& aList )
{
LIB_FIELD* field;
@ -1146,7 +1161,7 @@ void LIB_COMPONENT::GetFields( LIB_FIELDS& aList )
}
LIB_FIELD* LIB_COMPONENT::GetField( int aId )
LIB_FIELD* LIB_PART::GetField( int aId )
{
BOOST_FOREACH( LIB_ITEM& item, drawings )
{
@ -1163,7 +1178,7 @@ LIB_FIELD* LIB_COMPONENT::GetField( int aId )
}
LIB_FIELD* LIB_COMPONENT::FindField( const wxString& aFieldName )
LIB_FIELD* LIB_PART::FindField( const wxString& aFieldName )
{
BOOST_FOREACH( LIB_ITEM& item, drawings )
{
@ -1180,7 +1195,7 @@ LIB_FIELD* LIB_COMPONENT::FindField( const wxString& aFieldName )
}
LIB_FIELD& LIB_COMPONENT::GetValueField()
LIB_FIELD& LIB_PART::GetValueField()
{
LIB_FIELD* field = GetField( VALUE );
wxASSERT( field != NULL );
@ -1188,7 +1203,7 @@ LIB_FIELD& LIB_COMPONENT::GetValueField()
}
LIB_FIELD& LIB_COMPONENT::GetReferenceField()
LIB_FIELD& LIB_PART::GetReferenceField()
{
LIB_FIELD* field = GetField( REFERENCE );
wxASSERT( field != NULL );
@ -1196,7 +1211,7 @@ LIB_FIELD& LIB_COMPONENT::GetReferenceField()
}
bool LIB_COMPONENT::SaveDateAndTime( OUTPUTFORMATTER& aFormatter )
bool LIB_PART::SaveDateAndTime( OUTPUTFORMATTER& aFormatter )
{
int year, mon, day, hour, min, sec;
@ -1216,7 +1231,7 @@ bool LIB_COMPONENT::SaveDateAndTime( OUTPUTFORMATTER& aFormatter )
}
bool LIB_COMPONENT::LoadDateAndTime( char* aLine )
bool LIB_PART::LoadDateAndTime( char* aLine )
{
int year, mon, day, hour, min, sec;
@ -1235,7 +1250,7 @@ bool LIB_COMPONENT::LoadDateAndTime( char* aLine )
}
void LIB_COMPONENT::SetOffset( const wxPoint& aOffset )
void LIB_PART::SetOffset( const wxPoint& aOffset )
{
BOOST_FOREACH( LIB_ITEM& item, drawings )
{
@ -1244,13 +1259,13 @@ void LIB_COMPONENT::SetOffset( const wxPoint& aOffset )
}
void LIB_COMPONENT::RemoveDuplicateDrawItems()
void LIB_PART::RemoveDuplicateDrawItems()
{
drawings.unique();
}
bool LIB_COMPONENT::HasConversion() const
bool LIB_PART::HasConversion() const
{
for( unsigned ii = 0; ii < drawings.size(); ii++ )
{
@ -1263,7 +1278,7 @@ bool LIB_COMPONENT::HasConversion() const
}
void LIB_COMPONENT::ClearStatus()
void LIB_PART::ClearStatus()
{
BOOST_FOREACH( LIB_ITEM& item, drawings )
{
@ -1272,7 +1287,7 @@ void LIB_COMPONENT::ClearStatus()
}
int LIB_COMPONENT::SelectItems( EDA_RECT& aRect, int aUnit, int aConvert, bool aEditPinByPin )
int LIB_PART::SelectItems( EDA_RECT& aRect, int aUnit, int aConvert, bool aEditPinByPin )
{
int itemCount = 0;
@ -1303,7 +1318,7 @@ int LIB_COMPONENT::SelectItems( EDA_RECT& aRect, int aUnit, int aConvert, bool a
}
void LIB_COMPONENT::MoveSelectedItems( const wxPoint& aOffset )
void LIB_PART::MoveSelectedItems( const wxPoint& aOffset )
{
BOOST_FOREACH( LIB_ITEM& item, drawings )
{
@ -1318,7 +1333,7 @@ void LIB_COMPONENT::MoveSelectedItems( const wxPoint& aOffset )
}
void LIB_COMPONENT::ClearSelectedItems()
void LIB_PART::ClearSelectedItems()
{
BOOST_FOREACH( LIB_ITEM& item, drawings )
{
@ -1327,7 +1342,7 @@ void LIB_COMPONENT::ClearSelectedItems()
}
void LIB_COMPONENT::DeleteSelectedItems()
void LIB_PART::DeleteSelectedItems()
{
LIB_ITEMS::iterator item = drawings.begin();
@ -1357,7 +1372,7 @@ void LIB_COMPONENT::DeleteSelectedItems()
}
void LIB_COMPONENT::CopySelectedItems( const wxPoint& aOffset )
void LIB_PART::CopySelectedItems( const wxPoint& aOffset )
{
/* *do not* use iterators here, because new items
* are added to drawings that is a boost::ptr_vector.
@ -1390,7 +1405,7 @@ void LIB_COMPONENT::CopySelectedItems( const wxPoint& aOffset )
void LIB_COMPONENT::MirrorSelectedItemsH( const wxPoint& aCenter )
void LIB_PART::MirrorSelectedItemsH( const wxPoint& aCenter )
{
BOOST_FOREACH( LIB_ITEM& item, drawings )
{
@ -1404,7 +1419,7 @@ void LIB_COMPONENT::MirrorSelectedItemsH( const wxPoint& aCenter )
drawings.sort();
}
void LIB_COMPONENT::MirrorSelectedItemsV( const wxPoint& aCenter )
void LIB_PART::MirrorSelectedItemsV( const wxPoint& aCenter )
{
BOOST_FOREACH( LIB_ITEM& item, drawings )
{
@ -1418,7 +1433,7 @@ void LIB_COMPONENT::MirrorSelectedItemsV( const wxPoint& aCenter )
drawings.sort();
}
void LIB_COMPONENT::RotateSelectedItems( const wxPoint& aCenter )
void LIB_PART::RotateSelectedItems( const wxPoint& aCenter )
{
BOOST_FOREACH( LIB_ITEM& item, drawings )
{
@ -1434,7 +1449,7 @@ void LIB_COMPONENT::RotateSelectedItems( const wxPoint& aCenter )
LIB_ITEM* LIB_COMPONENT::LocateDrawItem( int aUnit, int aConvert,
LIB_ITEM* LIB_PART::LocateDrawItem( int aUnit, int aConvert,
KICAD_T aType, const wxPoint& aPoint )
{
BOOST_FOREACH( LIB_ITEM& item, drawings )
@ -1452,7 +1467,7 @@ LIB_ITEM* LIB_COMPONENT::LocateDrawItem( int aUnit, int aConvert,
}
LIB_ITEM* LIB_COMPONENT::LocateDrawItem( int aUnit, int aConvert, KICAD_T aType,
LIB_ITEM* LIB_PART::LocateDrawItem( int aUnit, int aConvert, KICAD_T aType,
const wxPoint& aPoint, const TRANSFORM& aTransform )
{
/* we use LocateDrawItem( int aUnit, int convert, KICAD_T type, const
@ -1473,7 +1488,7 @@ LIB_ITEM* LIB_COMPONENT::LocateDrawItem( int aUnit, int aConvert, KICAD_T aType,
}
void LIB_COMPONENT::SetPartCount( int aCount )
void LIB_PART::SetUnitCount( int aCount )
{
if( m_unitCount == aCount )
return;
@ -1520,7 +1535,7 @@ void LIB_COMPONENT::SetPartCount( int aCount )
}
void LIB_COMPONENT::SetConversion( bool aSetConvert )
void LIB_PART::SetConversion( bool aSetConvert )
{
if( aSetConvert == HasConversion() )
return;
@ -1559,7 +1574,7 @@ void LIB_COMPONENT::SetConversion( bool aSetConvert )
}
wxArrayString LIB_COMPONENT::GetAliasNames( bool aIncludeRoot ) const
wxArrayString LIB_PART::GetAliasNames( bool aIncludeRoot ) const
{
wxArrayString names;
@ -1577,14 +1592,14 @@ wxArrayString LIB_COMPONENT::GetAliasNames( bool aIncludeRoot ) const
}
bool LIB_COMPONENT::HasAlias( const wxString& aName ) const
bool LIB_PART::HasAlias( const wxString& aName ) const
{
wxCHECK2_MSG( !aName.IsEmpty(), return false,
wxT( "Cannot get alias with an empty name, bad programmer." ) );
for( size_t i = 0; i < m_aliases.size(); i++ )
{
if( aName.CmpNoCase( m_aliases[i]->GetName() ) == 0 )
if( Cmp_KEEPCASE( aName, m_aliases[i]->GetName() ) == 0 )
return true;
}
@ -1592,10 +1607,10 @@ bool LIB_COMPONENT::HasAlias( const wxString& aName ) const
}
void LIB_COMPONENT::SetAliases( const wxArrayString& aAliasList )
void LIB_PART::SetAliases( const wxArrayString& aAliasList )
{
wxCHECK_RET( m_library == NULL,
wxT( "Component aliases cannot be changed when they are owned by a library." ) );
wxCHECK_RET( !m_library,
wxT( "Part aliases cannot be changed when they are owned by a library." ) );
if( aAliasList == GetAliasNames() )
return;
@ -1624,17 +1639,19 @@ void LIB_COMPONENT::SetAliases( const wxArrayString& aAliasList )
}
void LIB_COMPONENT::RemoveAlias( const wxString& aName )
#if 0 // this version looked suspect to me, it did not rename a deleted root
void LIB_PART::RemoveAlias( const wxString& aName )
{
wxCHECK_RET( m_library == NULL,
wxT( "Component aliases cannot be changed when they are owned by a library." ) );
wxT( "Part aliases cannot be changed when they are owned by a library." ) );
wxCHECK_RET( !aName.IsEmpty(), wxT( "Cannot get alias with an empty name." ) );
LIB_ALIASES::iterator it;
for( it = m_aliases.begin(); it < m_aliases.end(); it++ )
{
if( aName.CmpNoCase( (*it)->GetName() ) == 0 )
if( Cmp_KEEPCASE( aName, (*it)->GetName() ) == 0 )
{
m_aliases.erase( it );
break;
@ -1642,39 +1659,53 @@ void LIB_COMPONENT::RemoveAlias( const wxString& aName )
}
}
LIB_ALIAS* LIB_COMPONENT::RemoveAlias( LIB_ALIAS* aAlias )
#else
void LIB_PART::RemoveAlias( const wxString& aName )
{
wxCHECK_MSG( aAlias != NULL, NULL, wxT( "Cannot remove alias by NULL pointer." ) );
LIB_ALIAS* a = GetAlias( aName );
if( a )
RemoveAlias( a );
}
#endif
LIB_ALIAS* LIB_PART::RemoveAlias( LIB_ALIAS* aAlias )
{
wxCHECK_MSG( aAlias, NULL, wxT( "Cannot remove alias by NULL pointer." ) );
LIB_ALIAS* nextAlias = NULL;
LIB_ALIASES::iterator it = find( m_aliases.begin(), m_aliases.end(), aAlias );
if( it != m_aliases.end() )
{
bool rename = aAlias->IsRoot();
DBG( printf( "%s: part:'%s' alias:'%s'\n", __func__,
TO_UTF8( m_name ),
TO_UTF8( aAlias->GetName() )
);)
it = m_aliases.erase( it );
delete aAlias;
if( !m_aliases.empty() )
{
if( it == m_aliases.end() )
it = m_aliases.begin();
nextAlias = (*it);
nextAlias = *it;
if( rename )
SetName( nextAlias->GetName() );
}
}
return nextAlias;
}
void LIB_COMPONENT::RemoveAllAliases()
void LIB_PART::RemoveAllAliases()
{
// Remove all of the aliases except the root alias.
while( m_aliases.size() > 1 )
@ -1682,14 +1713,14 @@ void LIB_COMPONENT::RemoveAllAliases()
}
LIB_ALIAS* LIB_COMPONENT::GetAlias( const wxString& aName )
LIB_ALIAS* LIB_PART::GetAlias( const wxString& aName )
{
wxCHECK2_MSG( !aName.IsEmpty(), return NULL,
wxT( "Cannot get alias with an empty name. Bad programmer!" ) );
for( size_t i = 0; i < m_aliases.size(); i++ )
{
if( aName.CmpNoCase( m_aliases[i]->GetName() ) == 0 )
if( Cmp_KEEPCASE( aName, m_aliases[i]->GetName() ) == 0 )
return m_aliases[i];
}
@ -1697,7 +1728,7 @@ LIB_ALIAS* LIB_COMPONENT::GetAlias( const wxString& aName )
}
LIB_ALIAS* LIB_COMPONENT::GetAlias( size_t aIndex )
LIB_ALIAS* LIB_PART::GetAlias( size_t aIndex )
{
wxCHECK2_MSG( aIndex < m_aliases.size(), return NULL,
wxT( "Illegal alias list index, bad programmer." ) );
@ -1706,10 +1737,10 @@ LIB_ALIAS* LIB_COMPONENT::GetAlias( size_t aIndex )
}
void LIB_COMPONENT::AddAlias( const wxString& aName )
void LIB_PART::AddAlias( const wxString& aName )
{
wxCHECK_RET( !HasAlias( aName ),
wxT( "Component <" ) + GetName() + wxT( "> already has an alias <" ) +
wxT( "Part <" ) + GetName() + wxT( "> already has an alias <" ) +
aName + wxT( ">. Bad programmer." ) );
m_aliases.push_back( new LIB_ALIAS( aName, this ) );
@ -1725,7 +1756,7 @@ void LIB_COMPONENT::AddAlias( const wxString& aName )
* @param aSep = the separator symbol (0 (no separator) or '.' , '-' and '_')
* @param aFirstId = the Id of the first part ('A' or '1')
*/
void LIB_COMPONENT::SetSubpartIdNotation( int aSep, int aFirstId )
void LIB_PART::SetSubpartIdNotation( int aSep, int aFirstId )
{
m_subpartFirstId = 'A';
m_subpartIdSeparator = 0;

View File

@ -33,15 +33,13 @@
#include <general.h>
#include <lib_draw_item.h>
#include <lib_field.h>
#include <map>
#include <boost/shared_ptr.hpp>
class LINE_READER;
class OUTPUTFORMATTER;
class CMP_LIBRARY;
class PART_LIB;
class LIB_ALIAS;
class LIB_COMPONENT;
class LIB_PART;
class LIB_FIELD;
@ -58,65 +56,50 @@ inline int Cmp_KEEPCASE( const wxString& aString1, const wxString& aString2 )
}
/**
* LIB_ALIAS map sorting.
*/
struct AliasMapSort
{
bool operator() ( const wxString& aItem1, const wxString& aItem2 ) const
{
return Cmp_KEEPCASE( aItem1, aItem2 ) < 0;
}
};
typedef std::vector<LIB_ALIAS*> LIB_ALIASES;
typedef boost::shared_ptr<LIB_PART> PART_SPTR; ///< shared pointer to LIB_PART
typedef boost::weak_ptr<LIB_PART> PART_REF; ///< weak pointer to LIB_PART
/**
* Alias map used by component library object.
*/
typedef std::map< wxString, LIB_ALIAS*, AliasMapSort > LIB_ALIAS_MAP;
typedef std::vector< LIB_ALIAS* > LIB_ALIASES;
/* values for member .m_options */
enum LibrEntryOptions
{
ENTRY_NORMAL, // Libentry is a standard component (real or alias)
ENTRY_NORMAL, // Libentry is a standard part (real or alias)
ENTRY_POWER // Libentry is a power symbol
};
/**
* Component library alias object definition.
* Part library alias object definition.
*
* Component aliases are not really components. An alias uses the component definition
* Part aliases are not really parts. An alias uses the part definition
* (graphic, pins...) but has its own name, keywords and documentation. Therefore, when
* the component is modified, alias of this component are modified. This is a simple
* method to create components that have the same physical layout with different names
* the part is modified, alias of this part are modified. This is a simple
* method to create parts that have the same physical layout with different names
* such as 74LS00, 74HC00 ... and many op amps.
*/
class LIB_ALIAS : public EDA_ITEM
{
/**
* The actual component of the alias.
* Actual LIB_PART referenced by [multiple] aliases.
*
* @note - Do not delete the root component. The root component is actually shared by
* all of the aliases associated with it. The component pointer will be delete
* in the destructor of the last alias that shares this component is deleted.
* Deleting the root component will likely cause Eeschema to crash.
* @note - Do not delete the shared part. The shared part is shared by
* all of the aliases associated with it. A shared LIB_PART will
* be deleted when all LIB_ALIASes pointing to it are deleted.
*/
LIB_COMPONENT* root;
LIB_PART* shared;
friend class LIB_COMPONENT;
friend class LIB_PART;
protected:
wxString name;
wxString description; ///< documentation for info
wxString keyWords; ///< keyword list (used for search for components by keyword)
wxString docFileName; ///< Associate doc file name
wxString name;
wxString description; ///< documentation for info
wxString keyWords; ///< keyword list (used for search for parts by keyword)
wxString docFileName; ///< Associate doc file name
public:
LIB_ALIAS( const wxString& aName, LIB_COMPONENT* aRootComponent );
LIB_ALIAS( const LIB_ALIAS& aAlias, LIB_COMPONENT* aRootComponent = NULL );
LIB_ALIAS( const wxString& aName, LIB_PART* aRootComponent );
LIB_ALIAS( const LIB_ALIAS& aAlias, LIB_PART* aRootComponent = NULL );
virtual ~LIB_ALIAS();
@ -126,22 +109,26 @@ public:
}
/**
* Get the alias root component.
* Function GetPart
* gets the shared LIB_PART.
*
* @return LIB_PART* - the LIB_PART shared by
* this LIB_ALIAS with possibly other LIB_ALIASes.
*/
LIB_COMPONENT* GetComponent() const
LIB_PART* GetPart() const
{
return root;
return shared;
}
virtual wxString GetLibraryName();
const wxString GetLibraryName();
bool IsRoot() const;
CMP_LIBRARY* GetLibrary();
PART_LIB* GetLib();
virtual const wxString& GetName() const { return name; }
const wxString& GetName() const { return name; }
virtual void SetName( const wxString& aName ) { name = aName; }
void SetName( const wxString& aName ) { name = aName; }
void SetDescription( const wxString& aDescription )
{
@ -174,7 +161,7 @@ public:
bool SaveDoc( OUTPUTFORMATTER& aFormatter );
/**
* Case insensitive comparison of the component entry name.
* KEEPCASE sensitive comparison of the part entry name.
*/
bool operator==( const wxChar* aName ) const;
bool operator!=( const wxChar* aName ) const
@ -195,66 +182,75 @@ extern int LibraryEntryCompare( const LIB_ALIAS* aItem1, const LIB_ALIAS* aItem2
/**
* Class LIB_COMPONENT
* defines a library component object.
* Class LIB_PART
* defines a library part object.
*
* A library component object is typically saved and loaded in a component library file (.lib).
* Library components are different from schematic components.
* A library part object is typically saved and loaded in a part library file (.lib).
* Library parts are different from schematic components.
*/
class LIB_COMPONENT : public EDA_ITEM
class LIB_PART : public EDA_ITEM
{
friend class CMP_LIBRARY;
friend class PART_LIB;
friend class LIB_ALIAS;
wxString m_name;
int m_pinNameOffset; ///< The offset in mils to draw the pin name. Set to 0
///< to draw the pin name above the pin.
bool m_unitsLocked; ///< True if component has multiple parts and changing
///< one part does not automatically change another part.
bool m_showPinNames; ///< Determines if component pin names are visible.
bool m_showPinNumbers; ///< Determines if component pin numbers are visible.
long m_dateModified; ///< Date the component was last modified.
LibrEntryOptions m_options; ///< Special component features such as POWER or NORMAL.)
int m_unitCount; ///< Number of units (parts) per package.
LIB_ITEMS drawings; ///< How to draw this part.
wxArrayString m_FootprintList; /**< List of suitable footprint names for the
component (wild card names accepted). */
LIB_ALIASES m_aliases; ///< List of alias object pointers associated with the
///< component.
CMP_LIBRARY* m_library; ///< Library the component belongs to if any.
PART_SPTR m_me; ///< http://www.boost.org/doc/libs/1_55_0/libs/smart_ptr/sp_techniques.html#weak_without_shared
wxString m_name;
int m_pinNameOffset; ///< The offset in mils to draw the pin name. Set to 0
///< to draw the pin name above the pin.
bool m_unitsLocked; ///< True if part has multiple units and changing
///< one unit does not automatically change another unit.
bool m_showPinNames; ///< Determines if part pin names are visible.
bool m_showPinNumbers; ///< Determines if part pin numbers are visible.
long m_dateModified; ///< Date the part was last modified.
LibrEntryOptions m_options; ///< Special part features such as POWER or NORMAL.)
int m_unitCount; ///< Number of units (parts) per package.
LIB_ITEMS drawings; ///< How to draw this part.
wxArrayString m_FootprintList; /**< List of suitable footprint names for the
part (wild card names accepted). */
LIB_ALIASES m_aliases; ///< List of alias object pointers associated with the
///< part.
PART_LIB* m_library; ///< Library the part belongs to if any.
static int m_subpartIdSeparator; ///< the separator char between
///< the subpart id and the reference
///< like U1A ( m_subpartIdSeparator = 0 ) or U1.A or U1-A
static int m_subpartFirstId; ///< the ascii char value to calculate the subpart symbol id
///< from the part number: only 'A', 'a' or '1' can be used,
///< other values have no sense.
static int m_subpartIdSeparator; ///< the separator char between
///< the subpart id and the reference
///< like U1A ( m_subpartIdSeparator = 0 ) or U1.A or U1-A
static int m_subpartFirstId; ///< the ascii char value to calculate the subpart symbol id
///< from the part number: only 'A', 'a' or '1' can be used,
///< other values have no sense.
private:
void deleteAllFields();
public:
LIB_COMPONENT( const wxString& aName, CMP_LIBRARY* aLibrary = NULL );
LIB_COMPONENT( LIB_COMPONENT& aComponent, CMP_LIBRARY* aLibrary = NULL );
// LIB_PART() { } // not legal
virtual ~LIB_COMPONENT();
public:
LIB_PART( const wxString& aName, PART_LIB* aLibrary = NULL );
LIB_PART( LIB_PART& aPart, PART_LIB* aLibrary = NULL );
virtual ~LIB_PART();
PART_SPTR SharedPtr()
{
// clone a shared pointer
return m_me;
}
virtual wxString GetClass() const
{
return wxT( "LIB_COMPONENT" );
return wxT( "LIB_PART" );
}
virtual void SetName( const wxString& aName );
wxString GetName() { return m_name; }
const wxString& GetName() { return m_name; }
wxString GetLibraryName();
const wxString GetLibraryName();
CMP_LIBRARY* GetLibrary() { return m_library; }
PART_LIB* GetLib() { return m_library; }
wxArrayString GetAliasNames( bool aIncludeRoot = true ) const;
size_t GetAliasCount() const { return m_aliases.size(); }
size_t GetAliasCount() const { return m_aliases.size(); }
LIB_ALIAS* GetAlias( size_t aIndex );
@ -263,7 +259,7 @@ public:
/**
* Function AddAlias
*
* Add an alias \a aName to the component.
* Add an alias \a aName to the part.
*
* Duplicate alias names are not added to the alias list. Debug builds will raise an
* assertion. Release builds will fail silently.
@ -273,7 +269,7 @@ public:
void AddAlias( const wxString& aName );
/**
* Test if alias \a aName is in component alias list.
* Test if alias \a aName is in part alias list.
*
* Alias name comparisons are case insensitive.
*
@ -285,7 +281,6 @@ public:
void SetAliases( const wxArrayString& aAliasList );
void RemoveAlias( const wxString& aName );
LIB_ALIAS* RemoveAlias( LIB_ALIAS* aAlias );
void RemoveAllAliases();
@ -294,7 +289,7 @@ public:
/**
* Function GetBoundingBox
* @return the component boundary box ( in user coordinates )
* @return the part bounding box ( in user coordinates )
* @param aUnit = unit selection = 0, or 1..n
* @param aConvert = 0, 1 or 2
* If aUnit == 0, unit is not used
@ -305,7 +300,7 @@ public:
/**
* Function GetBodyBoundingBox
* @return the component boundary box ( in user coordinates ) without fields
* @return the part bounding box ( in user coordinates ) without fields
* @param aUnit = unit selection = 0, or 1..n
* @param aConvert = 0, 1 or 2
* If aUnit == 0, unit is not used
@ -316,7 +311,7 @@ public:
/**
* Function SaveDateAndTime
* write the date and time of component to \a aFile in the format:
* write the date and time of part to \a aFile in the format:
* "Ti yy/mm/jj hh:mm:ss"
*
* @param aFormatter A reference to an #OUTPUTFORMATTER object containing the
@ -329,7 +324,7 @@ public:
/**
* Function Save
* writes the data structures out to \a aFormatter in the component library "*.lib"
* writes the data structures out to \a aFormatter in the part library "*.lib"
* format.
*
* @param aFormatter A reference to an OUTPUTFORMATTER to write to.
@ -338,7 +333,7 @@ public:
bool Save( OUTPUTFORMATTER& aFormatter );
/**
* Load component definition from \a aReader.
* Load part definition from \a aReader.
*
* @param aReader A LINE_READER object to load file from.
* @param aErrorMsg - Description of error on load failure.
@ -350,20 +345,20 @@ public:
bool LoadAliases( char* aLine, wxString& aErrorMsg );
bool LoadFootprints( LINE_READER& aReader, wxString& aErrorMsg );
bool IsPower() { return m_options == ENTRY_POWER; }
bool IsNormal() { return m_options == ENTRY_NORMAL; }
bool IsPower() { return m_options == ENTRY_POWER; }
bool IsNormal() { return m_options == ENTRY_NORMAL; }
void SetPower() { m_options = ENTRY_POWER; }
void SetNormal() { m_options = ENTRY_NORMAL; }
void SetPower() { m_options = ENTRY_POWER; }
void SetNormal() { m_options = ENTRY_NORMAL; }
void LockUnits( bool aLockUnits ) { m_unitsLocked = aLockUnits; }
bool UnitsLocked() { return m_unitsLocked; }
bool UnitsLocked() { return m_unitsLocked; }
/**
* Function SetFields
* overwrites all the existing in this component with fields supplied
* overwrites all the existing in this part with fields supplied
* in \a aFieldsList. The only known caller of this function is the
* library component field editor, and it establishes needed behavior.
* library part field editor, and it establishes needed behavior.
*
` * @param aFieldsList is a set of fields to import, removing all previous fields.
*/
@ -371,8 +366,8 @@ public:
/**
* Function GetFields
* returns a list of fields withing this component. The only known caller of
* this function is the library component field editor, and it establishes
* returns a list of fields withing this part. The only known caller of
* this function is the library part field editor, and it establishes
* needed behavior.
*
* @param aList - List to add fields to
@ -381,7 +376,7 @@ public:
/**
* Function FindField
* finds a field within this component matching \a aFieldName and returns
* finds a field within this part matching \a aFieldName and returns
* it or NULL if not found.
*/
LIB_FIELD* FindField( const wxString& aFieldName );
@ -401,21 +396,21 @@ public:
LIB_FIELD& GetReferenceField();
/**
* Draw component.
* Draw part.
*
* @param aPanel - Window to draw on. Can be NULL if not available.
* @param aDc - Device context to draw on.
* @param aOffset - Position to component.
* @param aMulti - Component unit if multiple parts per component.
* @param aOffset - Position of part.
* @param aMulti - unit if multiple units per part.
* @param aConvert - Component conversion (DeMorgan) if available.
* @param aDrawMode - Device context drawing mode, see wxDC.
* @param aColor - Color to draw component.
* @param aColor - Color to draw part.
* @param aTransform - Coordinate adjustment settings.
* @param aShowPinText - Show pin text if true.
* @param aDrawFields - Draw field text if true otherwise just draw
* body items (useful to draw a body in schematic,
* because fields of schematic components replace
* the lib component fields).
* the lib part fields).
* @param aOnlySelected - Draws only the body items that are selected.
* Used for block move redraws.
*/
@ -427,7 +422,7 @@ public:
bool aOnlySelected = false );
/**
* Plot lib component to plotter.
* Plot lib part to plotter.
* Lib Fields not are plotted here, because this plot function
* is used to plot schematic items, which have they own fields
*
@ -441,8 +436,8 @@ public:
const TRANSFORM& aTransform );
/**
* Plot Lib Fields only of the component to plotter.
* is used to plot the full lib component, outside the schematic
* Plot Lib Fields only of the part to plotter.
* is used to plot the full lib part, outside the schematic
*
* @param aPlotter - Plotter object to plot to.
* @param aUnit - Component part to plot.
@ -456,7 +451,7 @@ public:
/**
* Add a new draw \a aItem to the draw object list.
*
* @param aItem - New draw object to add to component.
* @param aItem - New draw object to add to part.
*/
void AddDrawItem( LIB_ITEM* aItem );
@ -498,15 +493,15 @@ public:
/**
* Return a list of pin object pointers from the draw item list.
*
* Note pin objects are owned by the draw list of the component.
* Note pin objects are owned by the draw list of the part.
* Deleting any of the objects will leave list in a unstable state
* and will likely segfault when the list is destroyed.
*
* @param aList - Pin list to place pin object pointers into.
* @param aUnit - Unit number of pin to add to list. Set to 0 to
* get pins from any component part.
* get pins from any part unit.
* @param aConvert - Convert number of pin to add to list. Set to 0 to
* get pins from any convert of component.
* get pins from any convert of part.
*/
void GetPins( LIB_PINS& aList, int aUnit = 0, int aConvert = 0 );
@ -514,7 +509,7 @@ public:
* Return pin object with the requested pin \a aNumber.
*
* @param aNumber - Number of the pin to find.
* @param aUnit - Unit of the component to find. Set to 0 if a specific
* @param aUnit - Unit of the part to find. Set to 0 if a specific
* unit number is not required.
* @param aConvert - Alternate body style filter (DeMorgan). Set to 0 if
* no alternate body style is required.
@ -523,7 +518,7 @@ public:
LIB_PIN* GetPin( const wxString& aNumber, int aUnit = 0, int aConvert = 0 );
/**
* Move the component \a aOffset.
* Move the part \a aOffset.
*
* @param aOffset - Offset displacement.
*/
@ -535,19 +530,19 @@ public:
void RemoveDuplicateDrawItems();
/**
* Test if component has more than one body conversion type (DeMorgan).
* Test if part has more than one body conversion type (DeMorgan).
*
* @return True if component has more than one conversion.
* @return True if part has more than one conversion.
*/
bool HasConversion() const;
/**
* Clears the status flag all draw objects in this component.
* Clears the status flag all draw objects in this part.
*/
void ClearStatus();
/**
* Checks all draw objects of component to see if they are with block.
* Checks all draw objects of part to see if they are with block.
*
* Use this method to mark draw objects as selected during block
* functions.
@ -571,7 +566,7 @@ public:
* Deletes the select draw items marked by a block select.
*
* The name and reference field will not be deleted. They are the
* minimum drawing items required for any component. Their properties
* minimum drawing items required for any part. Their properties
* can be changed but the cannot be removed.
*/
void DeleteSelectedItems();
@ -584,7 +579,7 @@ public:
/**
* Make a copy of the selected draw items marked by a block select.
*
* Fields are not copied. Only component body items are copied.
* Fields are not copied. Only part body items are copied.
* Copying fields would result in duplicate fields which does not
* make sense in this context.
*/
@ -643,29 +638,29 @@ public:
LIB_ITEMS& GetDrawItemList() { return drawings; }
/**
* Set the part per package count.
* Set the units per part count.
*
* If the count is greater than the current count, then the all of the
* current draw items are duplicated for each additional part. If the
* count is less than the current count, all draw objects for parts
* greater that count are removed from the component.
* count is less than the current count, all draw objects for units
* greater that count are removed from the part.
*
* @param count - Number of parts per package.
* @param count - Number of units per package.
*/
void SetPartCount( int count );
void SetUnitCount( int count );
int GetPartCount() const { return m_unitCount; }
int GetUnitCount() const { return m_unitCount; }
/**
* Function IsMulti
* @return true if the component has multiple parts per package.
* @return true if the part has multiple units per part.
* When happens, the reference has a sub reference ti identify part
*/
bool IsMulti() const { return m_unitCount > 1; }
/**
* Function SubReference
* @return the sub reference for component having multiple parts per package.
* @return the sub reference for part having multiple units per part.
* The sub reference identify the part (or unit)
* @param aUnit = the part identifier ( 1 to max count)
* @param aAddSeparator = true (default) to prpebd the sub ref
@ -700,15 +695,15 @@ public:
static void SetSubpartIdNotation( int aSep, int aFirstId );
/**
* Set or clear the alternate body style (DeMorgan) for the component.
* Set or clear the alternate body style (DeMorgan) for the part.
*
* If the component already has an alternate body style set and a
* If the part already has an alternate body style set and a
* asConvert if false, all of the existing draw items for the alternate
* body style are remove. If the alternate body style is not set and
* asConvert is true, than the base draw items are duplicated and
* added to the component.
* added to the part.
*
* @param aSetConvert - Set or clear the component alternate body style.
* @param aSetConvert - Set or clear the part alternate body style.
*/
void SetConversion( bool aSetConvert );
@ -726,7 +721,7 @@ public:
/**
* Set or clear the pin name visibility flag.
*
* @param aShow - True to make the component pin names visible.
* @param aShow - True to make the part pin names visible.
*/
void SetShowPinNames( bool aShow ) { m_showPinNames = aShow; }
@ -735,13 +730,13 @@ public:
/**
* Set or clear the pin number visibility flag.
*
* @param aShow - True to make the component pin numbers visible.
* @param aShow - True to make the part pin numbers visible.
*/
void SetShowPinNumbers( bool aShow ) { m_showPinNumbers = aShow; }
bool ShowPinNumbers() { return m_showPinNumbers; }
bool operator==( const LIB_COMPONENT* aComponent ) const { return this == aComponent; }
bool operator==( const LIB_PART* aPart ) const { return this == aPart; }
#if defined(DEBUG)
void Show( int nestLevel, std::ostream& os ) const { ShowDummy( os ); } // override

File diff suppressed because it is too large Load Diff

View File

@ -25,7 +25,7 @@
/**
* @file class_library.h
* @brief Definition for component library class.
* @brief Definition for part library class.
*/
#ifndef CLASS_LIBRARY_H
@ -35,18 +35,19 @@
#include <class_libentry.h>
#include <project.h>
class LINE_READER;
class OUTPUTFORMATTER;
/*
* Component Library version and file header macros.
* Part Library version and file header macros.
*/
#define LIB_VERSION_MAJOR 2
#define LIB_VERSION_MINOR 3
/* Must be the first line of component library (.lib) files. */
/* Must be the first line of part library (.lib) files. */
#define LIBFILE_IDENT "EESchema-LIBRARY Version"
#define LIB_VERSION( major, minor ) ( major * 100 + minor )
@ -59,59 +60,212 @@ class OUTPUTFORMATTER;
/*
* Library versions 2.3 and lower use the old separate library (.lib) and
* document (.dcm) files. Component libraries after 2.3 merged the library
* document (.dcm) files. Part libraries after 2.3 merged the library
* and document files into a single library file. This macro checks if the
* library version supports the old format
*/
#define USE_OLD_DOC_FILE_FORMAT( major, minor ) \
( LIB_VERSION( major, minor ) <= LIB_VERSION( 2, 3 ) )
/* Must be the first line of component library document (.dcm) files. */
/* Must be the first line of part library document (.dcm) files. */
#define DOCFILE_IDENT "EESchema-DOCLIB Version 2.0"
#define DOC_EXT wxT( "dcm" )
/* Helpers for creating a list of component libraries. */
class CMP_LIBRARY;
/* Helpers for creating a list of part libraries. */
class PART_LIB;
class wxRegEx;
/**
* LIB_ALIAS map sorting.
*/
struct AliasMapSort
{
bool operator() ( const wxString& aItem1, const wxString& aItem2 ) const
{
return Cmp_KEEPCASE( aItem1, aItem2 ) < 0;
}
};
typedef boost::ptr_vector< CMP_LIBRARY > CMP_LIBRARY_LIST;
/// Alias map used by part library object.
extern bool operator<( const CMP_LIBRARY& item1, const CMP_LIBRARY& item2 );
typedef std::map< wxString, LIB_ALIAS*, AliasMapSort > LIB_ALIAS_MAP;
typedef std::vector< LIB_ALIAS* > LIB_ALIASES;
typedef boost::ptr_vector< PART_LIB > PART_LIBS_BASE;
/**
* Class CMP_LIBRARY
* is used to load, save, search, and otherwise manipulate
* component library files.
* Class PART_LIBS
* is a collection of PART_LIBs. It extends from PROJECT::_ELEM so it can be
* hung in the PROJECT. It does not use any UI calls, but rather simply throws
* an IO_ERROR when there is a problem.
*/
class CMP_LIBRARY
class PART_LIBS : public PART_LIBS_BASE, public PROJECT::_ELEM
{
int type; ///< Library type indicator.
wxFileName fileName; ///< Library file name.
wxDateTime timeStamp; ///< Library save time and date.
int versionMajor; ///< Library major version number.
int versionMinor; ///< Library minor version number.
bool isCache; /**< False for the "standard" libraries,
True for the library cache */
wxString header; ///< first line of loaded library.
bool isModified; ///< Library modification status.
LIB_ALIAS_MAP aliases; ///< Map of aliases objects associated with the library.
static CMP_LIBRARY_LIST libraryList;
static wxArrayString libraryListSortOrder;
friend class LIB_COMPONENT;
static wxArrayString s_libraryListSortOrder;
public:
CMP_LIBRARY( int aType, const wxFileName& aFileName );
CMP_LIBRARY( int aType, const wxString& aFileName )
static int s_modify_generation; ///< helper for GetModifyHash()
PART_LIBS()
{
CMP_LIBRARY( aType, wxFileName( aFileName ) );
++s_modify_generation;
}
~CMP_LIBRARY();
/// Return the modification hash for all libraries. The value returned
/// changes on every library modification.
int GetModifyHash();
/**
* Function AddLibrary
* allocates and adds a part library to the library list.
*
* @param aFileName - File name object of part library.
* @param aErrorMsg - Error message if the part library failed to load.
* @return PART_LIB* - the new PART_LIB, which remains owned by this PART_LIBS container.
* @throw IO_ERROR if there's any problem loading.
*/
PART_LIB* AddLibrary( const wxString& aFileName ) throw( IO_ERROR );
/**
* Function AddLibrary
* inserts a part library into the library list.
*
* @param aFileName - File name object of part library.
* @param aIterator - Iterator to insert library in front of.
* @return PART_LIB* - the new PART_LIB, which remains owned by this PART_LIBS container.
* @throw IO_ERROR if there's any problem loading.
*/
PART_LIB* AddLibrary( const wxString& aFileName, PART_LIBS::iterator& aIterator ) throw( IO_ERROR );
/**
* Function RemoveLibrary
* removes a part library from the library list.
*
* @param aName - Name of part library to remove.
*/
void RemoveLibrary( const wxString& aName );
void RemoveAllLibraries() { clear(); }
/**
* Function LoadAllLibraries
* loads all of the project's libraries into this container, which should
* be cleared before calling it.
*/
void LoadAllLibraries( PROJECT* aProject ) throw( IO_ERROR );
/**
* Function LibNamesAndPaths
* either saves or loads the names of the currently configured part libraries
* (without paths).
*/
static void LibNamesAndPaths( PROJECT* aProject, bool doSave,
wxString* aPaths, wxArrayString* aNames=NULL ) throw( IO_ERROR );
/**
* Function cacheName
* returns the name of the cache library after potentially fixing it from
* an older naming scheme. That is, the old file is renamed if needed.
* @param aFullProjectFilename - the *.pro filename with absolute path.
*/
static const wxString CacheName( const wxString& aFullProjectFilename );
/**
* Function FindLibrary
* finds a part library by \a aName.
*
* @param aName - Library file name without path or extension to find.
* @return Part library if found, otherwise NULL.
*/
PART_LIB* FindLibrary( const wxString& aName );
/**
* Function GetLibraryNames
* returns the list of part library file names without path and extension.
*
* @param aSorted - Sort the list of name if true. Otherwise use the
* library load order.
* @return The list of library names.
*/
wxArrayString GetLibraryNames( bool aSorted = true );
/**
* Function FindLibPart
* searches all libraries in the list for a part.
*
* A part object will always be returned. If the entry found
* is an alias. The root part will be found and returned.
*
* @param aPartName - Name of part to search for.
* @param aLibraryName - Name of the library to search for part.
* @return LIB_PART* - The part object if found, otherwise NULL.
*/
LIB_PART* FindLibPart( const wxString& aPartName, const wxString& aLibraryName = wxEmptyString );
/**
* Function FindLibraryEntry
* searches all libraries in the list for an entry.
*
* The object can be either a part or an alias.
*
* @param aEntryName - Name of entry to search for.
* @param aLibraryName - Name of the library to search.
* @return The entry object if found, otherwise NULL.
*/
LIB_ALIAS* FindLibraryEntry( const wxString& aEntryName,
const wxString& aLibraryName = wxEmptyString );
/**
* Function RemoveCacheLibrary
* removes all cache libraries from library list.
*/
//void RemoveCacheLibrary();
int GetLibraryCount() { return size(); }
static void SetSortOrder( const wxArrayString& aSortOrder )
{
s_libraryListSortOrder = aSortOrder;
}
static wxArrayString& GetSortOrder()
{
return s_libraryListSortOrder;
}
};
bool operator<( const PART_LIB& item1, const PART_LIB& item2 );
/**
* Class PART_LIB
* is used to load, save, search, and otherwise manipulate
* part library files.
*/
class PART_LIB
{
int type; ///< Library type indicator.
wxFileName fileName; ///< Library file name.
wxDateTime timeStamp; ///< Library save time and date.
int versionMajor; ///< Library major version number.
int versionMinor; ///< Library minor version number.
bool isCache; /**< False for the "standard" libraries,
True for the library cache */
wxString header; ///< first line of loaded library.
bool isModified; ///< Library modification status.
LIB_ALIAS_MAP m_amap; ///< Map of alias objects associated with the library.
int m_mod_hash; ///< incremented each time library is changed.
friend class LIB_PART;
friend class PART_LIBS;
public:
PART_LIB( int aType, const wxString& aFileName );
~PART_LIB();
/**
* Function Save
@ -145,7 +299,7 @@ private:
bool SaveHeader( OUTPUTFORMATTER& aFormatter );
bool LoadHeader( LINE_READER& aLineReader );
void LoadAliases( LIB_COMPONENT* aComponent );
void LoadAliases( LIB_PART* aPart );
public:
/**
@ -155,18 +309,18 @@ public:
*/
bool IsEmpty() const
{
return aliases.empty();
return m_amap.empty();
}
/**
* Function GetCount
* returns the number of entries in the library.
*
* @return The number of component and alias entries.
* @return The number of part and alias entries.
*/
int GetCount() const
{
return aliases.size();
return m_amap.size();
}
bool IsModified() const
@ -218,21 +372,21 @@ public:
bool aSort = true );
/**
* Find components in library by key word regular expression search.
* Find parts in library by key word regular expression search.
*
* @param aNames - String array to place found component names into.
* @param aRe - Regular expression used to search component key words.
* @param aSort - Sort component name list.
* @param aNames - String array to place found part names into.
* @param aRe - Regular expression used to search part key words.
* @param aSort - Sort part name list.
*/
void SearchEntryNames( wxArrayString& aNames, const wxRegEx& aRe, bool aSort = true );
/**
* Checks \a aComponent for name conflict in the library.
* Checks \a aPart for name conflict in the library.
*
* @param aComponent - The component to check.
* @param aPart - The part to check.
* @return True if a conflict exists. Otherwise false.
*/
bool Conflicts( LIB_COMPONENT* aComponent );
bool Conflicts( LIB_PART* aPart );
/**
* Find entry by name.
@ -243,22 +397,19 @@ public:
LIB_ALIAS* FindEntry( const wxString& aName );
/**
* Find component by \a aName.
* Find part by \a aName.
*
* This is a helper for FindEntry so casting a LIB_ALIAS pointer to
* a LIB_COMPONENT pointer is not required.
* a LIB_PART pointer is not required.
*
* @param aName - Name of component, case insensitive.
* @return Component if found. NULL if not found.
* @param aName - Name of part, case insensitive.
* @return LIB_PART* - part if found, else NULL.
*/
LIB_COMPONENT* FindComponent( const wxString& aName );
LIB_PART* FindPart( const wxString& aName );
/**
* Find alias by \a nName.
*
* This is a helper for FindEntry so casting a LIB_ALIAS pointer to
* a LIB_ALIAS pointer is not required.
*
* @param aName - Name of alias, case insensitive.
* @return Alias if found. NULL if not found.
*/
@ -270,7 +421,7 @@ public:
/**
* Add a new \a aAlias entry to the library.
*
* First check if a component or alias with the same name already exists
* First check if a part or alias with the same name already exists
* in the library and add alias if no conflict occurs. Once the alias
* is added to the library it is owned by the library. Deleting the
* alias pointer will render the library unstable. Use RemoveEntry to
@ -282,23 +433,24 @@ public:
bool AddAlias( LIB_ALIAS* aAlias );
/**
* Add \a aComponent entry to library.
* Note a component can have an alias list,
* Add \a aPart entry to library.
* Note a part can have an alias list,
* so these alias will be added in library.
* Conflicts can happen if aliases are already existing.
* User is asked to choose what alias is removed (existing, or new)
* @param aComponent - Component to add.
* @return Added component if successful.
*
* @param aPart - Part to add, caller retains ownership, a clone is added.
* @return bool - true iff successful.
*/
LIB_COMPONENT* AddComponent( LIB_COMPONENT* aComponent );
bool AddPart( LIB_PART* aPart );
/**
* Safely remove \a aEntry from the library and return the next entry.
*
* The next entry returned depends on the entry being removed. If the entry being
* remove also removes the component, then the next entry from the list is returned.
* If the entry being used only removes an alias from a component, then the next alias
* of the component is returned.
* remove also removes the part, then the next entry from the list is returned.
* If the entry being used only removes an alias from a part, then the next alias
* of the part is returned.
*
* @param aEntry - Entry to remove from library.
* @return The next entry in the library or NULL if the library is empty.
@ -306,14 +458,13 @@ public:
LIB_ALIAS* RemoveEntry( LIB_ALIAS* aEntry );
/**
* Replace an existing component entry in the library.
* Note a component can have an alias list,
* Replace an existing part entry in the library.
* Note a part can have an alias list,
* so these alias will be added in library (and previously existing alias removed)
* @param aOldComponent - The component to replace.
* @param aNewComponent - The new component.
* @param aOldPart - The part to replace.
* @param aNewPart - The new part.
*/
LIB_COMPONENT* ReplaceComponent( LIB_COMPONENT* aOldComponent,
LIB_COMPONENT* aNewComponent );
LIB_PART* ReplacePart( LIB_PART* aOldPart, LIB_PART* aNewPart );
/**
* Return the first entry in the library.
@ -333,7 +484,6 @@ public:
*/
LIB_ALIAS* GetNextEntry( const wxString& aName );
/**
* Find previous library entry by \a aName.
*
@ -350,7 +500,7 @@ public:
*
* @return Name of library file.
*/
wxString GetName() const { return fileName.GetName(); }
const wxString GetName() const { return fileName.GetName(); }
/**
* Function GetFullFileName
@ -358,14 +508,14 @@ public:
*
* @return wxString - Full library file name with path and extension.
*/
wxString GetFullFileName() { return fileName.GetFullPath(); }
wxString GetFullFileName() { return fileName.GetFullPath(); }
/**
* Function GetLogicalName
* returns the logical name of the library.
* @return wxString - The logical name of this library.
*/
wxString GetLogicalName()
const wxString GetLogicalName()
{
/* for now is the filename without path or extension.
@ -381,151 +531,33 @@ public:
/**
* Function SetFileName
* sets the component library file name.
* sets the part library file name.
*
* @param aFileName - New library file name.
*/
void SetFileName( const wxFileName aFileName )
void SetFileName( const wxString& aFileName )
{
if( aFileName != fileName )
if( aFileName != fileName.GetFullName() )
fileName = aFileName;
}
/*
* The following static methods are for manipulating the list of
* component libraries. This eliminates the need for yet another
* global variable ( formerly g_LibraryList ) and gives some measure
* of safety from abusing the library list.
*/
/**
* Function LibraryExists
* tests for existence of a library.
*
* @param aLibptr - aLibptr.
* @return bool - true if exists, else false
*/
static bool LibraryExists( const CMP_LIBRARY* aLibptr );
/**
* Function LoadLibrary
* loads a component library file.
* allocates and loads a part library file.
*
* @param aFileName - File name of the component library to load.
* @param aErrorMsg - Error message if the component library failed to load.
* @return Library object if library file loaded successfully,
* otherwise NULL.
* @param aFileName - File name of the part library to load.
* @return PART_LIB* - the allocated and loaded PART_LIB, which is owned by
* the caller.
* @throw IO_ERROR if there's any problem loading the library.
*/
static CMP_LIBRARY* LoadLibrary( const wxFileName& aFileName, wxString& aErrorMsg );
/**
* Function AddLibrary
* adds a component library to the library list.
*
* @param aFileName - File name object of component library.
* @param aErrorMsg - Error message if the component library failed to load.
* @return True if library loaded properly otherwise false.
*/
static bool AddLibrary( const wxFileName& aFileName, wxString& aErrorMsg );
/**
* Function AddLibrary
* inserts a component library into the library list.
*
* @param aFileName - File name object of component library.
* @param aErrorMsg - Error message if the component library failed to load.
* @param aIterator - Iterator to insert library in front of.
* @return True if library loaded properly otherwise false.
*/
static bool AddLibrary( const wxFileName& aFileName, wxString& aErrorMsg,
CMP_LIBRARY_LIST::iterator& aIterator );
/**
* Function RemoveLibrary
* removes a component library from the library list.
*
* @param aName - Name of component library to remove.
*/
static void RemoveLibrary( const wxString& aName );
static void RemoveAllLibraries() { libraryList.clear(); }
/**
* Function FindLibrary
* finds a component library by \a aName.
*
* @param aName - Library file name without path or extension to find.
* @return Component library if found, otherwise NULL.
*/
static CMP_LIBRARY* FindLibrary( const wxString& aName );
/**
* Function GetLibraryNames
* returns the list of component library file names without path and extension.
*
* @param aSorted - Sort the list of name if true. Otherwise use the
* library load order.
* @return The list of library names.
*/
static wxArrayString GetLibraryNames( bool aSorted = true );
/**
* Function FindLibraryComponent
* searches all libraries in the list for a component.
*
* A component object will always be returned. If the entry found
* is an alias. The root component will be found and returned.
*
* @param aComponentName - Name of component to search for.
* @param aLibraryName - Name of the library to search for component.
* @return The component object if found, otherwise NULL.
*/
static LIB_COMPONENT* FindLibraryComponent( const wxString& aComponentName,
const wxString& aLibraryName = wxEmptyString );
/**
* Function FindLibraryEntry
* searches all libraries in the list for an entry.
*
* The object can be either a component or an alias.
*
* @param aEntryName - Name of entry to search for.
* @param aLibraryName - Name of the library to search.
* @return The entry object if found, otherwise NULL.
*/
static LIB_ALIAS* FindLibraryEntry( const wxString& aEntryName,
const wxString& aLibraryName = wxEmptyString );
/**
* Function RemoveCacheLibrary
* removes all cache libraries from library list.
*/
static void RemoveCacheLibrary();
static int GetLibraryCount() { return libraryList.size(); }
static CMP_LIBRARY_LIST& GetLibraryList()
{
return libraryList;
}
static void SetSortOrder( const wxArrayString& aSortOrder )
{
libraryListSortOrder = aSortOrder;
}
static wxArrayString& GetSortOrder( void )
{
return libraryListSortOrder;
}
static PART_LIB* LoadLibrary( const wxString& aFileName ) throw( IO_ERROR );
};
/**
* Case insensitive library name comparison.
*/
extern bool operator==( const CMP_LIBRARY& aLibrary, const wxString& aName );
extern bool operator!=( const CMP_LIBRARY& aLibrary, const wxString& aName );
bool operator==( const PART_LIB& aLibrary, const wxString& aName );
bool operator!=( const PART_LIB& aLibrary, const wxString& aName );
#endif // CLASS_LIBRARY_H

View File

@ -291,7 +291,7 @@ void SCH_REFERENCE_LIST::Annotate( bool aUseSheetNum, int aSheetIntervalId )
int LastReferenceNumber = 0;
int NumberOfUnits, Unit;
/* Components with an invisible reference (power...) always are re-annotated. */
// Components with an invisible reference (power...) always are re-annotated.
ResetHiddenReferences();
/* calculate index of the first component with the same reference prefix
@ -301,7 +301,7 @@ void SCH_REFERENCE_LIST::Annotate( bool aUseSheetNum, int aSheetIntervalId )
*/
unsigned first = 0;
/* calculate the last used number for this reference prefix: */
// calculate the last used number for this reference prefix:
#ifdef USE_OLD_ALGO
int minRefId = 0;
@ -330,7 +330,7 @@ void SCH_REFERENCE_LIST::Annotate( bool aUseSheetNum, int aSheetIntervalId )
if( ( componentFlatList[first].CompareRef( componentFlatList[ii] ) != 0 )
|| ( aUseSheetNum && ( componentFlatList[first].m_SheetNum != componentFlatList[ii].m_SheetNum ) ) )
{
/* New reference found: we need a new ref number for this reference */
// New reference found: we need a new ref number for this reference
first = ii;
#ifdef USE_OLD_ALGO
minRefId = 0;
@ -352,7 +352,7 @@ void SCH_REFERENCE_LIST::Annotate( bool aUseSheetNum, int aSheetIntervalId )
}
// Annotation of one part per package components (trivial case).
if( componentFlatList[ii].GetLibComponent()->GetPartCount() <= 1 )
if( componentFlatList[ii].GetLibComponent()->GetUnitCount() <= 1 )
{
if( componentFlatList[ii].m_IsNew )
{
@ -370,8 +370,8 @@ void SCH_REFERENCE_LIST::Annotate( bool aUseSheetNum, int aSheetIntervalId )
continue;
}
/* Annotation of multi-part components ( n parts per package ) (complex case) */
NumberOfUnits = componentFlatList[ii].GetLibComponent()->GetPartCount();
// Annotation of multi-unit parts ( n units per part ) (complex case)
NumberOfUnits = componentFlatList[ii].GetLibComponent()->GetUnitCount();
if( componentFlatList[ii].m_IsNew )
{
@ -382,7 +382,7 @@ void SCH_REFERENCE_LIST::Annotate( bool aUseSheetNum, int aSheetIntervalId )
#endif
componentFlatList[ii].m_NumRef = LastReferenceNumber;
if( !componentFlatList[ii].IsPartsLocked() )
if( !componentFlatList[ii].IsUnitsLocked() )
componentFlatList[ii].m_Unit = 1;
componentFlatList[ii].m_Flag = 1;
@ -400,9 +400,9 @@ void SCH_REFERENCE_LIST::Annotate( bool aUseSheetNum, int aSheetIntervalId )
int found = FindUnit( ii, Unit );
if( found >= 0 )
continue; /* this unit exists for this reference (unit already annotated) */
continue; // this unit exists for this reference (unit already annotated)
/* Search a component to annotate ( same prefix, same value, not annotated) */
// Search a component to annotate ( same prefix, same value, not annotated)
for( unsigned jj = ii + 1; jj < componentFlatList.size(); jj++ )
{
if( componentFlatList[jj].m_Flag ) // already tested
@ -420,8 +420,8 @@ void SCH_REFERENCE_LIST::Annotate( bool aUseSheetNum, int aSheetIntervalId )
if( !componentFlatList[jj].m_IsNew )
continue;
/* Component without reference number found, annotate it if possible */
if( !componentFlatList[jj].IsPartsLocked()
// Component without reference number found, annotate it if possible
if( !componentFlatList[jj].IsUnitsLocked()
|| ( componentFlatList[jj].m_Unit == Unit ) )
{
componentFlatList[jj].m_NumRef = componentFlatList[ii].m_NumRef;
@ -486,7 +486,7 @@ int SCH_REFERENCE_LIST::CheckAnnotation( wxArrayString* aMessageList )
// Error if unit number selected does not exist ( greater than the number of
// parts in the component ). This can happen if a component has changed in a
// library after a previous annotation.
if( std::max( componentFlatList[ii].GetLibComponent()->GetPartCount(), 1 )
if( std::max( componentFlatList[ii].GetLibComponent()->GetUnitCount(), 1 )
< componentFlatList[ii].m_Unit )
{
if( componentFlatList[ii].m_NumRef >= 0 )
@ -498,7 +498,7 @@ int SCH_REFERENCE_LIST::CheckAnnotation( wxArrayString* aMessageList )
GetChars( componentFlatList[ii].GetRef() ),
GetChars( tmp ),
componentFlatList[ii].m_Unit,
componentFlatList[ii].GetLibComponent()->GetPartCount() );
componentFlatList[ii].GetLibComponent()->GetUnitCount() );
if( aMessageList )
aMessageList->Add( msg );
@ -555,8 +555,8 @@ int SCH_REFERENCE_LIST::CheckAnnotation( wxArrayString* aMessageList )
/* Test error if units are different but number of parts per package
* too high (ex U3 ( 1 part) and we find U3B this is an error) */
if( componentFlatList[ii].GetLibComponent()->GetPartCount()
!= componentFlatList[ii + 1].GetLibComponent()->GetPartCount() )
if( componentFlatList[ii].GetLibComponent()->GetUnitCount()
!= componentFlatList[ii + 1].GetLibComponent()->GetUnitCount() )
{
if( componentFlatList[ii].m_NumRef >= 0 )
tmp << componentFlatList[ii].m_NumRef;
@ -584,7 +584,7 @@ int SCH_REFERENCE_LIST::CheckAnnotation( wxArrayString* aMessageList )
error++;
}
/* Error if values are different between units, for the same reference */
// Error if values are different between units, for the same reference
int next = ii + 1;
if( componentFlatList[ii].CompareValue( componentFlatList[next] ) != 0 )
@ -592,12 +592,12 @@ int SCH_REFERENCE_LIST::CheckAnnotation( wxArrayString* aMessageList )
msg.Printf( _( "Different values for %s%d%s (%s) and %s%d%s (%s)" ),
GetChars( componentFlatList[ii].GetRef() ),
componentFlatList[ii].m_NumRef,
GetChars( LIB_COMPONENT::SubReference(
GetChars( LIB_PART::SubReference(
componentFlatList[ii].m_Unit ) ),
GetChars( componentFlatList[ii].m_Value->GetText() ),
GetChars( componentFlatList[next].GetRef() ),
componentFlatList[next].m_NumRef,
GetChars( LIB_COMPONENT::SubReference(
GetChars( LIB_PART::SubReference(
componentFlatList[next].m_Unit ) ),
GetChars( componentFlatList[next].m_Value->GetText() ) );
@ -617,7 +617,7 @@ int SCH_REFERENCE_LIST::CheckAnnotation( wxArrayString* aMessageList )
|| ( componentFlatList[ii].GetSheetPath() != componentFlatList[ii + 1].GetSheetPath() ) )
continue;
/* Same time stamp found. */
// Same time stamp found.
wxString full_path;
full_path.Printf( wxT( "%s%8.8X" ),
@ -640,7 +640,7 @@ int SCH_REFERENCE_LIST::CheckAnnotation( wxArrayString* aMessageList )
}
SCH_REFERENCE::SCH_REFERENCE( SCH_COMPONENT* aComponent, LIB_COMPONENT* aLibComponent,
SCH_REFERENCE::SCH_REFERENCE( SCH_COMPONENT* aComponent, LIB_PART* aLibComponent,
SCH_SHEET_PATH& aSheetPath )
{
wxASSERT( aComponent != NULL && aLibComponent != NULL );
@ -694,7 +694,7 @@ void SCH_REFERENCE::Split()
{
m_IsNew = true;
if( !IsPartsLocked() )
if( !IsUnitsLocked() )
m_Unit = 0x7FFFFFFF;
refText.erase( ll ); // delete last char
@ -705,7 +705,7 @@ void SCH_REFERENCE::Split()
{
m_IsNew = true;
if( !IsPartsLocked() )
if( !IsUnitsLocked() )
m_Unit = 0x7FFFFFFF;
}
else

View File

@ -98,8 +98,11 @@ bool COMPONENT_TREE_SEARCH_CONTAINER::scoreComparator( const TREE_NODE* a1, cons
}
COMPONENT_TREE_SEARCH_CONTAINER::COMPONENT_TREE_SEARCH_CONTAINER()
: tree( NULL ), libraries_added( 0 ), preselect_unit_number( -1 )
COMPONENT_TREE_SEARCH_CONTAINER::COMPONENT_TREE_SEARCH_CONTAINER( PART_LIBS* aLibs ) :
tree( NULL ),
libraries_added( 0 ),
preselect_unit_number( -1 ),
m_libs( aLibs )
{
}
@ -127,7 +130,7 @@ void COMPONENT_TREE_SEARCH_CONTAINER::SetTree( wxTreeCtrl* aTree )
}
void COMPONENT_TREE_SEARCH_CONTAINER::AddLibrary( CMP_LIBRARY& aLib )
void COMPONENT_TREE_SEARCH_CONTAINER::AddLibrary( PART_LIB& aLib )
{
wxArrayString all_aliases;
@ -139,7 +142,7 @@ void COMPONENT_TREE_SEARCH_CONTAINER::AddLibrary( CMP_LIBRARY& aLib )
void COMPONENT_TREE_SEARCH_CONTAINER::AddAliasList( const wxString& aNodeName,
const wxArrayString& aAliasNameList,
CMP_LIBRARY* aOptionalLib )
PART_LIB* aOptionalLib )
{
TREE_NODE* const lib_node = new TREE_NODE( TREE_NODE::TYPE_LIB, NULL, NULL,
aNodeName, wxEmptyString, wxEmptyString );
@ -152,7 +155,7 @@ void COMPONENT_TREE_SEARCH_CONTAINER::AddAliasList( const wxString& aNodeName,
if( aOptionalLib )
a = aOptionalLib->FindAlias( aName );
else
a = CMP_LIBRARY::FindLibraryEntry( aName, wxEmptyString );
a = m_libs->FindLibraryEntry( aName, wxEmptyString );
if( a == NULL )
continue;
@ -186,12 +189,12 @@ void COMPONENT_TREE_SEARCH_CONTAINER::AddAliasList( const wxString& aNodeName,
a, a->GetName(), display_info, search_text );
nodes.push_back( alias_node );
if( a->GetComponent()->IsMulti() ) // Add all units as sub-nodes.
if( a->GetPart()->IsMulti() ) // Add all units as sub-nodes.
{
for( int u = 1; u <= a->GetComponent()->GetPartCount(); ++u )
for( int u = 1; u <= a->GetPart()->GetUnitCount(); ++u )
{
wxString unitName = _("Unit");
unitName += wxT( " " ) + LIB_COMPONENT::SubReference( u, false );
unitName += wxT( " " ) + LIB_PART::SubReference( u, false );
TREE_NODE* unit_node = new TREE_NODE( TREE_NODE::TYPE_UNIT,
alias_node, a,
unitName,

Some files were not shown because too many files have changed in this diff Show More