2011-10-11 20:23:56 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2015-02-28 16:56:09 +00:00
|
|
|
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2024-03-09 13:50:26 +00:00
|
|
|
* Copyright (C) 1992-2024 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-10-11 20:23:56 +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-01-30 10:49:51 +00:00
|
|
|
#include <sch_edit_frame.h>
|
2020-10-25 04:49:02 +00:00
|
|
|
#include <widgets/msgpanel.h>
|
2017-02-20 12:20:39 +00:00
|
|
|
#include <bitmaps.h>
|
2020-11-18 01:21:04 +00:00
|
|
|
#include <core/mirror.h>
|
2024-04-20 09:44:34 +00:00
|
|
|
#include <sch_pin.h>
|
2024-04-15 20:18:54 +00:00
|
|
|
#include <sch_shape.h>
|
2023-01-11 19:29:06 +00:00
|
|
|
#include <pgm_base.h>
|
2021-02-24 13:48:02 +00:00
|
|
|
#include <sch_symbol.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <sch_sheet_path.h>
|
2020-05-13 02:00:37 +00:00
|
|
|
#include <schematic.h>
|
2024-03-04 14:24:00 +00:00
|
|
|
#include <sim/sim_model.h>
|
|
|
|
#include <sim/spice_generator.h>
|
|
|
|
#include <sim/sim_lib_mgr.h>
|
2018-04-17 16:25:19 +00:00
|
|
|
#include <trace_helpers.h>
|
2020-10-14 03:37:48 +00:00
|
|
|
#include <trigo.h>
|
2021-04-17 14:10:59 +00:00
|
|
|
#include <refdes_utils.h>
|
2021-06-03 12:11:15 +00:00
|
|
|
#include <wx/log.h>
|
2023-01-11 19:29:06 +00:00
|
|
|
#include <settings/settings_manager.h>
|
2023-10-21 20:52:51 +00:00
|
|
|
#include <sch_plotter.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2022-12-16 13:42:49 +00:00
|
|
|
|
|
|
|
#include <utility>
|
2008-10-06 05:44:29 +00:00
|
|
|
|
2021-08-25 13:13:40 +00:00
|
|
|
|
2023-03-05 17:25:36 +00:00
|
|
|
std::unordered_map<TRANSFORM, int> SCH_SYMBOL::s_transformToOrientationCache;
|
|
|
|
|
|
|
|
|
2011-07-15 13:17:41 +00:00
|
|
|
/**
|
2024-04-09 11:55:44 +00:00
|
|
|
* Convert a wxString to UTF8 and replace any control characters with a ~, where a control
|
|
|
|
* character is one of the first ASCII values up to ' ' 32d.
|
2011-07-15 13:17:41 +00:00
|
|
|
*/
|
2016-07-11 19:48:46 +00:00
|
|
|
std::string toUTFTildaText( const wxString& txt )
|
2011-07-15 13:17:41 +00:00
|
|
|
{
|
|
|
|
std::string ret = TO_UTF8( txt );
|
|
|
|
|
2024-04-09 11:55:44 +00:00
|
|
|
for( char& c : ret )
|
2011-07-15 13:17:41 +00:00
|
|
|
{
|
2024-04-09 11:55:44 +00:00
|
|
|
if( (unsigned char) c <= ' ' )
|
|
|
|
c = '~';
|
2011-07-15 13:17:41 +00:00
|
|
|
}
|
2022-04-08 16:05:27 +00:00
|
|
|
|
2011-07-15 13:17:41 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
/**
|
2021-06-10 18:51:46 +00:00
|
|
|
* Used to draw a dummy shape when a LIB_SYMBOL is not found in library
|
2019-07-02 20:09:23 +00:00
|
|
|
*
|
2021-05-05 21:41:51 +00:00
|
|
|
* This symbol is a 400 mils square with the text "??"
|
2009-04-05 20:49:15 +00:00
|
|
|
*/
|
2021-06-10 18:51:46 +00:00
|
|
|
static LIB_SYMBOL* dummy()
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
static LIB_SYMBOL* 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
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
if( !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
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
symbol = new LIB_SYMBOL( wxEmptyString );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2024-04-15 20:18:54 +00:00
|
|
|
SCH_SHAPE* square = new SCH_SHAPE( SHAPE_T::RECTANGLE, LAYER_DEVICE );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2024-04-06 13:14:44 +00:00
|
|
|
square->SetPosition( VECTOR2I( schIUScale.MilsToIU( -200 ), schIUScale.MilsToIU( 200 ) ) );
|
2022-09-16 23:42:20 +00:00
|
|
|
square->SetEnd( VECTOR2I( schIUScale.MilsToIU( 200 ), schIUScale.MilsToIU( -200 ) ) );
|
2024-04-15 20:18:54 +00:00
|
|
|
symbol->AddDrawItem( square );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2024-04-14 18:04:53 +00:00
|
|
|
SCH_TEXT* text = new SCH_TEXT( { 0, 0 }, wxT( "??"), LAYER_DEVICE );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2023-02-19 03:40:07 +00:00
|
|
|
text->SetTextSize( VECTOR2I( schIUScale.MilsToIU( 150 ), schIUScale.MilsToIU( 150 ) ) );
|
2021-06-10 18:51:46 +00:00
|
|
|
symbol->AddDrawItem( text );
|
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
|
|
|
}
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
return symbol;
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
SCH_SYMBOL::SCH_SYMBOL() :
|
2024-04-02 17:28:17 +00:00
|
|
|
SYMBOL( nullptr, SCH_SYMBOL_T )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2022-01-04 01:00:40 +00:00
|
|
|
Init( VECTOR2I( 0, 0 ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
SCH_SYMBOL::SCH_SYMBOL( const LIB_SYMBOL& aSymbol, const LIB_ID& aLibId,
|
2024-01-26 16:16:13 +00:00
|
|
|
const SCH_SHEET_PATH* aSheet, int aUnit, int aBodyStyle,
|
2022-08-26 17:34:46 +00:00
|
|
|
const VECTOR2I& aPosition, EDA_ITEM* aParent ) :
|
2024-04-09 11:55:44 +00:00
|
|
|
SYMBOL( aParent, SCH_SYMBOL_T )
|
2008-10-06 05:44:29 +00:00
|
|
|
{
|
2022-04-08 16:05:27 +00:00
|
|
|
Init( aPosition );
|
2008-10-06 05:44:29 +00:00
|
|
|
|
2022-04-08 16:05:27 +00:00
|
|
|
m_unit = aUnit;
|
2024-01-26 16:16:13 +00:00
|
|
|
m_bodyStyle = aBodyStyle;
|
2018-11-22 21:30:36 +00:00
|
|
|
m_lib_id = aLibId;
|
2019-12-31 13:05:52 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
std::unique_ptr< LIB_SYMBOL > part;
|
2019-12-31 13:05:52 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
part = aSymbol.Flatten();
|
2019-12-31 13:05:52 +00:00
|
|
|
part->SetParent();
|
2020-04-16 16:43:50 +00:00
|
|
|
SetLibSymbol( part.release() );
|
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
|
|
|
|
2021-03-25 21:13:01 +00:00
|
|
|
// Copy fields from the library symbol
|
2021-04-09 16:10:40 +00:00
|
|
|
UpdateFields( aSheet,
|
2021-06-10 14:10:55 +00:00
|
|
|
true, /* update style */
|
|
|
|
false, /* update ref */
|
|
|
|
false, /* update other fields */
|
|
|
|
true, /* reset ref */
|
|
|
|
true /* reset other fields */ );
|
2009-10-21 20:02:25 +00:00
|
|
|
|
2021-04-17 14:10:59 +00:00
|
|
|
m_prefix = UTIL::GetRefDesPrefix( m_part->GetReferenceField().GetText() );
|
2021-04-17 11:29:15 +00:00
|
|
|
|
2021-02-02 19:20:40 +00:00
|
|
|
if( aSheet )
|
2021-04-17 14:10:59 +00:00
|
|
|
SetRef( aSheet, UTIL::GetRefDesUnannotated( m_prefix ) );
|
2021-08-25 13:13:40 +00:00
|
|
|
|
2023-04-15 15:51:10 +00:00
|
|
|
// Inherit the include in bill of materials and board netlist settings from flattened
|
|
|
|
// library symbol.
|
2023-08-08 16:32:08 +00:00
|
|
|
m_excludedFromSim = m_part->GetExcludedFromSim();
|
2023-06-25 02:03:06 +00:00
|
|
|
m_excludedFromBOM = m_part->GetExcludedFromBOM();
|
|
|
|
m_excludedFromBoard = m_part->GetExcludedFromBoard();
|
2008-10-06 05:44:29 +00:00
|
|
|
}
|
|
|
|
|
2020-04-16 16:43:50 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
SCH_SYMBOL::SCH_SYMBOL( const LIB_SYMBOL& aSymbol, const SCH_SHEET_PATH* aSheet,
|
2024-04-09 11:55:44 +00:00
|
|
|
const PICKED_SYMBOL& aSel, const VECTOR2I& aPosition, EDA_ITEM* aParent ) :
|
|
|
|
SCH_SYMBOL( aSymbol, aSel.LibId, aSheet, aSel.Unit, aSel.Convert, aPosition, aParent )
|
2019-05-01 09:24:43 +00:00
|
|
|
{
|
2021-03-25 21:13:01 +00:00
|
|
|
// Set any fields that were modified as part of the symbol selection
|
2021-02-28 13:28:23 +00:00
|
|
|
for( const std::pair<int, wxString>& i : aSel.Fields )
|
2019-05-01 09:24:43 +00:00
|
|
|
{
|
2022-11-16 13:33:25 +00:00
|
|
|
if( i.first == REFERENCE_FIELD )
|
|
|
|
SetRef( aSheet, i.second );
|
|
|
|
else if( SCH_FIELD* field = GetFieldById( i.first ) )
|
2019-05-01 09:24:43 +00:00
|
|
|
field->SetText( i.second );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-19 18:31:09 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL::SCH_SYMBOL( const SCH_SYMBOL& aSymbol ) :
|
2024-04-02 17:28:17 +00:00
|
|
|
SYMBOL( aSymbol )
|
2008-10-19 18:31:09 +00:00
|
|
|
{
|
2021-03-25 21:13:01 +00:00
|
|
|
m_parent = aSymbol.m_parent;
|
|
|
|
m_pos = aSymbol.m_pos;
|
|
|
|
m_unit = aSymbol.m_unit;
|
2024-01-26 16:16:13 +00:00
|
|
|
m_bodyStyle = aSymbol.m_bodyStyle;
|
2021-03-25 21:13:01 +00:00
|
|
|
m_lib_id = aSymbol.m_lib_id;
|
|
|
|
m_isInNetlist = aSymbol.m_isInNetlist;
|
2022-09-16 16:20:36 +00:00
|
|
|
m_DNP = aSymbol.m_DNP;
|
2019-11-06 19:15:42 +00:00
|
|
|
|
2021-03-25 21:13:01 +00:00
|
|
|
const_cast<KIID&>( m_Uuid ) = aSymbol.m_Uuid;
|
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
|
|
|
|
2021-03-25 21:13:01 +00:00
|
|
|
m_transform = aSymbol.m_transform;
|
|
|
|
m_prefix = aSymbol.m_prefix;
|
|
|
|
m_instanceReferences = aSymbol.m_instanceReferences;
|
|
|
|
m_fields = aSymbol.m_fields;
|
2010-12-21 15:13:09 +00:00
|
|
|
|
2021-03-25 21:13:01 +00:00
|
|
|
// Re-parent the fields, which before this had aSymbol as parent
|
2020-11-16 13:15:54 +00:00
|
|
|
for( SCH_FIELD& field : m_fields )
|
2019-04-22 10:14:47 +00:00
|
|
|
field.SetParent( this );
|
2015-06-08 00:07:42 +00:00
|
|
|
|
2023-08-28 11:29:47 +00:00
|
|
|
m_pins.clear();
|
|
|
|
|
2023-08-29 11:29:30 +00:00
|
|
|
// Copy (and re-parent) the pins
|
2023-08-28 11:29:47 +00:00
|
|
|
for( const std::unique_ptr<SCH_PIN>& pin : aSymbol.m_pins )
|
2023-08-29 11:29:30 +00:00
|
|
|
{
|
|
|
|
m_pins.emplace_back( std::make_unique<SCH_PIN>( *pin ) );
|
|
|
|
m_pins.back()->SetParent( this );
|
|
|
|
}
|
2023-08-28 11:29:47 +00:00
|
|
|
|
2023-09-26 18:30:02 +00:00
|
|
|
if( aSymbol.m_part )
|
|
|
|
SetLibSymbol( new LIB_SYMBOL( *aSymbol.m_part ) );
|
|
|
|
|
2021-03-25 21:13:01 +00:00
|
|
|
m_fieldsAutoplaced = aSymbol.m_fieldsAutoplaced;
|
|
|
|
m_schLibSymbolName = aSymbol.m_schLibSymbolName;
|
2008-10-19 18:31:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void SCH_SYMBOL::Init( const VECTOR2I& pos )
|
2009-10-16 17:18:23 +00:00
|
|
|
{
|
2024-01-26 16:16:13 +00:00
|
|
|
m_layer = LAYER_DEVICE;
|
|
|
|
m_pos = pos;
|
|
|
|
m_unit = 1; // In multi unit chip - which unit to draw.
|
2024-04-06 13:14:44 +00:00
|
|
|
m_bodyStyle = BODY_STYLE::BASE; // De Morgan Handling
|
2009-10-16 17:18:23 +00:00
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
// The rotation/mirror transformation matrix. pos normal
|
2010-12-14 21:39:31 +00:00
|
|
|
m_transform = TRANSFORM();
|
2009-10-16 17:18:23 +00:00
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
// construct only the mandatory fields, which are the first 4 only.
|
|
|
|
for( int i = 0; i < MANDATORY_FIELDS; ++i )
|
2009-10-16 17:18:23 +00:00
|
|
|
{
|
2020-11-16 13:15:54 +00:00
|
|
|
m_fields.emplace_back( pos, i, this, TEMPLATE_FIELDNAME::GetDefaultFieldName( i ) );
|
2009-10-16 17:18:23 +00:00
|
|
|
|
2020-11-12 21:31:41 +00:00
|
|
|
if( i == REFERENCE_FIELD )
|
2020-11-16 13:15:54 +00:00
|
|
|
m_fields.back().SetLayer( LAYER_REFERENCEPART );
|
2020-11-12 21:31:41 +00:00
|
|
|
else if( i == VALUE_FIELD )
|
2020-11-16 13:15:54 +00:00
|
|
|
m_fields.back().SetLayer( LAYER_VALUEPART );
|
2020-03-06 12:05:21 +00:00
|
|
|
else
|
2020-11-16 13:15:54 +00:00
|
|
|
m_fields.back().SetLayer( LAYER_FIELDS );
|
2009-10-16 17:18:23 +00:00
|
|
|
}
|
|
|
|
|
2015-04-26 16:32:16 +00:00
|
|
|
m_prefix = wxString( wxT( "U" ) );
|
2019-04-09 01:54:41 +00:00
|
|
|
m_isInNetlist = true;
|
2010-12-14 15:56:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
EDA_ITEM* SCH_SYMBOL::Clone() const
|
2010-12-21 15:13:09 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
return new SCH_SYMBOL( *this );
|
2010-12-21 15:13:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-02 19:48:10 +00:00
|
|
|
bool SCH_SYMBOL::IsMissingLibSymbol() const
|
|
|
|
{
|
2024-04-12 21:00:41 +00:00
|
|
|
return m_part == nullptr;
|
2022-09-02 19:48:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-11 10:47:47 +00:00
|
|
|
bool SCH_SYMBOL::IsMovableFromAnchorPoint() const
|
|
|
|
{
|
|
|
|
// If a symbol's anchor is not grid-aligned to its pins then moving from the anchor is
|
|
|
|
// going to end up moving the symbol's pins off-grid.
|
|
|
|
|
|
|
|
// The minimal grid size allowed to place a pin is 25 mils
|
2022-09-16 23:42:20 +00:00
|
|
|
const int min_grid_size = schIUScale.MilsToIU( 25 );
|
2022-04-11 10:47:47 +00:00
|
|
|
|
|
|
|
for( const std::unique_ptr<SCH_PIN>& pin : m_pins )
|
|
|
|
{
|
|
|
|
if( ( ( pin->GetPosition().x - m_pos.x ) % min_grid_size ) != 0 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( ( ( pin->GetPosition().y - m_pos.y ) % min_grid_size ) != 0 )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
void SCH_SYMBOL::SetLibId( const LIB_ID& aLibId )
|
2010-12-14 15:56:30 +00:00
|
|
|
{
|
2023-06-25 14:58:18 +00:00
|
|
|
m_lib_id = aLibId;
|
2017-03-09 23:33:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
wxString SCH_SYMBOL::GetSchSymbolLibraryName() const
|
2017-03-09 23:33:39 +00:00
|
|
|
{
|
2020-04-16 16:43:50 +00:00
|
|
|
if( !m_schLibSymbolName.IsEmpty() )
|
|
|
|
return m_schLibSymbolName;
|
|
|
|
else
|
2021-07-28 15:39:40 +00:00
|
|
|
return m_lib_id.Format();
|
2020-04-16 16:43:50 +00:00
|
|
|
}
|
2017-09-01 20:42:20 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
void SCH_SYMBOL::SetLibSymbol( LIB_SYMBOL* aLibSymbol )
|
2020-04-16 16:43:50 +00:00
|
|
|
{
|
2024-04-09 11:55:44 +00:00
|
|
|
wxCHECK2( !aLibSymbol || aLibSymbol->IsRoot(), aLibSymbol = nullptr );
|
2020-05-05 14:55:54 +00:00
|
|
|
|
2020-04-16 16:43:50 +00:00
|
|
|
m_part.reset( aLibSymbol );
|
2019-12-11 23:53:10 +00:00
|
|
|
UpdatePins();
|
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
|
|
|
}
|
|
|
|
|
2017-06-27 15:22:25 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
wxString SCH_SYMBOL::GetDescription() const
|
2017-04-02 12:09:01 +00:00
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
if( m_part )
|
|
|
|
return m_part->GetDescription();
|
2017-04-02 12:09:01 +00:00
|
|
|
|
|
|
|
return wxEmptyString;
|
|
|
|
}
|
|
|
|
|
2017-06-27 15:22:25 +00:00
|
|
|
|
2022-09-02 21:32:50 +00:00
|
|
|
wxString SCH_SYMBOL::GetKeyWords() const
|
|
|
|
{
|
|
|
|
if( m_part )
|
|
|
|
return m_part->GetKeyWords();
|
|
|
|
|
|
|
|
return wxEmptyString;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
wxString SCH_SYMBOL::GetDatasheet() const
|
2017-04-02 12:09:01 +00:00
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
if( m_part )
|
2020-06-01 13:13:32 +00:00
|
|
|
return m_part->GetDatasheetField().GetText();
|
2017-04-02 12:09:01 +00:00
|
|
|
|
|
|
|
return wxEmptyString;
|
|
|
|
}
|
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
|
|
|
|
2017-06-27 15:22:25 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
void SCH_SYMBOL::UpdatePins()
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2023-09-22 18:25:53 +00:00
|
|
|
std::map<wxString, wxString> altPinMap;
|
|
|
|
std::map<wxString, std::set<SCH_PIN*>> pinUuidMap;
|
|
|
|
std::set<SCH_PIN*> unassignedSchPins;
|
2024-04-20 09:44:34 +00:00
|
|
|
std::set<SCH_PIN*> unassignedLibPins;
|
2020-08-21 15:54:24 +00:00
|
|
|
|
|
|
|
for( const std::unique_ptr<SCH_PIN>& pin : m_pins )
|
|
|
|
{
|
2023-09-22 18:25:53 +00:00
|
|
|
pinUuidMap[ pin->GetNumber() ].insert( pin.get() );
|
|
|
|
|
|
|
|
unassignedSchPins.insert( pin.get() );
|
2021-01-25 22:01:49 +00:00
|
|
|
|
2020-08-21 15:54:24 +00:00
|
|
|
if( !pin->GetAlt().IsEmpty() )
|
|
|
|
altPinMap[ pin->GetNumber() ] = pin->GetAlt();
|
2024-02-09 13:09:19 +00:00
|
|
|
|
|
|
|
pin->SetLibPin( nullptr );
|
2020-08-21 15:54:24 +00:00
|
|
|
}
|
|
|
|
|
2019-12-11 23:53:10 +00:00
|
|
|
m_pinMap.clear();
|
|
|
|
|
2020-05-05 22:35:27 +00:00
|
|
|
if( !m_part )
|
|
|
|
return;
|
2019-04-03 09:14:36 +00:00
|
|
|
|
2024-04-20 09:44:34 +00:00
|
|
|
for( SCH_PIN* libPin : m_part->GetAllLibPins() )
|
2023-01-20 22:12:15 +00:00
|
|
|
{
|
2022-09-05 07:01:24 +00:00
|
|
|
// NW: Don't filter by unit: this data-structure is used for all instances,
|
2023-09-22 18:25:53 +00:00
|
|
|
// some of which might have different units.
|
2024-01-26 16:16:13 +00:00
|
|
|
if( libPin->GetBodyStyle() && m_bodyStyle && m_bodyStyle != libPin->GetBodyStyle() )
|
2022-09-05 07:01:24 +00:00
|
|
|
continue;
|
2019-04-25 22:10:45 +00:00
|
|
|
|
2023-09-22 18:25:53 +00:00
|
|
|
SCH_PIN* pin = nullptr;
|
2020-05-05 22:35:27 +00:00
|
|
|
|
2021-01-25 22:01:49 +00:00
|
|
|
auto ii = pinUuidMap.find( libPin->GetNumber() );
|
|
|
|
|
2023-09-22 18:25:53 +00:00
|
|
|
if( ii == pinUuidMap.end() || ii->second.empty() )
|
|
|
|
{
|
|
|
|
unassignedLibPins.insert( libPin );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto it = ii->second.begin();
|
|
|
|
pin = *it;
|
|
|
|
ii->second.erase( it );
|
|
|
|
pin->SetLibPin( libPin );
|
|
|
|
pin->SetPosition( libPin->GetPosition() );
|
|
|
|
|
|
|
|
unassignedSchPins.erase( pin );
|
2021-01-25 22:01:49 +00:00
|
|
|
|
|
|
|
auto iii = altPinMap.find( libPin->GetNumber() );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2021-01-25 22:01:49 +00:00
|
|
|
if( iii != altPinMap.end() )
|
2023-09-22 18:25:53 +00:00
|
|
|
pin->SetAlt( iii->second );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2023-09-22 18:25:53 +00:00
|
|
|
m_pinMap[ libPin ] = pin;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add any pins that were not found in the symbol
|
2024-04-20 09:44:34 +00:00
|
|
|
for( SCH_PIN* libPin : unassignedLibPins )
|
2023-09-22 18:25:53 +00:00
|
|
|
{
|
|
|
|
SCH_PIN* pin = nullptr;
|
|
|
|
|
|
|
|
// First try to re-use an existing pin
|
|
|
|
if( !unassignedSchPins.empty() )
|
|
|
|
{
|
|
|
|
auto it = unassignedSchPins.begin();
|
|
|
|
pin = *it;
|
|
|
|
unassignedSchPins.erase( it );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// This is a pin that was not found in the symbol, so create a new one.
|
2024-04-21 09:37:55 +00:00
|
|
|
pin = m_pins.emplace_back( std::make_unique<SCH_PIN>( SCH_PIN( this, libPin ) ) ).get();
|
2023-09-22 18:25:53 +00:00
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2023-09-22 18:25:53 +00:00
|
|
|
m_pinMap[ libPin ] = pin;
|
|
|
|
pin->SetLibPin( libPin );
|
|
|
|
pin->SetPosition( libPin->GetPosition() );
|
|
|
|
pin->SetNumber( libPin->GetNumber() );
|
|
|
|
|
|
|
|
auto iii = altPinMap.find( libPin->GetNumber() );
|
|
|
|
|
|
|
|
if( iii != altPinMap.end() )
|
|
|
|
pin->SetAlt( iii->second );
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we have any pins left in the symbol that were not found in the library, remove them.
|
|
|
|
for( auto it1 = m_pins.begin(); it1 != m_pins.end() && !unassignedSchPins.empty(); )
|
|
|
|
{
|
|
|
|
auto it2 = unassignedSchPins.find( it1->get() );
|
|
|
|
|
|
|
|
if( it2 != unassignedSchPins.end() )
|
|
|
|
{
|
|
|
|
it1 = m_pins.erase( it1 );
|
|
|
|
unassignedSchPins.erase( it2 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++it1;
|
|
|
|
}
|
2020-08-21 15:54:24 +00:00
|
|
|
}
|
2023-12-09 16:41:24 +00:00
|
|
|
|
|
|
|
// If the symbol is selected, then its pins are selected.
|
|
|
|
if( IsSelected() )
|
|
|
|
{
|
|
|
|
for( std::unique_ptr<SCH_PIN>& pin : m_pins )
|
|
|
|
pin->SetSelected();
|
|
|
|
}
|
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-26 16:16:13 +00:00
|
|
|
void SCH_SYMBOL::SetBodyStyle( int aBodyStyle )
|
2010-12-14 15:56:30 +00:00
|
|
|
{
|
2024-01-26 16:16:13 +00:00
|
|
|
if( m_bodyStyle != aBodyStyle )
|
2010-12-14 15:56:30 +00:00
|
|
|
{
|
2024-01-26 16:16:13 +00:00
|
|
|
m_bodyStyle = aBodyStyle;
|
2020-05-05 20:42:38 +00:00
|
|
|
|
|
|
|
// The convert may have a different pin layout so the update the pin map.
|
|
|
|
UpdatePins();
|
2010-12-14 15:56:30 +00:00
|
|
|
}
|
2009-10-16 17:18:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-02 17:28:17 +00:00
|
|
|
bool SCH_SYMBOL::HasAlternateBodyStyle() const
|
|
|
|
{
|
|
|
|
if( m_part )
|
|
|
|
return m_part->HasAlternateBodyStyle();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
void SCH_SYMBOL::SetTransform( const TRANSFORM& aTransform )
|
2010-12-14 21:39:31 +00:00
|
|
|
{
|
2024-04-12 21:00:41 +00:00
|
|
|
m_transform = aTransform;
|
2010-12-14 21:39:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
int SCH_SYMBOL::GetUnitCount() const
|
2011-06-17 13:24:22 +00:00
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
if( m_part )
|
|
|
|
return m_part->GetUnitCount();
|
2011-06-17 13:24:22 +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
|
|
|
return 0;
|
2011-06-17 13:24:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-14 22:11:37 +00:00
|
|
|
wxString SCH_SYMBOL::GetUnitDisplayName( int aUnit )
|
|
|
|
{
|
2023-11-12 23:42:36 +00:00
|
|
|
wxCHECK( m_part, ( wxString::Format( _( "Unit %s" ), SubReference( aUnit ) ) ) );
|
2022-09-14 22:11:37 +00:00
|
|
|
|
|
|
|
return m_part->GetUnitDisplayName( aUnit );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_SYMBOL::HasUnitDisplayName( int aUnit )
|
|
|
|
{
|
|
|
|
wxCHECK( m_part, false );
|
|
|
|
|
|
|
|
return m_part->HasUnitDisplayName( aUnit );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-05 21:35:32 +00:00
|
|
|
void SCH_SYMBOL::PrintBackground( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBodyStyle,
|
|
|
|
const VECTOR2I& aOffset, bool aDimmed )
|
2022-10-02 20:21:52 +00:00
|
|
|
{
|
2024-04-09 11:55:44 +00:00
|
|
|
wxCHECK( m_part, /* void */ );
|
|
|
|
|
|
|
|
SCH_RENDER_SETTINGS localRenderSettings( *aSettings );
|
|
|
|
localRenderSettings.m_Transform = m_transform;
|
|
|
|
localRenderSettings.m_ShowVisibleFields = false;
|
|
|
|
localRenderSettings.m_ShowHiddenFields = false;
|
2022-10-02 20:21:52 +00:00
|
|
|
|
2024-04-05 21:35:32 +00:00
|
|
|
if( GetDNP() )
|
|
|
|
aDimmed = true;
|
|
|
|
|
2024-04-09 11:55:44 +00:00
|
|
|
m_part->PrintBackground( &localRenderSettings, m_unit, m_bodyStyle, m_pos + aOffset, aDimmed );
|
2022-10-02 20:21:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-05 21:35:32 +00:00
|
|
|
void SCH_SYMBOL::Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBodyStyle,
|
|
|
|
const VECTOR2I& aOffset, bool aForceNoFill, bool aDimmed )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2024-04-09 11:55:44 +00:00
|
|
|
SCH_RENDER_SETTINGS localRenderSettings( *aSettings );
|
|
|
|
localRenderSettings.m_Transform = m_transform;
|
|
|
|
localRenderSettings.m_ShowVisibleFields = false;
|
|
|
|
localRenderSettings.m_ShowHiddenFields = false;
|
2017-02-19 18:40:26 +00:00
|
|
|
|
2024-04-05 21:35:32 +00:00
|
|
|
if( m_DNP )
|
|
|
|
aDimmed = true;
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
if( m_part )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2024-04-20 09:44:34 +00:00
|
|
|
std::vector<SCH_PIN*> libPins = m_part->GetPins( m_unit, m_bodyStyle );
|
|
|
|
LIB_SYMBOL tempSymbol( *m_part );
|
|
|
|
std::vector<SCH_PIN*> tempPins = tempSymbol.GetPins( m_unit, m_bodyStyle );
|
2023-03-03 10:56:58 +00:00
|
|
|
|
|
|
|
// Copy the pin info from the symbol to the temp pins
|
|
|
|
for( unsigned i = 0; i < tempPins.size(); ++ i )
|
|
|
|
{
|
|
|
|
SCH_PIN* symbolPin = GetPin( libPins[ i ] );
|
2024-04-20 09:44:34 +00:00
|
|
|
SCH_PIN* tempPin = tempPins[ i ];
|
2023-03-03 10:56:58 +00:00
|
|
|
|
|
|
|
tempPin->SetName( symbolPin->GetShownName() );
|
|
|
|
tempPin->SetType( symbolPin->GetType() );
|
|
|
|
tempPin->SetShape( symbolPin->GetShape() );
|
|
|
|
}
|
|
|
|
|
2024-04-06 13:14:44 +00:00
|
|
|
for( SCH_ITEM& item : tempSymbol.GetDrawItems() )
|
2023-11-05 10:41:02 +00:00
|
|
|
{
|
|
|
|
if( EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( &item ) )
|
|
|
|
{
|
|
|
|
// Use SCH_FIELD's text resolver
|
2024-04-09 11:55:44 +00:00
|
|
|
SCH_FIELD dummy( this, -1 );
|
2023-11-05 10:41:02 +00:00
|
|
|
dummy.SetText( text->GetText() );
|
|
|
|
text->SetText( dummy.GetShownText( false ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-09 11:55:44 +00:00
|
|
|
tempSymbol.Print( &localRenderSettings, m_unit, m_bodyStyle, m_pos + aOffset, false,
|
|
|
|
aDimmed );
|
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
|
|
|
}
|
|
|
|
else // Use dummy() part if the actual cannot be found.
|
|
|
|
{
|
2024-04-09 11:55:44 +00:00
|
|
|
dummy()->Print( &localRenderSettings, 0, 0, m_pos + aOffset, aForceNoFill, aDimmed );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
|
2020-11-16 13:15:54 +00:00
|
|
|
for( SCH_FIELD& field : m_fields )
|
2024-04-09 11:55:44 +00:00
|
|
|
field.Print( &localRenderSettings, m_unit, m_bodyStyle, aOffset, aForceNoFill, aDimmed );
|
2023-01-09 23:30:58 +00:00
|
|
|
|
|
|
|
if( m_DNP )
|
|
|
|
{
|
|
|
|
BOX2I bbox = GetBodyAndPinsBoundingBox();
|
2024-04-09 11:55:44 +00:00
|
|
|
wxDC* DC = localRenderSettings.GetPrintDC();
|
|
|
|
COLOR4D dnp_color = localRenderSettings.GetLayerColor( LAYER_DNP_MARKER );
|
2023-01-09 23:30:58 +00:00
|
|
|
|
|
|
|
GRFilledSegment( DC, bbox.GetOrigin(), bbox.GetEnd(),
|
2023-01-11 19:29:06 +00:00
|
|
|
3.0 * schIUScale.MilsToIU( DEFAULT_LINE_WIDTH_MILS ),
|
|
|
|
dnp_color );
|
2023-01-09 23:30:58 +00:00
|
|
|
|
|
|
|
GRFilledSegment( DC, bbox.GetOrigin() + VECTOR2I( bbox.GetWidth(), 0 ),
|
|
|
|
bbox.GetOrigin() + VECTOR2I( 0, bbox.GetHeight() ),
|
2023-01-11 19:29:06 +00:00
|
|
|
3.0 * schIUScale.MilsToIU( DEFAULT_LINE_WIDTH_MILS ),
|
|
|
|
dnp_color );
|
2023-01-09 23:30:58 +00:00
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-04 20:39:50 +00:00
|
|
|
bool SCH_SYMBOL::GetInstance( SCH_SYMBOL_INSTANCE& aInstance,
|
2022-12-25 16:04:45 +00:00
|
|
|
const KIID_PATH& aSheetPath, bool aTestFromEnd ) const
|
2022-10-01 12:44:21 +00:00
|
|
|
{
|
2023-01-04 20:39:50 +00:00
|
|
|
for( const SCH_SYMBOL_INSTANCE& instance : m_instanceReferences )
|
2022-10-01 12:44:21 +00:00
|
|
|
{
|
2022-12-25 16:04:45 +00:00
|
|
|
if( !aTestFromEnd )
|
|
|
|
{
|
|
|
|
if( instance.m_Path == aSheetPath )
|
|
|
|
{
|
|
|
|
aInstance = instance;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( instance.m_Path.EndsWith( aSheetPath ) )
|
2022-10-01 12:44:21 +00:00
|
|
|
{
|
|
|
|
aInstance = instance;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_SYMBOL::RemoveInstance( const SCH_SHEET_PATH& aInstancePath )
|
2023-12-01 19:18:47 +00:00
|
|
|
{
|
|
|
|
RemoveInstance( aInstancePath.Path() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_SYMBOL::RemoveInstance( const KIID_PATH& aInstancePath )
|
2022-10-01 12:44:21 +00:00
|
|
|
{
|
|
|
|
// Search for an existing path and remove it if found (should not occur)
|
|
|
|
for( unsigned ii = 0; ii < m_instanceReferences.size(); ii++ )
|
|
|
|
{
|
2023-12-01 19:18:47 +00:00
|
|
|
if( m_instanceReferences[ii].m_Path == aInstancePath )
|
2022-10-01 12:44:21 +00:00
|
|
|
{
|
2024-04-09 11:55:44 +00:00
|
|
|
wxLogTrace( traceSchSheetPaths, wxS( "Removing symbol instance:\n"
|
|
|
|
" sheet path %s\n"
|
|
|
|
" reference %s, unit %d from symbol %s." ),
|
2023-12-01 19:18:47 +00:00
|
|
|
aInstancePath.AsString(),
|
2022-10-01 12:44:21 +00:00
|
|
|
m_instanceReferences[ii].m_Reference,
|
|
|
|
m_instanceReferences[ii].m_Unit,
|
|
|
|
m_Uuid.AsString() );
|
|
|
|
|
|
|
|
m_instanceReferences.erase( m_instanceReferences.begin() + ii );
|
|
|
|
ii--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-25 14:25:39 +00:00
|
|
|
void SCH_SYMBOL::AddHierarchicalReference( const KIID_PATH& aPath, const wxString& aRef, int aUnit )
|
2008-04-12 18:39:20 +00:00
|
|
|
{
|
2008-04-15 19:38:19 +00:00
|
|
|
// Search for an existing path and remove it if found (should not occur)
|
2020-02-22 21:39:59 +00:00
|
|
|
for( unsigned ii = 0; ii < m_instanceReferences.size(); ii++ )
|
2008-04-15 19:38:19 +00:00
|
|
|
{
|
2020-02-22 21:39:59 +00:00
|
|
|
if( m_instanceReferences[ii].m_Path == aPath )
|
2008-04-15 19:38:19 +00:00
|
|
|
{
|
2024-04-09 11:55:44 +00:00
|
|
|
wxLogTrace( traceSchSheetPaths, wxS( "Removing symbol instance:\n"
|
|
|
|
" sheet path %s\n"
|
|
|
|
" reference %s, unit %d from symbol %s." ),
|
2024-04-12 21:00:41 +00:00
|
|
|
aPath.AsString(),
|
2024-04-09 11:55:44 +00:00
|
|
|
m_instanceReferences[ii].m_Reference,
|
|
|
|
m_instanceReferences[ii].m_Unit,
|
|
|
|
m_Uuid.AsString() );
|
2020-04-26 20:53:29 +00:00
|
|
|
|
2020-02-22 21:39:59 +00:00
|
|
|
m_instanceReferences.erase( m_instanceReferences.begin() + ii );
|
2008-04-16 08:40:31 +00:00
|
|
|
ii--;
|
2008-04-15 19:38:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-04 20:39:50 +00:00
|
|
|
SCH_SYMBOL_INSTANCE instance;
|
2020-02-22 21:39:59 +00:00
|
|
|
instance.m_Path = aPath;
|
|
|
|
instance.m_Reference = aRef;
|
|
|
|
instance.m_Unit = aUnit;
|
2020-04-26 20:53:29 +00:00
|
|
|
|
2024-04-09 11:55:44 +00:00
|
|
|
wxLogTrace( traceSchSheetPaths, wxS( "Adding symbol '%s' instance:\n"
|
|
|
|
" sheet path '%s'\n"
|
|
|
|
" reference '%s'\n"
|
|
|
|
" unit %d\n" ),
|
2022-10-01 12:44:21 +00:00
|
|
|
m_Uuid.AsString(),
|
|
|
|
aPath.AsString(),
|
|
|
|
aRef,
|
2022-11-25 14:25:39 +00:00
|
|
|
aUnit );
|
2020-04-26 20:53:29 +00:00
|
|
|
|
2020-02-22 21:39:59 +00:00
|
|
|
m_instanceReferences.push_back( instance );
|
2022-10-01 12:44:21 +00:00
|
|
|
|
|
|
|
// This should set the default instance to the first saved instance data for each symbol
|
|
|
|
// when importing sheets.
|
|
|
|
if( m_instanceReferences.size() == 1 )
|
|
|
|
{
|
|
|
|
m_fields[ REFERENCE_FIELD ].SetText( aRef );
|
|
|
|
m_unit = aUnit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-04 20:39:50 +00:00
|
|
|
void SCH_SYMBOL::AddHierarchicalReference( const SCH_SYMBOL_INSTANCE& aInstance )
|
2022-10-01 12:44:21 +00:00
|
|
|
{
|
2022-11-20 17:04:44 +00:00
|
|
|
KIID_PATH searchPath( aInstance.m_Path );
|
|
|
|
|
2023-01-04 20:39:50 +00:00
|
|
|
std::vector<SCH_SYMBOL_INSTANCE>::iterator resultIt;
|
2022-11-20 17:04:44 +00:00
|
|
|
|
|
|
|
do
|
2022-10-01 12:44:21 +00:00
|
|
|
{
|
2022-11-20 17:04:44 +00:00
|
|
|
resultIt = std::find_if( m_instanceReferences.begin(), m_instanceReferences.end(),
|
|
|
|
[searchPath]( const auto& it )
|
|
|
|
{
|
|
|
|
return it.m_Path == searchPath;
|
|
|
|
} );
|
|
|
|
|
|
|
|
if( resultIt != m_instanceReferences.end() )
|
2022-10-01 12:44:21 +00:00
|
|
|
{
|
2024-04-09 11:55:44 +00:00
|
|
|
wxLogTrace( traceSchSheetPaths, wxS( "Removing symbol instance:\n"
|
|
|
|
" sheet path %s\n"
|
|
|
|
" reference %s, unit %d from symbol %s." ),
|
2022-11-20 17:04:44 +00:00
|
|
|
aInstance.m_Path.AsString(),
|
|
|
|
resultIt->m_Reference,
|
|
|
|
resultIt->m_Unit,
|
|
|
|
m_Uuid.AsString() );
|
2022-10-01 12:44:21 +00:00
|
|
|
|
2022-11-20 17:04:44 +00:00
|
|
|
// Instance data should be unique by path. Double check just in case there was
|
|
|
|
// some buggy code in the past.
|
|
|
|
resultIt = m_instanceReferences.erase( resultIt );
|
2022-10-01 12:44:21 +00:00
|
|
|
}
|
|
|
|
}
|
2022-11-20 17:04:44 +00:00
|
|
|
while( resultIt != m_instanceReferences.end() );
|
2022-10-01 12:44:21 +00:00
|
|
|
|
2023-01-04 20:39:50 +00:00
|
|
|
SCH_SYMBOL_INSTANCE instance = aInstance;
|
2022-10-01 12:44:21 +00:00
|
|
|
|
2024-04-09 11:55:44 +00:00
|
|
|
wxLogTrace( traceSchSheetPaths, wxS( "Adding symbol '%s' instance:\n"
|
|
|
|
" sheet path '%s'\n"
|
|
|
|
" reference '%s'\n"
|
|
|
|
" unit %d\n" ),
|
2022-10-01 12:44:21 +00:00
|
|
|
m_Uuid.AsString(),
|
|
|
|
instance.m_Path.AsString(),
|
|
|
|
instance.m_Reference,
|
2022-11-25 14:25:39 +00:00
|
|
|
instance.m_Unit );
|
2022-10-01 12:44:21 +00:00
|
|
|
|
|
|
|
m_instanceReferences.push_back( instance );
|
|
|
|
|
|
|
|
// This should set the default instance to the first saved instance data for each symbol
|
|
|
|
// when importing sheets.
|
|
|
|
if( m_instanceReferences.size() == 1 )
|
|
|
|
{
|
|
|
|
m_fields[ REFERENCE_FIELD ].SetText( instance.m_Reference );
|
|
|
|
m_unit = instance.m_Unit;
|
|
|
|
}
|
2008-02-12 21:12:46 +00:00
|
|
|
}
|
|
|
|
|
2008-02-21 12:21:01 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
const wxString SCH_SYMBOL::GetRef( const SCH_SHEET_PATH* sheet, bool aIncludeUnit ) const
|
2008-02-12 21:12:46 +00:00
|
|
|
{
|
2020-02-22 21:39:59 +00:00
|
|
|
KIID_PATH path = sheet->Path();
|
2020-03-16 11:05:01 +00:00
|
|
|
wxString ref;
|
2022-07-21 14:48:47 +00:00
|
|
|
wxString subRef;
|
2008-02-21 12:21:01 +00:00
|
|
|
|
2023-01-04 20:39:50 +00:00
|
|
|
for( const SCH_SYMBOL_INSTANCE& instance : m_instanceReferences )
|
2008-02-21 12:21:01 +00:00
|
|
|
{
|
2020-02-22 21:39:59 +00:00
|
|
|
if( instance.m_Path == path )
|
2020-03-16 11:05:01 +00:00
|
|
|
{
|
|
|
|
ref = instance.m_Reference;
|
2023-11-12 23:42:36 +00:00
|
|
|
subRef = SubReference( instance.m_Unit );
|
2020-03-16 11:05:01 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-02-21 12:21:01 +00:00
|
|
|
}
|
|
|
|
|
2019-07-02 20:09:23 +00:00
|
|
|
// If it was not found in m_Paths array, then see if it is in m_Field[REFERENCE] -- if so,
|
|
|
|
// use this as a default for this path. This will happen if we load a version 1 schematic
|
|
|
|
// file. It will also mean that multiple instances of the same sheet by default all have
|
2021-03-25 21:13:01 +00:00
|
|
|
// the same symbol references, but perhaps this is best.
|
2020-11-12 21:31:41 +00:00
|
|
|
if( ref.IsEmpty() && !GetField( REFERENCE_FIELD )->GetText().IsEmpty() )
|
|
|
|
ref = GetField( REFERENCE_FIELD )->GetText();
|
2011-12-07 18:47:59 +00:00
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
if( ref.IsEmpty() )
|
2021-04-17 14:10:59 +00:00
|
|
|
ref = UTIL::GetRefDesUnannotated( m_prefix );
|
2020-03-16 11:05:01 +00:00
|
|
|
|
2020-04-11 19:11:29 +00:00
|
|
|
if( aIncludeUnit && GetUnitCount() > 1 )
|
2022-07-21 14:48:47 +00:00
|
|
|
ref += subRef;
|
2020-03-16 11:05:01 +00:00
|
|
|
|
|
|
|
return ref;
|
2008-02-12 21:12:46 +00:00
|
|
|
}
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2008-02-21 12:21:01 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
bool SCH_SYMBOL::IsReferenceStringValid( const wxString& aReferenceString )
|
2011-05-31 16:29:14 +00:00
|
|
|
{
|
2021-04-17 14:10:59 +00:00
|
|
|
return !UTIL::GetRefDesPrefix( aReferenceString ).IsEmpty();
|
2011-05-31 16:29:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
void SCH_SYMBOL::SetRef( const SCH_SHEET_PATH* sheet, const wxString& ref )
|
2008-02-12 21:12:46 +00:00
|
|
|
{
|
2020-02-22 21:39:59 +00:00
|
|
|
KIID_PATH path = sheet->Path();
|
2022-07-27 11:27:58 +00:00
|
|
|
bool found = false;
|
2008-04-12 18:39:20 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
// check to see if it is already there before inserting it
|
2023-01-04 20:39:50 +00:00
|
|
|
for( SCH_SYMBOL_INSTANCE& instance : m_instanceReferences )
|
2008-02-21 12:21:01 +00:00
|
|
|
{
|
2020-02-22 21:39:59 +00:00
|
|
|
if( instance.m_Path == path )
|
2008-02-21 12:21:01 +00:00
|
|
|
{
|
2022-07-27 11:27:58 +00:00
|
|
|
found = true;
|
2020-02-22 21:39:59 +00:00
|
|
|
instance.m_Reference = ref;
|
2022-07-27 11:27:58 +00:00
|
|
|
break;
|
2008-02-21 12:21:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-27 11:27:58 +00:00
|
|
|
if( !found )
|
2022-11-25 14:25:39 +00:00
|
|
|
AddHierarchicalReference( path, ref, m_unit );
|
2008-04-14 19:22:48 +00:00
|
|
|
|
2020-08-13 21:30:30 +00:00
|
|
|
for( std::unique_ptr<SCH_PIN>& pin : m_pins )
|
|
|
|
pin->ClearDefaultNetName( sheet );
|
|
|
|
|
2022-07-27 11:27:58 +00:00
|
|
|
if( Schematic() && *sheet == Schematic()->CurrentSheet() )
|
|
|
|
m_fields[ REFERENCE_FIELD ].SetText( ref );
|
2009-10-30 19:26:25 +00:00
|
|
|
|
2010-12-14 15:56:30 +00:00
|
|
|
// Reinit the m_prefix member if needed
|
2021-04-17 14:10:59 +00:00
|
|
|
m_prefix = UTIL::GetRefDesPrefix( ref );
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2021-04-17 11:29:15 +00:00
|
|
|
if( m_prefix.IsEmpty() )
|
|
|
|
m_prefix = wxT( "U" );
|
2019-04-09 01:54:41 +00:00
|
|
|
|
2021-03-25 21:13:01 +00:00
|
|
|
// Power symbols have references starting with # and are not included in netlists
|
2019-04-09 01:54:41 +00:00
|
|
|
m_isInNetlist = ! ref.StartsWith( wxT( "#" ) );
|
2008-02-12 21:12:46 +00:00
|
|
|
}
|
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2024-04-05 21:35:32 +00:00
|
|
|
bool SCH_SYMBOL::IsAnnotated( const SCH_SHEET_PATH* aSheet ) const
|
2019-05-19 15:40:14 +00:00
|
|
|
{
|
2020-02-22 21:39:59 +00:00
|
|
|
KIID_PATH path = aSheet->Path();
|
2019-05-19 15:40:14 +00:00
|
|
|
|
2023-01-04 20:39:50 +00:00
|
|
|
for( const SCH_SYMBOL_INSTANCE& instance : m_instanceReferences )
|
2019-05-19 15:40:14 +00:00
|
|
|
{
|
2020-02-22 21:39:59 +00:00
|
|
|
if( instance.m_Path == path )
|
|
|
|
return instance.m_Reference.Last() != '?';
|
2019-05-19 15:40:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-07 01:34:10 +00:00
|
|
|
void SCH_SYMBOL::UpdatePrefix()
|
|
|
|
{
|
|
|
|
wxString refDesignator = GetField( REFERENCE_FIELD )->GetText();
|
|
|
|
|
|
|
|
refDesignator.Replace( "~", " " );
|
|
|
|
|
|
|
|
wxString prefix = refDesignator;
|
|
|
|
|
|
|
|
while( prefix.Length() )
|
|
|
|
{
|
2022-12-08 23:56:55 +00:00
|
|
|
wxUniCharRef last = prefix.Last();
|
2022-12-07 01:34:10 +00:00
|
|
|
|
2022-12-08 23:56:55 +00:00
|
|
|
if( ( last >= '0' && last <= '9' ) || last == '?' || last == '*' )
|
|
|
|
prefix.RemoveLast();
|
|
|
|
else
|
|
|
|
break;
|
2022-12-07 01:34:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Avoid a prefix containing trailing/leading spaces
|
|
|
|
prefix.Trim( true );
|
|
|
|
prefix.Trim( false );
|
|
|
|
|
|
|
|
if( !prefix.IsEmpty() )
|
|
|
|
SetPrefix( prefix );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-11-12 23:42:36 +00:00
|
|
|
wxString SCH_SYMBOL::SubReference( int aUnit, bool aAddSeparator ) const
|
|
|
|
{
|
|
|
|
if( SCHEMATIC* schematic = Schematic() )
|
|
|
|
return schematic->Settings().SubReference( aUnit, aAddSeparator );
|
|
|
|
|
|
|
|
return LIB_SYMBOL::LetterSubReference( aUnit, 'A' );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
int SCH_SYMBOL::GetUnitSelection( const SCH_SHEET_PATH* aSheet ) const
|
2008-04-16 08:40:31 +00:00
|
|
|
{
|
2020-02-22 21:39:59 +00:00
|
|
|
KIID_PATH path = aSheet->Path();
|
2008-04-16 08:40:31 +00:00
|
|
|
|
2023-01-04 20:39:50 +00:00
|
|
|
for( const SCH_SYMBOL_INSTANCE& instance : m_instanceReferences )
|
2008-04-16 08:40:31 +00:00
|
|
|
{
|
2020-02-22 21:39:59 +00:00
|
|
|
if( instance.m_Path == path )
|
|
|
|
return instance.m_Unit;
|
2008-04-16 08:40:31 +00:00
|
|
|
}
|
|
|
|
|
2019-07-02 20:09:23 +00:00
|
|
|
// If it was not found in m_Paths array, then use m_unit. This will happen if we load a
|
|
|
|
// version 1 schematic file.
|
2010-12-14 15:56:30 +00:00
|
|
|
return m_unit;
|
2008-04-16 08:40:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
void SCH_SYMBOL::SetUnitSelection( const SCH_SHEET_PATH* aSheet, int aUnitSelection )
|
2008-04-16 08:40:31 +00:00
|
|
|
{
|
2020-02-22 21:39:59 +00:00
|
|
|
KIID_PATH path = aSheet->Path();
|
2008-04-16 08:40:31 +00:00
|
|
|
|
2020-02-22 21:39:59 +00:00
|
|
|
// check to see if it is already there before inserting it
|
2023-01-04 20:39:50 +00:00
|
|
|
for( SCH_SYMBOL_INSTANCE& instance : m_instanceReferences )
|
2008-04-16 08:40:31 +00:00
|
|
|
{
|
2020-02-22 21:39:59 +00:00
|
|
|
if( instance.m_Path == path )
|
2008-04-16 08:40:31 +00:00
|
|
|
{
|
2020-02-22 21:39:59 +00:00
|
|
|
instance.m_Unit = aUnitSelection;
|
2020-08-29 13:41:47 +00:00
|
|
|
return;
|
2008-04-16 08:40:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-29 13:41:47 +00:00
|
|
|
// didn't find it; better add it
|
2021-04-17 14:10:59 +00:00
|
|
|
AddHierarchicalReference( path, UTIL::GetRefDesUnannotated( m_prefix ), aUnitSelection );
|
2020-08-29 13:41:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
void SCH_SYMBOL::SetUnitSelection( int aUnitSelection )
|
2021-01-21 20:00:09 +00:00
|
|
|
{
|
2023-01-04 20:39:50 +00:00
|
|
|
for( SCH_SYMBOL_INSTANCE& instance : m_instanceReferences )
|
2021-01-21 20:00:09 +00:00
|
|
|
instance.m_Unit = aUnitSelection;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-05 21:35:32 +00:00
|
|
|
const wxString SCH_SYMBOL::GetValue( bool aResolve, const SCH_SHEET_PATH* aPath,
|
2024-04-12 21:00:41 +00:00
|
|
|
bool aAllowExtraText ) const
|
2020-08-29 13:41:47 +00:00
|
|
|
{
|
2022-11-25 14:25:39 +00:00
|
|
|
if( aResolve )
|
2023-05-05 13:21:56 +00:00
|
|
|
return GetField( VALUE_FIELD )->GetShownText( aPath, aAllowExtraText );
|
2020-11-17 21:36:17 +00:00
|
|
|
|
2022-11-25 14:25:39 +00:00
|
|
|
return GetField( VALUE_FIELD )->GetText();
|
2020-08-29 13:41:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-25 14:25:39 +00:00
|
|
|
void SCH_SYMBOL::SetValueFieldText( const wxString& aValue )
|
2020-08-29 13:41:47 +00:00
|
|
|
{
|
2022-11-25 14:25:39 +00:00
|
|
|
m_fields[ VALUE_FIELD ].SetText( aValue );
|
2020-08-29 13:41:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-05-05 13:21:56 +00:00
|
|
|
const wxString SCH_SYMBOL::GetFootprintFieldText( bool aResolve, const SCH_SHEET_PATH* aPath,
|
|
|
|
bool aAllowExtraText ) const
|
2020-08-29 13:41:47 +00:00
|
|
|
{
|
2022-11-25 14:25:39 +00:00
|
|
|
if( aResolve )
|
2023-05-05 13:21:56 +00:00
|
|
|
return GetField( FOOTPRINT_FIELD )->GetShownText( aPath, aAllowExtraText );
|
2020-08-29 13:41:47 +00:00
|
|
|
|
2022-11-25 14:25:39 +00:00
|
|
|
return GetField( FOOTPRINT_FIELD )->GetText();
|
2020-08-29 13:41:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-25 14:25:39 +00:00
|
|
|
void SCH_SYMBOL::SetFootprintFieldText( const wxString& aFootprint )
|
2020-08-29 13:41:47 +00:00
|
|
|
{
|
2022-11-25 14:25:39 +00:00
|
|
|
m_fields[ FOOTPRINT_FIELD ].SetText( aFootprint );
|
2008-04-16 08:40:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_FIELD* SCH_SYMBOL::GetField( MANDATORY_FIELD_T aFieldType )
|
2007-09-20 21:06:49 +00:00
|
|
|
{
|
2021-02-28 13:28:23 +00:00
|
|
|
return &m_fields[aFieldType];
|
|
|
|
}
|
2020-05-08 19:22:59 +00:00
|
|
|
|
2021-02-28 13:28:23 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
const SCH_FIELD* SCH_SYMBOL::GetField( MANDATORY_FIELD_T aFieldType ) const
|
2021-02-28 13:28:23 +00:00
|
|
|
{
|
|
|
|
return &m_fields[aFieldType];
|
2020-05-08 19:22:59 +00:00
|
|
|
}
|
2008-02-21 12:21:01 +00:00
|
|
|
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_FIELD* SCH_SYMBOL::GetFieldById( int aFieldId )
|
2020-05-08 19:22:59 +00:00
|
|
|
{
|
2024-04-09 11:55:44 +00:00
|
|
|
for( SCH_FIELD& field : m_fields )
|
2021-02-28 13:28:23 +00:00
|
|
|
{
|
2024-04-09 11:55:44 +00:00
|
|
|
if( field.GetId() == aFieldId )
|
|
|
|
return &field;
|
2021-02-28 13:28:23 +00:00
|
|
|
}
|
2020-05-08 19:22:59 +00:00
|
|
|
|
|
|
|
return nullptr;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2017-06-27 15:22:25 +00:00
|
|
|
|
2023-05-08 14:59:13 +00:00
|
|
|
SCH_FIELD* SCH_SYMBOL::GetFieldByName( const wxString& aFieldName )
|
|
|
|
{
|
2023-11-12 14:14:41 +00:00
|
|
|
for( SCH_FIELD& field : m_fields )
|
2023-05-08 14:59:13 +00:00
|
|
|
{
|
2023-11-12 14:14:41 +00:00
|
|
|
if( field.GetName() == aFieldName )
|
|
|
|
return &field;
|
2023-05-08 14:59:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-14 14:36:18 +00:00
|
|
|
const SCH_FIELD* SCH_SYMBOL::GetFieldByName( const wxString& aFieldName ) const
|
2017-04-02 12:09:01 +00:00
|
|
|
{
|
2020-11-16 13:15:54 +00:00
|
|
|
for( const SCH_FIELD& field : m_fields )
|
2017-04-02 12:09:01 +00:00
|
|
|
{
|
2023-11-12 14:14:41 +00:00
|
|
|
if( field.GetName() == aFieldName )
|
|
|
|
return &field;
|
2017-04-02 12:09:01 +00:00
|
|
|
}
|
|
|
|
|
2023-11-12 14:14:41 +00:00
|
|
|
return nullptr;
|
2017-04-02 12:09:01 +00:00
|
|
|
}
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
void SCH_SYMBOL::GetFields( std::vector<SCH_FIELD*>& aVector, bool aVisibleOnly )
|
2015-12-13 16:56:47 +00:00
|
|
|
{
|
2020-11-16 13:15:54 +00:00
|
|
|
for( SCH_FIELD& field : m_fields )
|
2015-12-13 16:56:47 +00:00
|
|
|
{
|
2022-11-03 11:20:29 +00:00
|
|
|
if( aVisibleOnly )
|
|
|
|
{
|
2023-11-12 14:14:41 +00:00
|
|
|
if( !field.IsVisible() || field.GetText().IsEmpty() )
|
2022-11-03 11:20:29 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
aVector.push_back( &field );
|
2015-12-13 16:56:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_FIELD* SCH_SYMBOL::AddField( const SCH_FIELD& aField )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2020-11-16 13:15:54 +00:00
|
|
|
m_fields.push_back( aField );
|
2023-11-12 14:14:41 +00:00
|
|
|
return &m_fields.back();
|
2010-06-17 16:30:10 +00:00
|
|
|
}
|
|
|
|
|
2017-06-27 15:22:25 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
void SCH_SYMBOL::RemoveField( const wxString& aFieldName )
|
2018-07-31 21:59:43 +00:00
|
|
|
{
|
2020-11-16 13:15:54 +00:00
|
|
|
for( unsigned i = MANDATORY_FIELDS; i < m_fields.size(); ++i )
|
2018-07-31 21:59:43 +00:00
|
|
|
{
|
2020-11-16 13:15:54 +00:00
|
|
|
if( aFieldName == m_fields[i].GetName( false ) )
|
2018-07-31 21:59:43 +00:00
|
|
|
{
|
2020-11-16 13:15:54 +00:00
|
|
|
m_fields.erase( m_fields.begin() + i );
|
2018-07-31 21:59:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-28 22:47:30 +00:00
|
|
|
SCH_FIELD* SCH_SYMBOL::FindField( const wxString& aFieldName, bool aIncludeDefaultFields,
|
|
|
|
bool aCaseInsensitive )
|
2010-06-17 16:30:10 +00:00
|
|
|
{
|
2017-05-22 14:05:36 +00:00
|
|
|
unsigned start = aIncludeDefaultFields ? 0 : MANDATORY_FIELDS;
|
|
|
|
|
2020-11-16 13:15:54 +00:00
|
|
|
for( unsigned i = start; i < m_fields.size(); ++i )
|
2010-06-17 16:30:10 +00:00
|
|
|
{
|
2023-06-28 22:47:30 +00:00
|
|
|
if( aCaseInsensitive )
|
|
|
|
{
|
|
|
|
if( aFieldName.Upper() == m_fields[i].GetName( false ).Upper() )
|
|
|
|
return &m_fields[i];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( aFieldName == m_fields[i].GetName( false ) )
|
|
|
|
return &m_fields[i];
|
|
|
|
}
|
2010-06-17 16:30:10 +00:00
|
|
|
}
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
return nullptr;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
void SCH_SYMBOL::UpdateFields( const SCH_SHEET_PATH* aPath, bool aUpdateStyle, bool aUpdateRef,
|
|
|
|
bool aUpdateOtherFields, bool aResetRef, bool aResetOtherFields )
|
2017-08-25 13:27:06 +00:00
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
if( m_part )
|
2017-08-25 13:27:06 +00:00
|
|
|
{
|
2024-04-12 21:00:41 +00:00
|
|
|
std::vector<SCH_FIELD*> fields;
|
2019-11-06 19:15:42 +00:00
|
|
|
m_part->GetFields( fields );
|
2017-08-25 13:27:06 +00:00
|
|
|
|
2024-04-12 21:00:41 +00:00
|
|
|
for( const SCH_FIELD* libField : fields )
|
2017-08-25 13:27:06 +00:00
|
|
|
{
|
2024-04-12 21:00:41 +00:00
|
|
|
int id = libField->GetId();
|
2017-08-25 13:27:06 +00:00
|
|
|
SCH_FIELD* schField;
|
|
|
|
|
2024-04-12 21:00:41 +00:00
|
|
|
if( libField->IsMandatory() )
|
2020-06-01 13:13:32 +00:00
|
|
|
{
|
2021-02-28 13:28:23 +00:00
|
|
|
schField = GetFieldById( id );
|
2020-06-01 13:13:32 +00:00
|
|
|
}
|
2017-08-25 13:27:06 +00:00
|
|
|
else
|
|
|
|
{
|
2020-12-15 15:06:19 +00:00
|
|
|
schField = FindField( libField->GetCanonicalName() );
|
2020-03-26 11:02:59 +00:00
|
|
|
|
|
|
|
if( !schField )
|
|
|
|
{
|
2020-12-15 15:06:19 +00:00
|
|
|
wxString fieldName = libField->GetCanonicalName();
|
2022-01-04 01:00:40 +00:00
|
|
|
SCH_FIELD newField( VECTOR2I( 0, 0 ), GetFieldCount(), this, fieldName );
|
2020-03-26 11:02:59 +00:00
|
|
|
schField = AddField( newField );
|
|
|
|
}
|
2017-08-25 13:27:06 +00:00
|
|
|
}
|
|
|
|
|
2021-04-09 16:10:40 +00:00
|
|
|
if( aUpdateStyle )
|
2017-08-25 13:27:06 +00:00
|
|
|
{
|
2020-12-15 15:06:19 +00:00
|
|
|
schField->ImportValues( *libField );
|
2022-01-04 01:00:40 +00:00
|
|
|
schField->SetTextPos( m_pos + libField->GetTextPos() );
|
2017-08-25 13:27:06 +00:00
|
|
|
}
|
|
|
|
|
2021-04-23 00:53:21 +00:00
|
|
|
if( id == REFERENCE_FIELD && aPath )
|
2021-04-09 16:10:40 +00:00
|
|
|
{
|
2021-08-22 18:54:42 +00:00
|
|
|
if( aResetRef )
|
2021-04-09 16:10:40 +00:00
|
|
|
SetRef( aPath, m_part->GetReferenceField().GetText() );
|
|
|
|
else if( aUpdateRef )
|
|
|
|
SetRef( aPath, libField->GetText() );
|
|
|
|
}
|
|
|
|
else if( id == VALUE_FIELD )
|
|
|
|
{
|
2022-11-25 14:25:39 +00:00
|
|
|
SetValueFieldText( UnescapeString( libField->GetText() ) );
|
2021-04-09 16:10:40 +00:00
|
|
|
}
|
|
|
|
else if( id == FOOTPRINT_FIELD )
|
2019-05-22 23:18:24 +00:00
|
|
|
{
|
2021-04-09 16:10:40 +00:00
|
|
|
if( aResetOtherFields || aUpdateOtherFields )
|
2022-11-25 14:25:39 +00:00
|
|
|
SetFootprintFieldText( libField->GetText() );
|
2019-05-22 23:18:24 +00:00
|
|
|
}
|
2021-02-28 13:28:23 +00:00
|
|
|
else if( id == DATASHEET_FIELD )
|
2019-05-22 23:18:24 +00:00
|
|
|
{
|
2021-04-09 16:10:40 +00:00
|
|
|
if( aResetOtherFields )
|
2021-06-30 10:53:04 +00:00
|
|
|
schField->SetText( GetDatasheet() ); // alias-specific value
|
2021-04-09 16:10:40 +00:00
|
|
|
else if( aUpdateOtherFields )
|
|
|
|
schField->SetText( libField->GetText() );
|
2019-05-22 23:18:24 +00:00
|
|
|
}
|
2018-11-22 21:30:36 +00:00
|
|
|
else
|
2019-05-22 23:18:24 +00:00
|
|
|
{
|
2021-04-09 16:10:40 +00:00
|
|
|
if( aResetOtherFields || aUpdateOtherFields )
|
|
|
|
schField->SetText( libField->GetText() );
|
2019-05-22 23:18:24 +00:00
|
|
|
}
|
2017-08-25 13:27:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
void SCH_SYMBOL::RunOnChildren( const std::function<void( SCH_ITEM* )>& aFunction )
|
2020-11-17 16:02:47 +00:00
|
|
|
{
|
|
|
|
for( const std::unique_ptr<SCH_PIN>& pin : m_pins )
|
|
|
|
aFunction( pin.get() );
|
|
|
|
|
|
|
|
for( SCH_FIELD& field : m_fields )
|
|
|
|
aFunction( &field );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_PIN* SCH_SYMBOL::GetPin( const wxString& aNumber ) const
|
2009-10-30 19:26:25 +00:00
|
|
|
{
|
2020-08-21 15:54:24 +00:00
|
|
|
for( const std::unique_ptr<SCH_PIN>& pin : m_pins )
|
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-08-21 15:54:24 +00:00
|
|
|
if( pin->GetNumber() == aNumber )
|
|
|
|
return pin.get();
|
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-06 19:15:42 +00:00
|
|
|
|
2020-08-21 15:54:24 +00:00
|
|
|
return nullptr;
|
2009-10-30 19:26:25 +00:00
|
|
|
}
|
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2024-04-21 14:54:34 +00:00
|
|
|
const SCH_PIN* SCH_SYMBOL::GetPin( const VECTOR2I& aPos ) const
|
|
|
|
{
|
|
|
|
for( const std::unique_ptr<SCH_PIN>& pin : m_pins )
|
|
|
|
{
|
|
|
|
int pin_unit = pin->GetLibPin() ? pin->GetLibPin()->GetUnit()
|
|
|
|
: GetUnit();
|
|
|
|
int pin_bodyStyle = pin->GetLibPin() ? pin->GetLibPin()->GetBodyStyle()
|
|
|
|
: GetBodyStyle();
|
|
|
|
|
|
|
|
if( pin_unit > 0 && pin_unit != GetUnit() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( pin_bodyStyle > 0 && pin_bodyStyle != GetBodyStyle() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( pin->IsPointClickableAnchor( aPos ) )
|
|
|
|
return pin.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-20 09:44:34 +00:00
|
|
|
std::vector<SCH_PIN*> SCH_SYMBOL::GetLibPins() const
|
2015-12-13 16:56:47 +00:00
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
if( m_part )
|
2024-04-20 09:44:34 +00:00
|
|
|
return m_part->GetPins( m_unit, m_bodyStyle );
|
|
|
|
|
|
|
|
return std::vector<SCH_PIN*>();
|
2015-12-13 16:56:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-20 09:44:34 +00:00
|
|
|
std::vector<SCH_PIN*> SCH_SYMBOL::GetAllLibPins() const
|
2022-08-22 05:40:23 +00:00
|
|
|
{
|
2022-12-16 13:42:49 +00:00
|
|
|
if( m_part )
|
2024-04-20 09:44:34 +00:00
|
|
|
return m_part->GetAllLibPins();
|
2022-12-16 13:42:49 +00:00
|
|
|
|
2024-04-20 09:44:34 +00:00
|
|
|
return std::vector<SCH_PIN*>();
|
2022-08-22 05:40:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-20 09:44:34 +00:00
|
|
|
SCH_PIN* SCH_SYMBOL::GetPin( SCH_PIN* aLibPin ) const
|
2020-01-17 02:33:16 +00:00
|
|
|
{
|
2023-09-22 18:25:53 +00:00
|
|
|
auto it = m_pinMap.find( aLibPin );
|
|
|
|
|
|
|
|
if( it != m_pinMap.end() )
|
|
|
|
return it->second;
|
|
|
|
|
|
|
|
wxFAIL_MSG_AT( "Pin not found", __FILE__, __LINE__, __FUNCTION__ );
|
|
|
|
return nullptr;
|
2020-08-21 15:54:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
std::vector<SCH_PIN*> SCH_SYMBOL::GetPins( const SCH_SHEET_PATH* aSheet ) const
|
2020-08-21 15:54:24 +00:00
|
|
|
{
|
|
|
|
std::vector<SCH_PIN*> pins;
|
2020-05-13 02:00:37 +00:00
|
|
|
|
2020-01-17 02:33:16 +00:00
|
|
|
if( aSheet == nullptr )
|
2020-05-13 02:00:37 +00:00
|
|
|
{
|
2021-03-25 21:13:01 +00:00
|
|
|
wxCHECK_MSG( Schematic(), pins, "Can't call GetPins on a symbol with no schematic" );
|
2020-05-13 02:00:37 +00:00
|
|
|
|
|
|
|
aSheet = &Schematic()->CurrentSheet();
|
|
|
|
}
|
2020-01-17 02:33:16 +00:00
|
|
|
|
|
|
|
int unit = GetUnitSelection( aSheet );
|
|
|
|
|
2022-03-17 20:23:14 +00:00
|
|
|
for( const std::unique_ptr<SCH_PIN>& p : m_pins )
|
2020-01-17 02:33:16 +00:00
|
|
|
{
|
2024-01-24 17:17:54 +00:00
|
|
|
if( unit && p->GetLibPin() && p->GetLibPin()->GetUnit()
|
|
|
|
&& ( p->GetLibPin()->GetUnit() != unit ) )
|
|
|
|
{
|
2020-01-17 02:33:16 +00:00
|
|
|
continue;
|
2024-01-24 17:17:54 +00:00
|
|
|
}
|
2020-01-17 02:33:16 +00:00
|
|
|
|
2020-08-21 15:54:24 +00:00
|
|
|
pins.push_back( p.get() );
|
2020-01-17 02:33:16 +00:00
|
|
|
}
|
|
|
|
|
2020-08-21 15:54:24 +00:00
|
|
|
return pins;
|
2020-01-17 02:33:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
void SCH_SYMBOL::SwapData( SCH_ITEM* aItem )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2023-07-08 17:37:47 +00:00
|
|
|
SCH_ITEM::SwapFlags( aItem );
|
|
|
|
|
2022-12-16 13:42:49 +00:00
|
|
|
wxCHECK_RET( aItem != nullptr && aItem->Type() == SCH_SYMBOL_T,
|
2021-03-25 21:13:01 +00:00
|
|
|
wxT( "Cannot swap data with invalid symbol." ) );
|
2011-04-08 17:41:52 +00:00
|
|
|
|
2024-04-09 11:55:44 +00:00
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( aItem );
|
2011-04-08 17:41:52 +00:00
|
|
|
|
2021-05-05 21:41:51 +00:00
|
|
|
std::swap( m_lib_id, symbol->m_lib_id );
|
2019-11-06 19:15:42 +00:00
|
|
|
|
2023-03-14 11:48:00 +00:00
|
|
|
m_pins.swap( symbol->m_pins ); // std::vector's swap()
|
|
|
|
|
|
|
|
for( std::unique_ptr<SCH_PIN>& pin : symbol->m_pins )
|
|
|
|
pin->SetParent( symbol );
|
|
|
|
|
|
|
|
for( std::unique_ptr<SCH_PIN>& pin : m_pins )
|
|
|
|
pin->SetParent( this );
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_SYMBOL* libSymbol = symbol->m_part.release();
|
2022-12-16 13:42:49 +00:00
|
|
|
symbol->m_part = std::move( m_part );
|
2021-05-05 21:41:51 +00:00
|
|
|
symbol->UpdatePins();
|
2021-06-10 18:51:46 +00:00
|
|
|
m_part.reset( libSymbol );
|
2019-12-11 23:53:10 +00:00
|
|
|
UpdatePins();
|
2019-11-06 19:15:42 +00:00
|
|
|
|
2021-05-05 21:41:51 +00:00
|
|
|
std::swap( m_pos, symbol->m_pos );
|
|
|
|
std::swap( m_unit, symbol->m_unit );
|
2024-01-26 16:16:13 +00:00
|
|
|
std::swap( m_bodyStyle, symbol->m_bodyStyle );
|
2008-10-06 05:44:29 +00:00
|
|
|
|
2021-05-05 21:41:51 +00:00
|
|
|
m_fields.swap( symbol->m_fields ); // std::vector's swap()
|
2008-10-18 13:42:21 +00:00
|
|
|
|
2021-05-05 21:41:51 +00:00
|
|
|
for( SCH_FIELD& field : symbol->m_fields )
|
|
|
|
field.SetParent( symbol );
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2020-11-16 13:15:54 +00:00
|
|
|
for( SCH_FIELD& field : m_fields )
|
2020-03-06 20:02:58 +00:00
|
|
|
field.SetParent( this );
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2019-04-26 10:31:11 +00:00
|
|
|
TRANSFORM tmp = m_transform;
|
|
|
|
|
2021-05-05 21:41:51 +00:00
|
|
|
m_transform = symbol->m_transform;
|
|
|
|
symbol->m_transform = tmp;
|
2019-04-26 10:31:11 +00:00
|
|
|
|
2023-08-08 16:32:08 +00:00
|
|
|
std::swap( m_excludedFromSim, symbol->m_excludedFromSim );
|
2023-06-25 02:03:06 +00:00
|
|
|
std::swap( m_excludedFromBOM, symbol->m_excludedFromBOM );
|
2023-01-06 22:40:00 +00:00
|
|
|
std::swap( m_DNP, symbol->m_DNP );
|
2023-06-25 02:03:06 +00:00
|
|
|
std::swap( m_excludedFromBoard, symbol->m_excludedFromBoard );
|
2023-01-06 22:40:00 +00:00
|
|
|
|
2021-05-05 21:41:51 +00:00
|
|
|
std::swap( m_instanceReferences, symbol->m_instanceReferences );
|
|
|
|
std::swap( m_schLibSymbolName, symbol->m_schLibSymbolName );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
void SCH_SYMBOL::GetContextualTextVars( wxArrayString* aVars ) const
|
2020-05-27 22:28:36 +00:00
|
|
|
{
|
|
|
|
for( int i = 0; i < MANDATORY_FIELDS; ++i )
|
2020-11-16 13:15:54 +00:00
|
|
|
aVars->push_back( m_fields[i].GetCanonicalName().Upper() );
|
2020-05-28 18:59:25 +00:00
|
|
|
|
2020-11-16 13:15:54 +00:00
|
|
|
for( size_t i = MANDATORY_FIELDS; i < m_fields.size(); ++i )
|
|
|
|
aVars->push_back( m_fields[i].GetName() );
|
2020-05-27 22:28:36 +00:00
|
|
|
|
2023-02-05 20:47:27 +00:00
|
|
|
aVars->push_back( wxT( "OP" ) );
|
2020-05-27 22:28:36 +00:00
|
|
|
aVars->push_back( wxT( "FOOTPRINT_LIBRARY" ) );
|
|
|
|
aVars->push_back( wxT( "FOOTPRINT_NAME" ) );
|
|
|
|
aVars->push_back( wxT( "UNIT" ) );
|
2022-08-27 03:53:23 +00:00
|
|
|
aVars->push_back( wxT( "SYMBOL_LIBRARY" ) );
|
|
|
|
aVars->push_back( wxT( "SYMBOL_NAME" ) );
|
2022-09-02 21:32:50 +00:00
|
|
|
aVars->push_back( wxT( "SYMBOL_DESCRIPTION" ) );
|
|
|
|
aVars->push_back( wxT( "SYMBOL_KEYWORDS" ) );
|
2022-09-13 12:45:59 +00:00
|
|
|
aVars->push_back( wxT( "EXCLUDE_FROM_BOM" ) );
|
|
|
|
aVars->push_back( wxT( "EXCLUDE_FROM_BOARD" ) );
|
2023-08-01 17:41:49 +00:00
|
|
|
aVars->push_back( wxT( "EXCLUDE_FROM_SIM" ) );
|
2022-09-16 16:20:36 +00:00
|
|
|
aVars->push_back( wxT( "DNP" ) );
|
2023-08-30 10:43:21 +00:00
|
|
|
aVars->push_back( wxT( "SHORT_NET_NAME(<pin_number>)" ) );
|
|
|
|
aVars->push_back( wxT( "NET_NAME(<pin_number>)" ) );
|
|
|
|
aVars->push_back( wxT( "NET_CLASS(<pin_number>)" ) );
|
|
|
|
aVars->push_back( wxT( "PIN_NAME(<pin_number>)" ) );
|
2020-05-27 22:28:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-05-06 18:22:14 +00:00
|
|
|
bool SCH_SYMBOL::ResolveTextVar( const SCH_SHEET_PATH* aPath, wxString* token, int aDepth ) const
|
2020-04-06 13:06:57 +00:00
|
|
|
{
|
2023-02-05 20:47:27 +00:00
|
|
|
static wxRegEx operatingPoint( wxT( "^"
|
|
|
|
"OP"
|
2024-03-04 14:24:00 +00:00
|
|
|
"(:[^.]*)?" // pin
|
2023-02-05 20:47:27 +00:00
|
|
|
"(.([0-9])?([a-zA-Z]*))?" // format
|
|
|
|
"$" ) );
|
|
|
|
|
2023-11-11 17:41:44 +00:00
|
|
|
wxCHECK( aPath, false );
|
|
|
|
|
2020-08-29 13:41:47 +00:00
|
|
|
SCHEMATIC* schematic = Schematic();
|
|
|
|
|
2023-11-11 17:41:44 +00:00
|
|
|
if( !schematic )
|
2022-05-29 19:29:32 +00:00
|
|
|
return false;
|
2021-07-06 17:32:34 +00:00
|
|
|
|
2023-02-05 20:47:27 +00:00
|
|
|
if( operatingPoint.Matches( *token ) )
|
|
|
|
{
|
2024-03-04 14:24:00 +00:00
|
|
|
wxString pin( operatingPoint.GetMatch( *token, 1 ).Lower() );
|
2023-02-05 20:47:27 +00:00
|
|
|
wxString precisionStr( operatingPoint.GetMatch( *token, 3 ) );
|
|
|
|
wxString range( operatingPoint.GetMatch( *token, 4 ) );
|
|
|
|
int precision = 3;
|
|
|
|
|
|
|
|
if( !precisionStr.IsEmpty() )
|
|
|
|
precision = precisionStr[0] - '0';
|
|
|
|
|
|
|
|
if( range.IsEmpty() )
|
2024-03-04 14:24:00 +00:00
|
|
|
range = wxS( "~A" );
|
|
|
|
|
|
|
|
SIM_LIB_MGR simLibMgr( &schematic->Prj() );
|
|
|
|
NULL_REPORTER devnull;
|
|
|
|
SIM_MODEL& model = simLibMgr.CreateModel( aPath, const_cast<SCH_SYMBOL&>( *this ),
|
|
|
|
devnull ).model;
|
|
|
|
SPICE_ITEM spiceItem;
|
|
|
|
spiceItem.refName = GetRef( aPath );
|
|
|
|
|
|
|
|
wxString spiceRef = model.SpiceGenerator().ItemName( spiceItem );
|
|
|
|
spiceRef = spiceRef.Lower();
|
|
|
|
|
|
|
|
if( pin.IsEmpty() )
|
2023-02-25 23:30:01 +00:00
|
|
|
{
|
2024-03-04 14:24:00 +00:00
|
|
|
*token = schematic->GetOperatingPoint( spiceRef, precision, range );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if( pin == wxS( ":power" ) )
|
|
|
|
{
|
|
|
|
if( range.IsEmpty() )
|
2023-02-25 23:30:01 +00:00
|
|
|
range = wxS( "~W" );
|
2024-03-04 14:24:00 +00:00
|
|
|
|
|
|
|
*token = schematic->GetOperatingPoint( spiceRef + wxS( ":power" ), precision, range );
|
|
|
|
return true;
|
2023-02-25 23:30:01 +00:00
|
|
|
}
|
2024-03-04 14:24:00 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
pin = pin.SubString( 1, -1 ); // Strip ':' from front
|
|
|
|
|
|
|
|
for( const std::reference_wrapper<const SIM_MODEL::PIN>& modelPin : model.GetPins() )
|
|
|
|
{
|
|
|
|
SCH_PIN* symbolPin = GetPin( modelPin.get().symbolPinNumber );
|
2023-02-05 20:47:27 +00:00
|
|
|
|
2024-03-04 14:24:00 +00:00
|
|
|
if( pin == symbolPin->GetName().Lower() || pin == symbolPin->GetNumber().Lower() )
|
|
|
|
{
|
|
|
|
if( model.GetPins().size() == 2 )
|
|
|
|
{
|
|
|
|
*token = schematic->GetOperatingPoint( spiceRef, precision, range );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxString signalName = spiceRef + wxS( ":" ) + modelPin.get().name;
|
|
|
|
*token = schematic->GetOperatingPoint( signalName, precision, range );
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-02-05 20:47:27 +00:00
|
|
|
|
2024-03-04 14:24:00 +00:00
|
|
|
*token = wxS( "?" );
|
2023-02-05 20:47:27 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-01-17 16:54:08 +00:00
|
|
|
if( token->Contains( ':' ) )
|
|
|
|
{
|
|
|
|
if( schematic->ResolveCrossReference( token, aDepth + 1 ) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-06 13:06:57 +00:00
|
|
|
for( int i = 0; i < MANDATORY_FIELDS; ++i )
|
|
|
|
{
|
2020-11-16 13:15:54 +00:00
|
|
|
if( token->IsSameAs( m_fields[ i ].GetCanonicalName().Upper() ) )
|
2020-04-06 13:06:57 +00:00
|
|
|
{
|
2021-07-06 17:32:34 +00:00
|
|
|
if( i == REFERENCE_FIELD )
|
2023-05-06 18:22:14 +00:00
|
|
|
*token = GetRef( aPath, true );
|
2020-08-29 13:41:47 +00:00
|
|
|
else
|
2023-05-05 13:21:56 +00:00
|
|
|
*token = m_fields[ i ].GetShownText( aPath, false, aDepth + 1 );
|
2020-08-29 13:41:47 +00:00
|
|
|
|
2020-04-06 13:06:57 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-16 13:15:54 +00:00
|
|
|
for( size_t i = MANDATORY_FIELDS; i < m_fields.size(); ++i )
|
2020-04-06 13:06:57 +00:00
|
|
|
{
|
2020-11-16 13:15:54 +00:00
|
|
|
if( token->IsSameAs( m_fields[ i ].GetName() )
|
|
|
|
|| token->IsSameAs( m_fields[ i ].GetName().Upper() ) )
|
2020-04-06 13:06:57 +00:00
|
|
|
{
|
2023-05-05 13:21:56 +00:00
|
|
|
*token = m_fields[ i ].GetShownText( aPath, false, aDepth + 1 );
|
2020-04-06 13:06:57 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2024-01-21 22:25:24 +00:00
|
|
|
|
|
|
|
// Consider missing simulation fields as empty, not un-resolved
|
|
|
|
if( token->IsSameAs( wxT( "SIM.DEVICE" ) )
|
|
|
|
|| token->IsSameAs( wxT( "SIM.TYPE" ) )
|
|
|
|
|| token->IsSameAs( wxT( "SIM.PINS" ) )
|
|
|
|
|| token->IsSameAs( wxT( "SIM.PARAMS" ) )
|
|
|
|
|| token->IsSameAs( wxT( "SIM.LIBRARY" ) )
|
|
|
|
|| token->IsSameAs( wxT( "SIM.NAME" ) ) )
|
|
|
|
{
|
|
|
|
*token = wxEmptyString;
|
|
|
|
return true;
|
|
|
|
}
|
2020-04-06 13:06:57 +00:00
|
|
|
|
2021-06-30 11:23:01 +00:00
|
|
|
for( const TEMPLATE_FIELDNAME& templateFieldname :
|
|
|
|
schematic->Settings().m_TemplateFieldNames.GetTemplateFieldNames() )
|
|
|
|
{
|
|
|
|
if( token->IsSameAs( templateFieldname.m_Name )
|
|
|
|
|| token->IsSameAs( templateFieldname.m_Name.Upper() ) )
|
|
|
|
{
|
|
|
|
// If we didn't find it in the fields list then it isn't set on this symbol.
|
|
|
|
// Just return an empty string.
|
|
|
|
*token = wxEmptyString;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-06 13:06:57 +00:00
|
|
|
if( token->IsSameAs( wxT( "FOOTPRINT_LIBRARY" ) ) )
|
|
|
|
{
|
2023-05-06 18:22:14 +00:00
|
|
|
wxString footprint = GetFootprintFieldText( true, aPath, false );
|
2020-08-29 13:41:47 +00:00
|
|
|
|
|
|
|
wxArrayString parts = wxSplit( footprint, ':' );
|
2020-04-06 13:06:57 +00:00
|
|
|
|
2023-09-18 07:12:12 +00:00
|
|
|
if( parts.Count() > 0 )
|
|
|
|
*token = parts[ 0 ];
|
|
|
|
else
|
|
|
|
*token = wxEmptyString;
|
|
|
|
|
2020-04-06 13:06:57 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if( token->IsSameAs( wxT( "FOOTPRINT_NAME" ) ) )
|
|
|
|
{
|
2023-05-06 18:22:14 +00:00
|
|
|
wxString footprint = GetFootprintFieldText( true, aPath, false );
|
2020-08-29 13:41:47 +00:00
|
|
|
|
|
|
|
wxArrayString parts = wxSplit( footprint, ':' );
|
2020-04-06 13:06:57 +00:00
|
|
|
|
2023-09-18 07:12:12 +00:00
|
|
|
if( parts.Count() > 1 )
|
|
|
|
*token = parts[ std::min( 1, (int) parts.size() - 1 ) ];
|
|
|
|
else
|
|
|
|
*token = wxEmptyString;
|
|
|
|
|
2020-04-06 13:06:57 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if( token->IsSameAs( wxT( "UNIT" ) ) )
|
|
|
|
{
|
2023-11-12 23:42:36 +00:00
|
|
|
*token = SubReference( GetUnitSelection( aPath ) );
|
2020-04-06 13:06:57 +00:00
|
|
|
return true;
|
|
|
|
}
|
2022-08-27 00:30:48 +00:00
|
|
|
else if( token->IsSameAs( wxT( "SYMBOL_LIBRARY" ) ) )
|
|
|
|
{
|
2023-09-14 15:35:19 +00:00
|
|
|
*token = m_lib_id.GetUniStringLibNickname();
|
2022-08-27 00:30:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if( token->IsSameAs( wxT( "SYMBOL_NAME" ) ) )
|
|
|
|
{
|
2023-09-14 15:35:19 +00:00
|
|
|
*token = m_lib_id.GetUniStringLibItemName();
|
2022-08-27 00:30:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
2022-09-02 21:32:50 +00:00
|
|
|
else if( token->IsSameAs( wxT( "SYMBOL_DESCRIPTION" ) ) )
|
|
|
|
{
|
|
|
|
*token = GetDescription();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if( token->IsSameAs( wxT( "SYMBOL_KEYWORDS" ) ) )
|
|
|
|
{
|
|
|
|
*token = GetKeyWords();
|
|
|
|
return true;
|
|
|
|
}
|
2022-09-13 12:45:59 +00:00
|
|
|
else if( token->IsSameAs( wxT( "EXCLUDE_FROM_BOM" ) ) )
|
|
|
|
{
|
2024-04-09 11:55:44 +00:00
|
|
|
*token = this->GetExcludedFromBOM() ? _( "Excluded from BOM" ) : wxString( "" );
|
2022-09-13 12:45:59 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if( token->IsSameAs( wxT( "EXCLUDE_FROM_BOARD" ) ) )
|
|
|
|
{
|
2024-04-09 11:55:44 +00:00
|
|
|
*token = this->GetExcludedFromBoard() ? _( "Excluded from board" ) : wxString( "" );
|
2022-09-16 16:20:36 +00:00
|
|
|
return true;
|
|
|
|
}
|
2023-08-01 17:41:49 +00:00
|
|
|
else if( token->IsSameAs( wxT( "EXCLUDE_FROM_SIM" ) ) )
|
|
|
|
{
|
2024-04-09 11:55:44 +00:00
|
|
|
*token = this->GetExcludedFromSim() ? _( "Excluded from simulation" ) : wxString( "" );
|
2023-08-01 17:41:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
2022-09-16 16:20:36 +00:00
|
|
|
else if( token->IsSameAs( wxT( "DNP" ) ) )
|
|
|
|
{
|
2024-04-09 11:55:44 +00:00
|
|
|
*token = this->GetDNP() ? _( "DNP" ) : wxString( "" );
|
2022-09-13 12:45:59 +00:00
|
|
|
return true;
|
|
|
|
}
|
2023-08-30 10:43:21 +00:00
|
|
|
else if( token->StartsWith( wxT( "SHORT_NET_NAME(" ) )
|
|
|
|
|| token->StartsWith( wxT( "NET_NAME(" ) )
|
|
|
|
|| token->StartsWith( wxT( "NET_CLASS(" ) )
|
|
|
|
|| token->StartsWith( wxT( "PIN_NAME(" ) ) )
|
|
|
|
{
|
|
|
|
wxString pinNumber = token->AfterFirst( '(' );
|
|
|
|
pinNumber = pinNumber.BeforeLast( ')' );
|
|
|
|
|
|
|
|
for( SCH_PIN* pin : GetPins( aPath ) )
|
|
|
|
{
|
|
|
|
if( pin->GetNumber() == pinNumber )
|
|
|
|
{
|
|
|
|
if( token->StartsWith( wxT( "PIN_NAME" ) ) )
|
|
|
|
{
|
|
|
|
*token = pin->GetAlt().IsEmpty() ? pin->GetName() : pin->GetAlt();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
SCH_CONNECTION* conn = pin->Connection( aPath );
|
|
|
|
|
|
|
|
if( !conn )
|
|
|
|
*token = wxEmptyString;
|
|
|
|
else if( token->StartsWith( wxT( "SHORT_NET_NAME" ) ) )
|
|
|
|
*token = conn->LocalName();
|
|
|
|
else if( token->StartsWith( wxT( "NET_NAME" ) ) )
|
|
|
|
*token = conn->Name();
|
|
|
|
else if( token->StartsWith( wxT( "NET_CLASS" ) ) )
|
|
|
|
*token = pin->GetEffectiveNetClass( aPath )->GetName();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-06 13:06:57 +00:00
|
|
|
|
2023-01-17 16:54:08 +00:00
|
|
|
// See if parent can resolve it (this will recurse to ancestors)
|
2023-06-12 12:41:25 +00:00
|
|
|
if( aPath->Last() && aPath->Last()->ResolveTextVar( aPath, token, aDepth + 1 ) )
|
2023-05-06 18:22:14 +00:00
|
|
|
return true;
|
2023-01-17 16:54:08 +00:00
|
|
|
|
2020-04-06 13:06:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-13 22:37:42 +00:00
|
|
|
void SCH_SYMBOL::ClearAnnotation( const SCH_SHEET_PATH* aSheetPath, bool aResetPrefix )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2018-06-08 04:34:17 +00:00
|
|
|
if( aSheetPath )
|
|
|
|
{
|
2020-02-22 21:39:59 +00:00
|
|
|
KIID_PATH path = aSheetPath->Path();
|
2010-12-14 15:56:30 +00:00
|
|
|
|
2023-01-04 20:39:50 +00:00
|
|
|
for( SCH_SYMBOL_INSTANCE& instance : m_instanceReferences )
|
2008-04-21 06:34:56 +00:00
|
|
|
{
|
2020-02-22 21:39:59 +00:00
|
|
|
if( instance.m_Path == path )
|
2022-04-13 22:37:42 +00:00
|
|
|
{
|
|
|
|
if( instance.m_Reference.IsEmpty() || aResetPrefix )
|
|
|
|
instance.m_Reference = UTIL::GetRefDesUnannotated( m_prefix );
|
|
|
|
else
|
|
|
|
instance.m_Reference = UTIL::GetRefDesUnannotated( instance.m_Reference );
|
|
|
|
}
|
2008-04-21 06:34:56 +00:00
|
|
|
}
|
2008-02-21 12:21:01 +00:00
|
|
|
}
|
2020-02-22 21:39:59 +00:00
|
|
|
else
|
|
|
|
{
|
2023-01-04 20:39:50 +00:00
|
|
|
for( SCH_SYMBOL_INSTANCE& instance : m_instanceReferences )
|
2022-04-13 22:37:42 +00:00
|
|
|
{
|
|
|
|
if( instance.m_Reference.IsEmpty() || aResetPrefix)
|
|
|
|
instance.m_Reference = UTIL::GetRefDesUnannotated( m_prefix );
|
|
|
|
else
|
|
|
|
instance.m_Reference = UTIL::GetRefDesUnannotated( instance.m_Reference );
|
|
|
|
}
|
2020-02-22 21:39:59 +00:00
|
|
|
}
|
2008-05-15 11:20:19 +00:00
|
|
|
|
2020-08-13 21:30:30 +00:00
|
|
|
for( std::unique_ptr<SCH_PIN>& pin : m_pins )
|
|
|
|
pin->ClearDefaultNetName( aSheetPath );
|
|
|
|
|
2008-04-21 06:34:56 +00:00
|
|
|
// These 2 changes do not work in complex hierarchy.
|
|
|
|
// When a clear annotation is made, the calling function must call a
|
|
|
|
// UpdateAllScreenReferences for the active sheet.
|
2008-05-15 11:20:19 +00:00
|
|
|
// But this call cannot made here.
|
2022-04-13 22:37:42 +00:00
|
|
|
wxString currentReference = m_fields[REFERENCE_FIELD].GetText();
|
|
|
|
|
|
|
|
if( currentReference.IsEmpty() || aResetPrefix )
|
|
|
|
m_fields[REFERENCE_FIELD].SetText( UTIL::GetRefDesUnannotated( m_prefix ) );
|
|
|
|
else
|
|
|
|
m_fields[REFERENCE_FIELD].SetText( UTIL::GetRefDesUnannotated( currentReference ) );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
bool SCH_SYMBOL::AddSheetPathReferenceEntryIfMissing( const KIID_PATH& aSheetPath )
|
2018-09-03 10:11:39 +00:00
|
|
|
{
|
2022-10-01 12:44:21 +00:00
|
|
|
// An empty sheet path is illegal, at a minimum the root sheet UUID must be present.
|
2020-02-22 21:39:59 +00:00
|
|
|
wxCHECK( aSheetPath.size() > 0, false );
|
2018-09-03 10:11:39 +00:00
|
|
|
|
2023-01-04 20:39:50 +00:00
|
|
|
for( const SCH_SYMBOL_INSTANCE& instance : m_instanceReferences )
|
2018-09-03 10:11:39 +00:00
|
|
|
{
|
|
|
|
// if aSheetPath is found, nothing to do:
|
2020-02-22 21:39:59 +00:00
|
|
|
if( instance.m_Path == aSheetPath )
|
2018-09-04 16:46:03 +00:00
|
|
|
return false;
|
2018-09-03 10:11:39 +00:00
|
|
|
}
|
|
|
|
|
2020-02-22 21:39:59 +00:00
|
|
|
// This entry does not exist: add it, with its last-used reference
|
2020-11-16 13:15:54 +00:00
|
|
|
AddHierarchicalReference( aSheetPath, m_fields[REFERENCE_FIELD].GetText(), m_unit );
|
2018-09-04 16:46:03 +00:00
|
|
|
return true;
|
2018-09-03 10:11:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
void SCH_SYMBOL::SetOrientation( int aOrientation )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2010-10-20 20:24:26 +00:00
|
|
|
TRANSFORM temp = TRANSFORM();
|
2011-07-15 13:17:41 +00:00
|
|
|
bool transform = false;
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2010-01-13 21:15:54 +00:00
|
|
|
switch( aOrientation )
|
2007-09-20 21:06:49 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
case SYM_ORIENT_0:
|
|
|
|
case SYM_NORMAL: // default transform matrix
|
2010-12-14 21:39:31 +00:00
|
|
|
m_transform.x1 = 1;
|
|
|
|
m_transform.y2 = -1;
|
|
|
|
m_transform.x2 = m_transform.y1 = 0;
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
case SYM_ROTATE_COUNTERCLOCKWISE: // Rotate + (incremental rotation)
|
2010-10-20 20:24:26 +00:00
|
|
|
temp.x1 = temp.y2 = 0;
|
|
|
|
temp.y1 = 1;
|
|
|
|
temp.x2 = -1;
|
2011-07-15 13:17:41 +00:00
|
|
|
transform = true;
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
case SYM_ROTATE_CLOCKWISE: // Rotate - (incremental rotation)
|
2010-10-20 20:24:26 +00:00
|
|
|
temp.x1 = temp.y2 = 0;
|
|
|
|
temp.y1 = -1;
|
|
|
|
temp.x2 = 1;
|
2011-07-15 13:17:41 +00:00
|
|
|
transform = true;
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
case SYM_MIRROR_Y: // Mirror Y (incremental rotation)
|
2010-10-20 20:24:26 +00:00
|
|
|
temp.x1 = -1;
|
|
|
|
temp.y2 = 1;
|
|
|
|
temp.y1 = temp.x2 = 0;
|
2011-07-15 13:17:41 +00:00
|
|
|
transform = true;
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
case SYM_MIRROR_X: // Mirror X (incremental rotation)
|
2010-10-20 20:24:26 +00:00
|
|
|
temp.x1 = 1;
|
|
|
|
temp.y2 = -1;
|
|
|
|
temp.y1 = temp.x2 = 0;
|
2011-10-07 14:41:30 +00:00
|
|
|
transform = true;
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
case SYM_ORIENT_90:
|
|
|
|
SetOrientation( SYM_ORIENT_0 );
|
|
|
|
SetOrientation( SYM_ROTATE_COUNTERCLOCKWISE );
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
case SYM_ORIENT_180:
|
|
|
|
SetOrientation( SYM_ORIENT_0 );
|
|
|
|
SetOrientation( SYM_ROTATE_COUNTERCLOCKWISE );
|
|
|
|
SetOrientation( SYM_ROTATE_COUNTERCLOCKWISE );
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
case SYM_ORIENT_270:
|
|
|
|
SetOrientation( SYM_ORIENT_0 );
|
|
|
|
SetOrientation( SYM_ROTATE_CLOCKWISE );
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
case ( SYM_ORIENT_0 + SYM_MIRROR_X ):
|
|
|
|
SetOrientation( SYM_ORIENT_0 );
|
|
|
|
SetOrientation( SYM_MIRROR_X );
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
case ( SYM_ORIENT_0 + SYM_MIRROR_Y ):
|
|
|
|
SetOrientation( SYM_ORIENT_0 );
|
|
|
|
SetOrientation( SYM_MIRROR_Y );
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
2024-01-19 13:29:08 +00:00
|
|
|
case ( SYM_ORIENT_0 + SYM_MIRROR_X + SYM_MIRROR_Y ):
|
|
|
|
SetOrientation( SYM_ORIENT_0 );
|
|
|
|
SetOrientation( SYM_MIRROR_X );
|
|
|
|
SetOrientation( SYM_MIRROR_Y );
|
|
|
|
break;
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
case ( SYM_ORIENT_90 + SYM_MIRROR_X ):
|
|
|
|
SetOrientation( SYM_ORIENT_90 );
|
|
|
|
SetOrientation( SYM_MIRROR_X );
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
case ( SYM_ORIENT_90 + SYM_MIRROR_Y ):
|
|
|
|
SetOrientation( SYM_ORIENT_90 );
|
|
|
|
SetOrientation( SYM_MIRROR_Y );
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
2024-01-19 13:29:08 +00:00
|
|
|
case ( SYM_ORIENT_90 + SYM_MIRROR_X + SYM_MIRROR_Y ):
|
|
|
|
SetOrientation( SYM_ORIENT_90 );
|
|
|
|
SetOrientation( SYM_MIRROR_X );
|
|
|
|
SetOrientation( SYM_MIRROR_Y );
|
|
|
|
break;
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
case ( SYM_ORIENT_180 + SYM_MIRROR_X ):
|
|
|
|
SetOrientation( SYM_ORIENT_180 );
|
|
|
|
SetOrientation( SYM_MIRROR_X );
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
case ( SYM_ORIENT_180 + SYM_MIRROR_Y ):
|
|
|
|
SetOrientation( SYM_ORIENT_180 );
|
|
|
|
SetOrientation( SYM_MIRROR_Y );
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
2024-01-19 13:29:08 +00:00
|
|
|
case ( SYM_ORIENT_180 + SYM_MIRROR_X + SYM_MIRROR_Y ):
|
|
|
|
SetOrientation( SYM_ORIENT_180 );
|
|
|
|
SetOrientation( SYM_MIRROR_X );
|
|
|
|
SetOrientation( SYM_MIRROR_Y );
|
|
|
|
break;
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
case ( SYM_ORIENT_270 + SYM_MIRROR_X ):
|
|
|
|
SetOrientation( SYM_ORIENT_270 );
|
|
|
|
SetOrientation( SYM_MIRROR_X );
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
case ( SYM_ORIENT_270 + SYM_MIRROR_Y ):
|
|
|
|
SetOrientation( SYM_ORIENT_270 );
|
|
|
|
SetOrientation( SYM_MIRROR_Y );
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
2024-01-19 13:29:08 +00:00
|
|
|
case ( SYM_ORIENT_270 + SYM_MIRROR_X + SYM_MIRROR_Y ):
|
|
|
|
SetOrientation( SYM_ORIENT_270 );
|
|
|
|
SetOrientation( SYM_MIRROR_X );
|
|
|
|
SetOrientation( SYM_MIRROR_Y );
|
|
|
|
break;
|
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
default:
|
2012-01-22 17:20:22 +00:00
|
|
|
transform = false;
|
2020-04-16 16:43:50 +00:00
|
|
|
wxFAIL_MSG( "Invalid schematic symbol orientation type." );
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-07-15 13:17:41 +00:00
|
|
|
if( transform )
|
2008-04-12 18:39:20 +00:00
|
|
|
{
|
|
|
|
/* The new matrix transform is the old matrix transform modified by the
|
2010-12-23 10:00:55 +00:00
|
|
|
* requested transformation, which is the temp transform (rot,
|
2009-04-05 20:49:15 +00:00
|
|
|
* mirror ..) in order to have (in term of matrix transform):
|
2010-12-14 21:39:31 +00:00
|
|
|
* transform coord = new_m_transform * coord
|
|
|
|
* where transform coord is the coord modified by new_m_transform from
|
2009-04-05 20:49:15 +00:00
|
|
|
* the initial value coord.
|
2010-12-23 10:00:55 +00:00
|
|
|
* new_m_transform is computed (from old_m_transform and temp) to
|
2009-04-05 20:49:15 +00:00
|
|
|
* have:
|
2010-12-23 10:00:55 +00:00
|
|
|
* transform coord = old_m_transform * temp
|
2008-04-12 18:39:20 +00:00
|
|
|
*/
|
2010-10-20 20:24:26 +00:00
|
|
|
TRANSFORM newTransform;
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2010-12-14 21:39:31 +00:00
|
|
|
newTransform.x1 = m_transform.x1 * temp.x1 + m_transform.x2 * temp.y1;
|
|
|
|
newTransform.y1 = m_transform.y1 * temp.x1 + m_transform.y2 * temp.y1;
|
|
|
|
newTransform.x2 = m_transform.x1 * temp.x2 + m_transform.x2 * temp.y2;
|
|
|
|
newTransform.y2 = m_transform.y1 * temp.x2 + m_transform.y2 * temp.y2;
|
|
|
|
m_transform = newTransform;
|
2007-09-20 21:06:49 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-16 16:20:36 +00:00
|
|
|
int SCH_SYMBOL::GetOrientation() const
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2023-03-05 17:25:36 +00:00
|
|
|
/*
|
|
|
|
* This is slow, but also a bizarre algorithm. I don't feel like unteasing the algorithm right
|
|
|
|
* now, so let's just cache it for the moment.
|
|
|
|
*/
|
|
|
|
if( s_transformToOrientationCache.count( m_transform ) )
|
|
|
|
return s_transformToOrientationCache.at( m_transform );
|
|
|
|
|
2018-09-01 23:29:19 +00:00
|
|
|
int rotate_values[] =
|
2007-09-20 21:06:49 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SYM_ORIENT_0,
|
|
|
|
SYM_ORIENT_90,
|
|
|
|
SYM_ORIENT_180,
|
|
|
|
SYM_ORIENT_270,
|
|
|
|
SYM_MIRROR_X + SYM_ORIENT_0,
|
|
|
|
SYM_MIRROR_X + SYM_ORIENT_90,
|
|
|
|
SYM_MIRROR_X + SYM_ORIENT_270,
|
|
|
|
SYM_MIRROR_Y,
|
|
|
|
SYM_MIRROR_Y + SYM_ORIENT_0,
|
|
|
|
SYM_MIRROR_Y + SYM_ORIENT_90,
|
|
|
|
SYM_MIRROR_Y + SYM_ORIENT_180,
|
|
|
|
SYM_MIRROR_Y + SYM_ORIENT_270
|
2009-04-09 11:34:41 +00:00
|
|
|
};
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2009-04-09 11:34:41 +00:00
|
|
|
// Try to find the current transform option:
|
2018-09-01 23:29:19 +00:00
|
|
|
TRANSFORM transform = m_transform;
|
2022-09-16 16:20:36 +00:00
|
|
|
SCH_SYMBOL temp( *this );
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2018-09-01 23:29:19 +00:00
|
|
|
for( int type_rotate : rotate_values )
|
2007-09-20 21:06:49 +00:00
|
|
|
{
|
2022-09-16 16:20:36 +00:00
|
|
|
temp.SetOrientation( type_rotate );
|
2010-10-20 20:24:26 +00:00
|
|
|
|
2022-09-16 16:20:36 +00:00
|
|
|
if( transform == temp.GetTransform() )
|
2023-03-05 17:25:36 +00:00
|
|
|
{
|
|
|
|
s_transformToOrientationCache[m_transform] = type_rotate;
|
2009-04-09 11:34:41 +00:00
|
|
|
return type_rotate;
|
2023-03-05 17:25:36 +00:00
|
|
|
}
|
2007-09-20 21:06:49 +00:00
|
|
|
}
|
|
|
|
|
2009-04-09 11:34:41 +00:00
|
|
|
// Error: orientation not found in list (should not happen)
|
2020-04-16 16:43:50 +00:00
|
|
|
wxFAIL_MSG( "Schematic symbol orientation matrix internal error." );
|
2010-10-20 20:24:26 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
return SYM_NORMAL;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
#if defined(DEBUG)
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
void SCH_SYMBOL::Show( int nestLevel, std::ostream& os ) const
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-09-20 21:06:49 +00:00
|
|
|
// for now, make it look like XML:
|
2009-12-02 21:44:03 +00:00
|
|
|
NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str()
|
2021-02-28 13:28:23 +00:00
|
|
|
<< " ref=\"" << TO_UTF8( GetField( REFERENCE_FIELD )->GetName() )
|
2009-12-02 21:44:03 +00:00
|
|
|
<< '"' << " chipName=\""
|
2024-03-21 03:25:15 +00:00
|
|
|
<< GetLibId().Format().wx_str() << '"' << m_pos
|
2020-11-14 14:29:11 +00:00
|
|
|
<< " layer=\"" << m_layer
|
2010-08-03 05:11:05 +00:00
|
|
|
<< '"' << ">\n";
|
2008-02-21 12:21:01 +00:00
|
|
|
|
|
|
|
// skip the reference, it's been output already.
|
2009-04-05 20:49:15 +00:00
|
|
|
for( int i = 1; i < GetFieldCount(); ++i )
|
2007-09-20 21:06:49 +00:00
|
|
|
{
|
2021-02-28 13:28:23 +00:00
|
|
|
const wxString& value = GetFields()[i].GetText();
|
2008-02-21 12:21:01 +00:00
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
if( !value.IsEmpty() )
|
|
|
|
{
|
2009-12-02 21:44:03 +00:00
|
|
|
NestedSpace( nestLevel + 1, os ) << "<field" << " name=\""
|
2021-02-28 13:28:23 +00:00
|
|
|
<< TO_UTF8( GetFields()[i].GetName() )
|
2010-09-05 17:01:48 +00:00
|
|
|
<< '"' << " value=\""
|
2011-02-28 18:36:19 +00:00
|
|
|
<< TO_UTF8( value ) << "\"/>\n";
|
2007-09-20 21:06:49 +00:00
|
|
|
}
|
2008-02-21 12:21:01 +00:00
|
|
|
}
|
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
NestedSpace( nestLevel, os ) << "</" << TO_UTF8( GetClass().Lower() ) << ">\n";
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2008-02-21 12:21:01 +00:00
|
|
|
#endif
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
|
2022-08-30 23:28:18 +00:00
|
|
|
BOX2I SCH_SYMBOL::doGetBoundingBox( bool aIncludePins, bool aIncludeFields ) const
|
2008-04-15 19:38:19 +00:00
|
|
|
{
|
2022-08-30 23:28:18 +00:00
|
|
|
BOX2I bBox;
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
if( m_part )
|
2024-01-26 16:16:13 +00:00
|
|
|
bBox = m_part->GetBodyBoundingBox( m_unit, m_bodyStyle, aIncludePins, false );
|
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
|
|
|
else
|
2024-01-26 16:16:13 +00:00
|
|
|
bBox = dummy()->GetBodyBoundingBox( m_unit, m_bodyStyle, aIncludePins, false );
|
2010-12-10 19:47:44 +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
|
|
|
int x0 = bBox.GetX();
|
|
|
|
int xm = bBox.GetRight();
|
2010-12-10 19:47:44 +00:00
|
|
|
|
|
|
|
// We must reverse Y values, because matrix orientation
|
|
|
|
// suppose Y axis normal for the library items coordinates,
|
2010-12-14 21:39:31 +00:00
|
|
|
// m_transform reverse Y values, but bBox is already reversed!
|
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 y0 = -bBox.GetY();
|
|
|
|
int ym = -bBox.GetBottom();
|
2010-12-10 19:47:44 +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
|
|
|
// Compute the real Boundary box (rotated, mirrored ...)
|
2010-12-14 21:39:31 +00:00
|
|
|
int x1 = m_transform.x1 * x0 + m_transform.y1 * y0;
|
|
|
|
int y1 = m_transform.x2 * x0 + m_transform.y2 * y0;
|
|
|
|
int x2 = m_transform.x1 * xm + m_transform.y1 * ym;
|
|
|
|
int y2 = m_transform.x2 * xm + m_transform.y2 * ym;
|
2010-12-10 19:47:44 +00:00
|
|
|
|
|
|
|
bBox.SetX( x1 );
|
|
|
|
bBox.SetY( y1 );
|
|
|
|
bBox.SetWidth( x2 - x1 );
|
|
|
|
bBox.SetHeight( y2 - y1 );
|
2020-01-23 14:03:46 +00:00
|
|
|
bBox.Normalize();
|
2008-04-15 19:38:19 +00:00
|
|
|
|
2020-11-16 13:15:54 +00:00
|
|
|
bBox.Offset( m_pos );
|
2021-09-23 21:07:19 +00:00
|
|
|
|
|
|
|
if( aIncludeFields )
|
|
|
|
{
|
|
|
|
for( const SCH_FIELD& field : m_fields )
|
|
|
|
{
|
|
|
|
if( field.IsVisible() )
|
|
|
|
bBox.Merge( field.GetBoundingBox() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-13 15:59:00 +00:00
|
|
|
return bBox;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-30 23:28:18 +00:00
|
|
|
BOX2I SCH_SYMBOL::GetBodyBoundingBox() const
|
2010-12-13 15:59:00 +00:00
|
|
|
{
|
2023-10-03 13:35:46 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
return doGetBoundingBox( false, false );
|
|
|
|
}
|
|
|
|
catch( const boost::bad_pointer& exc )
|
|
|
|
{
|
|
|
|
// This may be overkill and could be an assertion but we are more likely to
|
|
|
|
// find any boost pointer container errors this way.
|
|
|
|
wxLogError( wxT( "Boost bad pointer exception '%s' occurred." ), exc.what() );
|
|
|
|
return BOX2I();
|
|
|
|
}
|
2008-04-12 18:39:20 +00:00
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
BOX2I SCH_SYMBOL::GetBodyAndPinsBoundingBox() const
|
2020-08-13 06:50:41 +00:00
|
|
|
{
|
2021-09-23 21:07:19 +00:00
|
|
|
return doGetBoundingBox( true, false );
|
|
|
|
}
|
2020-08-13 06:50:41 +00:00
|
|
|
|
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
const BOX2I SCH_SYMBOL::GetBoundingBox() const
|
2021-09-23 21:07:19 +00:00
|
|
|
{
|
|
|
|
return doGetBoundingBox( true, true );
|
2020-08-13 06:50:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-26 23:22:32 +00:00
|
|
|
void SCH_SYMBOL::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2017-10-22 00:48:25 +00:00
|
|
|
wxString msg;
|
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( aFrame );
|
2020-09-06 12:05:07 +00:00
|
|
|
SCH_SHEET_PATH* currentSheet = schframe ? &schframe->GetCurrentSheet() : nullptr;
|
2020-05-13 02:00:37 +00:00
|
|
|
|
2023-04-09 11:14:21 +00:00
|
|
|
auto addExcludes =
|
|
|
|
[&]()
|
2024-04-09 11:55:44 +00:00
|
|
|
{
|
|
|
|
wxArrayString msgs;
|
2023-04-09 11:14:21 +00:00
|
|
|
|
2024-04-09 11:55:44 +00:00
|
|
|
if( GetExcludedFromSim() )
|
|
|
|
msgs.Add( _( "Simulation" ) );
|
2023-04-09 11:14:21 +00:00
|
|
|
|
2024-04-09 11:55:44 +00:00
|
|
|
if( GetExcludedFromBOM() )
|
|
|
|
msgs.Add( _( "BOM" ) );
|
2023-04-09 11:14:21 +00:00
|
|
|
|
2024-04-09 11:55:44 +00:00
|
|
|
if( GetExcludedFromBoard() )
|
|
|
|
msgs.Add( _( "Board" ) );
|
2023-04-09 11:14:21 +00:00
|
|
|
|
2024-04-09 11:55:44 +00:00
|
|
|
if( GetDNP() )
|
|
|
|
msgs.Add( _( "DNP" ) );
|
2023-04-09 11:14:21 +00:00
|
|
|
|
2024-04-09 11:55:44 +00:00
|
|
|
msg = wxJoin( msgs, '|' );
|
|
|
|
msg.Replace( '|', wxS( ", " ) );
|
2023-04-09 11:14:21 +00:00
|
|
|
|
2024-04-09 11:55:44 +00:00
|
|
|
if( !msg.empty() )
|
|
|
|
aList.emplace_back( _( "Exclude from" ), msg );
|
|
|
|
};
|
2023-04-09 11:14: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
|
|
|
// part and alias can differ if alias is not the root
|
2019-11-06 19:15:42 +00:00
|
|
|
if( m_part )
|
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-06 19:15:42 +00:00
|
|
|
if( m_part.get() != dummy() )
|
2017-08-01 19:34:34 +00:00
|
|
|
{
|
2022-07-12 03:45:21 +00:00
|
|
|
if( m_part->IsPower() )
|
|
|
|
{
|
2023-05-05 13:21:56 +00:00
|
|
|
// Don't use GetShownText(); we want to see the variable references here
|
|
|
|
aList.emplace_back( _( "Power symbol" ),
|
|
|
|
KIUI::EllipsizeStatusText( aFrame, GetField( VALUE_FIELD )->GetText() ) );
|
2022-07-12 03:45:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-05-05 13:21:56 +00:00
|
|
|
aList.emplace_back( _( "Reference" ),
|
|
|
|
UnescapeString( GetRef( currentSheet ) ) );
|
|
|
|
|
|
|
|
// Don't use GetShownText(); we want to see the variable references here
|
|
|
|
aList.emplace_back( _( "Value" ),
|
|
|
|
KIUI::EllipsizeStatusText( aFrame, GetField( VALUE_FIELD )->GetText() ) );
|
2023-04-09 11:14:21 +00:00
|
|
|
addExcludes();
|
2023-05-05 13:21:56 +00:00
|
|
|
aList.emplace_back( _( "Name" ),
|
|
|
|
KIUI::EllipsizeStatusText( aFrame, GetLibId().GetLibItemName() ) );
|
2022-07-12 03:45:21 +00:00
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2021-03-25 21:13:01 +00:00
|
|
|
#if 0 // Display symbol flags, for debug only
|
2021-09-28 13:28:35 +00:00
|
|
|
aList.emplace_back( _( "flags" ), wxString::Format( "%X", GetEditFlags() ) );
|
2020-05-22 18:25:43 +00:00
|
|
|
#endif
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
if( !m_part->IsRoot() )
|
|
|
|
{
|
|
|
|
msg = _( "Missing parent" );
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
std::shared_ptr< LIB_SYMBOL > parent = m_part->GetParent().lock();
|
2010-12-13 15:59:00 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
if( parent )
|
|
|
|
msg = parent->GetName();
|
|
|
|
|
2022-11-16 17:09:59 +00:00
|
|
|
aList.emplace_back( _( "Derived from" ), UnescapeString( msg ) );
|
2019-11-06 19:15:42 +00:00
|
|
|
}
|
2017-09-01 20:42:20 +00:00
|
|
|
else if( !m_lib_id.GetLibNickname().empty() )
|
2020-04-16 16:43:50 +00:00
|
|
|
{
|
2021-09-28 13:28:35 +00:00
|
|
|
aList.emplace_back( _( "Library" ), m_lib_id.GetLibNickname() );
|
2020-04-16 16:43:50 +00:00
|
|
|
}
|
2017-09-01 20:42:20 +00:00
|
|
|
else
|
2020-04-16 16:43:50 +00:00
|
|
|
{
|
2021-09-28 13:28:35 +00:00
|
|
|
aList.emplace_back( _( "Library" ), _( "Undefined!!!" ) );
|
2020-04-16 16:43:50 +00:00
|
|
|
}
|
2009-09-18 14:56:05 +00:00
|
|
|
|
2017-08-01 19:34:34 +00:00
|
|
|
// Display the current associated footprint, if exists.
|
2023-05-05 13:21:56 +00:00
|
|
|
// Don't use GetShownText(); we want to see the variable references here
|
|
|
|
msg = KIUI::EllipsizeStatusText( aFrame, GetField( FOOTPRINT_FIELD )->GetText() );
|
2020-08-29 13:41:47 +00:00
|
|
|
|
|
|
|
if( msg.IsEmpty() )
|
2017-08-01 19:34:34 +00:00
|
|
|
msg = _( "<Unknown>" );
|
2013-11-09 16:30:49 +00:00
|
|
|
|
2021-09-28 13:28:35 +00:00
|
|
|
aList.emplace_back( _( "Footprint" ), msg );
|
2013-02-11 18:50:55 +00:00
|
|
|
|
2021-03-25 21:13:01 +00:00
|
|
|
// Display description of the symbol, and keywords found in lib
|
2023-07-31 15:22:09 +00:00
|
|
|
aList.emplace_back( _( "Description" ) + wxT( ": " )
|
|
|
|
+ GetField( DESCRIPTION_FIELD )->GetText(),
|
2023-04-30 15:36:27 +00:00
|
|
|
_( "Keywords" ) + wxT( ": " ) + m_part->GetKeyWords() );
|
2017-08-01 19:34:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-09-28 13:28:35 +00:00
|
|
|
aList.emplace_back( _( "Reference" ), GetRef( currentSheet ) );
|
2023-05-05 13:21:56 +00:00
|
|
|
// Don't use GetShownText(); we want to see the variable references here
|
|
|
|
aList.emplace_back( _( "Value" ),
|
|
|
|
KIUI::EllipsizeStatusText( aFrame, GetField( VALUE_FIELD )->GetText() ) );
|
2023-04-09 11:14:21 +00:00
|
|
|
addExcludes();
|
2023-05-05 13:21:56 +00:00
|
|
|
aList.emplace_back( _( "Name" ),
|
|
|
|
KIUI::EllipsizeStatusText( aFrame, GetLibId().GetLibItemName() ) );
|
2017-10-22 00:48:25 +00:00
|
|
|
|
|
|
|
wxString libNickname = GetLibId().GetLibNickname();
|
|
|
|
|
|
|
|
if( libNickname.empty() )
|
2021-09-28 13:28:35 +00:00
|
|
|
msg = _( "No library defined!" );
|
2017-10-22 00:48:25 +00:00
|
|
|
else
|
2019-04-04 22:49:49 +00:00
|
|
|
msg.Printf( _( "Symbol not found in %s!" ), libNickname );
|
2021-09-28 13:28:35 +00:00
|
|
|
|
|
|
|
aList.emplace_back( _( "Library" ), msg );
|
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
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
2009-07-27 14:32:40 +00:00
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
BITMAPS SCH_SYMBOL::GetMenuImage() const
|
2017-02-20 12:20:39 +00:00
|
|
|
{
|
2021-03-08 02:59:07 +00:00
|
|
|
return BITMAPS::add_component;
|
2017-02-20 12:20:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
void SCH_SYMBOL::MirrorHorizontally( int aCenter )
|
2009-07-27 14:32:40 +00:00
|
|
|
{
|
2020-11-16 13:15:54 +00:00
|
|
|
int dx = m_pos.x;
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
SetOrientation( SYM_MIRROR_Y );
|
2021-02-16 20:45:25 +00:00
|
|
|
MIRROR( m_pos.x, aCenter );
|
2020-11-16 13:15:54 +00:00
|
|
|
dx -= m_pos.x; // dx,0 is the move vector for this transform
|
2009-07-27 14:32:40 +00:00
|
|
|
|
2020-11-16 13:15:54 +00:00
|
|
|
for( SCH_FIELD& field : m_fields )
|
2009-07-27 14:32:40 +00:00
|
|
|
{
|
2021-03-25 21:13:01 +00:00
|
|
|
// Move the fields to the new position because the symbol itself has moved.
|
2021-12-29 21:30:11 +00:00
|
|
|
VECTOR2I pos = field.GetTextPos();
|
2013-03-18 19:36:07 +00:00
|
|
|
pos.x -= dx;
|
2020-03-06 20:02:58 +00:00
|
|
|
field.SetTextPos( pos );
|
2009-07-27 14:32:40 +00:00
|
|
|
}
|
|
|
|
}
|
2010-03-16 18:22:59 +00:00
|
|
|
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
void SCH_SYMBOL::MirrorVertically( int aCenter )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2020-11-16 13:15:54 +00:00
|
|
|
int dy = m_pos.y;
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
SetOrientation( SYM_MIRROR_X );
|
2021-02-16 20:45:25 +00:00
|
|
|
MIRROR( m_pos.y, aCenter );
|
2021-10-28 20:44:58 +00:00
|
|
|
dy -= m_pos.y; // 0,dy is the move vector for this transform
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2020-11-16 13:15:54 +00:00
|
|
|
for( SCH_FIELD& field : m_fields )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2021-03-25 21:13:01 +00:00
|
|
|
// Move the fields to the new position because the symbol itself has moved.
|
2021-12-29 21:30:11 +00:00
|
|
|
VECTOR2I pos = field.GetTextPos();
|
2013-03-18 19:36:07 +00:00
|
|
|
pos.y -= dy;
|
2020-03-06 20:02:58 +00:00
|
|
|
field.SetTextPos( pos );
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-04 22:51:22 +00:00
|
|
|
void SCH_SYMBOL::Rotate( const VECTOR2I& aCenter, bool aRotateCCW )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I prev = m_pos;
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2024-04-04 22:51:22 +00:00
|
|
|
RotatePoint( m_pos, aCenter, aRotateCCW ? ANGLE_270 : ANGLE_90 );
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2024-04-04 22:51:22 +00:00
|
|
|
SetOrientation( aRotateCCW ? SYM_ROTATE_CLOCKWISE : SYM_ROTATE_COUNTERCLOCKWISE );
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2020-11-16 13:15:54 +00:00
|
|
|
for( SCH_FIELD& field : m_fields )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2021-03-25 21:13:01 +00:00
|
|
|
// Move the fields to the new position because the symbol itself has moved.
|
2021-12-29 21:30:11 +00:00
|
|
|
VECTOR2I pos = field.GetTextPos();
|
2020-11-16 13:15:54 +00:00
|
|
|
pos.x -= prev.x - m_pos.x;
|
|
|
|
pos.y -= prev.y - m_pos.y;
|
2020-03-06 12:05:21 +00:00
|
|
|
field.SetTextPos( pos );
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-05 02:40:38 +00:00
|
|
|
bool SCH_SYMBOL::Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
|
2010-03-16 18:22:59 +00:00
|
|
|
{
|
2021-03-25 21:13:01 +00:00
|
|
|
// Symbols are searchable via the child field and pin item text.
|
2010-03-16 18:22:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
2010-11-03 14:13:15 +00:00
|
|
|
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
void SCH_SYMBOL::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
2024-04-09 11:55:44 +00:00
|
|
|
for( std::unique_ptr<SCH_PIN>& pin : m_pins )
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
2024-04-20 09:44:34 +00:00
|
|
|
SCH_PIN* lib_pin = pin->GetLibPin();
|
2010-11-03 14:13:15 +00:00
|
|
|
|
2024-01-24 17:17:54 +00:00
|
|
|
if( lib_pin && lib_pin->GetUnit() && m_unit && ( m_unit != lib_pin->GetUnit() ) )
|
2020-02-08 18:32:11 +00:00
|
|
|
continue;
|
2010-11-03 14:13:15 +00:00
|
|
|
|
2024-02-01 08:00:13 +00:00
|
|
|
DANGLING_END_ITEM item( PIN_END, lib_pin, GetPinPhysicalPosition( lib_pin ), this );
|
|
|
|
aItemList.push_back( item );
|
2010-11-03 14:13:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-02-12 08:01:45 +00:00
|
|
|
bool SCH_SYMBOL::UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemListByType,
|
|
|
|
std::vector<DANGLING_END_ITEM>& aItemListByPos,
|
|
|
|
const SCH_SHEET_PATH* aPath )
|
2015-06-08 00:07:42 +00:00
|
|
|
{
|
2017-12-11 03:28:34 +00:00
|
|
|
bool changed = false;
|
2015-06-08 00:07:42 +00:00
|
|
|
|
2020-04-11 12:00:38 +00:00
|
|
|
for( std::unique_ptr<SCH_PIN>& pin : m_pins )
|
2015-06-08 00:07:42 +00:00
|
|
|
{
|
2020-01-17 02:33:16 +00:00
|
|
|
bool previousState = pin->IsDangling();
|
|
|
|
pin->SetIsDangling( true );
|
2015-07-20 19:49:32 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I pos = m_transform.TransformCoordinate( pin->GetLocalPosition() ) + m_pos;
|
2015-06-08 00:07:42 +00:00
|
|
|
|
2024-02-12 08:01:45 +00:00
|
|
|
auto lower = DANGLING_END_ITEM_HELPER::get_lower_pos( aItemListByPos, pos );
|
|
|
|
bool do_break = false;
|
|
|
|
|
|
|
|
for( auto it = lower; it < aItemListByPos.end() && it->GetPosition() == pos; it++ )
|
2017-12-11 03:28:34 +00:00
|
|
|
{
|
2024-02-12 08:01:45 +00:00
|
|
|
DANGLING_END_ITEM& each_item = *it;
|
2017-12-11 03:28:34 +00:00
|
|
|
// Some people like to stack pins on top of each other in a symbol to indicate
|
|
|
|
// internal connection. While technically connected, it is not particularly useful
|
|
|
|
// to display them that way, so skip any pins that are in the same symbol as this
|
|
|
|
// one.
|
|
|
|
if( each_item.GetParent() == this )
|
|
|
|
continue;
|
2015-06-08 00:07:42 +00:00
|
|
|
|
2017-12-11 03:28:34 +00:00
|
|
|
switch( each_item.GetType() )
|
|
|
|
{
|
|
|
|
case PIN_END:
|
|
|
|
case LABEL_END:
|
|
|
|
case SHEET_LABEL_END:
|
2021-09-24 11:18:54 +00:00
|
|
|
case WIRE_END:
|
2017-12-11 03:28:34 +00:00
|
|
|
case NO_CONNECT_END:
|
|
|
|
case JUNCTION_END:
|
2024-02-12 08:01:45 +00:00
|
|
|
pin->SetIsDangling( false );
|
|
|
|
do_break = true;
|
2017-12-11 03:28:34 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-02-12 08:01:45 +00:00
|
|
|
if( do_break )
|
2017-12-11 03:28:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-01-17 02:33:16 +00:00
|
|
|
changed = ( changed || ( previousState != pin->IsDangling() ) );
|
2015-06-08 00:07:42 +00:00
|
|
|
}
|
2017-12-11 03:28:34 +00:00
|
|
|
|
2015-06-08 00:07:42 +00:00
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-20 09:44:34 +00:00
|
|
|
VECTOR2I SCH_SYMBOL::GetPinPhysicalPosition( const SCH_PIN* Pin ) const
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
2024-04-20 09:44:34 +00:00
|
|
|
wxCHECK_MSG( Pin != nullptr && Pin->Type() == SCH_PIN_T, VECTOR2I( 0, 0 ),
|
2010-11-03 14:13:15 +00:00
|
|
|
wxT( "Cannot get physical position of pin." ) );
|
|
|
|
|
2020-11-16 13:15:54 +00:00
|
|
|
return m_transform.TransformCoordinate( Pin->GetPosition() ) + m_pos;
|
2010-11-03 14:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-03-09 13:50:26 +00:00
|
|
|
bool SCH_SYMBOL::HasConnectivityChanges( const SCH_ITEM* aItem,
|
|
|
|
const SCH_SHEET_PATH* aInstance ) const
|
|
|
|
{
|
|
|
|
// Do not compare to ourself.
|
|
|
|
if( aItem == this )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const SCH_SYMBOL* symbol = dynamic_cast<const SCH_SYMBOL*>( aItem );
|
|
|
|
|
|
|
|
// Don't compare against a different SCH_ITEM.
|
|
|
|
wxCHECK( symbol, false );
|
|
|
|
|
|
|
|
if( GetPosition() != symbol->GetPosition() )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if( GetLibId() != symbol->GetLibId() )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if( GetUnitSelection( aInstance ) != symbol->GetUnitSelection( aInstance ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if( GetRef( aInstance ) != symbol->GetRef( aInstance ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Power symbol value field changes are connectivity changes.
|
|
|
|
if( IsPower()
|
2024-04-05 21:35:32 +00:00
|
|
|
&& ( GetValue( true, aInstance, false ) != symbol->GetValue( true, aInstance, false ) ) )
|
2024-03-09 13:50:26 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
if( m_pins.size() != symbol->m_pins.size() )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
for( size_t i = 0; i < m_pins.size(); i++ )
|
|
|
|
{
|
|
|
|
if( m_pins[i]->HasConnectivityChanges( symbol->m_pins[i].get() ) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
std::vector<VECTOR2I> SCH_SYMBOL::GetConnectionPoints() const
|
2017-12-11 03:28:34 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
std::vector<VECTOR2I> retval;
|
2020-09-08 13:27:13 +00:00
|
|
|
|
2020-04-11 12:00:38 +00:00
|
|
|
for( const std::unique_ptr<SCH_PIN>& pin : m_pins )
|
2020-04-03 15:40:59 +00:00
|
|
|
{
|
|
|
|
// Collect only pins attached to the current unit and convert.
|
2021-03-25 21:13:01 +00:00
|
|
|
// others are not associated to this symbol instance
|
2024-01-26 16:16:13 +00:00
|
|
|
int pin_unit = pin->GetLibPin() ? pin->GetLibPin()->GetUnit()
|
|
|
|
: GetUnit();
|
|
|
|
int pin_bodyStyle = pin->GetLibPin() ? pin->GetLibPin()->GetBodyStyle()
|
|
|
|
: GetBodyStyle();
|
2020-04-03 15:40:59 +00:00
|
|
|
|
|
|
|
if( pin_unit > 0 && pin_unit != GetUnit() )
|
|
|
|
continue;
|
|
|
|
|
2024-01-26 16:16:13 +00:00
|
|
|
if( pin_bodyStyle > 0 && pin_bodyStyle != GetBodyStyle() )
|
2020-04-03 15:40:59 +00:00
|
|
|
continue;
|
|
|
|
|
2020-11-16 13:15:54 +00:00
|
|
|
retval.push_back( m_transform.TransformCoordinate( pin->GetLocalPosition() ) + m_pos );
|
2020-04-03 15:40:59 +00:00
|
|
|
}
|
2020-09-08 13:27:13 +00:00
|
|
|
|
|
|
|
return retval;
|
2017-12-11 03:28:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-06 13:14:44 +00:00
|
|
|
SCH_ITEM* SCH_SYMBOL::GetDrawItem( const VECTOR2I& aPosition, KICAD_T aType )
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
if( m_part )
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
2021-03-25 21:13:01 +00:00
|
|
|
// Calculate the position relative to the symbol.
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I libPosition = aPosition - m_pos;
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2024-01-26 16:16:13 +00:00
|
|
|
return m_part->LocateDrawItem( m_unit, m_bodyStyle, aType, libPosition, m_transform );
|
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
|
|
|
}
|
2010-12-13 15:59:00 +00:00
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
return nullptr;
|
2010-12-13 15:59:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-12 03:27:44 +00:00
|
|
|
wxString SCH_SYMBOL::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const
|
2011-03-25 19:16:05 +00:00
|
|
|
{
|
2020-09-19 16:12:00 +00:00
|
|
|
return wxString::Format( _( "Symbol %s [%s]" ),
|
2023-05-05 13:21:56 +00:00
|
|
|
KIUI::EllipsizeMenuText( GetField( REFERENCE_FIELD )->GetText() ),
|
|
|
|
KIUI::EllipsizeMenuText( GetLibId().GetLibItemName() ) );
|
2011-03-25 19:16:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-30 00:00:39 +00:00
|
|
|
INSPECT_RESULT SCH_SYMBOL::Visit( INSPECTOR aInspector, void* aTestData,
|
2022-08-21 19:54:07 +00:00
|
|
|
const std::vector<KICAD_T>& aScanTypes )
|
2010-12-13 15:59:00 +00:00
|
|
|
{
|
2022-08-20 09:27:35 +00:00
|
|
|
for( KICAD_T scanType : aScanTypes )
|
2010-12-13 15:59:00 +00:00
|
|
|
{
|
2022-08-20 09:27:35 +00:00
|
|
|
if( scanType == SCH_LOCATE_ANY_T
|
|
|
|
|| ( scanType == SCH_SYMBOL_T )
|
|
|
|
|| ( scanType == SCH_SYMBOL_LOCATE_POWER_T && m_part && m_part->IsPower() ) )
|
2010-12-13 15:59:00 +00:00
|
|
|
{
|
2022-07-30 00:00:39 +00:00
|
|
|
if( INSPECT_RESULT::QUIT == aInspector( this, aTestData ) )
|
|
|
|
return INSPECT_RESULT::QUIT;
|
2011-03-25 19:16: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
|
|
|
|
2022-08-20 09:27:35 +00:00
|
|
|
if( scanType == SCH_LOCATE_ANY_T || scanType == SCH_FIELD_T )
|
2011-03-25 19:16:05 +00:00
|
|
|
{
|
2020-11-16 13:15:54 +00:00
|
|
|
for( SCH_FIELD& field : m_fields )
|
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-07-30 00:00:39 +00:00
|
|
|
if( INSPECT_RESULT::QUIT == aInspector( &field, (void*) this ) )
|
|
|
|
return INSPECT_RESULT::QUIT;
|
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-05-08 18:56:03 +00:00
|
|
|
}
|
2010-12-13 15:59:00 +00:00
|
|
|
|
2022-08-20 09:27:35 +00:00
|
|
|
if( scanType == SCH_FIELD_LOCATE_REFERENCE_T )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2022-07-30 00:00:39 +00:00
|
|
|
if( INSPECT_RESULT::QUIT == aInspector( GetField( REFERENCE_FIELD ), (void*) this ) )
|
|
|
|
return INSPECT_RESULT::QUIT;
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
2012-12-08 17:24:49 +00:00
|
|
|
|
2022-08-20 09:27:35 +00:00
|
|
|
if( scanType == SCH_FIELD_LOCATE_VALUE_T
|
|
|
|
|| ( scanType == SCH_SYMBOL_LOCATE_POWER_T && m_part && m_part->IsPower() ) )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2022-07-30 00:00:39 +00:00
|
|
|
if( INSPECT_RESULT::QUIT == aInspector( GetField( VALUE_FIELD ), (void*) this ) )
|
|
|
|
return INSPECT_RESULT::QUIT;
|
2019-05-08 18:56:03 +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
|
|
|
|
2022-08-20 09:27:35 +00:00
|
|
|
if( scanType == SCH_FIELD_LOCATE_FOOTPRINT_T )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2022-07-30 00:00:39 +00:00
|
|
|
if( INSPECT_RESULT::QUIT == aInspector( GetField( FOOTPRINT_FIELD ), (void*) this ) )
|
|
|
|
return INSPECT_RESULT::QUIT;
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
2010-12-13 15:59:00 +00:00
|
|
|
|
2022-08-20 09:27:35 +00:00
|
|
|
if( scanType == SCH_FIELD_LOCATE_DATASHEET_T )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2022-07-30 00:00:39 +00:00
|
|
|
if( INSPECT_RESULT::QUIT == aInspector( GetField( DATASHEET_FIELD ), (void*) this ) )
|
|
|
|
return INSPECT_RESULT::QUIT;
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2022-08-20 09:27:35 +00:00
|
|
|
if( scanType == SCH_LOCATE_ANY_T || scanType == SCH_PIN_T )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2020-04-11 12:00:38 +00:00
|
|
|
for( const std::unique_ptr<SCH_PIN>& pin : m_pins )
|
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-04-03 14:34:37 +00:00
|
|
|
// Collect only pins attached to the current unit and convert.
|
2021-03-25 21:13:01 +00:00
|
|
|
// others are not associated to this symbol instance
|
2024-01-26 16:16:13 +00:00
|
|
|
int pin_unit = pin->GetLibPin() ? pin->GetLibPin()->GetUnit()
|
|
|
|
: GetUnit();
|
|
|
|
int pin_bodyStyle = pin->GetLibPin() ? pin->GetLibPin()->GetBodyStyle()
|
|
|
|
: GetBodyStyle();
|
2020-04-03 14:34:37 +00:00
|
|
|
|
|
|
|
if( pin_unit > 0 && pin_unit != GetUnit() )
|
|
|
|
continue;
|
|
|
|
|
2024-01-26 16:16:13 +00:00
|
|
|
if( pin_bodyStyle > 0 && pin_bodyStyle != GetBodyStyle() )
|
2020-04-03 14:34:37 +00:00
|
|
|
continue;
|
|
|
|
|
2022-07-30 00:00:39 +00:00
|
|
|
if( INSPECT_RESULT::QUIT == aInspector( pin.get(), (void*) this ) )
|
|
|
|
return INSPECT_RESULT::QUIT;
|
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
|
|
|
}
|
2010-12-13 15:59:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-30 00:00:39 +00:00
|
|
|
return INSPECT_RESULT::CONTINUE;
|
2011-03-25 19:16:05 +00:00
|
|
|
}
|
2010-12-13 15:59:00 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
bool SCH_SYMBOL::operator <( const SCH_ITEM& aItem ) const
|
2011-03-25 19:16:05 +00:00
|
|
|
{
|
|
|
|
if( Type() != aItem.Type() )
|
|
|
|
return Type() < aItem.Type();
|
|
|
|
|
2024-04-09 11:55:44 +00:00
|
|
|
const SCH_SYMBOL* symbol = static_cast<const SCH_SYMBOL*>( &aItem );
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
BOX2I rect = GetBodyAndPinsBoundingBox();
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2021-09-23 21:07:19 +00:00
|
|
|
if( rect.GetArea() != symbol->GetBodyAndPinsBoundingBox().GetArea() )
|
|
|
|
return rect.GetArea() < symbol->GetBodyAndPinsBoundingBox().GetArea();
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
if( m_pos.x != symbol->m_pos.x )
|
|
|
|
return m_pos.x < symbol->m_pos.x;
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
if( m_pos.y != symbol->m_pos.y )
|
|
|
|
return m_pos.y < symbol->m_pos.y;
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2020-02-20 12:11:04 +00:00
|
|
|
return m_Uuid < aItem.m_Uuid; // Ensure deterministic sort
|
2011-03-25 19:16:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
bool SCH_SYMBOL::operator==( const SCH_SYMBOL& aSymbol ) const
|
2012-02-22 21:37:34 +00:00
|
|
|
{
|
2021-03-25 21:13:01 +00:00
|
|
|
if( GetFieldCount() != aSymbol.GetFieldCount() )
|
2012-02-22 21:37:34 +00:00
|
|
|
return false;
|
|
|
|
|
2020-11-12 21:31:41 +00:00
|
|
|
for( int i = VALUE_FIELD; i < GetFieldCount(); i++ )
|
2012-02-22 21:37:34 +00:00
|
|
|
{
|
2021-03-25 21:13:01 +00:00
|
|
|
if( GetFields()[i].GetText().Cmp( aSymbol.GetFields()[i].GetText() ) != 0 )
|
2012-02-22 21:37:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
bool SCH_SYMBOL::operator!=( const SCH_SYMBOL& aSymbol ) const
|
2012-02-22 21:37:34 +00:00
|
|
|
{
|
2021-03-25 21:13:01 +00:00
|
|
|
return !( *this == aSymbol );
|
2012-02-22 21:37:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-09 11:55:44 +00:00
|
|
|
SCH_SYMBOL& SCH_SYMBOL::operator=( const SCH_SYMBOL& aSymbol )
|
2012-01-09 20:26:55 +00:00
|
|
|
{
|
2024-04-09 11:55:44 +00:00
|
|
|
wxCHECK_MSG( Type() == aSymbol.Type(), *this,
|
|
|
|
wxT( "Cannot assign object type " ) + aSymbol.GetClass() + wxT( " to type " ) +
|
2012-01-09 20:26:55 +00:00
|
|
|
GetClass() );
|
|
|
|
|
2024-04-09 11:55:44 +00:00
|
|
|
if( &aSymbol != this )
|
2012-01-09 20:26:55 +00:00
|
|
|
{
|
2024-04-09 11:55:44 +00:00
|
|
|
SYMBOL::operator=( aSymbol );
|
2019-11-06 19:15:42 +00:00
|
|
|
|
2024-04-09 11:55:44 +00:00
|
|
|
m_lib_id = aSymbol.m_lib_id;
|
|
|
|
m_part.reset( aSymbol.m_part ? new LIB_SYMBOL( *aSymbol.m_part ) : nullptr );
|
|
|
|
m_pos = aSymbol.m_pos;
|
|
|
|
m_unit = aSymbol.m_unit;
|
|
|
|
m_bodyStyle = aSymbol.m_bodyStyle;
|
|
|
|
m_transform = aSymbol.m_transform;
|
2019-11-06 19:15:42 +00:00
|
|
|
|
2024-04-09 11:55:44 +00:00
|
|
|
m_instanceReferences = aSymbol.m_instanceReferences;
|
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
|
|
|
|
2024-04-09 11:55:44 +00:00
|
|
|
m_fields = aSymbol.m_fields; // std::vector's assignment operator
|
2012-01-09 20:26:55 +00:00
|
|
|
|
2021-03-25 21:13:01 +00:00
|
|
|
// Reparent fields after assignment to new symbol.
|
2020-11-16 13:15:54 +00:00
|
|
|
for( SCH_FIELD& field : m_fields )
|
2019-04-22 10:14:47 +00:00
|
|
|
field.SetParent( this );
|
|
|
|
|
2019-12-11 23:53:10 +00:00
|
|
|
UpdatePins();
|
2012-01-09 20:26:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
bool SCH_SYMBOL::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
|
2011-03-25 19:16:05 +00:00
|
|
|
{
|
2022-08-30 23:28:18 +00:00
|
|
|
BOX2I bBox = GetBodyBoundingBox();
|
2021-11-28 18:59:55 +00:00
|
|
|
bBox.Inflate( aAccuracy / 2 );
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
if( bBox.Contains( aPosition ) )
|
2011-03-25 19:16:05 +00:00
|
|
|
return true;
|
2010-12-13 15:59:00 +00:00
|
|
|
|
|
|
|
return false;
|
2010-12-10 19:47:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-31 09:33:46 +00:00
|
|
|
bool SCH_SYMBOL::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
|
2010-12-10 19:47:44 +00:00
|
|
|
{
|
2020-11-14 18:11:28 +00:00
|
|
|
if( m_flags & STRUCT_DELETED || m_flags & SKIP_STRUCT )
|
2012-03-15 14:31:16 +00:00
|
|
|
return false;
|
|
|
|
|
2022-08-31 09:33:46 +00:00
|
|
|
BOX2I rect = aRect;
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2021-11-28 18:59:55 +00:00
|
|
|
rect.Inflate( aAccuracy / 2 );
|
2010-12-10 19:47:44 +00:00
|
|
|
|
|
|
|
if( aContained )
|
2012-03-12 10:04:40 +00:00
|
|
|
return rect.Contains( GetBodyBoundingBox() );
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2012-03-12 10:04:40 +00:00
|
|
|
return rect.Intersects( GetBodyBoundingBox() );
|
2010-12-10 19:47:44 +00:00
|
|
|
}
|
2010-12-13 15:59:00 +00:00
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
bool SCH_SYMBOL::doIsConnected( const VECTOR2I& aPosition ) const
|
2010-12-13 15:59:00 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I new_pos = m_transform.InverseTransform().TransformCoordinate( aPosition - m_pos );
|
2019-04-03 09:14:36 +00:00
|
|
|
|
2024-04-12 21:00:41 +00:00
|
|
|
for( const std::unique_ptr<SCH_PIN>& pin : m_pins )
|
2019-04-03 09:14:36 +00:00
|
|
|
{
|
2020-12-17 19:34:09 +00:00
|
|
|
if( pin->GetType() == ELECTRICAL_PINTYPE::PT_NC )
|
|
|
|
continue;
|
|
|
|
|
2020-04-03 15:40:59 +00:00
|
|
|
// Collect only pins attached to the current unit and convert.
|
2021-03-25 21:13:01 +00:00
|
|
|
// others are not associated to this symbol instance
|
2024-01-26 16:16:13 +00:00
|
|
|
int pin_unit = pin->GetLibPin() ? pin->GetLibPin()->GetUnit()
|
|
|
|
: GetUnit();
|
|
|
|
int pin_bodyStyle = pin->GetLibPin() ? pin->GetLibPin()->GetBodyStyle()
|
|
|
|
: GetBodyStyle();
|
2020-04-03 15:40:59 +00:00
|
|
|
|
|
|
|
if( pin_unit > 0 && pin_unit != GetUnit() )
|
|
|
|
continue;
|
|
|
|
|
2024-01-26 16:16:13 +00:00
|
|
|
if( pin_bodyStyle > 0 && pin_bodyStyle != GetBodyStyle() )
|
2020-04-03 15:40:59 +00:00
|
|
|
continue;
|
|
|
|
|
2020-04-24 13:36:10 +00:00
|
|
|
if( pin->GetLocalPosition() == new_pos )
|
2019-04-03 09:14:36 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2010-12-13 15:59:00 +00:00
|
|
|
}
|
2011-06-17 13:24:22 +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
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
bool SCH_SYMBOL::IsInNetlist() const
|
2013-09-27 17:58:58 +00:00
|
|
|
{
|
2019-04-09 01:54:41 +00:00
|
|
|
return m_isInNetlist;
|
2013-09-27 17:58:58 +00:00
|
|
|
}
|
2011-06-17 13:24:22 +00:00
|
|
|
|
2013-09-28 22:53:55 +00:00
|
|
|
|
2024-04-05 21:35:32 +00:00
|
|
|
void SCH_SYMBOL::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
|
|
|
|
int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed )
|
2011-06-17 13:24:22 +00:00
|
|
|
{
|
2022-02-10 19:49:25 +00:00
|
|
|
if( aBackground )
|
|
|
|
return;
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
if( m_part )
|
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
|
|
|
{
|
2024-04-20 09:44:34 +00:00
|
|
|
std::vector<SCH_PIN*> libPins = m_part->GetPins( GetUnit(), GetBodyStyle() );
|
2011-06-17 13:24:22 +00:00
|
|
|
|
2022-06-10 21:37:24 +00:00
|
|
|
// Copy the source so we can re-orient and translate it.
|
2024-04-20 09:44:34 +00:00
|
|
|
LIB_SYMBOL tempSymbol( *m_part );
|
|
|
|
std::vector<SCH_PIN*> tempPins = tempSymbol.GetPins( GetUnit(), GetBodyStyle() );
|
2022-02-10 19:49:25 +00:00
|
|
|
|
2022-06-10 21:37:24 +00:00
|
|
|
// Copy the pin info from the symbol to the temp pins
|
|
|
|
for( unsigned i = 0; i < tempPins.size(); ++ i )
|
|
|
|
{
|
|
|
|
SCH_PIN* symbolPin = GetPin( libPins[ i ] );
|
2024-04-20 09:44:34 +00:00
|
|
|
SCH_PIN* tempPin = tempPins[ i ];
|
2022-02-10 19:49:25 +00:00
|
|
|
|
2022-06-10 21:37:24 +00:00
|
|
|
tempPin->SetName( symbolPin->GetShownName() );
|
|
|
|
tempPin->SetType( symbolPin->GetType() );
|
|
|
|
tempPin->SetShape( symbolPin->GetShape() );
|
2022-02-10 19:49:25 +00:00
|
|
|
|
2022-06-10 21:37:24 +00:00
|
|
|
if( symbolPin->IsDangling() )
|
|
|
|
tempPin->SetFlags( IS_DANGLING );
|
|
|
|
}
|
2022-02-10 19:49:25 +00:00
|
|
|
|
2024-04-06 13:14:44 +00:00
|
|
|
for( SCH_ITEM& item : tempSymbol.GetDrawItems() )
|
2023-10-02 14:38:22 +00:00
|
|
|
{
|
|
|
|
if( EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( &item ) )
|
|
|
|
{
|
|
|
|
// Use SCH_FIELD's text resolver
|
2024-04-09 11:55:44 +00:00
|
|
|
SCH_FIELD dummy( this, -1 );
|
2023-10-02 14:38:22 +00:00
|
|
|
dummy.SetText( text->GetText() );
|
|
|
|
text->SetText( dummy.GetShownText( false ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-18 14:20:46 +00:00
|
|
|
SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter );
|
|
|
|
TRANSFORM savedTransform = renderSettings->m_Transform;
|
2024-04-08 13:26:48 +00:00
|
|
|
renderSettings->m_Transform = GetTransform();
|
2022-06-10 21:37:24 +00:00
|
|
|
aPlotter->StartBlock( nullptr );
|
|
|
|
|
|
|
|
for( bool local_background : { true, false } )
|
|
|
|
{
|
2024-04-05 21:35:32 +00:00
|
|
|
tempSymbol.Plot( aPlotter, local_background, aPlotOpts, GetUnit(), GetBodyStyle(),
|
|
|
|
m_pos, GetDNP() );
|
2011-06-17 13:24:22 +00:00
|
|
|
|
2023-10-02 14:38:22 +00:00
|
|
|
for( SCH_FIELD field : m_fields )
|
|
|
|
{
|
|
|
|
field.ClearRenderCache();
|
2024-04-05 21:35:32 +00:00
|
|
|
field.Plot( aPlotter, local_background, aPlotOpts, GetUnit(), GetBodyStyle(),
|
|
|
|
m_pos, GetDNP() );
|
2023-10-02 14:38:22 +00:00
|
|
|
}
|
2022-06-10 21:37:24 +00:00
|
|
|
}
|
2019-01-27 00:58:33 +00:00
|
|
|
|
2023-01-09 23:30:58 +00:00
|
|
|
if( m_DNP )
|
2024-04-18 14:20:46 +00:00
|
|
|
PlotDNP( aPlotter );
|
2023-01-09 23:30:58 +00:00
|
|
|
|
2023-10-21 20:52:51 +00:00
|
|
|
SCH_SHEET_PATH* sheet = &Schematic()->CurrentSheet();
|
2022-09-05 22:28:44 +00:00
|
|
|
|
2023-10-21 20:52:51 +00:00
|
|
|
// Plot attributes to a hypertext menu
|
2024-04-05 21:35:32 +00:00
|
|
|
if( aPlotOpts.m_PDFPropertyPopups )
|
2022-09-05 22:28:44 +00:00
|
|
|
{
|
2023-10-21 20:52:51 +00:00
|
|
|
std::vector<wxString> properties;
|
2023-07-05 09:08:25 +00:00
|
|
|
|
2023-10-21 20:52:51 +00:00
|
|
|
for( const SCH_FIELD& field : GetFields() )
|
|
|
|
{
|
|
|
|
wxString text_field = field.GetShownText( sheet, false);
|
2022-09-05 22:28:44 +00:00
|
|
|
|
2023-10-21 20:52:51 +00:00
|
|
|
if( text_field.IsEmpty() )
|
|
|
|
continue;
|
2022-09-05 22:28:44 +00:00
|
|
|
|
2023-10-21 20:52:51 +00:00
|
|
|
properties.emplace_back( wxString::Format( wxT( "!%s = %s" ),
|
|
|
|
field.GetName(), text_field ) );
|
|
|
|
}
|
2022-09-05 22:28:44 +00:00
|
|
|
|
2023-10-21 20:52:51 +00:00
|
|
|
if( !m_part->GetKeyWords().IsEmpty() )
|
|
|
|
{
|
|
|
|
properties.emplace_back( wxString::Format( wxT( "!%s = %s" ),
|
|
|
|
_( "Keywords" ),
|
|
|
|
m_part->GetKeyWords() ) );
|
|
|
|
}
|
2023-01-09 23:30:58 +00:00
|
|
|
|
2023-10-21 20:52:51 +00:00
|
|
|
aPlotter->HyperlinkMenu( GetBoundingBox(), properties );
|
|
|
|
}
|
2023-01-09 23:30:58 +00:00
|
|
|
|
2019-01-27 00:58:33 +00:00
|
|
|
aPlotter->EndBlock( nullptr );
|
2024-04-08 13:26:48 +00:00
|
|
|
renderSettings->m_Transform = savedTransform;
|
2022-09-25 01:45:48 +00:00
|
|
|
|
2022-09-25 12:50:48 +00:00
|
|
|
if( !m_part->IsPower() )
|
2023-05-05 13:21:56 +00:00
|
|
|
aPlotter->Bookmark( GetBoundingBox(), GetRef( sheet ), _( "Symbols" ) );
|
2011-06-17 13:24:22 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-24 11:17:35 +00:00
|
|
|
|
2018-12-31 12:54:26 +00:00
|
|
|
|
2024-04-18 14:20:46 +00:00
|
|
|
void SCH_SYMBOL::PlotDNP( PLOTTER* aPlotter ) const
|
|
|
|
{
|
|
|
|
COLOR_SETTINGS* colors = Pgm().GetSettingsManager().GetColorSettings();
|
|
|
|
BOX2I bbox = GetBodyAndPinsBoundingBox();
|
|
|
|
int strokeWidth = 3.0 * schIUScale.MilsToIU( DEFAULT_LINE_WIDTH_MILS );
|
|
|
|
|
|
|
|
aPlotter->SetColor( colors->GetColor( LAYER_DNP_MARKER ) );
|
|
|
|
|
|
|
|
aPlotter->ThickSegment( bbox.GetOrigin(), bbox.GetEnd(), strokeWidth, FILLED, nullptr );
|
|
|
|
|
|
|
|
aPlotter->ThickSegment( bbox.GetOrigin() + VECTOR2I( bbox.GetWidth(), 0 ),
|
|
|
|
bbox.GetOrigin() + VECTOR2I( 0, bbox.GetHeight() ),
|
|
|
|
strokeWidth, FILLED, nullptr );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-05 23:37:36 +00:00
|
|
|
void SCH_SYMBOL::PlotPins( PLOTTER* aPlotter ) const
|
|
|
|
{
|
|
|
|
if( m_part )
|
|
|
|
{
|
2024-04-08 13:26:48 +00:00
|
|
|
SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter );
|
|
|
|
TRANSFORM savedTransform = renderSettings->m_Transform;
|
|
|
|
renderSettings->m_Transform = GetTransform();
|
|
|
|
|
2024-04-20 09:44:34 +00:00
|
|
|
std::vector<SCH_PIN*> libPins = m_part->GetPins( GetUnit(), GetBodyStyle() );
|
2022-07-05 23:37:36 +00:00
|
|
|
|
|
|
|
// Copy the source to stay const
|
2024-04-20 09:44:34 +00:00
|
|
|
LIB_SYMBOL tempSymbol( *m_part );
|
|
|
|
std::vector<SCH_PIN*> tempPins = tempSymbol.GetPins( GetUnit(), GetBodyStyle() );
|
|
|
|
SCH_PLOT_OPTS plotOpts;
|
2022-07-05 23:37:36 +00:00
|
|
|
|
|
|
|
// Copy the pin info from the symbol to the temp pins
|
|
|
|
for( unsigned i = 0; i < tempPins.size(); ++ i )
|
|
|
|
{
|
|
|
|
SCH_PIN* symbolPin = GetPin( libPins[ i ] );
|
2024-04-20 09:44:34 +00:00
|
|
|
SCH_PIN* tempPin = tempPins[ i ];
|
2022-07-05 23:37:36 +00:00
|
|
|
|
|
|
|
tempPin->SetName( symbolPin->GetShownName() );
|
|
|
|
tempPin->SetType( symbolPin->GetType() );
|
|
|
|
tempPin->SetShape( symbolPin->GetShape() );
|
2024-04-05 21:35:32 +00:00
|
|
|
tempPin->Plot( aPlotter, false, plotOpts, GetUnit(), GetBodyStyle(), m_pos, GetDNP() );
|
2022-07-05 23:37:36 +00:00
|
|
|
}
|
2024-04-08 13:26:48 +00:00
|
|
|
|
|
|
|
renderSettings->m_Transform = savedTransform;
|
2022-07-05 23:37:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
bool SCH_SYMBOL::HasBrightenedPins()
|
2019-03-08 00:16:59 +00:00
|
|
|
{
|
2024-04-02 17:28:17 +00:00
|
|
|
for( const std::unique_ptr<SCH_PIN>& pin : m_pins )
|
2019-04-03 09:14:36 +00:00
|
|
|
{
|
2020-01-17 02:33:16 +00:00
|
|
|
if( pin->IsBrightened() )
|
2019-04-03 09:14:36 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2019-03-08 00:16:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
void SCH_SYMBOL::ClearBrightenedPins()
|
2019-03-08 00:16:59 +00:00
|
|
|
{
|
2024-04-02 17:28:17 +00:00
|
|
|
for( std::unique_ptr<SCH_PIN>& pin : m_pins )
|
2020-01-17 02:33:16 +00:00
|
|
|
pin->ClearBrightened();
|
2019-03-08 00:16:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
bool SCH_SYMBOL::IsPointClickableAnchor( const VECTOR2I& aPos ) const
|
2021-02-17 17:03:55 +00:00
|
|
|
{
|
2021-03-21 23:18:13 +00:00
|
|
|
for( const std::unique_ptr<SCH_PIN>& pin : m_pins )
|
|
|
|
{
|
2024-01-26 16:16:13 +00:00
|
|
|
int pin_unit = pin->GetLibPin() ? pin->GetLibPin()->GetUnit()
|
|
|
|
: GetUnit();
|
|
|
|
int pin_bodyStyle = pin->GetLibPin() ? pin->GetLibPin()->GetBodyStyle()
|
|
|
|
: GetBodyStyle();
|
2021-03-21 23:18:13 +00:00
|
|
|
|
|
|
|
if( pin_unit > 0 && pin_unit != GetUnit() )
|
|
|
|
continue;
|
|
|
|
|
2024-01-26 16:16:13 +00:00
|
|
|
if( pin_bodyStyle > 0 && pin_bodyStyle != GetBodyStyle() )
|
2021-03-21 23:18:13 +00:00
|
|
|
continue;
|
|
|
|
|
2021-02-17 17:03:55 +00:00
|
|
|
if( pin->IsPointClickableAnchor( aPos ) )
|
|
|
|
return true;
|
2021-03-21 23:18:13 +00:00
|
|
|
}
|
2021-02-17 17:03:55 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2023-03-16 14:31:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool SCH_SYMBOL::IsSymbolLikePowerGlobalLabel() const
|
|
|
|
{
|
|
|
|
// return true if the symbol is equivalent to a global label:
|
|
|
|
// It is a Power symbol
|
|
|
|
// It has only one pin type Power input
|
|
|
|
|
|
|
|
if( !GetLibSymbolRef() || !GetLibSymbolRef()->IsPower() )
|
|
|
|
return false;
|
|
|
|
|
2024-04-20 09:44:34 +00:00
|
|
|
std::vector<SCH_PIN*> pin_list = GetAllLibPins();
|
2023-03-16 14:31:39 +00:00
|
|
|
|
|
|
|
if( pin_list.size() != 1 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return pin_list[0]->GetType() == ELECTRICAL_PINTYPE::PT_POWER_IN;
|
|
|
|
}
|
|
|
|
|
2023-05-05 12:53:29 +00:00
|
|
|
|
|
|
|
bool SCH_SYMBOL::IsPower() const
|
|
|
|
{
|
|
|
|
wxCHECK( m_part, false );
|
|
|
|
|
|
|
|
return m_part->IsPower();
|
|
|
|
}
|
2023-06-21 01:57:20 +00:00
|
|
|
|
|
|
|
|
2024-04-02 17:28:17 +00:00
|
|
|
bool SCH_SYMBOL::IsNormal() const
|
|
|
|
{
|
|
|
|
wxCHECK( m_part, false );
|
|
|
|
|
|
|
|
return m_part->IsNormal();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-09-14 21:39:42 +00:00
|
|
|
bool SCH_SYMBOL::operator==( const SCH_ITEM& aOther ) const
|
|
|
|
{
|
|
|
|
if( Type() != aOther.Type() )
|
|
|
|
return false;
|
|
|
|
|
2024-04-09 11:55:44 +00:00
|
|
|
const SCH_SYMBOL& symbol = static_cast<const SCH_SYMBOL&>( aOther );
|
2023-09-14 21:39:42 +00:00
|
|
|
|
|
|
|
if( GetLibId() != symbol.GetLibId() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( GetPosition() != symbol.GetPosition() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( GetUnit() != symbol.GetUnit() )
|
|
|
|
return false;
|
|
|
|
|
2024-01-26 16:16:13 +00:00
|
|
|
if( GetBodyStyle() != symbol.GetBodyStyle() )
|
2023-09-14 21:39:42 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if( GetTransform() != symbol.GetTransform() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( GetFields() != symbol.GetFields() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( m_pins.size() != symbol.m_pins.size() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for( unsigned i = 0; i < m_pins.size(); ++i )
|
|
|
|
{
|
|
|
|
if( !( *m_pins[i] == *symbol.m_pins[i] ) )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double SCH_SYMBOL::Similarity( const SCH_ITEM& aOther ) const
|
|
|
|
{
|
|
|
|
if( Type() != aOther.Type() )
|
|
|
|
return 0.0;
|
|
|
|
|
2024-04-09 11:55:44 +00:00
|
|
|
const SCH_SYMBOL& symbol = static_cast<const SCH_SYMBOL&>( aOther );
|
2023-09-14 21:39:42 +00:00
|
|
|
|
|
|
|
if( GetLibId() != symbol.GetLibId() )
|
|
|
|
return 0.0;
|
|
|
|
|
|
|
|
if( GetPosition() == symbol.GetPosition() )
|
|
|
|
return 1.0;
|
|
|
|
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-21 01:57:20 +00:00
|
|
|
static struct SCH_SYMBOL_DESC
|
|
|
|
{
|
|
|
|
SCH_SYMBOL_DESC()
|
|
|
|
{
|
2024-01-18 16:11:33 +00:00
|
|
|
ENUM_MAP<SYMBOL_ORIENTATION_PROP>::Instance()
|
|
|
|
.Map( SYMBOL_ANGLE_0, wxS( "0" ) )
|
|
|
|
.Map( SYMBOL_ANGLE_90, wxS( "90" ) )
|
|
|
|
.Map( SYMBOL_ANGLE_180, wxS( "180" ) )
|
|
|
|
.Map( SYMBOL_ANGLE_270, wxS( "270" ) );
|
|
|
|
|
2023-06-21 01:57:20 +00:00
|
|
|
PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
|
|
|
|
REGISTER_TYPE( SCH_SYMBOL );
|
2024-04-02 17:28:17 +00:00
|
|
|
propMgr.InheritsAfter( TYPE_HASH( SCH_SYMBOL ), TYPE_HASH( SYMBOL ) );
|
2023-06-25 02:03:06 +00:00
|
|
|
|
2024-01-18 16:11:33 +00:00
|
|
|
propMgr.AddProperty( new PROPERTY<SCH_SYMBOL, int>( _HKI( "Position X" ),
|
|
|
|
&SCH_SYMBOL::SetX, &SCH_SYMBOL::GetX, PROPERTY_DISPLAY::PT_COORD,
|
|
|
|
ORIGIN_TRANSFORMS::ABS_X_COORD ) );
|
|
|
|
propMgr.AddProperty( new PROPERTY<SCH_SYMBOL, int>( _HKI( "Position Y" ),
|
|
|
|
&SCH_SYMBOL::SetY, &SCH_SYMBOL::GetY, PROPERTY_DISPLAY::PT_COORD,
|
|
|
|
ORIGIN_TRANSFORMS::ABS_Y_COORD ) );
|
|
|
|
|
|
|
|
propMgr.AddProperty( new PROPERTY_ENUM<SCH_SYMBOL, SYMBOL_ORIENTATION_PROP>(
|
2024-01-19 13:29:08 +00:00
|
|
|
_HKI( "Orientation" ),
|
|
|
|
&SCH_SYMBOL::SetOrientationProp, &SCH_SYMBOL::GetOrientationProp ) );
|
|
|
|
propMgr.AddProperty( new PROPERTY<SCH_SYMBOL, bool>( _HKI( "Mirror X" ),
|
|
|
|
&SCH_SYMBOL::SetMirrorX, &SCH_SYMBOL::GetMirrorX ) );
|
|
|
|
propMgr.AddProperty( new PROPERTY<SCH_SYMBOL, bool>( _HKI( "Mirror Y" ),
|
|
|
|
&SCH_SYMBOL::SetMirrorY, &SCH_SYMBOL::GetMirrorY ) );
|
2024-01-18 16:11:33 +00:00
|
|
|
|
2024-04-09 11:55:44 +00:00
|
|
|
auto hasLibPart =
|
|
|
|
[]( INSPECTABLE* aItem ) -> bool
|
|
|
|
{
|
|
|
|
if( SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( aItem ) )
|
|
|
|
return symbol->GetLibSymbolRef() != nullptr;
|
2024-02-06 00:08:56 +00:00
|
|
|
|
2024-04-09 11:55:44 +00:00
|
|
|
return false;
|
|
|
|
};
|
2024-02-06 00:08:56 +00:00
|
|
|
|
2024-04-18 09:58:39 +00:00
|
|
|
propMgr.AddProperty( new PROPERTY<SYMBOL, bool>( _HKI( "Pin numbers" ),
|
|
|
|
&SYMBOL::SetShowPinNumbers, &SYMBOL::GetShowPinNumbers ) )
|
2024-02-06 00:08:56 +00:00
|
|
|
.SetAvailableFunc( hasLibPart );
|
|
|
|
|
2024-04-18 09:58:39 +00:00
|
|
|
propMgr.AddProperty( new PROPERTY<SYMBOL, bool>( _HKI( "Pin names" ),
|
|
|
|
&SYMBOL::SetShowPinNames, &SYMBOL::GetShowPinNames ) )
|
2024-02-06 00:08:56 +00:00
|
|
|
.SetAvailableFunc( hasLibPart );
|
2024-01-18 16:11:33 +00:00
|
|
|
|
|
|
|
const wxString groupFields = _HKI( "Fields" );
|
|
|
|
|
|
|
|
propMgr.AddProperty( new PROPERTY<SCH_SYMBOL, wxString>( _HKI( "Reference" ),
|
|
|
|
&SCH_SYMBOL::SetRefProp, &SCH_SYMBOL::GetRefProp ),
|
|
|
|
groupFields );
|
|
|
|
propMgr.AddProperty( new PROPERTY<SCH_SYMBOL, wxString>( _HKI( "Value" ),
|
|
|
|
&SCH_SYMBOL::SetValueProp, &SCH_SYMBOL::GetValueProp ),
|
|
|
|
groupFields );
|
|
|
|
propMgr.AddProperty( new PROPERTY<SCH_SYMBOL, wxString>( _HKI( "Library Link" ),
|
|
|
|
NO_SETTER( SCH_SYMBOL, wxString ), &SCH_SYMBOL::GetSymbolIDAsString ),
|
|
|
|
groupFields );
|
|
|
|
propMgr.AddProperty( new PROPERTY<SCH_SYMBOL, wxString>( _HKI( "Library Description" ),
|
|
|
|
NO_SETTER( SCH_SYMBOL, wxString ), &SCH_SYMBOL::GetDescription ),
|
|
|
|
groupFields );
|
|
|
|
propMgr.AddProperty( new PROPERTY<SCH_SYMBOL, wxString>( _HKI( "Keywords" ),
|
|
|
|
NO_SETTER( SCH_SYMBOL, wxString ), &SCH_SYMBOL::GetKeyWords ),
|
|
|
|
groupFields );
|
|
|
|
|
2023-06-25 02:03:06 +00:00
|
|
|
const wxString groupAttributes = _HKI( "Attributes" );
|
|
|
|
|
2024-04-18 09:58:39 +00:00
|
|
|
propMgr.AddProperty( new PROPERTY<SYMBOL, bool>( _HKI( "Exclude From Board" ),
|
|
|
|
&SYMBOL::SetExcludedFromBoard, &SYMBOL::GetExcludedFromBoard ),
|
|
|
|
groupAttributes );
|
|
|
|
propMgr.AddProperty( new PROPERTY<SYMBOL, bool>( _HKI( "Exclude From Simulation" ),
|
|
|
|
&SYMBOL::SetExcludedFromSim, &SYMBOL::GetExcludedFromSim ),
|
|
|
|
groupAttributes );
|
|
|
|
propMgr.AddProperty( new PROPERTY<SYMBOL, bool>( _HKI( "Exclude From Bill of Materials" ),
|
|
|
|
&SYMBOL::SetExcludedFromBOM, &SYMBOL::GetExcludedFromBOM ),
|
|
|
|
groupAttributes );
|
|
|
|
propMgr.AddProperty( new PROPERTY<SYMBOL, bool>( _HKI( "Do not Populate" ),
|
|
|
|
&SYMBOL::SetDNP, &SYMBOL::GetDNP ),
|
|
|
|
groupAttributes );
|
2023-06-21 01:57:20 +00:00
|
|
|
}
|
|
|
|
} _SCH_SYMBOL_DESC;
|
2024-01-18 16:11:33 +00:00
|
|
|
|
|
|
|
ENUM_TO_WXANY( SYMBOL_ORIENTATION_PROP )
|