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>
|
2022-12-08 23:56:55 +00:00
|
|
|
* Copyright (C) 2022 CERN
|
2023-03-23 17:26:32 +00:00
|
|
|
* Copyright (C) 2004-2023 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
|
|
|
|
*/
|
|
|
|
|
2018-08-03 12:18:26 +00:00
|
|
|
#include <sch_draw_panel.h>
|
2021-08-18 20:38:14 +00:00
|
|
|
#include <plotters/plotter.h>
|
2018-01-30 08:56:43 +00:00
|
|
|
#include <sch_screen.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <richio.h>
|
|
|
|
#include <template_fieldnames.h>
|
|
|
|
#include <transform.h>
|
2021-06-15 13:24:55 +00:00
|
|
|
#include <symbol_library.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <lib_pin.h>
|
2020-02-03 16:46:58 +00:00
|
|
|
#include <settings/color_settings.h>
|
2021-07-18 23:08:54 +00:00
|
|
|
#include <lib_shape.h>
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2023-05-09 11:22:17 +00:00
|
|
|
#include <memory>
|
|
|
|
|
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
|
2021-06-10 18:51:46 +00:00
|
|
|
int LIB_SYMBOL::m_subpartIdSeparator = 0;
|
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
|
|
|
|
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)
|
2021-06-09 19:32:58 +00:00
|
|
|
// if this a digit, a number is used as id symbol
|
2021-06-10 18:51:46 +00:00
|
|
|
int LIB_SYMBOL::m_subpartFirstId = 'A';
|
2013-05-19 19:35:49 +00:00
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
|
2023-05-01 20:26:29 +00:00
|
|
|
std::vector<SEARCH_TERM> LIB_SYMBOL::GetSearchTerms()
|
2009-08-27 11:41:56 +00:00
|
|
|
{
|
2023-05-01 20:26:29 +00:00
|
|
|
std::vector<SEARCH_TERM> terms;
|
2018-08-05 11:56:02 +00:00
|
|
|
|
2023-05-01 20:26:29 +00:00
|
|
|
terms.emplace_back( SEARCH_TERM( GetName(), 8 ) );
|
2018-07-27 20:47:51 +00:00
|
|
|
|
2023-05-01 20:26:29 +00:00
|
|
|
wxStringTokenizer keywordTokenizer( GetKeyWords(), wxS( " " ), wxTOKEN_STRTOK );
|
|
|
|
|
|
|
|
while( keywordTokenizer.HasMoreTokens() )
|
|
|
|
terms.emplace_back( SEARCH_TERM( keywordTokenizer.GetNextToken(), 4 ) );
|
2018-07-27 20:47:51 +00:00
|
|
|
|
2022-08-28 23:02:12 +00:00
|
|
|
// TODO(JE) rework this later so we can highlight matches in their column
|
|
|
|
std::map<wxString, wxString> fields;
|
|
|
|
GetChooserFields( fields );
|
|
|
|
|
2023-05-01 20:26:29 +00:00
|
|
|
for( const auto& [ name, text ] : fields )
|
|
|
|
terms.emplace_back( SEARCH_TERM( text, 4 ) );
|
|
|
|
|
|
|
|
// Also include keywords as one long string, just in case
|
|
|
|
terms.emplace_back( SEARCH_TERM( GetKeyWords(), 1 ) );
|
|
|
|
terms.emplace_back( SEARCH_TERM( GetDescription(), 1 ) );
|
|
|
|
|
|
|
|
wxString footprint = GetFootprintField().GetText();
|
|
|
|
|
|
|
|
if( !footprint.IsEmpty() )
|
|
|
|
terms.emplace_back( SEARCH_TERM( GetFootprintField().GetText(), 1 ) );
|
2022-08-28 23:02:12 +00:00
|
|
|
|
2023-05-01 20:26:29 +00:00
|
|
|
return terms;
|
2018-07-27 20:47:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-28 23:02:12 +00:00
|
|
|
void LIB_SYMBOL::GetChooserFields( std::map<wxString , wxString>& aColumnMap )
|
|
|
|
{
|
|
|
|
for( LIB_ITEM& item : m_drawings[ LIB_FIELD_T ] )
|
|
|
|
{
|
|
|
|
LIB_FIELD* field = static_cast<LIB_FIELD*>( &item );
|
|
|
|
|
|
|
|
if( field->ShowInChooser() )
|
2023-05-01 20:26:29 +00:00
|
|
|
aColumnMap[field->GetName()] = field->EDA_TEXT::GetShownText( false );
|
2022-08-28 23:02:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
bool operator<( const LIB_SYMBOL& aItem1, const LIB_SYMBOL& 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
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
LIB_SYMBOL::LIB_SYMBOL( const wxString& aName, LIB_SYMBOL* aParent, SYMBOL_LIB* aLibrary ) :
|
2021-06-10 18:51:46 +00:00
|
|
|
EDA_ITEM( LIB_SYMBOL_T ),
|
2020-09-09 13:03:37 +00:00
|
|
|
m_me( this, null_deleter() ),
|
2023-08-08 16:32:08 +00:00
|
|
|
m_excludedFromSim( false ),
|
2023-06-25 02:03:06 +00:00
|
|
|
m_excludedFromBOM( false ),
|
|
|
|
m_excludedFromBoard( false )
|
2008-12-31 09:27:19 +00:00
|
|
|
{
|
2020-12-14 13:47:32 +00:00
|
|
|
m_lastModDate = 0;
|
|
|
|
m_unitCount = 1;
|
2022-09-16 23:42:20 +00:00
|
|
|
m_pinNameOffset = schIUScale.MilsToIU( DEFAULT_PIN_NAME_OFFSET );
|
2020-12-14 13:47:32 +00:00
|
|
|
m_options = ENTRY_NORMAL;
|
|
|
|
m_unitsLocked = false;
|
|
|
|
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.
|
2023-06-19 17:08:18 +00:00
|
|
|
m_drawings[LIB_FIELD_T].reserve( MANDATORY_FIELDS );
|
|
|
|
for( int i = 0; i < MANDATORY_FIELDS; i++ )
|
|
|
|
m_drawings[LIB_FIELD_T].push_back( new LIB_FIELD( this, i ) );
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
LIB_SYMBOL::LIB_SYMBOL( const LIB_SYMBOL& aSymbol, SYMBOL_LIB* aLibrary ) :
|
2021-06-10 18:51:46 +00:00
|
|
|
EDA_ITEM( aSymbol ),
|
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
|
|
|
|
2020-12-14 13:47:32 +00:00
|
|
|
m_library = aLibrary;
|
2021-06-10 18:51:46 +00:00
|
|
|
m_name = aSymbol.m_name;
|
|
|
|
m_fpFilters = wxArrayString( aSymbol.m_fpFilters );
|
|
|
|
m_unitCount = aSymbol.m_unitCount;
|
|
|
|
m_unitsLocked = aSymbol.m_unitsLocked;
|
|
|
|
m_pinNameOffset = aSymbol.m_pinNameOffset;
|
|
|
|
m_showPinNumbers = aSymbol.m_showPinNumbers;
|
2023-08-08 16:32:08 +00:00
|
|
|
m_excludedFromSim = aSymbol.m_excludedFromSim;
|
2023-06-25 02:03:06 +00:00
|
|
|
m_excludedFromBOM = aSymbol.m_excludedFromBOM;
|
|
|
|
m_excludedFromBoard = aSymbol.m_excludedFromBoard;
|
|
|
|
m_showPinNames = aSymbol.m_showPinNames;
|
2021-06-10 18:51:46 +00:00
|
|
|
m_lastModDate = aSymbol.m_lastModDate;
|
|
|
|
m_options = aSymbol.m_options;
|
|
|
|
m_libId = aSymbol.m_libId;
|
|
|
|
m_keyWords = aSymbol.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
|
|
|
|
2022-09-14 22:11:37 +00:00
|
|
|
aSymbol.CopyUnitDisplayNames( m_unitDisplayNames );
|
|
|
|
|
2020-03-21 23:24:41 +00:00
|
|
|
ClearSelected();
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
for( const LIB_ITEM& oldItem : aSymbol.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." );
|
2022-04-01 04:30:50 +00:00
|
|
|
return;
|
2020-01-13 15:00:39 +00:00
|
|
|
}
|
2009-09-25 18:49:04 +00:00
|
|
|
}
|
2019-12-13 21:51:59 +00:00
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
LIB_SYMBOL_SPTR parent = aSymbol.m_parent.lock();
|
2019-12-13 21:51:59 +00:00
|
|
|
|
|
|
|
if( parent )
|
|
|
|
SetParent( parent.get() );
|
2009-09-25 18:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
const LIB_SYMBOL& LIB_SYMBOL::operator=( const LIB_SYMBOL& aSymbol )
|
2019-12-26 13:00:59 +00:00
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
if( &aSymbol == this )
|
|
|
|
return aSymbol;
|
2019-12-26 13:00:59 +00:00
|
|
|
|
|
|
|
LIB_ITEM* newItem;
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
m_library = aSymbol.m_library;
|
|
|
|
m_name = aSymbol.m_name;
|
|
|
|
m_fpFilters = wxArrayString( aSymbol.m_fpFilters );
|
|
|
|
m_unitCount = aSymbol.m_unitCount;
|
|
|
|
m_unitsLocked = aSymbol.m_unitsLocked;
|
|
|
|
m_pinNameOffset = aSymbol.m_pinNameOffset;
|
|
|
|
m_showPinNumbers = aSymbol.m_showPinNumbers;
|
|
|
|
m_showPinNames = aSymbol.m_showPinNames;
|
2023-08-08 16:32:08 +00:00
|
|
|
m_excludedFromSim = aSymbol.m_excludedFromSim;
|
2023-06-25 02:03:06 +00:00
|
|
|
m_excludedFromBOM = aSymbol.m_excludedFromBOM;
|
|
|
|
m_excludedFromBoard = aSymbol.m_excludedFromBoard;
|
2021-06-10 18:51:46 +00:00
|
|
|
m_lastModDate = aSymbol.m_lastModDate;
|
|
|
|
m_options = aSymbol.m_options;
|
|
|
|
m_libId = aSymbol.m_libId;
|
|
|
|
m_keyWords = aSymbol.m_keyWords;
|
2019-12-26 13:00:59 +00:00
|
|
|
|
2022-09-14 22:11:37 +00:00
|
|
|
m_unitDisplayNames.clear();
|
|
|
|
aSymbol.CopyUnitDisplayNames( m_unitDisplayNames );
|
|
|
|
|
2019-12-26 13:00:59 +00:00
|
|
|
m_drawings.clear();
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
for( const LIB_ITEM& oldItem : aSymbol.m_drawings )
|
2019-12-26 13:00:59 +00:00
|
|
|
{
|
|
|
|
if( ( oldItem.GetFlags() & ( IS_NEW | STRUCT_DELETED ) ) != 0 )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
newItem = (LIB_ITEM*) oldItem.Clone();
|
|
|
|
newItem->SetParent( this );
|
|
|
|
m_drawings.push_back( newItem );
|
|
|
|
}
|
|
|
|
|
2021-03-04 22:59:24 +00:00
|
|
|
m_drawings.sort();
|
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
LIB_SYMBOL_SPTR parent = aSymbol.m_parent.lock();
|
2019-12-26 13:00:59 +00:00
|
|
|
|
|
|
|
if( parent )
|
|
|
|
SetParent( parent.get() );
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-20 16:05:31 +00:00
|
|
|
unsigned LIB_SYMBOL::GetInheritanceDepth() const
|
|
|
|
{
|
|
|
|
unsigned depth = 0;
|
|
|
|
|
|
|
|
LIB_SYMBOL_SPTR parent = GetParent().lock();
|
|
|
|
|
|
|
|
while( parent )
|
|
|
|
{
|
|
|
|
depth += 1;
|
|
|
|
parent = parent->GetParent().lock();
|
|
|
|
}
|
|
|
|
|
|
|
|
return depth;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-09 11:25:32 +00:00
|
|
|
#define REPORT( msg ) { if( aReporter ) aReporter->Report( msg ); }
|
|
|
|
#define ITEM_DESC( item ) ( item )->GetItemDescription( &unitsProvider )
|
|
|
|
|
|
|
|
int LIB_SYMBOL::Compare( const LIB_SYMBOL& aRhs, int aCompareFlags, REPORTER* aReporter ) const
|
2019-11-06 19:15:42 +00:00
|
|
|
{
|
2023-03-09 11:25:32 +00:00
|
|
|
UNITS_PROVIDER unitsProvider( schIUScale, EDA_UNITS::MILLIMETRES );
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
if( m_me == aRhs.m_me )
|
|
|
|
return 0;
|
|
|
|
|
2023-03-09 11:25:32 +00:00
|
|
|
if( !aReporter && ( aCompareFlags & LIB_ITEM::COMPARE_FLAGS::ERC ) == 0 )
|
2022-04-09 12:58:53 +00:00
|
|
|
{
|
2023-03-09 11:25:32 +00:00
|
|
|
if( int tmp = m_name.Cmp( aRhs.m_name ) )
|
|
|
|
return tmp;
|
2022-04-09 12:58:53 +00:00
|
|
|
|
2023-03-09 11:25:32 +00:00
|
|
|
if( int tmp = m_libId.compare( aRhs.m_libId ) )
|
|
|
|
return tmp;
|
2019-11-06 19:15:42 +00:00
|
|
|
|
2023-03-09 11:25:32 +00:00
|
|
|
if( m_parent.lock() < aRhs.m_parent.lock() )
|
|
|
|
return -1;
|
2019-11-06 19:15:42 +00:00
|
|
|
|
2023-03-09 11:25:32 +00:00
|
|
|
if( m_parent.lock() > aRhs.m_parent.lock() )
|
|
|
|
return 1;
|
2022-04-09 12:58:53 +00:00
|
|
|
}
|
2019-11-06 19:15:42 +00:00
|
|
|
|
2023-03-09 11:25:32 +00:00
|
|
|
int retv = 0;
|
2019-11-06 19:15:42 +00:00
|
|
|
|
|
|
|
if( m_options != aRhs.m_options )
|
2023-03-09 11:25:32 +00:00
|
|
|
{
|
|
|
|
retv = ( m_options == ENTRY_NORMAL ) ? -1 : 1;
|
|
|
|
REPORT( _( "Power flag differs." ) );
|
2023-04-12 16:40:52 +00:00
|
|
|
|
|
|
|
if( !aReporter )
|
|
|
|
return retv;
|
2023-03-09 11:25:32 +00:00
|
|
|
}
|
2019-11-06 19:15:42 +00:00
|
|
|
|
2023-03-09 11:25:32 +00:00
|
|
|
if( int tmp = m_unitCount - aRhs.m_unitCount )
|
|
|
|
{
|
|
|
|
retv = tmp;
|
|
|
|
REPORT( _( "Unit count differs." ) );
|
2023-04-12 16:40:52 +00:00
|
|
|
|
|
|
|
if( !aReporter )
|
|
|
|
return retv;
|
2023-03-09 11:25:32 +00:00
|
|
|
}
|
|
|
|
|
2023-04-08 19:28:45 +00:00
|
|
|
// Make sure shapes and pins are sorted. No need with fields as those are
|
|
|
|
// matched by id/name.
|
2023-03-09 17:41:18 +00:00
|
|
|
|
|
|
|
std::set<const LIB_ITEM*, LIB_ITEM::cmp_items> aShapes;
|
|
|
|
std::set<const LIB_ITEM*> aFields;
|
2023-04-08 19:28:45 +00:00
|
|
|
std::set<const LIB_ITEM*, LIB_ITEM::cmp_items> aPins;
|
2019-11-06 19:15:42 +00:00
|
|
|
|
2023-03-09 11:25:32 +00:00
|
|
|
for( auto it = m_drawings.begin(); it != m_drawings.end(); ++it )
|
2019-11-06 19:15:42 +00:00
|
|
|
{
|
2023-03-09 11:25:32 +00:00
|
|
|
if( it->Type() == LIB_SHAPE_T )
|
|
|
|
aShapes.insert( &(*it) );
|
|
|
|
else if( it->Type() == LIB_FIELD_T )
|
|
|
|
aFields.insert( &(*it) );
|
|
|
|
else if( it->Type() == LIB_PIN_T )
|
|
|
|
aPins.insert( &(*it) );
|
|
|
|
}
|
2021-03-04 22:59:24 +00:00
|
|
|
|
2023-03-09 17:41:18 +00:00
|
|
|
std::set<const LIB_ITEM*, LIB_ITEM::cmp_items> bShapes;
|
|
|
|
std::set<const LIB_ITEM*> bFields;
|
2023-04-08 19:28:45 +00:00
|
|
|
std::set<const LIB_ITEM*, LIB_ITEM::cmp_items> bPins;
|
2021-03-04 22:59:24 +00:00
|
|
|
|
2023-03-09 11:25:32 +00:00
|
|
|
for( auto it = aRhs.m_drawings.begin(); it != aRhs.m_drawings.end(); ++it )
|
|
|
|
{
|
|
|
|
if( it->Type() == LIB_SHAPE_T )
|
|
|
|
bShapes.insert( &(*it) );
|
|
|
|
else if( it->Type() == LIB_FIELD_T )
|
|
|
|
bFields.insert( &(*it) );
|
|
|
|
else if( it->Type() == LIB_PIN_T )
|
|
|
|
bPins.insert( &(*it) );
|
|
|
|
}
|
2019-11-06 19:15:42 +00:00
|
|
|
|
2023-03-09 11:25:32 +00:00
|
|
|
if( int tmp = static_cast<int>( aShapes.size() - bShapes.size() ) )
|
|
|
|
{
|
|
|
|
retv = tmp;
|
|
|
|
REPORT( _( "Graphic item count differs." ) );
|
2023-04-12 16:40:52 +00:00
|
|
|
|
|
|
|
if( !aReporter )
|
|
|
|
return retv;
|
2023-03-09 11:25:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( auto aIt = aShapes.begin(), bIt = bShapes.begin(); aIt != aShapes.end(); aIt++, bIt++ )
|
2021-12-12 22:01:13 +00:00
|
|
|
{
|
2023-03-09 11:25:32 +00:00
|
|
|
if( int tmp2 = (*aIt)->compare( *(*bIt), aCompareFlags ) )
|
2022-04-09 12:58:53 +00:00
|
|
|
{
|
2023-03-09 11:25:32 +00:00
|
|
|
retv = tmp2;
|
|
|
|
REPORT( wxString::Format( _( "%s differs." ), ITEM_DESC( *aIt ) ) );
|
2023-04-12 16:40:52 +00:00
|
|
|
|
|
|
|
if( !aReporter )
|
|
|
|
return retv;
|
2022-04-09 12:58:53 +00:00
|
|
|
}
|
2021-12-12 22:01:13 +00:00
|
|
|
}
|
2023-03-09 11:25:32 +00:00
|
|
|
}
|
|
|
|
|
2023-04-08 19:28:45 +00:00
|
|
|
if( int tmp = static_cast<int>( aPins.size() - bPins.size() ) )
|
|
|
|
{
|
|
|
|
retv = tmp;
|
|
|
|
REPORT( _( "Pin count differs." ) );
|
2023-03-09 11:25:32 +00:00
|
|
|
|
2023-04-12 16:40:52 +00:00
|
|
|
if( !aReporter )
|
|
|
|
return retv;
|
|
|
|
}
|
|
|
|
else
|
2023-03-09 11:25:32 +00:00
|
|
|
{
|
2023-04-12 16:40:52 +00:00
|
|
|
for( const LIB_ITEM* aPinItem : aPins )
|
|
|
|
{
|
|
|
|
const LIB_PIN* aPin = static_cast<const LIB_PIN*>( aPinItem );
|
|
|
|
const LIB_PIN* bPin = aRhs.GetPin( aPin->GetNumber(), aPin->GetUnit(),
|
|
|
|
aPin->GetConvert() );
|
2023-03-09 11:25:32 +00:00
|
|
|
|
2023-04-12 16:40:52 +00:00
|
|
|
if( !bPin )
|
|
|
|
{
|
|
|
|
retv = 1;
|
|
|
|
REPORT( wxString::Format( _( "Pin %s not found." ), aPin->GetNumber() ) );
|
2023-03-09 11:25:32 +00:00
|
|
|
|
2023-04-12 16:40:52 +00:00
|
|
|
if( !aReporter )
|
|
|
|
return retv;
|
|
|
|
}
|
2023-05-28 18:49:04 +00:00
|
|
|
else if( int tmp2 = aPinItem->compare( *bPin, aCompareFlags ) )
|
2023-04-12 16:40:52 +00:00
|
|
|
{
|
|
|
|
retv = tmp2;
|
|
|
|
REPORT( wxString::Format( _( "Pin %s differs." ), aPin->GetNumber() ) );
|
|
|
|
|
|
|
|
if( !aReporter )
|
|
|
|
return retv;
|
|
|
|
}
|
2021-12-12 22:01:13 +00:00
|
|
|
}
|
2019-11-06 19:15:42 +00:00
|
|
|
}
|
|
|
|
|
2023-03-09 11:25:32 +00:00
|
|
|
for( const LIB_ITEM* aFieldItem : aFields )
|
|
|
|
{
|
|
|
|
const LIB_FIELD* aField = static_cast<const LIB_FIELD*>( aFieldItem );
|
|
|
|
const LIB_FIELD* bField = nullptr;
|
|
|
|
int tmp = 0;
|
2021-12-12 22:01:13 +00:00
|
|
|
|
2023-05-29 11:40:00 +00:00
|
|
|
if( aField->GetId() >= 0 && aField->GetId() < MANDATORY_FIELDS )
|
2023-03-09 11:25:32 +00:00
|
|
|
bField = aRhs.GetFieldById( aField->GetId() );
|
|
|
|
else
|
|
|
|
bField = aRhs.FindField( aField->GetName() );
|
2021-12-12 22:01:13 +00:00
|
|
|
|
2023-03-09 11:25:32 +00:00
|
|
|
if( !bField )
|
|
|
|
{
|
|
|
|
tmp = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tmp = aFieldItem->compare( *bField, aCompareFlags );
|
|
|
|
}
|
2021-12-12 22:01:13 +00:00
|
|
|
|
2023-03-09 11:25:32 +00:00
|
|
|
if( tmp )
|
|
|
|
{
|
|
|
|
retv = tmp;
|
|
|
|
REPORT( wxString::Format( _( "%s field differs." ), aField->GetName( false ) ) );
|
2023-04-12 16:40:52 +00:00
|
|
|
|
|
|
|
if( !aReporter )
|
|
|
|
return retv;
|
2023-03-09 11:25:32 +00:00
|
|
|
}
|
|
|
|
}
|
2021-12-12 22:01:13 +00:00
|
|
|
|
2023-03-09 11:25:32 +00:00
|
|
|
if( int tmp = static_cast<int>( aFields.size() - bFields.size() ) )
|
|
|
|
{
|
|
|
|
retv = tmp;
|
|
|
|
REPORT( _( "Field count differs." ) );
|
2023-04-12 16:40:52 +00:00
|
|
|
|
|
|
|
if( !aReporter )
|
|
|
|
return retv;
|
2021-12-12 22:01:13 +00:00
|
|
|
}
|
|
|
|
|
2023-03-09 11:25:32 +00:00
|
|
|
if( int tmp = static_cast<int>( m_fpFilters.GetCount() - aRhs.m_fpFilters.GetCount() ) )
|
2019-11-06 19:15:42 +00:00
|
|
|
{
|
2023-03-09 11:25:32 +00:00
|
|
|
retv = tmp;
|
|
|
|
REPORT( _( "Footprint filters differs." ) );
|
2023-04-12 16:40:52 +00:00
|
|
|
|
|
|
|
if( !aReporter )
|
|
|
|
return retv;
|
2023-03-09 11:25:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( size_t i = 0; i < m_fpFilters.GetCount(); i++ )
|
|
|
|
{
|
|
|
|
if( int tmp2 = m_fpFilters[i].Cmp( aRhs.m_fpFilters[i] ) )
|
|
|
|
{
|
|
|
|
retv = tmp2;
|
|
|
|
REPORT( _( "Footprint filters differ." ) );
|
2023-04-12 16:40:52 +00:00
|
|
|
|
|
|
|
if( !aReporter )
|
|
|
|
return retv;
|
2023-03-09 11:25:32 +00:00
|
|
|
}
|
|
|
|
}
|
2019-11-06 19:15:42 +00:00
|
|
|
}
|
|
|
|
|
2023-03-09 11:25:32 +00:00
|
|
|
if( int tmp = m_keyWords.Cmp( aRhs.m_keyWords ) )
|
|
|
|
{
|
|
|
|
retv = tmp;
|
|
|
|
REPORT( _( "Symbol keywords differ." ) );
|
2023-04-12 16:40:52 +00:00
|
|
|
|
|
|
|
if( !aReporter )
|
|
|
|
return retv;
|
2023-03-09 11:25:32 +00:00
|
|
|
}
|
2019-11-06 19:15:42 +00:00
|
|
|
|
2023-03-09 11:25:32 +00:00
|
|
|
if( int tmp = m_pinNameOffset - aRhs.m_pinNameOffset )
|
|
|
|
{
|
|
|
|
retv = tmp;
|
|
|
|
REPORT( _( "Symbol pin name offsets differ." ) );
|
2023-04-12 16:40:52 +00:00
|
|
|
|
|
|
|
if( !aReporter )
|
|
|
|
return retv;
|
2023-03-09 11:25:32 +00:00
|
|
|
}
|
|
|
|
|
2022-03-03 12:20:30 +00:00
|
|
|
if( ( aCompareFlags & LIB_ITEM::COMPARE_FLAGS::ERC ) == 0 )
|
|
|
|
{
|
|
|
|
if( m_showPinNames != aRhs.m_showPinNames )
|
2023-03-09 11:25:32 +00:00
|
|
|
{
|
|
|
|
retv = ( m_showPinNames ) ? 1 : -1;
|
|
|
|
REPORT( _( "Show pin names settings differ." ) );
|
2023-04-12 16:40:52 +00:00
|
|
|
|
|
|
|
if( !aReporter )
|
|
|
|
return retv;
|
2023-03-09 11:25:32 +00:00
|
|
|
}
|
2019-11-06 19:15:42 +00:00
|
|
|
|
2022-03-03 12:20:30 +00:00
|
|
|
if( m_showPinNumbers != aRhs.m_showPinNumbers )
|
2023-03-09 11:25:32 +00:00
|
|
|
{
|
|
|
|
retv = ( m_showPinNumbers ) ? 1 : -1;
|
|
|
|
REPORT( _( "Show pin numbers settings differ." ) );
|
2023-04-12 16:40:52 +00:00
|
|
|
|
|
|
|
if( !aReporter )
|
|
|
|
return retv;
|
2023-03-09 11:25:32 +00:00
|
|
|
}
|
2019-11-06 19:15:42 +00:00
|
|
|
|
2023-08-08 16:32:08 +00:00
|
|
|
if( m_excludedFromSim != aRhs.m_excludedFromSim )
|
|
|
|
{
|
|
|
|
retv = ( m_excludedFromSim ) ? -1 : 1;
|
|
|
|
REPORT( _( "Exclude from simulation settings differ." ) );
|
|
|
|
|
|
|
|
if( !aReporter )
|
|
|
|
return retv;
|
|
|
|
}
|
|
|
|
|
2023-06-25 02:03:06 +00:00
|
|
|
if( m_excludedFromBOM != aRhs.m_excludedFromBOM )
|
2023-03-09 11:25:32 +00:00
|
|
|
{
|
2023-06-25 02:03:06 +00:00
|
|
|
retv = ( m_excludedFromBOM ) ? -1 : 1;
|
2023-03-09 11:25:32 +00:00
|
|
|
REPORT( _( "Exclude from bill of materials settings differ." ) );
|
2023-04-12 16:40:52 +00:00
|
|
|
|
|
|
|
if( !aReporter )
|
|
|
|
return retv;
|
2023-03-09 11:25:32 +00:00
|
|
|
}
|
2020-09-09 13:03:37 +00:00
|
|
|
|
2023-06-25 02:03:06 +00:00
|
|
|
if( m_excludedFromBoard != aRhs.m_excludedFromBoard )
|
2023-03-09 11:25:32 +00:00
|
|
|
{
|
2023-06-25 02:03:06 +00:00
|
|
|
retv = ( m_excludedFromBoard ) ? -1 : 1;
|
2023-03-09 11:25:32 +00:00
|
|
|
REPORT( _( "Exclude from board settings differ." ) );
|
2023-04-12 16:40:52 +00:00
|
|
|
|
|
|
|
if( !aReporter )
|
|
|
|
return retv;
|
2023-03-09 11:25:32 +00:00
|
|
|
}
|
2022-03-03 12:20:30 +00:00
|
|
|
}
|
2020-09-09 13:03:37 +00:00
|
|
|
|
2023-03-09 11:25:32 +00:00
|
|
|
if( !aReporter )
|
2022-09-14 22:11:37 +00:00
|
|
|
{
|
2023-03-09 11:25:32 +00:00
|
|
|
if( m_unitsLocked != aRhs.m_unitsLocked )
|
|
|
|
return ( m_unitsLocked ) ? 1 : -1;
|
|
|
|
|
|
|
|
// Compare unit display names
|
|
|
|
if( m_unitDisplayNames < aRhs.m_unitDisplayNames )
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else if( m_unitDisplayNames > aRhs.m_unitDisplayNames )
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2022-09-14 22:11:37 +00:00
|
|
|
}
|
|
|
|
|
2023-03-09 11:25:32 +00:00
|
|
|
return retv;
|
2019-11-06 19:15:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-20 16:05:31 +00:00
|
|
|
LIB_SYMBOL_REF LIB_SYMBOL::GetRootSymbol() const
|
|
|
|
{
|
|
|
|
const LIB_SYMBOL_SPTR sp = m_parent.lock();
|
|
|
|
|
|
|
|
// Recurse until the parent symbol is empty.
|
|
|
|
if( sp )
|
|
|
|
return sp->GetRootSymbol();
|
|
|
|
|
|
|
|
return m_me;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
wxString LIB_SYMBOL::GetUnitReference( int aUnit )
|
2019-11-06 19:15:42 +00:00
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
return LIB_SYMBOL::SubReference( aUnit, false );
|
2019-11-06 19:15:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-14 22:11:37 +00:00
|
|
|
bool LIB_SYMBOL::HasUnitDisplayName( int aUnit )
|
|
|
|
{
|
|
|
|
return ( m_unitDisplayNames.count( aUnit ) == 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString LIB_SYMBOL::GetUnitDisplayName( int aUnit )
|
|
|
|
{
|
|
|
|
if( HasUnitDisplayName( aUnit ) )
|
|
|
|
{
|
|
|
|
return m_unitDisplayNames[aUnit];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return wxString::Format( _( "Unit %s" ), GetUnitReference( aUnit ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LIB_SYMBOL::CopyUnitDisplayNames( std::map<int, wxString>& aTarget ) const
|
|
|
|
{
|
|
|
|
for( const auto& it : m_unitDisplayNames )
|
|
|
|
{
|
|
|
|
aTarget[it.first] = it.second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LIB_SYMBOL::SetUnitDisplayName( int aUnit, const wxString& aName )
|
|
|
|
{
|
|
|
|
if( aUnit <= GetUnitCount() )
|
|
|
|
{
|
|
|
|
if( aName.Length() > 0 )
|
|
|
|
{
|
|
|
|
m_unitDisplayNames[aUnit] = aName;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_unitDisplayNames.erase( aUnit );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
void LIB_SYMBOL::SetName( const wxString& aName )
|
2019-11-06 19:15:42 +00:00
|
|
|
{
|
2021-06-30 10:53:04 +00:00
|
|
|
m_name = aName;
|
2021-06-30 11:00:06 +00:00
|
|
|
m_libId.SetLibItemName( aName );
|
2019-11-06 19:15:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
void LIB_SYMBOL::SetParent( LIB_SYMBOL* aParent )
|
2019-11-06 19:15:42 +00:00
|
|
|
{
|
|
|
|
if( aParent )
|
|
|
|
m_parent = aParent->SharedPtr();
|
|
|
|
else
|
|
|
|
m_parent.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
std::unique_ptr< LIB_SYMBOL > LIB_SYMBOL::Flatten() const
|
2019-11-06 19:15:42 +00:00
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
std::unique_ptr< LIB_SYMBOL > retv;
|
2019-11-06 19:15:42 +00:00
|
|
|
|
|
|
|
if( IsAlias() )
|
|
|
|
{
|
2021-06-15 12:31:28 +00:00
|
|
|
LIB_SYMBOL_SPTR parent = m_parent.lock();
|
2019-11-06 19:15:42 +00:00
|
|
|
|
|
|
|
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.
|
2023-06-13 19:52:42 +00:00
|
|
|
if( parent->IsAlias() )
|
|
|
|
retv = parent->Flatten();
|
|
|
|
else
|
|
|
|
retv = std::make_unique<LIB_SYMBOL>( *parent.get() );
|
2019-11-06 19:15:42 +00:00
|
|
|
|
2021-12-12 22:01:13 +00:00
|
|
|
retv->m_name = m_name;
|
|
|
|
retv->SetLibId( m_libId );
|
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++ )
|
|
|
|
{
|
2021-02-28 13:28:23 +00:00
|
|
|
wxString tmp = GetFieldById( i )->GetText();
|
2020-06-01 13:13:32 +00:00
|
|
|
|
|
|
|
// If the field isn't defined then inherit the parent field value.
|
|
|
|
if( tmp.IsEmpty() )
|
2023-09-14 23:11:57 +00:00
|
|
|
retv->GetFieldById( i )->SetText( retv->GetFieldById( i )->GetText() );
|
2020-06-01 13:13:32 +00:00
|
|
|
else
|
2021-02-28 13:28:23 +00:00
|
|
|
*retv->GetFieldById( i ) = *GetFieldById( i );
|
2020-06-01 13:13:32 +00:00
|
|
|
}
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-14 13:47:32 +00:00
|
|
|
retv->SetKeyWords( m_keyWords.IsEmpty() ? parent->GetKeyWords() : m_keyWords );
|
|
|
|
retv->SetFPFilters( m_fpFilters.IsEmpty() ? parent->GetFPFilters() : m_fpFilters );
|
2023-04-15 15:51:10 +00:00
|
|
|
|
2023-08-08 16:32:08 +00:00
|
|
|
retv->SetExcludedFromSim( parent->GetExcludedFromSim() );
|
2023-06-25 02:03:06 +00:00
|
|
|
retv->SetExcludedFromBOM( parent->GetExcludedFromBOM() );
|
|
|
|
retv->SetExcludedFromBoard( parent->GetExcludedFromBoard() );
|
2023-04-15 15:51:10 +00:00
|
|
|
|
2021-12-12 22:01:13 +00:00
|
|
|
retv->UpdateFieldOrdinals();
|
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
|
|
|
{
|
2023-05-09 11:22:17 +00:00
|
|
|
retv = std::make_unique<LIB_SYMBOL>( *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
|
|
|
|
2022-01-07 17:42:43 +00:00
|
|
|
void LIB_SYMBOL::ClearCaches()
|
|
|
|
{
|
|
|
|
for( LIB_ITEM& item : m_drawings )
|
|
|
|
{
|
|
|
|
if( EDA_TEXT* eda_text = dynamic_cast<EDA_TEXT*>( &item ) )
|
|
|
|
{
|
|
|
|
eda_text->ClearBoundingBoxCache();
|
|
|
|
eda_text->ClearRenderCache();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
const wxString LIB_SYMBOL::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
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
bool LIB_SYMBOL::IsPower() const
|
2021-02-10 00:10:58 +00:00
|
|
|
{
|
2021-06-15 12:31:28 +00:00
|
|
|
if( LIB_SYMBOL_SPTR parent = m_parent.lock() )
|
2023-09-14 23:11:57 +00:00
|
|
|
{
|
|
|
|
if( parent->IsRoot() )
|
|
|
|
return parent->m_options == ENTRY_POWER;
|
|
|
|
else
|
|
|
|
return parent->IsPower();
|
|
|
|
}
|
2021-02-10 00:10:58 +00:00
|
|
|
|
|
|
|
return m_options == ENTRY_POWER;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
void LIB_SYMBOL::SetPower()
|
2021-02-10 00:10:58 +00:00
|
|
|
{
|
2021-06-15 12:31:28 +00:00
|
|
|
if( LIB_SYMBOL_SPTR parent = m_parent.lock() )
|
2023-09-14 23:11:57 +00:00
|
|
|
{
|
|
|
|
if( parent->IsRoot() )
|
|
|
|
parent->m_options = ENTRY_POWER;
|
|
|
|
else
|
|
|
|
parent->SetPower();
|
|
|
|
}
|
2021-02-10 00:10:58 +00:00
|
|
|
|
|
|
|
m_options = ENTRY_POWER;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
bool LIB_SYMBOL::IsNormal() const
|
2021-02-10 00:10:58 +00:00
|
|
|
{
|
2021-06-15 12:31:28 +00:00
|
|
|
if( LIB_SYMBOL_SPTR parent = m_parent.lock() )
|
2023-09-14 23:11:57 +00:00
|
|
|
{
|
|
|
|
if( parent->IsRoot() )
|
|
|
|
return parent->m_options == ENTRY_NORMAL;
|
|
|
|
else
|
|
|
|
return parent->IsNormal();
|
|
|
|
}
|
2021-02-10 00:10:58 +00:00
|
|
|
|
|
|
|
return m_options == ENTRY_NORMAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
void LIB_SYMBOL::SetNormal()
|
2021-02-10 00:10:58 +00:00
|
|
|
{
|
2021-06-15 12:31:28 +00:00
|
|
|
if( LIB_SYMBOL_SPTR parent = m_parent.lock() )
|
2023-09-14 23:11:57 +00:00
|
|
|
{
|
|
|
|
if( parent->IsRoot() )
|
|
|
|
parent->m_options = ENTRY_NORMAL;
|
|
|
|
else
|
|
|
|
parent->SetNormal();
|
|
|
|
}
|
2021-02-10 00:10:58 +00:00
|
|
|
|
|
|
|
m_options = ENTRY_NORMAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
wxString LIB_SYMBOL::SubReference( int aUnit, bool aAddSeparator )
|
2010-04-24 11:27:38 +00:00
|
|
|
{
|
|
|
|
wxString subRef;
|
2013-05-19 19:35:49 +00:00
|
|
|
|
2022-10-06 22:03:58 +00:00
|
|
|
if( aUnit < 1 )
|
|
|
|
return 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' )
|
2022-06-19 11:53:36 +00:00
|
|
|
{
|
2013-05-19 19:35:49 +00:00
|
|
|
subRef << aUnit;
|
2022-06-19 11:53:36 +00:00
|
|
|
}
|
2013-05-19 19:35:49 +00:00
|
|
|
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;
|
2022-12-16 10:48:26 +00:00
|
|
|
wxString suffix;
|
2015-04-07 11:52:29 +00:00
|
|
|
|
2022-10-06 22:03:58 +00:00
|
|
|
do
|
2015-04-07 11:52:29 +00:00
|
|
|
{
|
2022-10-06 22:03:58 +00:00
|
|
|
u = ( aUnit - 1 ) % 26;
|
2022-12-16 10:48:26 +00:00
|
|
|
suffix = wxChar( m_subpartFirstId + u ) + suffix;
|
2022-10-06 22:03:58 +00:00
|
|
|
aUnit = ( aUnit - u ) / 26;
|
|
|
|
} while( aUnit > 0 );
|
2015-04-07 11:52:29 +00:00
|
|
|
|
2022-12-16 10:48:26 +00:00
|
|
|
subRef << suffix;
|
2015-04-07 11:52:29 +00:00
|
|
|
}
|
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
|
|
|
|
2022-10-02 20:21:52 +00:00
|
|
|
void LIB_SYMBOL::PrintBackground( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset,
|
|
|
|
int aUnit, int aConvert, const LIB_SYMBOL_OPTIONS& aOpts, bool aDimmed )
|
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
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
for( LIB_ITEM& item : m_drawings )
|
2010-03-28 14:46:49 +00:00
|
|
|
{
|
2022-05-02 14:28:09 +00:00
|
|
|
// Do not print private items
|
|
|
|
if( item.IsPrivate() )
|
|
|
|
continue;
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
if( item.Type() == LIB_SHAPE_T )
|
|
|
|
{
|
|
|
|
LIB_SHAPE& shape = static_cast<LIB_SHAPE&>( item );
|
2010-03-28 14:46:49 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
// Do not draw items not attached to the current part
|
|
|
|
if( aUnit && shape.m_unit && ( shape.m_unit != aUnit ) )
|
|
|
|
continue;
|
2010-03-28 14:46:49 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
if( aConvert && shape.m_convert && ( shape.m_convert != aConvert ) )
|
|
|
|
continue;
|
2010-03-28 14:46:49 +00:00
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
if( shape.GetFillMode() == FILL_T::FILLED_WITH_BG_BODYCOLOR )
|
2022-09-16 16:20:36 +00:00
|
|
|
shape.Print( aSettings, aOffset, (void*) false, aOpts.transform, aDimmed );
|
2021-07-18 23:08:54 +00:00
|
|
|
}
|
2010-03-28 14:46:49 +00:00
|
|
|
}
|
|
|
|
}
|
2022-10-02 20:21:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LIB_SYMBOL::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset, int aUnit,
|
|
|
|
int aConvert, const LIB_SYMBOL_OPTIONS& aOpts, bool aDimmed )
|
|
|
|
{
|
2010-03-28 14:46:49 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
for( LIB_ITEM& item : m_drawings )
|
2009-09-04 18:57:37 +00:00
|
|
|
{
|
2022-05-02 14:28:09 +00:00
|
|
|
// Do not print private items
|
|
|
|
if( item.IsPrivate() )
|
|
|
|
continue;
|
|
|
|
|
2012-06-06 14:12:39 +00:00
|
|
|
// Do not draw items not attached to the current part
|
2021-07-18 23:08:54 +00:00
|
|
|
if( aUnit && item.m_unit && ( item.m_unit != aUnit ) )
|
2009-09-04 18:57:37 +00:00
|
|
|
continue;
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
if( aConvert && item.m_convert && ( item.m_convert != aConvert ) )
|
2009-09-04 18:57:37 +00:00
|
|
|
continue;
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
if( item.Type() == LIB_FIELD_T )
|
2017-02-19 18:40:26 +00:00
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
LIB_FIELD& field = static_cast<LIB_FIELD&>( item );
|
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
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
if( item.Type() == LIB_PIN_T )
|
2009-09-04 18:57:37 +00:00
|
|
|
{
|
2022-09-16 16:20:36 +00:00
|
|
|
item.Print( aSettings, aOffset, (void*) &aOpts, aOpts.transform, aDimmed );
|
2009-09-04 18:57:37 +00:00
|
|
|
}
|
2021-07-18 23:08:54 +00:00
|
|
|
else if( item.Type() == LIB_FIELD_T )
|
2009-09-04 18:57:37 +00:00
|
|
|
{
|
2022-12-16 13:42:49 +00:00
|
|
|
item.Print( aSettings, aOffset, nullptr, aOpts.transform, aDimmed );
|
2021-07-18 23:08:54 +00:00
|
|
|
}
|
|
|
|
else if( item.Type() == LIB_SHAPE_T )
|
|
|
|
{
|
|
|
|
LIB_SHAPE& shape = static_cast<LIB_SHAPE&>( item );
|
2021-07-17 19:56:18 +00:00
|
|
|
bool forceNoFill = shape.GetFillMode() == FILL_T::FILLED_WITH_BG_BODYCOLOR;
|
2021-07-18 23:08:54 +00:00
|
|
|
|
2022-09-16 16:20:36 +00:00
|
|
|
shape.Print( aSettings, aOffset, (void*) forceNoFill, aOpts.transform, aDimmed );
|
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
|
|
|
{
|
2022-09-16 16:20:36 +00:00
|
|
|
item.Print( aSettings, aOffset, (void*) false, aOpts.transform, aDimmed );
|
2009-09-04 18:57:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-16 16:20:36 +00:00
|
|
|
void LIB_SYMBOL::Plot( PLOTTER *aPlotter, int aUnit, int aConvert, bool aBackground,
|
2022-10-21 21:28:31 +00:00
|
|
|
const VECTOR2I &aOffset, const TRANSFORM &aTransform, bool aDimmed ) const
|
2009-10-05 17:52:41 +00:00
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
wxASSERT( aPlotter != nullptr );
|
2009-10-05 17:52:41 +00:00
|
|
|
|
2022-09-16 16:20:36 +00:00
|
|
|
COLOR4D color = aPlotter->RenderSettings()->GetLayerColor( LAYER_DEVICE );
|
|
|
|
COLOR4D bg = aPlotter->RenderSettings()->GetBackgroundColor();
|
|
|
|
|
|
|
|
if( bg == COLOR4D::UNSPECIFIED || !aPlotter->GetColorMode() )
|
|
|
|
bg = COLOR4D::WHITE;
|
|
|
|
|
|
|
|
if( aDimmed )
|
2023-01-11 20:53:09 +00:00
|
|
|
{
|
|
|
|
color.Desaturate( );
|
2022-09-16 16:20:36 +00:00
|
|
|
color = color.Mix( bg, 0.5f );
|
2023-01-11 20:53:09 +00:00
|
|
|
}
|
2023-05-09 11:22:17 +00:00
|
|
|
|
2022-09-16 16:20:36 +00:00
|
|
|
aPlotter->SetColor( color );
|
2013-05-18 09:38:23 +00:00
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
for( const LIB_ITEM& item : m_drawings )
|
2014-11-12 10:32:02 +00:00
|
|
|
{
|
2022-05-03 18:40:59 +00:00
|
|
|
// Do not plot private items
|
|
|
|
if( item.IsPrivate() )
|
|
|
|
continue;
|
|
|
|
|
2022-10-21 21:28:31 +00:00
|
|
|
// LIB_FIELDs are not plotted here, because this plot function is used to plot schematic
|
|
|
|
// items which have their own SCH_FIELDs
|
2014-11-12 10:32:02 +00:00
|
|
|
if( item.Type() == LIB_FIELD_T )
|
|
|
|
continue;
|
|
|
|
|
2021-01-26 22:54:10 +00:00
|
|
|
if( aUnit && item.m_unit && ( item.m_unit != aUnit ) )
|
2014-11-12 10:32:02 +00:00
|
|
|
continue;
|
|
|
|
|
2021-01-26 22:54:10 +00:00
|
|
|
if( aConvert && item.m_convert && ( item.m_convert != aConvert ) )
|
2014-11-12 10:32:02 +00:00
|
|
|
continue;
|
|
|
|
|
2022-09-16 16:20:36 +00:00
|
|
|
item.Plot( aPlotter, aBackground, aOffset, aTransform, aDimmed );
|
2013-05-18 09:38:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-01 16:49:19 +00:00
|
|
|
|
2022-02-10 19:49:25 +00:00
|
|
|
void LIB_SYMBOL::PlotLibFields( PLOTTER* aPlotter, int aUnit, int aConvert, bool aBackground,
|
2023-01-06 04:32:24 +00:00
|
|
|
const VECTOR2I& aOffset, const TRANSFORM& aTransform, bool aDimmed,
|
|
|
|
bool aPlotHidden )
|
2013-05-18 09:38:23 +00:00
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
wxASSERT( aPlotter != nullptr );
|
2013-05-18 09:38:23 +00:00
|
|
|
|
2022-09-16 16:20:36 +00:00
|
|
|
COLOR4D color = aPlotter->RenderSettings()->GetLayerColor( LAYER_FIELDS );
|
|
|
|
COLOR4D bg = aPlotter->RenderSettings()->GetBackgroundColor();
|
|
|
|
|
|
|
|
if( bg == COLOR4D::UNSPECIFIED || !aPlotter->GetColorMode() )
|
|
|
|
bg = COLOR4D::WHITE;
|
|
|
|
|
|
|
|
if( aDimmed )
|
2023-01-11 20:53:09 +00:00
|
|
|
{
|
|
|
|
color.Desaturate( );
|
2022-09-16 16:20:36 +00:00
|
|
|
color = color.Mix( bg, 0.5f );
|
2023-01-11 20:53:09 +00:00
|
|
|
}
|
2022-09-16 16:20:36 +00:00
|
|
|
|
|
|
|
aPlotter->SetColor( color );
|
2013-05-18 09:38:23 +00:00
|
|
|
|
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;
|
|
|
|
|
2023-01-06 04:32:24 +00:00
|
|
|
if( !aPlotHidden && !( (LIB_FIELD&) item ).IsVisible() )
|
|
|
|
continue;
|
|
|
|
|
2021-01-26 22:54:10 +00:00
|
|
|
if( aUnit && item.m_unit && ( item.m_unit != aUnit ) )
|
2013-05-18 09:38:23 +00:00
|
|
|
continue;
|
2009-10-05 17:52:41 +00:00
|
|
|
|
2021-01-26 22:54:10 +00:00
|
|
|
if( aConvert && item.m_convert && ( item.m_convert != aConvert ) )
|
2013-05-18 09:38:23 +00:00
|
|
|
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
|
2023-05-05 13:21:56 +00:00
|
|
|
wxString tmp = field.GetShownText( true );
|
2019-11-06 19:15:42 +00:00
|
|
|
|
2020-11-12 21:31:41 +00:00
|
|
|
if( field.GetId() == REFERENCE_FIELD )
|
2013-05-18 09:38:23 +00:00
|
|
|
{
|
|
|
|
wxString text = field.GetFullText( aUnit );
|
|
|
|
field.SetText( text );
|
|
|
|
}
|
2019-11-06 19:15:42 +00:00
|
|
|
|
2022-09-16 16:20:36 +00:00
|
|
|
item.Plot( aPlotter, aBackground, aOffset, aTransform, aDimmed );
|
2013-05-18 09:38:23 +00:00
|
|
|
field.SetText( tmp );
|
2009-10-05 17:52:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-09-05 21:01:27 +00:00
|
|
|
void LIB_SYMBOL::FixupDrawItems()
|
|
|
|
{
|
|
|
|
std::vector<LIB_SHAPE*> potential_top_items;
|
|
|
|
std::vector<LIB_ITEM*> bottom_items;
|
|
|
|
|
|
|
|
for( LIB_ITEM& item : m_drawings )
|
|
|
|
{
|
|
|
|
if( item.Type() == LIB_SHAPE_T )
|
|
|
|
{
|
|
|
|
LIB_SHAPE& shape = static_cast<LIB_SHAPE&>( item );
|
|
|
|
|
|
|
|
if( shape.GetFillMode() == FILL_T::FILLED_WITH_COLOR )
|
|
|
|
potential_top_items.push_back( &shape );
|
|
|
|
else
|
|
|
|
bottom_items.push_back( &item );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bottom_items.push_back( &item );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::sort( potential_top_items.begin(), potential_top_items.end(),
|
|
|
|
[]( LIB_ITEM* a, LIB_ITEM* b )
|
|
|
|
{
|
|
|
|
return a->GetBoundingBox().GetArea() > b->GetBoundingBox().GetArea();
|
|
|
|
} );
|
|
|
|
|
|
|
|
|
|
|
|
for( LIB_SHAPE* item : potential_top_items )
|
|
|
|
{
|
|
|
|
for( LIB_ITEM* bottom_item : bottom_items )
|
|
|
|
{
|
|
|
|
if( item->GetBoundingBox().Contains( bottom_item->GetBoundingBox() ) )
|
|
|
|
{
|
|
|
|
item->SetFillMode( FILL_T::FILLED_WITH_BG_BODYCOLOR );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
void LIB_SYMBOL::RemoveDrawItem( LIB_ITEM* aItem )
|
2009-09-04 18:57:37 +00:00
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
wxASSERT( aItem != nullptr );
|
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
|
|
|
{
|
2021-07-19 12:16:42 +00:00
|
|
|
if( &*i == aItem )
|
2009-09-29 18:38:21 +00:00
|
|
|
{
|
2017-08-14 14:53:25 +00:00
|
|
|
items.erase( i );
|
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
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
void LIB_SYMBOL::AddDrawItem( LIB_ITEM* aItem, bool aSort )
|
2009-09-29 18:38:21 +00:00
|
|
|
{
|
2021-03-04 22:59:24 +00:00
|
|
|
wxCHECK( aItem, /* void */ );
|
2009-09-29 18:38:21 +00:00
|
|
|
|
2017-09-17 08:26:06 +00:00
|
|
|
m_drawings.push_back( aItem );
|
2021-03-04 22:59:24 +00:00
|
|
|
|
|
|
|
if( aSort )
|
|
|
|
m_drawings.sort();
|
2009-09-29 18:38:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
void LIB_SYMBOL::GetPins( LIB_PINS& aList, int aUnit, int aConvert ) const
|
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
|
2021-01-26 22:54:10 +00:00
|
|
|
* when m_unit == 0, the body item is common to units
|
|
|
|
* when m_convert == 0, the body item is common to shapes
|
2009-10-26 12:01:46 +00:00
|
|
|
*/
|
2021-05-05 22:31:47 +00:00
|
|
|
|
2023-08-31 10:36:07 +00:00
|
|
|
LIB_SYMBOL_SPTR parent = m_parent.lock();
|
2021-05-05 22:31:47 +00:00
|
|
|
const LIB_ITEMS_CONTAINER& drawItems = parent ? parent->m_drawings : m_drawings;
|
|
|
|
|
|
|
|
for( const LIB_ITEM& item : drawItems[LIB_PIN_T] )
|
2009-10-14 19:43:31 +00:00
|
|
|
{
|
2009-10-26 12:01:46 +00:00
|
|
|
// Unit filtering:
|
2021-01-26 22:54:10 +00:00
|
|
|
if( aUnit && item.m_unit && ( item.m_unit != aUnit ) )
|
2021-05-05 22:31:47 +00:00
|
|
|
continue;
|
2009-10-26 12:01:46 +00:00
|
|
|
|
2023-08-31 10:36:07 +00:00
|
|
|
// De Morgan variant filtering:
|
2021-01-26 22:54:10 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-16 13:42:49 +00:00
|
|
|
std::vector<LIB_PIN*> LIB_SYMBOL::GetAllLibPins() const
|
2022-12-09 20:02:47 +00:00
|
|
|
{
|
|
|
|
std::vector<LIB_PIN*> pinList;
|
|
|
|
|
2022-12-16 13:42:49 +00:00
|
|
|
GetPins( pinList, 0, 0 );
|
2022-12-09 20:02:47 +00:00
|
|
|
return pinList;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-02 22:32:20 +00:00
|
|
|
int LIB_SYMBOL::GetPinCount()
|
|
|
|
{
|
|
|
|
std::vector<LIB_PIN*> pinList;
|
|
|
|
|
|
|
|
GetPins( pinList, 0, 1 ); // All units, but a single convert
|
|
|
|
return pinList.size();
|
|
|
|
}
|
|
|
|
|
2022-12-09 20:02:47 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_PIN* LIB_SYMBOL::GetPin( const wxString& aNumber, int aUnit, int aConvert ) const
|
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
|
|
|
|
2022-12-16 13:42:49 +00:00
|
|
|
for( LIB_PIN* pin : pinList )
|
2009-10-30 19:26:25 +00:00
|
|
|
{
|
2022-12-16 13:42:49 +00:00
|
|
|
wxASSERT( pin->Type() == LIB_PIN_T );
|
2009-10-30 19:26:25 +00:00
|
|
|
|
2022-12-16 13:42:49 +00:00
|
|
|
if( aNumber == pin->GetNumber() )
|
|
|
|
return pin;
|
2009-10-30 19:26:25 +00:00
|
|
|
}
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
return nullptr;
|
2009-10-30 19:26:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
bool LIB_SYMBOL::PinsConflictWith( const LIB_SYMBOL& aOtherPart, bool aTestNums, bool aTestNames,
|
|
|
|
bool aTestType, bool aTestOrientation, bool aTestLength ) const
|
2015-04-25 22:26:51 +00:00
|
|
|
{
|
|
|
|
LIB_PINS thisPinList;
|
|
|
|
GetPins( thisPinList, /* aUnit */ 0, /* aConvert */ 0 );
|
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
for( const 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;
|
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
for( const 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;
|
2021-06-09 19:32:58 +00:00
|
|
|
break; // Match found so search is complete.
|
2015-04-25 22:26:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( !foundMatch )
|
|
|
|
{
|
|
|
|
// This means there was not an identical (according to the arguments)
|
2021-06-14 18:00:08 +00:00
|
|
|
// pin at the same position in the other symbol.
|
2015-04-25 22:26:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The loop never gave up, so no conflicts were found.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-13 03:47:56 +00:00
|
|
|
const BOX2I LIB_SYMBOL::GetUnitBoundingBox( int aUnit, int aConvert,
|
|
|
|
bool aIgnoreHiddenFields ) const
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2022-08-31 09:15:42 +00:00
|
|
|
BOX2I bBox; // Start with a fresh BOX2I so the Merge algorithm works
|
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
|
|
|
{
|
2021-01-26 22:54:10 +00:00
|
|
|
if( item.m_unit > 0
|
|
|
|
&& m_unitCount > 1
|
|
|
|
&& aUnit > 0
|
|
|
|
&& aUnit != item.m_unit )
|
|
|
|
{
|
2009-09-29 18:38:21 +00:00
|
|
|
continue;
|
2021-01-26 22:54:10 +00:00
|
|
|
}
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2021-01-26 22:54:10 +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
|
|
|
|
2022-12-13 03:47:56 +00:00
|
|
|
if( aIgnoreHiddenFields && ( item.Type() == LIB_FIELD_T )
|
|
|
|
&& !( (LIB_FIELD&) item ).IsVisible() )
|
2009-11-20 19:51:39 +00:00
|
|
|
continue;
|
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
bBox.Merge( item.GetBoundingBox() );
|
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
|
|
|
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
void LIB_SYMBOL::ViewGetLayers( int aLayers[], int& aCount ) const
|
2018-10-21 12:50:31 +00:00
|
|
|
{
|
2023-06-12 14:38:36 +00:00
|
|
|
aCount = 0;
|
|
|
|
aLayers[ aCount++ ] = LAYER_DEVICE;
|
|
|
|
aLayers[ aCount++ ] = LAYER_DEVICE_BACKGROUND;
|
|
|
|
aLayers[ aCount++ ] = LAYER_REFERENCEPART;
|
|
|
|
aLayers[ aCount++ ] = LAYER_VALUEPART;
|
|
|
|
aLayers[ aCount++ ] = LAYER_FIELDS;
|
|
|
|
aLayers[ aCount++ ] = LAYER_PRIVATE_NOTES;
|
|
|
|
aLayers[ aCount++ ] = LAYER_NOTES_BACKGROUND;
|
|
|
|
aLayers[ aCount++ ] = LAYER_SELECTION_SHADOWS;
|
2018-10-21 12:50:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-30 23:28:18 +00:00
|
|
|
const BOX2I LIB_SYMBOL::GetBodyBoundingBox( int aUnit, int aConvert, bool aIncludePins,
|
|
|
|
bool aIncludePrivateItems ) const
|
2011-02-27 19:54:01 +00:00
|
|
|
{
|
2022-08-30 23:28:18 +00:00
|
|
|
BOX2I 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
|
|
|
{
|
2021-03-14 22:29:41 +00:00
|
|
|
if( item.m_unit > 0 && aUnit > 0 && aUnit != item.m_unit )
|
2011-02-27 19:54:01 +00:00
|
|
|
continue;
|
|
|
|
|
2021-01-26 22:54:10 +00:00
|
|
|
if( item.m_convert > 0 && aConvert > 0 && aConvert != item.m_convert )
|
2011-02-27 19:54:01 +00:00
|
|
|
continue;
|
|
|
|
|
2022-03-06 16:12:49 +00:00
|
|
|
if( item.IsPrivate() && !aIncludePrivateItems )
|
|
|
|
continue;
|
|
|
|
|
2015-12-13 16:56:47 +00:00
|
|
|
if( item.Type() == LIB_FIELD_T )
|
2011-02-27 19:54:01 +00:00
|
|
|
continue;
|
|
|
|
|
2021-03-14 22:29:41 +00:00
|
|
|
if( item.Type() == LIB_PIN_T )
|
2021-09-23 21:07:19 +00:00
|
|
|
{
|
2021-09-24 15:19:21 +00:00
|
|
|
const LIB_PIN& pin = static_cast<const LIB_PIN&>( item );
|
|
|
|
|
2022-06-08 23:04:49 +00:00
|
|
|
if( pin.IsVisible() )
|
|
|
|
{
|
|
|
|
// Note: the roots of the pins are always included for symbols that don't have
|
|
|
|
// a well-defined body.
|
2021-09-24 15:19:21 +00:00
|
|
|
|
2022-06-08 23:04:49 +00:00
|
|
|
if( aIncludePins )
|
2022-07-23 22:26:03 +00:00
|
|
|
bbox.Merge( pin.GetBoundingBox( false, false, false ) );
|
2022-06-08 23:04:49 +00:00
|
|
|
else
|
|
|
|
bbox.Merge( pin.GetPinRoot() );
|
|
|
|
}
|
2021-09-23 21:07:19 +00:00
|
|
|
}
|
2021-03-14 22:29:41 +00:00
|
|
|
else
|
2021-09-23 21:07:19 +00:00
|
|
|
{
|
2021-03-14 22:29:41 +00:00
|
|
|
bbox.Merge( item.GetBoundingBox() );
|
2021-09-23 21:07:19 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
void LIB_SYMBOL::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
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
void LIB_SYMBOL::AddField( LIB_FIELD* aField )
|
2020-12-15 15:06:19 +00:00
|
|
|
{
|
|
|
|
AddDrawItem( aField );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-09 20:02:47 +00:00
|
|
|
void LIB_SYMBOL::SetFields( const std::vector<LIB_FIELD>& aFields )
|
2010-06-17 16:30:10 +00:00
|
|
|
{
|
|
|
|
deleteAllFields();
|
|
|
|
|
2022-12-09 20:02:47 +00:00
|
|
|
for( size_t ii = 0; ii < aFields.size(); ++ii )
|
2010-06-17 16:30:10 +00:00
|
|
|
{
|
|
|
|
// drawings is a ptr_vector, new and copy an object on the heap.
|
2022-12-09 20:02:47 +00:00
|
|
|
LIB_FIELD* field = new LIB_FIELD( aFields[ ii ] );
|
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
|
|
|
}
|
2021-03-04 22:59:24 +00:00
|
|
|
|
|
|
|
m_drawings.sort();
|
2009-10-21 20:02:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
void LIB_SYMBOL::GetFields( std::vector<LIB_FIELD*>& aList )
|
2009-10-21 20:02:25 +00:00
|
|
|
{
|
2021-02-28 13:28:23 +00:00
|
|
|
// Grab the MANDATORY_FIELDS first, in expected order given by enum MANDATORY_FIELD_T
|
2020-12-15 15:06:19 +00:00
|
|
|
for( int id = 0; id < MANDATORY_FIELDS; ++id )
|
2021-02-28 13:28:23 +00:00
|
|
|
aList.push_back( GetFieldById( id ) );
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2020-12-15 15:06:19 +00:00
|
|
|
// Now grab all the rest of fields.
|
|
|
|
for( LIB_ITEM& item : m_drawings[ LIB_FIELD_T ] )
|
2010-06-17 16:30:10 +00:00
|
|
|
{
|
2020-12-15 15:06:19 +00:00
|
|
|
LIB_FIELD* field = static_cast<LIB_FIELD*>( &item );
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2020-12-15 15:06:19 +00:00
|
|
|
if( !field->IsMandatory() )
|
|
|
|
aList.push_back( field );
|
2010-06-17 16:30:10 +00:00
|
|
|
}
|
2020-12-15 15:06:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
void LIB_SYMBOL::GetFields( std::vector<LIB_FIELD>& aList )
|
2020-12-15 15:06:19 +00:00
|
|
|
{
|
2021-02-28 13:28:23 +00:00
|
|
|
// Grab the MANDATORY_FIELDS first, in expected order given by enum MANDATORY_FIELD_T
|
2020-12-15 15:06:19 +00:00
|
|
|
for( int id = 0; id < MANDATORY_FIELDS; ++id )
|
2021-02-28 13:28:23 +00:00
|
|
|
aList.push_back( *GetFieldById( id ) );
|
2010-06-17 16:30:10 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
{
|
2020-12-15 15:06:19 +00:00
|
|
|
LIB_FIELD* field = static_cast<LIB_FIELD*>( &item );
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2020-12-15 15:06:19 +00:00
|
|
|
if( !field->IsMandatory() )
|
|
|
|
aList.push_back( *field );
|
2008-12-31 15:01:29 +00:00
|
|
|
}
|
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_FIELD* LIB_SYMBOL::GetFieldById( 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;
|
|
|
|
}
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
return nullptr;
|
2009-10-21 20:02:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-28 22:47:30 +00:00
|
|
|
LIB_FIELD* LIB_SYMBOL::FindField( const wxString& aFieldName, bool aCaseInsensitive )
|
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
|
|
|
{
|
2023-06-28 22:47:30 +00:00
|
|
|
if( aCaseInsensitive )
|
|
|
|
{
|
|
|
|
if( static_cast<LIB_FIELD*>( &item )->GetCanonicalName().Upper() == aFieldName.Upper() )
|
|
|
|
return static_cast<LIB_FIELD*>( &item );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( static_cast<LIB_FIELD*>( &item )->GetCanonicalName() == aFieldName )
|
|
|
|
return static_cast<LIB_FIELD*>( &item );
|
|
|
|
}
|
2020-06-02 19:27:22 +00:00
|
|
|
}
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
return nullptr;
|
2020-06-02 19:27:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-28 22:47:30 +00:00
|
|
|
const LIB_FIELD* LIB_SYMBOL::FindField( const wxString& aFieldName,
|
|
|
|
const bool aCaseInsensitive ) const
|
2020-06-02 19:27:22 +00:00
|
|
|
{
|
|
|
|
for( const LIB_ITEM& item : m_drawings[ LIB_FIELD_T ] )
|
|
|
|
{
|
2023-06-28 22:47:30 +00:00
|
|
|
if( aCaseInsensitive )
|
|
|
|
{
|
|
|
|
if( static_cast<const LIB_FIELD*>( &item )->GetCanonicalName().Upper()
|
|
|
|
== aFieldName.Upper() )
|
|
|
|
return static_cast<const LIB_FIELD*>( &item );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( static_cast<const LIB_FIELD*>( &item )->GetCanonicalName() == aFieldName )
|
|
|
|
return static_cast<const LIB_FIELD*>( &item );
|
|
|
|
}
|
2010-06-17 16:30:10 +00:00
|
|
|
}
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
return nullptr;
|
2010-06-17 16:30:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_FIELD& LIB_SYMBOL::GetValueField()
|
2009-10-21 20:02:25 +00:00
|
|
|
{
|
2021-02-28 13:28:23 +00:00
|
|
|
LIB_FIELD* field = GetFieldById( VALUE_FIELD );
|
2021-07-16 20:13:26 +00:00
|
|
|
wxASSERT( field != nullptr );
|
2009-10-21 20:02:25 +00:00
|
|
|
return *field;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_FIELD& LIB_SYMBOL::GetReferenceField()
|
2009-10-21 20:02:25 +00:00
|
|
|
{
|
2021-02-28 13:28:23 +00:00
|
|
|
LIB_FIELD* field = GetFieldById( REFERENCE_FIELD );
|
2021-07-16 20:13:26 +00:00
|
|
|
wxASSERT( field != nullptr );
|
2009-10-21 20:02:25 +00:00
|
|
|
return *field;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_FIELD& LIB_SYMBOL::GetFootprintField()
|
2017-07-09 13:08:33 +00:00
|
|
|
{
|
2021-02-28 13:28:23 +00:00
|
|
|
LIB_FIELD* field = GetFieldById( FOOTPRINT_FIELD );
|
2021-07-16 20:13:26 +00:00
|
|
|
wxASSERT( field != nullptr );
|
2017-07-09 13:08:33 +00:00
|
|
|
return *field;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_FIELD& LIB_SYMBOL::GetDatasheetField()
|
2020-06-01 13:13:32 +00:00
|
|
|
{
|
2021-02-28 13:28:23 +00:00
|
|
|
LIB_FIELD* field = GetFieldById( DATASHEET_FIELD );
|
2021-07-16 20:13:26 +00:00
|
|
|
wxASSERT( field != nullptr );
|
2020-06-01 13:13:32 +00:00
|
|
|
return *field;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-19 17:08:18 +00:00
|
|
|
LIB_FIELD& LIB_SYMBOL::GetDescriptionField()
|
|
|
|
{
|
|
|
|
LIB_FIELD* field = GetFieldById( DESCRIPTION_FIELD );
|
|
|
|
wxASSERT( field != nullptr );
|
|
|
|
return *field;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-08 23:56:55 +00:00
|
|
|
wxString LIB_SYMBOL::GetPrefix()
|
|
|
|
{
|
|
|
|
wxString refDesignator = GetFieldById( REFERENCE_FIELD )->GetText();
|
|
|
|
|
2023-01-17 04:14:38 +00:00
|
|
|
refDesignator.Replace( wxS( "~" ), wxS( " " ) );
|
2022-12-08 23:56:55 +00:00
|
|
|
|
|
|
|
wxString prefix = refDesignator;
|
|
|
|
|
|
|
|
while( prefix.Length() )
|
|
|
|
{
|
|
|
|
wxUniCharRef last = prefix.Last();
|
|
|
|
|
|
|
|
if( ( last >= '0' && last <= '9' ) || last == '?' || last == '*' )
|
|
|
|
prefix.RemoveLast();
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Avoid a prefix containing trailing/leading spaces
|
|
|
|
prefix.Trim( true );
|
|
|
|
prefix.Trim( false );
|
|
|
|
|
|
|
|
return prefix;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-04-29 00:02:42 +00:00
|
|
|
void LIB_SYMBOL::RunOnChildren( const std::function<void( LIB_ITEM* )>& aFunction )
|
|
|
|
{
|
|
|
|
for( LIB_ITEM& item : m_drawings )
|
|
|
|
aFunction( &item );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-12 22:01:13 +00:00
|
|
|
int LIB_SYMBOL::UpdateFieldOrdinals()
|
|
|
|
{
|
|
|
|
int retv = 0;
|
|
|
|
int lastOrdinal = MANDATORY_FIELDS;
|
|
|
|
|
|
|
|
for( LIB_ITEM& item : m_drawings[ LIB_FIELD_T ] )
|
|
|
|
{
|
|
|
|
LIB_FIELD* field = dynamic_cast<LIB_FIELD*>( &item );
|
|
|
|
|
|
|
|
wxCHECK2( field, continue );
|
|
|
|
|
|
|
|
// Mandatory fields were already resolved always have the same ordinal values.
|
|
|
|
if( field->IsMandatory() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( field->GetId() != lastOrdinal )
|
|
|
|
{
|
|
|
|
field->SetId( lastOrdinal );
|
|
|
|
retv += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
lastOrdinal += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int LIB_SYMBOL::GetNextAvailableFieldId() const
|
|
|
|
{
|
|
|
|
int retv = MANDATORY_FIELDS;
|
|
|
|
|
|
|
|
while( GetFieldById( retv ) )
|
|
|
|
retv += 1;
|
|
|
|
|
|
|
|
return retv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void LIB_SYMBOL::SetOffset( const VECTOR2I& 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
void LIB_SYMBOL::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
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
bool LIB_SYMBOL::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
|
|
|
{
|
2021-01-26 22:54:10 +00:00
|
|
|
if( item.m_convert > LIB_ITEM::LIB_CONVERT::BASE )
|
2009-09-14 13:24:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
if( LIB_SYMBOL_SPTR parent = m_parent.lock() )
|
2019-11-07 14:09:24 +00:00
|
|
|
{
|
|
|
|
for( const LIB_ITEM& item : parent->GetDrawItems() )
|
|
|
|
{
|
2021-01-26 22:54:10 +00:00
|
|
|
if( item.m_convert > LIB_ITEM::LIB_CONVERT::BASE )
|
2019-11-07 14:09:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-14 13:24:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-08-31 10:36:07 +00:00
|
|
|
|
2022-05-14 22:33:43 +00:00
|
|
|
int LIB_SYMBOL::GetMaxPinNumber() const
|
|
|
|
{
|
|
|
|
int maxPinNumber = 0;
|
|
|
|
LIB_SYMBOL_SPTR parent = m_parent.lock();
|
|
|
|
const LIB_ITEMS_CONTAINER& drawItems = parent ? parent->m_drawings : m_drawings;
|
|
|
|
|
|
|
|
for( const LIB_ITEM& item : drawItems[LIB_PIN_T] )
|
|
|
|
{
|
|
|
|
const LIB_PIN* pin = static_cast<const LIB_PIN*>( &item );
|
|
|
|
long currentPinNumber = 0;
|
|
|
|
|
2023-09-03 18:05:33 +00:00
|
|
|
if( pin->GetNumber().ToLong( ¤tPinNumber ) )
|
|
|
|
maxPinNumber = std::max( maxPinNumber, (int) currentPinNumber );
|
2022-05-14 22:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return maxPinNumber;
|
|
|
|
}
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
void LIB_SYMBOL::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
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
void LIB_SYMBOL::ClearEditFlags()
|
2019-05-11 10:06:28 +00:00
|
|
|
{
|
|
|
|
for( LIB_ITEM& item : m_drawings )
|
|
|
|
item.ClearEditFlags();
|
2009-09-29 18:38:21 +00:00
|
|
|
}
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
LIB_ITEM* LIB_SYMBOL::LocateDrawItem( int aUnit, int aConvert, KICAD_T aType,
|
|
|
|
const VECTOR2I& 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
|
|
|
{
|
2021-01-26 22:54:10 +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;
|
2021-01-26 22:54:10 +00:00
|
|
|
}
|
2009-09-29 18:38:21 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
return nullptr;
|
2009-09-29 18:38:21 +00:00
|
|
|
}
|
2009-10-05 17:52:41 +00:00
|
|
|
|
2010-12-14 15:56:30 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_ITEM* LIB_SYMBOL::LocateDrawItem( int aUnit, int aConvert, KICAD_T aType,
|
2022-01-01 06:04:08 +00:00
|
|
|
const VECTOR2I& 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
|
2022-01-01 06:04:08 +00:00
|
|
|
* VECTOR2I& 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
|
|
|
|
2022-07-30 00:00:39 +00:00
|
|
|
INSPECT_RESULT LIB_SYMBOL::Visit( INSPECTOR aInspector, void* aTestData,
|
2022-08-21 19:54:07 +00:00
|
|
|
const std::vector<KICAD_T>& aScanTypes )
|
2019-05-06 02:32:01 +00:00
|
|
|
{
|
|
|
|
// The part itself is never inspected, only its children
|
|
|
|
for( LIB_ITEM& item : m_drawings )
|
|
|
|
{
|
2022-08-20 09:27:35 +00:00
|
|
|
if( item.IsType( aScanTypes ) )
|
2019-05-06 02:32:01 +00:00
|
|
|
{
|
2022-07-30 00:00:39 +00:00
|
|
|
if( aInspector( &item, aTestData ) == INSPECT_RESULT::QUIT )
|
|
|
|
return INSPECT_RESULT::QUIT;
|
2019-05-06 02:32:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-30 00:00:39 +00:00
|
|
|
return INSPECT_RESULT::CONTINUE;
|
2019-05-06 02:32:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
void LIB_SYMBOL::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
|
|
|
{
|
2021-01-26 22:54:10 +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
|
|
|
{
|
2021-01-26 22:54:10 +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
|
|
|
{
|
2023-09-03 18:05:33 +00:00
|
|
|
LIB_ITEM* newItem = (LIB_ITEM*) item.Duplicate();
|
2021-01-26 22:54:10 +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
|
|
|
|
2021-11-02 16:37:01 +00:00
|
|
|
for( LIB_ITEM* item : tmp )
|
2017-09-17 08:26:06 +00:00
|
|
|
m_drawings.push_back( item );
|
2009-10-05 17:52:41 +00:00
|
|
|
}
|
|
|
|
|
2021-03-04 22:59:24 +00:00
|
|
|
m_drawings.sort();
|
2010-10-25 15:43:42 +00:00
|
|
|
m_unitCount = aCount;
|
2009-10-05 17:52:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
int LIB_SYMBOL::GetUnitCount() const
|
2019-11-06 19:15:42 +00:00
|
|
|
{
|
2021-06-15 12:31:28 +00:00
|
|
|
if( LIB_SYMBOL_SPTR parent = m_parent.lock() )
|
2019-11-06 19:15:42 +00:00
|
|
|
return parent->GetUnitCount();
|
|
|
|
|
|
|
|
return m_unitCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
void LIB_SYMBOL::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;
|
|
|
|
|
2021-01-26 22:54:10 +00:00
|
|
|
if( item.m_convert == 1 )
|
2020-02-28 14:03:09 +00:00
|
|
|
{
|
2023-09-03 18:05:33 +00:00
|
|
|
LIB_ITEM* newItem = (LIB_ITEM*) item.Duplicate();
|
2021-01-26 22:54:10 +00:00
|
|
|
newItem->m_convert = 2;
|
2020-02-28 14:03:09 +00:00
|
|
|
tmp.push_back( newItem );
|
|
|
|
}
|
2009-10-05 17:52:41 +00:00
|
|
|
}
|
2016-02-19 21:29:56 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
// Transfer the new pins to the LIB_SYMBOL.
|
2020-02-28 14:03:09 +00:00
|
|
|
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
|
|
|
{
|
2021-01-26 22:54:10 +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
|
|
|
}
|
|
|
|
}
|
2021-03-04 22:59:24 +00:00
|
|
|
|
|
|
|
m_drawings.sort();
|
2009-10-05 17:52:41 +00:00
|
|
|
}
|
2010-02-17 13:22:25 +00:00
|
|
|
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
void LIB_SYMBOL::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
|
|
|
|
|
|
|
|
2021-11-02 18:32:39 +00:00
|
|
|
std::vector<LIB_ITEM*> LIB_SYMBOL::GetUnitDrawItems( int aUnit, int aConvert )
|
2020-02-13 13:39:52 +00:00
|
|
|
{
|
|
|
|
std::vector<LIB_ITEM*> unitItems;
|
|
|
|
|
|
|
|
for( LIB_ITEM& item : m_drawings )
|
|
|
|
{
|
|
|
|
if( item.Type() == LIB_FIELD_T )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( ( aConvert == -1 && item.GetUnit() == aUnit )
|
2021-11-02 16:37:01 +00:00
|
|
|
|| ( aUnit == -1 && item.GetConvert() == aConvert )
|
|
|
|
|| ( aUnit == item.GetUnit() && aConvert == item.GetConvert() ) )
|
|
|
|
{
|
2020-02-13 13:39:52 +00:00
|
|
|
unitItems.push_back( &item );
|
2021-11-02 16:37:01 +00:00
|
|
|
}
|
2020-02-13 13:39:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return unitItems;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-02 18:32:39 +00:00
|
|
|
std::vector<struct LIB_SYMBOL_UNIT> LIB_SYMBOL::GetUnitDrawItems()
|
2020-02-13 13:39:52 +00:00
|
|
|
{
|
2021-11-02 18:32:39 +00:00
|
|
|
std::vector<struct LIB_SYMBOL_UNIT> units;
|
2020-02-13 13:39:52 +00:00
|
|
|
|
|
|
|
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(),
|
2021-11-02 18:32:39 +00:00
|
|
|
[unit, convert]( const LIB_SYMBOL_UNIT& a )
|
2021-11-02 16:37:01 +00:00
|
|
|
{
|
2020-02-13 13:39:52 +00:00
|
|
|
return a.m_unit == unit && a.m_convert == convert;
|
|
|
|
} );
|
|
|
|
|
|
|
|
if( it == units.end() )
|
|
|
|
{
|
2021-11-02 18:32:39 +00:00
|
|
|
struct LIB_SYMBOL_UNIT newUnit;
|
2020-02-13 13:39:52 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-02 18:32:39 +00:00
|
|
|
std::vector<struct LIB_SYMBOL_UNIT> LIB_SYMBOL::GetUniqueUnits()
|
2020-02-13 13:39:52 +00:00
|
|
|
{
|
|
|
|
int unitNum;
|
|
|
|
size_t i;
|
2021-11-02 18:32:39 +00:00
|
|
|
struct LIB_SYMBOL_UNIT unit;
|
2020-02-13 13:39:52 +00:00
|
|
|
std::vector<LIB_ITEM*> compareDrawItems;
|
|
|
|
std::vector<LIB_ITEM*> currentDrawItems;
|
2021-11-02 18:32:39 +00:00
|
|
|
std::vector<struct LIB_SYMBOL_UNIT> uniqueUnits;
|
2020-02-13 13:39:52 +00:00
|
|
|
|
2021-06-09 19:32:58 +00:00
|
|
|
// The first unit is guaranteed to be unique so always include it.
|
2020-02-13 13:39:52 +00:00
|
|
|
unit.m_unit = 1;
|
|
|
|
unit.m_convert = 1;
|
2021-11-02 18:32:39 +00:00
|
|
|
unit.m_items = GetUnitDrawItems( 1, 1 );
|
2020-02-13 13:39:52 +00:00
|
|
|
|
|
|
|
// 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++ )
|
|
|
|
{
|
2021-11-02 18:32:39 +00:00
|
|
|
compareDrawItems = GetUnitDrawItems( unitNum, 1 );
|
2020-02-13 13:39:52 +00:00
|
|
|
|
|
|
|
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() )
|
|
|
|
{
|
2021-11-02 18:32:39 +00:00
|
|
|
currentDrawItems = GetUnitDrawItems( 1, 2 );
|
2020-02-13 13:39:52 +00:00
|
|
|
|
|
|
|
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++ )
|
|
|
|
{
|
2021-11-02 18:32:39 +00:00
|
|
|
compareDrawItems = GetUnitDrawItems( unitNum, 2 );
|
2020-02-13 13:39:52 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|