2011-10-31 20:49:48 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2015-01-27 18:40:52 +00:00
|
|
|
* Copyright (C) 2004-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2017-09-21 12:58:08 +00:00
|
|
|
* Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
|
2020-01-23 14:03:46 +00:00
|
|
|
* Copyright (C) 2004-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-10-31 20:49:48 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <macros.h>
|
|
|
|
#include <kicad_string.h>
|
2018-08-03 12:18:26 +00:00
|
|
|
#include <sch_draw_panel.h>
|
2018-01-28 18:12:26 +00:00
|
|
|
#include <plotter.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <gr_basic.h>
|
2018-01-30 08:56:43 +00:00
|
|
|
#include <sch_screen.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <richio.h>
|
2018-04-13 13:58:25 +00:00
|
|
|
#include <trace_helpers.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <general.h>
|
|
|
|
#include <template_fieldnames.h>
|
|
|
|
#include <transform.h>
|
|
|
|
#include <class_library.h>
|
|
|
|
#include <class_libentry.h>
|
|
|
|
#include <lib_pin.h>
|
|
|
|
#include <lib_arc.h>
|
2020-02-03 16:46:58 +00:00
|
|
|
#include <settings/color_settings.h>
|
2008-12-31 09:27:19 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2013-05-19 19:35:49 +00:00
|
|
|
// the separator char between the subpart id and the reference
|
|
|
|
// 0 (no separator) or '.' or some other character
|
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.
2014-08-13 20:28:54 +00:00
|
|
|
int LIB_PART::m_subpartIdSeparator = 0;
|
|
|
|
|
2013-05-19 19:35:49 +00:00
|
|
|
// 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
|
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.
2014-08-13 20:28:54 +00:00
|
|
|
int LIB_PART::m_subpartFirstId = 'A';
|
2013-05-19 19:35:49 +00:00
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
wxString LIB_PART::GetSearchText()
|
2009-08-27 11:41:56 +00:00
|
|
|
{
|
2018-08-05 11:56:02 +00:00
|
|
|
// Matches are scored by offset from front of string, so inclusion of this spacer
|
|
|
|
// discounts matches found after it.
|
|
|
|
static const wxString discount( wxT( " " ) );
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
wxString text = GetKeyWords() + discount + GetDescription();
|
|
|
|
wxString footprint = GetFootprintField().GetText();
|
2018-07-27 20:47:51 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
if( !footprint.IsEmpty() )
|
2018-07-27 20:47:51 +00:00
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
text += discount + footprint;
|
2018-07-27 20:47:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
bool operator<( const LIB_PART& aItem1, const LIB_PART& aItem2 )
|
2009-08-27 11:41:56 +00:00
|
|
|
{
|
2018-07-27 20:47:51 +00:00
|
|
|
return aItem1.GetName() < aItem2.GetName();
|
2009-08-27 11:41:56 +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.
2014-08-13 20:28:54 +00:00
|
|
|
/// 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
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-12-01 16:49:19 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
LIB_PART::LIB_PART( const wxString& aName, LIB_PART* aParent, PART_LIB* aLibrary ) :
|
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.
2014-08-13 20:28:54 +00:00
|
|
|
EDA_ITEM( LIB_PART_T ),
|
2020-09-09 13:03:37 +00:00
|
|
|
m_me( this, null_deleter() ),
|
|
|
|
m_includeInBom( true ),
|
|
|
|
m_includeOnBoard( true )
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2017-12-14 16:24:29 +00:00
|
|
|
m_dateLastEdition = 0;
|
2010-10-25 15:43:42 +00:00
|
|
|
m_unitCount = 1;
|
2020-02-13 13:39:52 +00:00
|
|
|
m_pinNameOffset = Mils2iu( DEFAULT_PIN_NAME_OFFSET );
|
2010-02-16 17:49:17 +00:00
|
|
|
m_options = ENTRY_NORMAL;
|
2012-01-22 17:20:22 +00:00
|
|
|
m_unitsLocked = false;
|
2010-06-24 18:31:43 +00:00
|
|
|
m_showPinNumbers = true;
|
|
|
|
m_showPinNames = true;
|
2009-10-21 20:02:25 +00:00
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
// Add the MANDATORY_FIELDS in RAM only. These are assumed to be present
|
|
|
|
// when the field editors are invoked.
|
2018-08-07 01:17:00 +00:00
|
|
|
m_drawings[LIB_FIELD_T].reserve( 4 );
|
2017-11-12 20:49:38 +00:00
|
|
|
m_drawings[LIB_FIELD_T].push_back( new LIB_FIELD( this, VALUE ) );
|
2017-09-17 08:26:06 +00:00
|
|
|
m_drawings[LIB_FIELD_T].push_back( new LIB_FIELD( this, REFERENCE ) );
|
|
|
|
m_drawings[LIB_FIELD_T].push_back( new LIB_FIELD( this, FOOTPRINT ) );
|
|
|
|
m_drawings[LIB_FIELD_T].push_back( new LIB_FIELD( this, DATASHEET ) );
|
2017-11-12 20:49:38 +00:00
|
|
|
|
|
|
|
SetName( aName );
|
2019-12-13 21:51:59 +00:00
|
|
|
|
|
|
|
if( aParent )
|
|
|
|
SetParent( aParent );
|
|
|
|
|
|
|
|
SetLib( aLibrary );
|
2008-12-31 09:27:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-11-08 20:50:04 +00:00
|
|
|
LIB_PART::LIB_PART( const LIB_PART& aPart, PART_LIB* aLibrary ) :
|
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.
2014-08-13 20:28:54 +00:00
|
|
|
EDA_ITEM( aPart ),
|
2017-09-17 08:26:06 +00:00
|
|
|
m_me( this, null_deleter() )
|
2009-09-25 18:49:04 +00:00
|
|
|
{
|
2011-04-27 19:44:32 +00:00
|
|
|
LIB_ITEM* newItem;
|
2009-09-25 18:49:04 +00:00
|
|
|
|
2010-10-25 15:43:42 +00:00
|
|
|
m_library = aLibrary;
|
2019-11-06 19:15:42 +00:00
|
|
|
m_name = aPart.m_name;
|
|
|
|
m_FootprintList = wxArrayString( aPart.m_FootprintList );
|
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.
2014-08-13 20:28:54 +00:00
|
|
|
m_unitCount = aPart.m_unitCount;
|
|
|
|
m_unitsLocked = aPart.m_unitsLocked;
|
|
|
|
m_pinNameOffset = aPart.m_pinNameOffset;
|
|
|
|
m_showPinNumbers = aPart.m_showPinNumbers;
|
2020-09-09 13:03:37 +00:00
|
|
|
m_includeInBom = aPart.m_includeInBom;
|
|
|
|
m_includeOnBoard = aPart.m_includeOnBoard;
|
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.
2014-08-13 20:28:54 +00:00
|
|
|
m_showPinNames = aPart.m_showPinNames;
|
2017-12-14 16:24:29 +00:00
|
|
|
m_dateLastEdition = aPart.m_dateLastEdition;
|
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.
2014-08-13 20:28:54 +00:00
|
|
|
m_options = aPart.m_options;
|
2017-11-10 02:24:43 +00:00
|
|
|
m_libId = aPart.m_libId;
|
2019-11-06 19:15:42 +00:00
|
|
|
m_description = aPart.m_description;
|
|
|
|
m_keyWords = aPart.m_keyWords;
|
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.
2014-08-13 20:28:54 +00:00
|
|
|
|
2020-03-21 23:24:41 +00:00
|
|
|
ClearSelected();
|
|
|
|
|
2019-11-08 20:50:04 +00:00
|
|
|
for( const LIB_ITEM& oldItem : aPart.m_drawings )
|
2009-09-25 18:49:04 +00:00
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
if( ( oldItem.GetFlags() & ( IS_NEW | STRUCT_DELETED ) ) != 0 )
|
2009-09-25 18:49:04 +00:00
|
|
|
continue;
|
|
|
|
|
2020-01-13 15:00:39 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
newItem = (LIB_ITEM*) oldItem.Clone();
|
2020-03-21 23:24:41 +00:00
|
|
|
newItem->ClearSelected();
|
2020-01-13 15:00:39 +00:00
|
|
|
newItem->SetParent( this );
|
|
|
|
m_drawings.push_back( newItem );
|
|
|
|
}
|
|
|
|
catch( ... )
|
|
|
|
{
|
|
|
|
wxFAIL_MSG( "Failed to clone LIB_ITEM." );
|
|
|
|
}
|
2009-09-25 18:49:04 +00:00
|
|
|
}
|
2019-12-13 21:51:59 +00:00
|
|
|
|
|
|
|
PART_SPTR parent = aPart.m_parent.lock();
|
|
|
|
|
|
|
|
if( parent )
|
|
|
|
SetParent( parent.get() );
|
2009-09-25 18:49:04 +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.
2014-08-13 20:28:54 +00:00
|
|
|
LIB_PART::~LIB_PART()
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-26 13:00:59 +00:00
|
|
|
const LIB_PART& LIB_PART::operator=( const LIB_PART& aPart )
|
|
|
|
{
|
|
|
|
if( &aPart == this )
|
|
|
|
return aPart;
|
|
|
|
|
|
|
|
LIB_ITEM* newItem;
|
|
|
|
|
|
|
|
m_library = aPart.m_library;
|
|
|
|
m_name = aPart.m_name;
|
|
|
|
m_FootprintList = wxArrayString( 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;
|
2020-09-09 13:03:37 +00:00
|
|
|
m_includeInBom = aPart.m_includeInBom;
|
|
|
|
m_includeOnBoard = aPart.m_includeOnBoard;
|
2019-12-26 13:00:59 +00:00
|
|
|
m_dateLastEdition = aPart.m_dateLastEdition;
|
|
|
|
m_options = aPart.m_options;
|
|
|
|
m_libId = aPart.m_libId;
|
|
|
|
m_description = aPart.m_description;
|
|
|
|
m_keyWords = aPart.m_keyWords;
|
|
|
|
|
|
|
|
m_drawings.clear();
|
|
|
|
|
|
|
|
for( const LIB_ITEM& oldItem : aPart.m_drawings )
|
|
|
|
{
|
|
|
|
if( ( oldItem.GetFlags() & ( IS_NEW | STRUCT_DELETED ) ) != 0 )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
newItem = (LIB_ITEM*) oldItem.Clone();
|
|
|
|
newItem->SetParent( this );
|
|
|
|
m_drawings.push_back( newItem );
|
|
|
|
}
|
|
|
|
|
|
|
|
PART_SPTR parent = aPart.m_parent.lock();
|
|
|
|
|
|
|
|
if( parent )
|
|
|
|
SetParent( parent.get() );
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
int LIB_PART::Compare( const LIB_PART& aRhs ) const
|
|
|
|
{
|
|
|
|
if( m_me == aRhs.m_me )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
int retv = m_name.Cmp( aRhs.m_name );
|
|
|
|
|
|
|
|
if( retv )
|
|
|
|
return retv;
|
|
|
|
|
|
|
|
retv = m_libId.compare( aRhs.m_libId );
|
|
|
|
|
|
|
|
if( retv )
|
|
|
|
return retv;
|
|
|
|
|
|
|
|
if( m_parent.lock() < aRhs.m_parent.lock() )
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if( m_parent.lock() > aRhs.m_parent.lock() )
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if( m_options != aRhs.m_options )
|
|
|
|
return ( m_options == ENTRY_NORMAL ) ? -1 : 1;
|
|
|
|
|
|
|
|
if( m_unitCount != aRhs.m_unitCount )
|
|
|
|
return m_unitCount - aRhs.m_unitCount;
|
|
|
|
|
|
|
|
if( m_drawings.size() != aRhs.m_drawings.size() )
|
|
|
|
return m_drawings.size() - aRhs.m_drawings.size();
|
|
|
|
|
|
|
|
LIB_ITEMS_CONTAINER::CONST_ITERATOR lhsItem = m_drawings.begin();
|
|
|
|
LIB_ITEMS_CONTAINER::CONST_ITERATOR rhsItem = aRhs.m_drawings.begin();
|
|
|
|
|
|
|
|
while( lhsItem != m_drawings.end() )
|
|
|
|
{
|
|
|
|
if( lhsItem->Type() != rhsItem->Type() )
|
|
|
|
return lhsItem->Type() - rhsItem->Type();
|
|
|
|
|
|
|
|
retv = lhsItem->compare( *rhsItem );
|
|
|
|
|
|
|
|
if( retv )
|
|
|
|
return retv;
|
|
|
|
|
|
|
|
++lhsItem;
|
|
|
|
++rhsItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_FootprintList.GetCount() != aRhs.m_FootprintList.GetCount() )
|
|
|
|
return m_FootprintList.GetCount() - aRhs.m_FootprintList.GetCount();
|
|
|
|
|
|
|
|
for( size_t i = 0; i < m_FootprintList.GetCount(); i++ )
|
|
|
|
{
|
|
|
|
retv = m_FootprintList[i].Cmp( aRhs.m_FootprintList[i] );
|
|
|
|
|
|
|
|
if( retv )
|
|
|
|
return retv;
|
|
|
|
}
|
|
|
|
|
|
|
|
retv = m_description.Cmp( aRhs.m_description );
|
|
|
|
|
|
|
|
if( retv )
|
|
|
|
return retv;
|
|
|
|
|
|
|
|
retv = m_keyWords.Cmp( aRhs.m_keyWords );
|
|
|
|
|
|
|
|
if( retv )
|
|
|
|
return retv;
|
|
|
|
|
|
|
|
if( m_pinNameOffset != aRhs.m_pinNameOffset )
|
|
|
|
return m_pinNameOffset - aRhs.m_pinNameOffset;
|
|
|
|
|
|
|
|
if( m_unitsLocked != aRhs.m_unitsLocked )
|
|
|
|
return ( m_unitsLocked ) ? 1 : -1;
|
|
|
|
|
|
|
|
if( m_showPinNames != aRhs.m_showPinNames )
|
|
|
|
return ( m_showPinNames ) ? 1 : -1;
|
|
|
|
|
|
|
|
if( m_showPinNumbers != aRhs.m_showPinNumbers )
|
|
|
|
return ( m_showPinNumbers ) ? 1 : -1;
|
|
|
|
|
2020-09-09 13:03:37 +00:00
|
|
|
if( m_includeInBom != aRhs.m_includeInBom )
|
|
|
|
return ( m_includeInBom ) ? 1 : -1;
|
|
|
|
|
|
|
|
if( m_includeOnBoard != aRhs.m_includeOnBoard )
|
|
|
|
return ( m_includeOnBoard ) ? 1 : -1;
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString LIB_PART::GetUnitReference( int aUnit )
|
|
|
|
{
|
|
|
|
return LIB_PART::SubReference( aUnit, false );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LIB_PART::SetName( const wxString& aName )
|
|
|
|
{
|
|
|
|
wxString validatedName = LIB_ID::FixIllegalChars( aName, LIB_ID::ID_SCH );
|
|
|
|
|
|
|
|
m_name = validatedName;
|
|
|
|
m_libId.SetLibItemName( validatedName, false );
|
|
|
|
|
|
|
|
GetValueField().SetText( validatedName );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LIB_PART::SetParent( LIB_PART* aParent )
|
|
|
|
{
|
|
|
|
if( aParent )
|
|
|
|
m_parent = aParent->SharedPtr();
|
|
|
|
else
|
|
|
|
m_parent.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::unique_ptr< LIB_PART > LIB_PART::Flatten() const
|
|
|
|
{
|
|
|
|
std::unique_ptr< LIB_PART > retv;
|
|
|
|
|
|
|
|
if( IsAlias() )
|
|
|
|
{
|
|
|
|
PART_SPTR parent = m_parent.lock();
|
|
|
|
|
|
|
|
wxCHECK_MSG( parent, retv,
|
|
|
|
wxString::Format( "Parent of derived symbol '%s' undefined", m_name ) );
|
|
|
|
|
2019-11-07 14:09:24 +00:00
|
|
|
// Copy the parent.
|
2019-11-08 20:50:04 +00:00
|
|
|
retv.reset( new LIB_PART( *parent.get() ) );
|
2019-11-06 19:15:42 +00:00
|
|
|
|
2019-11-07 14:09:24 +00:00
|
|
|
retv->SetName( m_name );
|
2019-11-06 19:15:42 +00:00
|
|
|
|
2020-06-01 17:45:46 +00:00
|
|
|
// Now add the inherited part mandatory field (this) information.
|
2020-06-01 13:13:32 +00:00
|
|
|
for( int i = 0; i < MANDATORY_FIELDS; i++ )
|
|
|
|
{
|
|
|
|
wxString tmp = GetField( i )->GetText();
|
|
|
|
|
|
|
|
// If the field isn't defined then inherit the parent field value.
|
|
|
|
if( tmp.IsEmpty() )
|
|
|
|
retv->GetField( i )->SetText( parent->GetField( i )->GetText() );
|
|
|
|
else
|
|
|
|
*retv->GetField( i ) = *GetField( i );
|
|
|
|
}
|
|
|
|
|
2020-06-01 17:45:46 +00:00
|
|
|
// Grab all the rest of derived symbol fields.
|
|
|
|
for( const LIB_ITEM& item : m_drawings[ LIB_FIELD_T ] )
|
|
|
|
{
|
|
|
|
const LIB_FIELD* aliasField = dynamic_cast<const LIB_FIELD*>( &item );
|
|
|
|
|
|
|
|
wxCHECK2( aliasField, continue );
|
|
|
|
|
|
|
|
// Mandatory fields were already resolved.
|
|
|
|
if( aliasField->IsMandatory() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
LIB_FIELD* newField = new LIB_FIELD( *aliasField );
|
|
|
|
newField->SetParent( retv.get() );
|
|
|
|
|
|
|
|
LIB_FIELD* parentField = retv->FindField( aliasField->GetName() );
|
|
|
|
|
|
|
|
if( !parentField ) // Derived symbol field does not exist in parent symbol.
|
|
|
|
{
|
|
|
|
retv->AddDrawItem( newField );
|
|
|
|
}
|
|
|
|
else // Derived symbol field overrides the parent symbol field.
|
|
|
|
{
|
|
|
|
retv->RemoveDrawItem( parentField );
|
|
|
|
retv->AddDrawItem( newField );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-07 14:09:24 +00:00
|
|
|
retv->SetKeyWords( m_keyWords );
|
|
|
|
retv->SetDescription( m_description );
|
2019-11-06 19:15:42 +00:00
|
|
|
}
|
|
|
|
else
|
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.
2014-08-13 20:28:54 +00:00
|
|
|
{
|
2019-11-08 20:50:04 +00:00
|
|
|
retv.reset( new LIB_PART( *this ) );
|
2010-10-04 18:54:14 +00:00
|
|
|
}
|
2019-11-06 19:15:42 +00:00
|
|
|
|
|
|
|
return retv;
|
2008-12-31 09:27:19 +00:00
|
|
|
}
|
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
const wxString LIB_PART::GetLibraryName() const
|
2010-10-25 15:43:42 +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.
2014-08-13 20:28:54 +00:00
|
|
|
if( m_library )
|
2010-10-25 15:43:42 +00:00
|
|
|
return m_library->GetName();
|
|
|
|
|
2018-08-05 13:03:23 +00:00
|
|
|
return m_libId.GetLibNickname();
|
2010-10-25 15:43:42 +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.
2014-08-13 20:28:54 +00:00
|
|
|
wxString LIB_PART::SubReference( int aUnit, bool aAddSeparator )
|
2010-04-24 11:27:38 +00:00
|
|
|
{
|
|
|
|
wxString subRef;
|
2013-05-19 19:35:49 +00:00
|
|
|
|
|
|
|
if( m_subpartIdSeparator != 0 && aAddSeparator )
|
|
|
|
subRef << wxChar( m_subpartIdSeparator );
|
|
|
|
|
|
|
|
if( m_subpartFirstId >= '0' && m_subpartFirstId <= '9' )
|
|
|
|
subRef << aUnit;
|
|
|
|
else
|
2015-04-07 11:52:29 +00:00
|
|
|
{
|
|
|
|
// use letters as notation. To allow more than 26 units, the sub ref
|
|
|
|
// use one letter if letter = A .. Z or a ... z, and 2 letters otherwise
|
|
|
|
// first letter is expected to be 'A' or 'a' (i.e. 26 letters are available)
|
|
|
|
int u;
|
2015-04-07 13:19:30 +00:00
|
|
|
aUnit -= 1; // Unit number starts to 1. now to 0.
|
2015-04-07 11:52:29 +00:00
|
|
|
|
2015-04-07 13:19:30 +00:00
|
|
|
while( aUnit >= 26 ) // more than one letter are needed
|
2015-04-07 11:52:29 +00:00
|
|
|
{
|
|
|
|
u = aUnit / 26;
|
|
|
|
subRef << wxChar( m_subpartFirstId + u -1 );
|
|
|
|
aUnit %= 26;
|
|
|
|
}
|
|
|
|
|
2015-04-07 13:19:30 +00:00
|
|
|
u = m_subpartFirstId + aUnit;
|
2015-04-07 11:52:29 +00:00
|
|
|
subRef << wxChar( u );
|
|
|
|
}
|
2013-05-19 19:35:49 +00:00
|
|
|
|
2010-04-24 11:27:38 +00:00
|
|
|
return subRef;
|
|
|
|
}
|
|
|
|
|
2008-12-31 09:27:19 +00:00
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
void LIB_PART::Print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset, int aMulti,
|
|
|
|
int aConvert, const PART_DRAW_OPTIONS& aOpts )
|
2009-09-04 18:57:37 +00:00
|
|
|
{
|
2010-03-28 14:46:49 +00:00
|
|
|
/* draw background for filled items using background option
|
|
|
|
* Solid lines will be drawn after the background
|
2019-04-04 22:49:49 +00:00
|
|
|
* Note also, background is not drawn when printing in black and white
|
2010-03-28 14:46:49 +00:00
|
|
|
*/
|
2019-05-31 12:15:25 +00:00
|
|
|
if( !GetGRForceBlackPenState() )
|
2010-03-28 14:46:49 +00:00
|
|
|
{
|
2017-09-17 08:26:06 +00:00
|
|
|
for( LIB_ITEM& drawItem : m_drawings )
|
2010-03-28 14:46:49 +00:00
|
|
|
{
|
|
|
|
if( drawItem.m_Fill != FILLED_WITH_BG_BODYCOLOR )
|
|
|
|
continue;
|
|
|
|
|
2012-06-06 14:12:39 +00:00
|
|
|
// Do not draw items not attached to the current part
|
2010-03-28 14:46:49 +00:00
|
|
|
if( aMulti && drawItem.m_Unit && ( drawItem.m_Unit != aMulti ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( aConvert && drawItem.m_Convert && ( drawItem.m_Convert != aConvert ) )
|
|
|
|
continue;
|
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
if( drawItem.Type() == LIB_FIELD_T )
|
2010-03-28 14:46:49 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// Now, draw only the background for items with
|
|
|
|
// m_Fill == FILLED_WITH_BG_BODYCOLOR:
|
2020-04-14 12:25:00 +00:00
|
|
|
drawItem.Print( aSettings, aOffset, (void*) false, aOpts.transform );
|
2010-03-28 14:46:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-17 08:26:06 +00:00
|
|
|
for( LIB_ITEM& drawItem : m_drawings )
|
2009-09-04 18:57:37 +00:00
|
|
|
{
|
2012-06-06 14:12:39 +00:00
|
|
|
// Do not draw items not attached to the current part
|
2009-12-15 21:11:05 +00:00
|
|
|
if( aMulti && drawItem.m_Unit && ( drawItem.m_Unit != aMulti ) )
|
2009-09-04 18:57:37 +00:00
|
|
|
continue;
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( aConvert && drawItem.m_Convert && ( drawItem.m_Convert != aConvert ) )
|
2009-09-04 18:57:37 +00:00
|
|
|
continue;
|
|
|
|
|
2017-02-19 18:40:26 +00:00
|
|
|
if( drawItem.Type() == LIB_FIELD_T )
|
|
|
|
{
|
2018-09-06 15:55:37 +00:00
|
|
|
LIB_FIELD& field = static_cast<LIB_FIELD&>( drawItem );
|
2017-02-19 18:40:26 +00:00
|
|
|
|
|
|
|
if( field.IsVisible() && !aOpts.draw_visible_fields )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( !field.IsVisible() && !aOpts.draw_hidden_fields )
|
|
|
|
continue;
|
|
|
|
}
|
2009-09-04 18:57:37 +00:00
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
if( drawItem.Type() == LIB_PIN_T )
|
2009-09-04 18:57:37 +00:00
|
|
|
{
|
2020-04-14 12:25:00 +00:00
|
|
|
drawItem.Print( aSettings, aOffset, (void*) &aOpts, aOpts.transform );
|
2009-09-04 18:57:37 +00:00
|
|
|
}
|
2010-12-10 19:47:44 +00:00
|
|
|
else if( drawItem.Type() == LIB_FIELD_T )
|
2009-09-04 18:57:37 +00:00
|
|
|
{
|
2020-04-14 12:25:00 +00:00
|
|
|
drawItem.Print( aSettings, aOffset, (void*) NULL, aOpts.transform );
|
2009-09-04 18:57:37 +00:00
|
|
|
}
|
2009-10-21 20:02:25 +00:00
|
|
|
else
|
2009-09-04 18:57:37 +00:00
|
|
|
{
|
2010-03-28 14:46:49 +00:00
|
|
|
bool forceNoFill = drawItem.m_Fill == FILLED_WITH_BG_BODYCOLOR;
|
2020-04-14 12:25:00 +00:00
|
|
|
drawItem.Print( aSettings, aOffset, (void*) forceNoFill, aOpts.transform );
|
2009-09-04 18:57:37 +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.
2014-08-13 20:28:54 +00:00
|
|
|
void LIB_PART::Plot( PLOTTER* aPlotter, int aUnit, int aConvert,
|
2017-12-01 16:49:19 +00:00
|
|
|
const wxPoint& aOffset, const TRANSFORM& aTransform )
|
2009-10-05 17:52:41 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
wxASSERT( aPlotter != NULL );
|
2009-10-05 17:52:41 +00:00
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
aPlotter->SetColor( aPlotter->RenderSettings()->GetLayerColor( LAYER_DEVICE ) );
|
2013-05-18 09:38:23 +00:00
|
|
|
bool fill = aPlotter->GetColorMode();
|
|
|
|
|
2014-11-12 10:32:02 +00:00
|
|
|
// draw background for filled items using background option
|
|
|
|
// Solid lines will be drawn after the background
|
2017-09-17 08:26:06 +00:00
|
|
|
for( LIB_ITEM& item : m_drawings )
|
2009-10-05 17:52:41 +00:00
|
|
|
{
|
2014-11-12 10:32:02 +00:00
|
|
|
// Lib Fields are not plotted here, because this plot function
|
2013-05-18 09:38:23 +00:00
|
|
|
// is used to plot schematic items, which have they own fields
|
|
|
|
if( item.Type() == LIB_FIELD_T )
|
|
|
|
continue;
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( aUnit && item.m_Unit && ( item.m_Unit != aUnit ) )
|
2009-10-05 17:52:41 +00:00
|
|
|
continue;
|
2011-10-31 20:49:48 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( aConvert && item.m_Convert && ( item.m_Convert != aConvert ) )
|
2009-10-05 17:52:41 +00:00
|
|
|
continue;
|
|
|
|
|
2014-11-12 10:32:02 +00:00
|
|
|
if( item.m_Fill == FILLED_WITH_BG_BODYCOLOR )
|
|
|
|
item.Plot( aPlotter, aOffset, fill, aTransform );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Not filled items and filled shapes are now plotted
|
2019-08-20 14:01:16 +00:00
|
|
|
// Items that have BG fills only get re-stroked to ensure the edges are in the foreground
|
2017-09-17 08:26:06 +00:00
|
|
|
for( LIB_ITEM& item : m_drawings )
|
2014-11-12 10:32:02 +00:00
|
|
|
{
|
|
|
|
if( item.Type() == LIB_FIELD_T )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( aUnit && item.m_Unit && ( item.m_Unit != aUnit ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( aConvert && item.m_Convert && ( item.m_Convert != aConvert ) )
|
|
|
|
continue;
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
item.Plot( aPlotter, aOffset, fill && ( item.m_Fill != FILLED_WITH_BG_BODYCOLOR ),
|
|
|
|
aTransform );
|
2013-05-18 09:38:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-01 16:49:19 +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.
2014-08-13 20:28:54 +00:00
|
|
|
void LIB_PART::PlotLibFields( PLOTTER* aPlotter, int aUnit, int aConvert,
|
2017-12-01 16:49:19 +00:00
|
|
|
const wxPoint& aOffset, const TRANSFORM& aTransform )
|
2013-05-18 09:38:23 +00:00
|
|
|
{
|
|
|
|
wxASSERT( aPlotter != NULL );
|
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
aPlotter->SetColor( aPlotter->RenderSettings()->GetLayerColor( LAYER_FIELDS ) );
|
2013-05-18 09:38:23 +00:00
|
|
|
bool fill = aPlotter->GetColorMode();
|
|
|
|
|
2017-09-17 08:26:06 +00:00
|
|
|
for( LIB_ITEM& item : m_drawings )
|
2013-05-18 09:38:23 +00:00
|
|
|
{
|
|
|
|
if( item.Type() != LIB_FIELD_T )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( aUnit && item.m_Unit && ( item.m_Unit != aUnit ) )
|
|
|
|
continue;
|
2009-10-05 17:52:41 +00:00
|
|
|
|
2013-05-18 09:38:23 +00:00
|
|
|
if( aConvert && item.m_Convert && ( item.m_Convert != aConvert ) )
|
|
|
|
continue;
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
LIB_FIELD& field = (LIB_FIELD&) item;
|
|
|
|
|
2015-01-27 18:40:52 +00:00
|
|
|
// The reference is a special case: we should change the basic text
|
2013-05-18 09:38:23 +00:00
|
|
|
// to add '?' and the part id
|
2014-09-13 18:15:45 +00:00
|
|
|
wxString tmp = field.GetShownText();
|
2019-11-06 19:15:42 +00:00
|
|
|
|
2013-05-18 09:38:23 +00:00
|
|
|
if( field.GetId() == REFERENCE )
|
|
|
|
{
|
|
|
|
wxString text = field.GetFullText( aUnit );
|
|
|
|
field.SetText( text );
|
|
|
|
}
|
2019-11-06 19:15:42 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
item.Plot( aPlotter, aOffset, fill, aTransform );
|
2013-05-18 09:38:23 +00:00
|
|
|
field.SetText( tmp );
|
2009-10-05 17:52:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-31 12:15:25 +00:00
|
|
|
void LIB_PART::RemoveDrawItem( LIB_ITEM* aItem )
|
2009-09-04 18:57:37 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
wxASSERT( aItem != NULL );
|
2009-09-04 18:57:37 +00:00
|
|
|
|
2015-02-06 15:34:11 +00:00
|
|
|
// none of the MANDATORY_FIELDS may be removed in RAM, but they may be
|
2010-06-17 16:30:10 +00:00
|
|
|
// omitted when saving to disk.
|
2010-12-10 19:47:44 +00:00
|
|
|
if( aItem->Type() == LIB_FIELD_T )
|
2009-10-21 20:02:25 +00:00
|
|
|
{
|
2020-04-01 14:00:40 +00:00
|
|
|
if( static_cast<LIB_FIELD*>( aItem )->IsMandatory() )
|
2009-10-21 20:02:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-17 08:26:06 +00:00
|
|
|
LIB_ITEMS& items = m_drawings[ aItem->Type() ];
|
2009-09-04 18:57:37 +00:00
|
|
|
|
2017-08-14 14:53:25 +00:00
|
|
|
for( LIB_ITEMS::iterator i = items.begin(); i != items.end(); i++ )
|
2009-09-04 18:57:37 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
if( *i == aItem )
|
2009-09-29 18:38:21 +00:00
|
|
|
{
|
2017-08-14 14:53:25 +00:00
|
|
|
items.erase( i );
|
2011-02-24 22:29:43 +00:00
|
|
|
SetModified();
|
2009-10-21 20:02:25 +00:00
|
|
|
break;
|
2009-09-04 18:57:37 +00:00
|
|
|
}
|
2009-09-29 18:38:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-04 18:57:37 +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.
2014-08-13 20:28:54 +00:00
|
|
|
void LIB_PART::AddDrawItem( LIB_ITEM* aItem )
|
2009-09-29 18:38:21 +00:00
|
|
|
{
|
2019-05-27 03:12:27 +00:00
|
|
|
if( !aItem )
|
|
|
|
return;
|
2009-09-29 18:38:21 +00:00
|
|
|
|
2017-09-17 08:26:06 +00:00
|
|
|
m_drawings.push_back( aItem );
|
2009-09-29 18:38:21 +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.
2014-08-13 20:28:54 +00:00
|
|
|
LIB_ITEM* LIB_PART::GetNextDrawItem( LIB_ITEM* aItem, KICAD_T aType )
|
2009-09-29 18:38:21 +00:00
|
|
|
{
|
2017-09-17 08:26:06 +00:00
|
|
|
if( aItem == NULL )
|
2019-11-06 19:15:42 +00:00
|
|
|
{
|
|
|
|
LIB_ITEMS_CONTAINER::ITERATOR it1 = m_drawings.begin( aType );
|
|
|
|
|
|
|
|
return (it1 != m_drawings.end( aType ) ) ? &( *( m_drawings.begin( aType ) ) ) : nullptr;
|
|
|
|
}
|
2009-09-29 18:38:21 +00:00
|
|
|
|
2017-09-17 09:09:56 +00:00
|
|
|
// Search for the last item, assume aItem is of type aType
|
2017-09-17 08:26:06 +00:00
|
|
|
wxASSERT( ( aType == TYPE_NOT_INIT ) || ( aType == aItem->Type() ) );
|
|
|
|
LIB_ITEMS_CONTAINER::ITERATOR it = m_drawings.begin( aType );
|
2017-09-17 09:09:56 +00:00
|
|
|
|
2017-09-17 08:26:06 +00:00
|
|
|
while( ( it != m_drawings.end( aType ) ) && ( aItem != &( *it ) ) )
|
|
|
|
++it;
|
2009-09-29 18:38:21 +00:00
|
|
|
|
2009-10-08 16:45:59 +00:00
|
|
|
// Search the next item
|
2017-09-17 08:26:06 +00:00
|
|
|
if( it != m_drawings.end( aType ) )
|
2009-10-08 16:45:59 +00:00
|
|
|
{
|
2017-09-17 08:26:06 +00:00
|
|
|
++it;
|
2017-09-17 09:09:56 +00:00
|
|
|
|
2017-09-17 08:26:06 +00:00
|
|
|
if( it != m_drawings.end( aType ) )
|
|
|
|
return &( *it );
|
2009-09-29 18:38:21 +00:00
|
|
|
}
|
|
|
|
|
2009-10-05 17:52:41 +00:00
|
|
|
return NULL;
|
2009-09-04 18:57:37 +00:00
|
|
|
}
|
|
|
|
|
2009-12-15 21:11:05 +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.
2014-08-13 20:28:54 +00:00
|
|
|
void LIB_PART::GetPins( LIB_PINS& aList, int aUnit, int aConvert )
|
2009-10-14 19:43:31 +00:00
|
|
|
{
|
2009-10-26 12:01:46 +00:00
|
|
|
/* Notes:
|
2009-12-15 21:11:05 +00:00
|
|
|
* when aUnit == 0: no unit filtering
|
|
|
|
* when aConvert == 0: no convert (shape selection) filtering
|
2009-10-26 12:01:46 +00:00
|
|
|
* when .m_Unit == 0, the body item is common to units
|
2009-10-26 19:00:46 +00:00
|
|
|
* when .m_Convert == 0, the body item is common to shapes
|
2009-10-26 12:01:46 +00:00
|
|
|
*/
|
2017-09-17 08:26:06 +00:00
|
|
|
for( LIB_ITEM& item : m_drawings[ LIB_PIN_T ] )
|
2009-10-14 19:43:31 +00:00
|
|
|
{
|
2009-10-26 12:01:46 +00:00
|
|
|
// Unit filtering:
|
2009-12-15 21:11:05 +00:00
|
|
|
if( aUnit && item.m_Unit && ( item.m_Unit != aUnit ) )
|
2009-10-26 12:01:46 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// Shape filtering:
|
2009-12-15 21:11:05 +00:00
|
|
|
if( aConvert && item.m_Convert && ( item.m_Convert != aConvert ) )
|
2009-10-14 19:43:31 +00:00
|
|
|
continue;
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
aList.push_back( (LIB_PIN*) &item );
|
2009-10-14 19:43:31 +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.
2014-08-13 20:28:54 +00:00
|
|
|
LIB_PIN* LIB_PART::GetPin( const wxString& aNumber, int aUnit, int aConvert )
|
2009-10-30 19:26:25 +00:00
|
|
|
{
|
2011-04-27 19:44:32 +00:00
|
|
|
LIB_PINS pinList;
|
2009-10-30 19:26:25 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
GetPins( pinList, aUnit, aConvert );
|
2009-10-30 19:26:25 +00:00
|
|
|
|
|
|
|
for( size_t i = 0; i < pinList.size(); i++ )
|
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
wxASSERT( pinList[i]->Type() == LIB_PIN_T );
|
2009-10-30 19:26:25 +00:00
|
|
|
|
2017-08-10 15:00:28 +00:00
|
|
|
if( aNumber == pinList[i]->GetNumber() )
|
2009-10-30 19:26:25 +00:00
|
|
|
return pinList[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-25 22:26:51 +00:00
|
|
|
bool LIB_PART::PinsConflictWith( LIB_PART& aOtherPart, bool aTestNums, bool aTestNames,
|
|
|
|
bool aTestType, bool aTestOrientation, bool aTestLength )
|
|
|
|
{
|
|
|
|
LIB_PINS thisPinList;
|
|
|
|
GetPins( thisPinList, /* aUnit */ 0, /* aConvert */ 0 );
|
|
|
|
|
2016-06-29 20:07:55 +00:00
|
|
|
for( LIB_PIN* eachThisPin : thisPinList )
|
2015-04-25 22:26:51 +00:00
|
|
|
{
|
|
|
|
wxASSERT( eachThisPin );
|
|
|
|
LIB_PINS otherPinList;
|
|
|
|
aOtherPart.GetPins( otherPinList, /* aUnit */ 0, /* aConvert */ 0 );
|
|
|
|
bool foundMatch = false;
|
|
|
|
|
2016-06-29 20:07:55 +00:00
|
|
|
for( LIB_PIN* eachOtherPin : otherPinList )
|
2015-04-25 22:26:51 +00:00
|
|
|
{
|
|
|
|
wxASSERT( eachOtherPin );
|
2020-04-02 00:17:25 +00:00
|
|
|
|
|
|
|
// Same unit?
|
|
|
|
if( eachThisPin->GetUnit() != eachOtherPin->GetUnit() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Same body stype?
|
|
|
|
if( eachThisPin->GetConvert() != eachOtherPin->GetConvert() )
|
|
|
|
continue;
|
|
|
|
|
2015-04-25 22:26:51 +00:00
|
|
|
// Same position?
|
|
|
|
if( eachThisPin->GetPosition() != eachOtherPin->GetPosition() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Same number?
|
2019-11-06 19:15:42 +00:00
|
|
|
if( aTestNums && ( eachThisPin->GetNumber() != eachOtherPin->GetNumber() ) )
|
2015-04-25 22:26:51 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// Same name?
|
2019-11-06 19:15:42 +00:00
|
|
|
if( aTestNames && ( eachThisPin->GetName() != eachOtherPin->GetName() ) )
|
2015-04-25 22:26:51 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// Same electrical type?
|
2019-11-06 19:15:42 +00:00
|
|
|
if( aTestType && ( eachThisPin->GetType() != eachOtherPin->GetType() ) )
|
2015-04-25 22:26:51 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// Same orientation?
|
2019-11-06 19:15:42 +00:00
|
|
|
if( aTestOrientation
|
|
|
|
&& ( eachThisPin->GetOrientation() != eachOtherPin->GetOrientation() ) )
|
2015-04-25 22:26:51 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// Same length?
|
2019-11-06 19:15:42 +00:00
|
|
|
if( aTestLength && ( eachThisPin->GetLength() != eachOtherPin->GetLength() ) )
|
2015-04-25 22:26:51 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
foundMatch = true;
|
2020-04-02 00:17:25 +00:00
|
|
|
break; // Match found so seach is complete.
|
2015-04-25 22:26:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( !foundMatch )
|
|
|
|
{
|
|
|
|
// This means there was not an identical (according to the arguments)
|
|
|
|
// pin at the same position in the other component.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The loop never gave up, so no conflicts were found.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-30 05:31:48 +00:00
|
|
|
const EDA_RECT LIB_PART::GetUnitBoundingBox( int aUnit, int aConvert ) const
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2015-06-18 14:56:08 +00:00
|
|
|
EDA_RECT bBox;
|
|
|
|
bool initialized = false;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2017-09-17 08:26:06 +00:00
|
|
|
for( const LIB_ITEM& item : m_drawings )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2010-10-25 15:43:42 +00:00
|
|
|
if( ( item.m_Unit > 0 ) && ( ( m_unitCount > 1 ) && ( aUnit > 0 )
|
2009-12-15 21:11:05 +00:00
|
|
|
&& ( aUnit != item.m_Unit ) ) )
|
2009-09-29 18:38:21 +00:00
|
|
|
continue;
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2010-09-09 17:37:25 +00:00
|
|
|
if( item.m_Convert > 0 && ( ( aConvert > 0 ) && ( aConvert != item.m_Convert ) ) )
|
2009-09-29 18:38:21 +00:00
|
|
|
continue;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
if ( ( item.Type() == LIB_FIELD_T ) && !( ( LIB_FIELD& ) item ).IsVisible() )
|
2009-11-20 19:51:39 +00:00
|
|
|
continue;
|
|
|
|
|
2015-06-18 14:56:08 +00:00
|
|
|
if( initialized )
|
|
|
|
bBox.Merge( item.GetBoundingBox() );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bBox = item.GetBoundingBox();
|
|
|
|
initialized = true;
|
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return bBox;
|
2008-12-31 09:27:19 +00:00
|
|
|
}
|
2008-12-31 15:01:29 +00:00
|
|
|
|
|
|
|
|
2018-10-21 12:50:31 +00:00
|
|
|
void LIB_PART::ViewGetLayers( int aLayers[], int& aCount ) const
|
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
aCount = 6;
|
2018-10-21 12:50:31 +00:00
|
|
|
aLayers[0] = LAYER_DEVICE;
|
|
|
|
aLayers[1] = LAYER_DEVICE_BACKGROUND;
|
2019-11-06 19:15:42 +00:00
|
|
|
aLayers[2] = LAYER_REFERENCEPART;
|
|
|
|
aLayers[3] = LAYER_VALUEPART;
|
|
|
|
aLayers[4] = LAYER_FIELDS;
|
|
|
|
aLayers[5] = LAYER_SELECTION_SHADOWS;
|
2018-10-21 12:50:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-18 17:28:14 +00:00
|
|
|
const EDA_RECT LIB_PART::GetBodyBoundingBox( int aUnit, int aConvert ) const
|
2011-02-27 19:54:01 +00:00
|
|
|
{
|
2020-01-23 14:03:46 +00:00
|
|
|
EDA_RECT bbox;
|
2011-02-27 19:54:01 +00:00
|
|
|
|
2017-09-17 08:26:06 +00:00
|
|
|
for( const LIB_ITEM& item : m_drawings )
|
2011-02-27 19:54:01 +00:00
|
|
|
{
|
|
|
|
if( ( item.m_Unit > 0 ) && ( ( m_unitCount > 1 ) && ( aUnit > 0 )
|
|
|
|
&& ( aUnit != item.m_Unit ) ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( item.m_Convert > 0 && ( ( aConvert > 0 ) && ( aConvert != item.m_Convert ) ) )
|
|
|
|
continue;
|
|
|
|
|
2015-12-13 16:56:47 +00:00
|
|
|
if( item.Type() == LIB_FIELD_T )
|
2011-02-27 19:54:01 +00:00
|
|
|
continue;
|
|
|
|
|
2020-01-23 14:03:46 +00:00
|
|
|
bbox.Merge( item.GetBoundingBox() );
|
2011-02-27 19:54:01 +00:00
|
|
|
}
|
|
|
|
|
2020-01-23 14:03:46 +00:00
|
|
|
return bbox;
|
2011-02-27 19:54:01 +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.
2014-08-13 20:28:54 +00:00
|
|
|
void LIB_PART::deleteAllFields()
|
2008-12-31 15:01:29 +00:00
|
|
|
{
|
2017-09-17 08:26:06 +00:00
|
|
|
m_drawings[ LIB_FIELD_T ].clear();
|
2010-06-17 16:30:10 +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.
2014-08-13 20:28:54 +00:00
|
|
|
void LIB_PART::SetFields( const std::vector <LIB_FIELD>& aFields )
|
2010-06-17 16:30:10 +00:00
|
|
|
{
|
|
|
|
deleteAllFields();
|
|
|
|
|
|
|
|
for( unsigned i=0; i<aFields.size(); ++i )
|
|
|
|
{
|
|
|
|
// drawings is a ptr_vector, new and copy an object on the heap.
|
|
|
|
LIB_FIELD* field = new LIB_FIELD( aFields[i] );
|
2009-10-21 20:02:25 +00:00
|
|
|
|
2014-10-26 11:42:25 +00:00
|
|
|
field->SetParent( this );
|
2017-09-17 08:26:06 +00:00
|
|
|
m_drawings.push_back( field );
|
2008-12-31 15:01:29 +00:00
|
|
|
}
|
2009-10-21 20:02:25 +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.
2014-08-13 20:28:54 +00:00
|
|
|
void LIB_PART::GetFields( LIB_FIELDS& aList )
|
2009-10-21 20:02:25 +00:00
|
|
|
{
|
2010-06-17 16:30:10 +00:00
|
|
|
LIB_FIELD* field;
|
|
|
|
|
|
|
|
// Grab the MANDATORY_FIELDS first, in expected order given by
|
|
|
|
// enum NumFieldType
|
|
|
|
for( int id=0; id<MANDATORY_FIELDS; ++id )
|
|
|
|
{
|
|
|
|
field = GetField( id );
|
|
|
|
|
|
|
|
// the MANDATORY_FIELDS are exactly that in RAM.
|
|
|
|
wxASSERT( field );
|
|
|
|
|
|
|
|
aList.push_back( *field );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now grab all the rest of fields.
|
2017-09-17 08:26:06 +00:00
|
|
|
for( LIB_ITEM& item : m_drawings[ LIB_FIELD_T ] )
|
2008-12-31 15:01:29 +00:00
|
|
|
{
|
2010-06-17 16:30:10 +00:00
|
|
|
field = ( LIB_FIELD* ) &item;
|
2011-10-31 20:49:48 +00:00
|
|
|
|
2020-04-01 14:00:40 +00:00
|
|
|
if( field->IsMandatory() )
|
2010-06-17 16:30:10 +00:00
|
|
|
continue; // was added above
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
aList.push_back( *field );
|
2008-12-31 15:01:29 +00:00
|
|
|
}
|
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
|
2019-11-07 14:09:24 +00:00
|
|
|
LIB_FIELD* LIB_PART::GetField( int aId ) const
|
2009-10-21 20:02:25 +00:00
|
|
|
{
|
2019-11-07 14:09:24 +00:00
|
|
|
for( const LIB_ITEM& item : m_drawings[ LIB_FIELD_T ] )
|
2009-10-21 20:02:25 +00:00
|
|
|
{
|
|
|
|
LIB_FIELD* field = ( LIB_FIELD* ) &item;
|
|
|
|
|
2010-12-07 16:10:42 +00:00
|
|
|
if( field->GetId() == aId )
|
2009-10-21 20:02:25 +00:00
|
|
|
return field;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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.
2014-08-13 20:28:54 +00:00
|
|
|
LIB_FIELD* LIB_PART::FindField( const wxString& aFieldName )
|
2010-06-17 16:30:10 +00:00
|
|
|
{
|
2017-09-17 08:26:06 +00:00
|
|
|
for( LIB_ITEM& item : m_drawings[ LIB_FIELD_T ] )
|
2010-06-17 16:30:10 +00:00
|
|
|
{
|
2020-06-02 19:27:22 +00:00
|
|
|
if( static_cast<LIB_FIELD*>( &item )->GetCanonicalName() == aFieldName )
|
|
|
|
return static_cast<LIB_FIELD*>( &item );
|
|
|
|
}
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2020-06-02 19:27:22 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const LIB_FIELD* LIB_PART::FindField( const wxString& aFieldName ) const
|
|
|
|
{
|
|
|
|
for( const LIB_ITEM& item : m_drawings[ LIB_FIELD_T ] )
|
|
|
|
{
|
|
|
|
if( static_cast<const LIB_FIELD*>( &item )->GetCanonicalName() == aFieldName )
|
|
|
|
return static_cast<const LIB_FIELD*>( &item );
|
2010-06-17 16:30:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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.
2014-08-13 20:28:54 +00:00
|
|
|
LIB_FIELD& LIB_PART::GetValueField()
|
2009-10-21 20:02:25 +00:00
|
|
|
{
|
|
|
|
LIB_FIELD* field = GetField( VALUE );
|
|
|
|
wxASSERT( field != NULL );
|
|
|
|
return *field;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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.
2014-08-13 20:28:54 +00:00
|
|
|
LIB_FIELD& LIB_PART::GetReferenceField()
|
2009-10-21 20:02:25 +00:00
|
|
|
{
|
|
|
|
LIB_FIELD* field = GetField( REFERENCE );
|
|
|
|
wxASSERT( field != NULL );
|
|
|
|
return *field;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-09 13:08:33 +00:00
|
|
|
LIB_FIELD& LIB_PART::GetFootprintField()
|
|
|
|
{
|
|
|
|
LIB_FIELD* field = GetField( FOOTPRINT );
|
|
|
|
wxASSERT( field != NULL );
|
|
|
|
return *field;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-01 13:13:32 +00:00
|
|
|
LIB_FIELD& LIB_PART::GetDatasheetField()
|
|
|
|
{
|
|
|
|
LIB_FIELD* field = GetField( DATASHEET );
|
|
|
|
wxASSERT( field != NULL );
|
|
|
|
return *field;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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.
2014-08-13 20:28:54 +00:00
|
|
|
void LIB_PART::SetOffset( const wxPoint& aOffset )
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2017-09-17 08:26:06 +00:00
|
|
|
for( LIB_ITEM& item : m_drawings )
|
2019-05-09 07:57:07 +00:00
|
|
|
item.Offset( aOffset );
|
2009-09-14 13:24:17 +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.
2014-08-13 20:28:54 +00:00
|
|
|
void LIB_PART::RemoveDuplicateDrawItems()
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2017-09-17 08:26:06 +00:00
|
|
|
m_drawings.unique();
|
2009-09-14 13:24:17 +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.
2014-08-13 20:28:54 +00:00
|
|
|
bool LIB_PART::HasConversion() const
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2017-09-17 08:26:06 +00:00
|
|
|
for( const LIB_ITEM& item : m_drawings )
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2019-04-15 13:59:36 +00:00
|
|
|
if( item.m_Convert > LIB_ITEM::LIB_CONVERT::BASE )
|
2009-09-14 13:24:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-11-07 14:09:24 +00:00
|
|
|
if( PART_SPTR parent = m_parent.lock() )
|
|
|
|
{
|
|
|
|
for( const LIB_ITEM& item : parent->GetDrawItems() )
|
|
|
|
{
|
|
|
|
if( item.m_Convert > LIB_ITEM::LIB_CONVERT::BASE )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-14 13:24:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
|
2019-05-11 10:06:28 +00:00
|
|
|
void LIB_PART::ClearTempFlags()
|
2009-09-29 18:38:21 +00:00
|
|
|
{
|
2017-09-17 08:26:06 +00:00
|
|
|
for( LIB_ITEM& item : m_drawings )
|
2019-05-11 10:06:28 +00:00
|
|
|
item.ClearTempFlags();
|
|
|
|
}
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
|
2019-05-11 10:06:28 +00:00
|
|
|
void LIB_PART::ClearEditFlags()
|
|
|
|
{
|
|
|
|
for( LIB_ITEM& item : m_drawings )
|
|
|
|
item.ClearEditFlags();
|
2009-09-29 18:38:21 +00:00
|
|
|
}
|
|
|
|
|
2019-11-06 19:15:42 +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.
2014-08-13 20:28:54 +00:00
|
|
|
LIB_ITEM* LIB_PART::LocateDrawItem( int aUnit, int aConvert,
|
2015-01-27 18:40:52 +00:00
|
|
|
KICAD_T aType, const wxPoint& aPoint )
|
2009-09-29 18:38:21 +00:00
|
|
|
{
|
2017-09-17 08:26:06 +00:00
|
|
|
for( LIB_ITEM& item : m_drawings )
|
2009-09-29 18:38:21 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
if( ( aUnit && item.m_Unit && ( aUnit != item.m_Unit) )
|
|
|
|
|| ( aConvert && item.m_Convert && ( aConvert != item.m_Convert ) )
|
|
|
|
|| ( ( item.Type() != aType ) && ( aType != TYPE_NOT_INIT ) ) )
|
2009-09-29 18:38:21 +00:00
|
|
|
continue;
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( item.HitTest( aPoint ) )
|
2009-10-05 17:52:41 +00:00
|
|
|
return &item;
|
2009-09-29 18:38:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-10-05 17:52:41 +00:00
|
|
|
|
2010-12-14 15:56:30 +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.
2014-08-13 20:28:54 +00:00
|
|
|
LIB_ITEM* LIB_PART::LocateDrawItem( int aUnit, int aConvert, KICAD_T aType,
|
2015-01-27 18:40:52 +00:00
|
|
|
const wxPoint& aPoint, const TRANSFORM& aTransform )
|
2009-10-06 13:52:43 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
/* we use LocateDrawItem( int aUnit, int convert, KICAD_T type, const
|
2009-10-19 19:00:47 +00:00
|
|
|
* wxPoint& pt ) to search items.
|
2011-05-05 17:45:35 +00:00
|
|
|
* because this function uses DefaultTransform as orient/mirror matrix
|
|
|
|
* we temporary copy aTransform in DefaultTransform
|
2009-10-19 19:00:47 +00:00
|
|
|
*/
|
2011-04-27 19:44:32 +00:00
|
|
|
LIB_ITEM* item;
|
2010-12-23 10:00:55 +00:00
|
|
|
TRANSFORM transform = DefaultTransform;
|
2010-12-23 10:53:12 +00:00
|
|
|
DefaultTransform = aTransform;
|
2010-10-20 20:24:26 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
item = LocateDrawItem( aUnit, aConvert, aType, aPoint );
|
2010-10-20 20:24:26 +00:00
|
|
|
|
2013-05-24 23:58:29 +00:00
|
|
|
// Restore matrix
|
2010-12-23 10:00:55 +00:00
|
|
|
DefaultTransform = transform;
|
2009-10-08 16:45:59 +00:00
|
|
|
|
2009-10-06 13:52:43 +00:00
|
|
|
return item;
|
|
|
|
}
|
2009-10-05 17:52:41 +00:00
|
|
|
|
2009-10-19 19:00:47 +00:00
|
|
|
|
2019-05-06 02:32:01 +00:00
|
|
|
SEARCH_RESULT LIB_PART::Visit( INSPECTOR aInspector, void* aTestData, const KICAD_T aFilterTypes[] )
|
|
|
|
{
|
|
|
|
// The part itself is never inspected, only its children
|
|
|
|
for( LIB_ITEM& item : m_drawings )
|
|
|
|
{
|
|
|
|
if( item.IsType( aFilterTypes ) )
|
|
|
|
{
|
2019-12-28 00:55:11 +00:00
|
|
|
if( aInspector( &item, aTestData ) == SEARCH_RESULT::QUIT )
|
|
|
|
return SEARCH_RESULT::QUIT;
|
2019-05-06 02:32:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-28 00:55:11 +00:00
|
|
|
return SEARCH_RESULT::CONTINUE;
|
2019-05-06 02:32:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-28 14:03:09 +00:00
|
|
|
void LIB_PART::SetUnitCount( int aCount, bool aDuplicateDrawItems )
|
2009-10-05 17:52:41 +00:00
|
|
|
{
|
2010-10-25 15:43:42 +00:00
|
|
|
if( m_unitCount == aCount )
|
2009-10-05 17:52:41 +00:00
|
|
|
return;
|
|
|
|
|
2010-10-25 15:43:42 +00:00
|
|
|
if( aCount < m_unitCount )
|
2009-10-05 17:52:41 +00:00
|
|
|
{
|
2017-09-17 08:26:06 +00:00
|
|
|
LIB_ITEMS_CONTAINER::ITERATOR i = m_drawings.begin();
|
2009-10-05 17:52:41 +00:00
|
|
|
|
2017-09-17 08:26:06 +00:00
|
|
|
while( i != m_drawings.end() )
|
2009-10-05 17:52:41 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
if( i->m_Unit > aCount )
|
2017-09-17 08:26:06 +00:00
|
|
|
i = m_drawings.erase( i );
|
2009-10-05 17:52:41 +00:00
|
|
|
else
|
2017-08-14 14:53:25 +00:00
|
|
|
++i;
|
2009-10-05 17:52:41 +00:00
|
|
|
}
|
|
|
|
}
|
2020-02-28 14:03:09 +00:00
|
|
|
else if( aDuplicateDrawItems )
|
2009-10-05 17:52:41 +00:00
|
|
|
{
|
2010-10-25 15:43:42 +00:00
|
|
|
int prevCount = m_unitCount;
|
2009-10-05 17:52:41 +00:00
|
|
|
|
2017-09-17 09:09:56 +00:00
|
|
|
// Temporary storage for new items, as adding new items directly to
|
|
|
|
// m_drawings may cause the buffer reallocation which invalidates the
|
|
|
|
// iterators
|
2017-09-17 08:26:06 +00:00
|
|
|
std::vector< LIB_ITEM* > tmp;
|
2017-09-17 09:09:56 +00:00
|
|
|
|
2017-09-17 08:26:06 +00:00
|
|
|
for( LIB_ITEM& item : m_drawings )
|
2009-10-05 17:52:41 +00:00
|
|
|
{
|
2017-09-17 08:26:06 +00:00
|
|
|
if( item.m_Unit != 1 )
|
2009-10-05 17:52:41 +00:00
|
|
|
continue;
|
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
for( int j = prevCount + 1; j <= aCount; j++ )
|
2009-10-05 17:52:41 +00:00
|
|
|
{
|
2017-09-17 08:26:06 +00:00
|
|
|
LIB_ITEM* newItem = (LIB_ITEM*) item.Clone();
|
2009-10-05 17:52:41 +00:00
|
|
|
newItem->m_Unit = j;
|
2017-09-17 08:26:06 +00:00
|
|
|
tmp.push_back( newItem );
|
2009-10-05 17:52:41 +00:00
|
|
|
}
|
|
|
|
}
|
2017-09-17 09:09:56 +00:00
|
|
|
|
2017-09-17 08:26:06 +00:00
|
|
|
for( auto item : tmp )
|
|
|
|
m_drawings.push_back( item );
|
2009-10-05 17:52:41 +00:00
|
|
|
}
|
|
|
|
|
2010-10-25 15:43:42 +00:00
|
|
|
m_unitCount = aCount;
|
2009-10-05 17:52:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
int LIB_PART::GetUnitCount() const
|
|
|
|
{
|
|
|
|
if( PART_SPTR parent = m_parent.lock() )
|
|
|
|
return parent->GetUnitCount();
|
|
|
|
|
|
|
|
return m_unitCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-28 14:03:09 +00:00
|
|
|
void LIB_PART::SetConversion( bool aSetConvert, bool aDuplicatePins )
|
2009-10-05 17:52:41 +00:00
|
|
|
{
|
2009-12-15 21:11:05 +00:00
|
|
|
if( aSetConvert == HasConversion() )
|
2009-10-05 17:52:41 +00:00
|
|
|
return;
|
2009-12-15 21:11:05 +00:00
|
|
|
|
2009-10-10 17:27:53 +00:00
|
|
|
// Duplicate items to create the converted shape
|
2009-12-15 21:11:05 +00:00
|
|
|
if( aSetConvert )
|
2009-10-05 17:52:41 +00:00
|
|
|
{
|
2020-02-28 14:03:09 +00:00
|
|
|
if( aDuplicatePins )
|
2009-10-05 17:52:41 +00:00
|
|
|
{
|
2020-02-28 14:03:09 +00:00
|
|
|
std::vector< LIB_ITEM* > tmp; // Temporarily store the duplicated pins here.
|
2011-10-31 20:49:48 +00:00
|
|
|
|
2020-02-28 14:03:09 +00:00
|
|
|
for( LIB_ITEM& item : m_drawings )
|
2009-10-05 17:52:41 +00:00
|
|
|
{
|
2020-02-28 14:03:09 +00:00
|
|
|
// Only pins are duplicated.
|
|
|
|
if( item.Type() != LIB_PIN_T )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( item.m_Convert == 1 )
|
|
|
|
{
|
|
|
|
LIB_ITEM* newItem = (LIB_ITEM*) item.Clone();
|
|
|
|
newItem->m_Convert = 2;
|
|
|
|
tmp.push_back( newItem );
|
|
|
|
}
|
2009-10-05 17:52:41 +00:00
|
|
|
}
|
2016-02-19 21:29:56 +00:00
|
|
|
|
2020-02-28 14:03:09 +00:00
|
|
|
// Transfer the new pins to the LIB_PART.
|
|
|
|
for( unsigned i = 0; i < tmp.size(); i++ )
|
|
|
|
m_drawings.push_back( tmp[i] );
|
|
|
|
}
|
2009-10-05 17:52:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-12-17 11:03:26 +00:00
|
|
|
// Delete converted shape items because the converted shape does
|
2009-10-19 19:00:47 +00:00
|
|
|
// not exist
|
2017-09-17 08:26:06 +00:00
|
|
|
LIB_ITEMS_CONTAINER::ITERATOR i = m_drawings.begin();
|
2009-10-05 17:52:41 +00:00
|
|
|
|
2017-09-17 08:26:06 +00:00
|
|
|
while( i != m_drawings.end() )
|
2009-10-05 17:52:41 +00:00
|
|
|
{
|
|
|
|
if( i->m_Convert > 1 )
|
2017-09-17 08:26:06 +00:00
|
|
|
i = m_drawings.erase( i );
|
2009-10-05 17:52:41 +00:00
|
|
|
else
|
2017-08-14 14:53:25 +00:00
|
|
|
++i;
|
2009-10-05 17:52:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-02-17 13:22:25 +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.
2014-08-13 20:28:54 +00:00
|
|
|
void LIB_PART::SetSubpartIdNotation( int aSep, int aFirstId )
|
2013-07-19 18:27:22 +00:00
|
|
|
{
|
|
|
|
m_subpartFirstId = 'A';
|
|
|
|
m_subpartIdSeparator = 0;
|
|
|
|
|
|
|
|
if( aSep == '.' || aSep == '-' || aSep == '_' )
|
|
|
|
m_subpartIdSeparator = aSep;
|
|
|
|
|
|
|
|
if( aFirstId == '1' && aSep != 0 )
|
|
|
|
m_subpartFirstId = aFirstId;
|
|
|
|
}
|
2020-02-13 13:39:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
std::vector<LIB_ITEM*> LIB_PART::GetUnitItems( int aUnit, int aConvert )
|
|
|
|
{
|
|
|
|
std::vector<LIB_ITEM*> unitItems;
|
|
|
|
|
|
|
|
for( LIB_ITEM& item : m_drawings )
|
|
|
|
{
|
|
|
|
if( item.Type() == LIB_FIELD_T )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( ( aConvert == -1 && item.GetUnit() == aUnit )
|
|
|
|
|| ( aUnit == -1 && item.GetConvert() == aConvert )
|
|
|
|
|| ( aUnit == item.GetUnit() && aConvert == item.GetConvert() ) )
|
|
|
|
unitItems.push_back( &item );
|
|
|
|
}
|
|
|
|
|
|
|
|
return unitItems;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<struct PART_UNITS> LIB_PART::GetUnitDrawItems()
|
|
|
|
{
|
|
|
|
std::vector<struct PART_UNITS> units;
|
|
|
|
|
|
|
|
for( LIB_ITEM& item : m_drawings )
|
|
|
|
{
|
|
|
|
if( item.Type() == LIB_FIELD_T )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
int unit = item.GetUnit();
|
|
|
|
int convert = item.GetConvert();
|
|
|
|
|
|
|
|
auto it = std::find_if( units.begin(), units.end(),
|
|
|
|
[unit, convert] ( const auto& a ) {
|
|
|
|
return a.m_unit == unit && a.m_convert == convert;
|
|
|
|
} );
|
|
|
|
|
|
|
|
if( it == units.end() )
|
|
|
|
{
|
|
|
|
struct PART_UNITS newUnit;
|
|
|
|
newUnit.m_unit = item.GetUnit();
|
|
|
|
newUnit.m_convert = item.GetConvert();
|
|
|
|
newUnit.m_items.push_back( &item );
|
|
|
|
units.emplace_back( newUnit );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
it->m_items.push_back( &item );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return units;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<struct PART_UNITS> LIB_PART::GetUniqueUnits()
|
|
|
|
{
|
|
|
|
int unitNum;
|
|
|
|
size_t i;
|
|
|
|
struct PART_UNITS unit;
|
|
|
|
std::vector<LIB_ITEM*> compareDrawItems;
|
|
|
|
std::vector<LIB_ITEM*> currentDrawItems;
|
|
|
|
std::vector<struct PART_UNITS> uniqueUnits;
|
|
|
|
|
|
|
|
// The first unit is guarenteed to be unique so always include it.
|
|
|
|
unit.m_unit = 1;
|
|
|
|
unit.m_convert = 1;
|
|
|
|
unit.m_items = GetUnitItems( 1, 1 );
|
|
|
|
|
|
|
|
// There are no unique units if there are no draw items other than fields.
|
|
|
|
if( unit.m_items.size() == 0 )
|
|
|
|
return uniqueUnits;
|
|
|
|
|
|
|
|
uniqueUnits.emplace_back( unit );
|
|
|
|
|
|
|
|
if( ( GetUnitCount() == 1 || UnitsLocked() ) && !HasConversion() )
|
|
|
|
return uniqueUnits;
|
|
|
|
|
|
|
|
currentDrawItems = unit.m_items;
|
|
|
|
|
|
|
|
for( unitNum = 2; unitNum <= GetUnitCount(); unitNum++ )
|
|
|
|
{
|
|
|
|
compareDrawItems = GetUnitItems( unitNum, 1 );
|
|
|
|
|
|
|
|
wxCHECK2_MSG( compareDrawItems.size() != 0, continue,
|
|
|
|
"Multiple unit symbol defined with empty units." );
|
|
|
|
|
|
|
|
if( currentDrawItems.size() != compareDrawItems.size() )
|
|
|
|
{
|
|
|
|
unit.m_unit = unitNum;
|
|
|
|
unit.m_convert = 1;
|
|
|
|
unit.m_items = compareDrawItems;
|
|
|
|
uniqueUnits.emplace_back( unit );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( i = 0; i < currentDrawItems.size(); i++ )
|
|
|
|
{
|
|
|
|
if( currentDrawItems[i]->compare( *compareDrawItems[i],
|
|
|
|
LIB_ITEM::COMPARE_FLAGS::UNIT ) != 0 )
|
|
|
|
{
|
|
|
|
unit.m_unit = unitNum;
|
|
|
|
unit.m_convert = 1;
|
|
|
|
unit.m_items = compareDrawItems;
|
|
|
|
uniqueUnits.emplace_back( unit );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( HasConversion() )
|
|
|
|
{
|
|
|
|
currentDrawItems = GetUnitItems( 1, 2 );
|
|
|
|
|
|
|
|
if( ( GetUnitCount() == 1 || UnitsLocked() ) )
|
|
|
|
{
|
|
|
|
unit.m_unit = 1;
|
|
|
|
unit.m_convert = 2;
|
|
|
|
unit.m_items = currentDrawItems;
|
|
|
|
uniqueUnits.emplace_back( unit );
|
|
|
|
|
|
|
|
return uniqueUnits;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( unitNum = 2; unitNum <= GetUnitCount(); unitNum++ )
|
|
|
|
{
|
|
|
|
compareDrawItems = GetUnitItems( unitNum, 2 );
|
|
|
|
|
|
|
|
wxCHECK2_MSG( compareDrawItems.size() != 0, continue,
|
|
|
|
"Multiple unit symbol defined with empty units." );
|
|
|
|
|
|
|
|
if( currentDrawItems.size() != compareDrawItems.size() )
|
|
|
|
{
|
|
|
|
unit.m_unit = unitNum;
|
|
|
|
unit.m_convert = 2;
|
|
|
|
unit.m_items = compareDrawItems;
|
|
|
|
uniqueUnits.emplace_back( unit );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( i = 0; i < currentDrawItems.size(); i++ )
|
|
|
|
{
|
|
|
|
if( currentDrawItems[i]->compare( *compareDrawItems[i],
|
|
|
|
LIB_ITEM::COMPARE_FLAGS::UNIT ) != 0 )
|
|
|
|
{
|
|
|
|
unit.m_unit = unitNum;
|
|
|
|
unit.m_convert = 2;
|
|
|
|
unit.m_items = compareDrawItems;
|
|
|
|
uniqueUnits.emplace_back( unit );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return uniqueUnits;
|
|
|
|
}
|