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
|
2020-01-23 14:03:46 +00:00
|
|
|
* Copyright (C) 1992-2020 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>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <lib_rectangle.h>
|
|
|
|
#include <lib_pin.h>
|
|
|
|
#include <lib_text.h>
|
|
|
|
#include <sch_component.h>
|
|
|
|
#include <sch_sheet_path.h>
|
2020-05-13 02:00:37 +00:00
|
|
|
#include <schematic.h>
|
2018-04-17 16:25:19 +00:00
|
|
|
#include <trace_helpers.h>
|
2020-10-14 03:37:48 +00:00
|
|
|
#include <trigo.h>
|
2018-04-17 16:25:19 +00:00
|
|
|
|
2008-10-06 05:44:29 +00:00
|
|
|
|
2011-07-15 13:17:41 +00:00
|
|
|
/**
|
2019-11-06 19:15:42 +00:00
|
|
|
* Convert a wxString to UTF8 and replace any control characters with a ~,
|
2011-07-15 13:17:41 +00:00
|
|
|
* where a control character is one of the first ASCII values up to ' ' 32d.
|
|
|
|
*/
|
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 );
|
|
|
|
|
|
|
|
for( std::string::iterator it = ret.begin(); it!=ret.end(); ++it )
|
|
|
|
{
|
|
|
|
if( (unsigned char) *it <= ' ' )
|
|
|
|
*it = '~';
|
|
|
|
}
|
|
|
|
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
|
|
|
/**
|
2019-07-02 20:09:23 +00:00
|
|
|
* Used to draw a dummy shape when a LIB_PART is not found in library
|
|
|
|
*
|
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
|
|
|
* This component is a 400 mils square with the text ??
|
|
|
|
* DEF DUMMY U 0 40 Y Y 1 0 N
|
|
|
|
* F0 "U" 0 -350 60 H V
|
|
|
|
* F1 "DUMMY" 0 350 60 H V
|
|
|
|
* DRAW
|
|
|
|
* T 0 0 0 150 0 0 0 ??
|
|
|
|
* S -200 200 200 -200 0 1 0
|
|
|
|
* ENDDRAW
|
|
|
|
* ENDDEF
|
2009-04-05 20:49:15 +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
|
|
|
static LIB_PART* dummy()
|
2009-04-05 20:49:15 +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
|
|
|
static LIB_PART* part;
|
|
|
|
|
|
|
|
if( !part )
|
|
|
|
{
|
|
|
|
part = new LIB_PART( wxEmptyString );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
LIB_RECTANGLE* square = new LIB_RECTANGLE( part );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2019-12-30 18:28:00 +00:00
|
|
|
square->MoveTo( wxPoint( Mils2iu( -200 ), Mils2iu( 200 ) ) );
|
|
|
|
square->SetEndPosition( wxPoint( Mils2iu( 200 ), Mils2iu( -200 ) ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
LIB_TEXT* text = new LIB_TEXT( part );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2019-12-30 18:28:00 +00:00
|
|
|
text->SetTextSize( wxSize( Mils2iu( 150 ), Mils2iu( 150 ) ) );
|
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
|
|
|
text->SetText( wxString( wxT( "??" ) ) );
|
2009-04-05 20:49:15 +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->AddDrawItem( square );
|
|
|
|
part->AddDrawItem( text );
|
|
|
|
}
|
|
|
|
|
|
|
|
return part;
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-16 17:18:23 +00:00
|
|
|
SCH_COMPONENT::SCH_COMPONENT( const wxPoint& aPos, SCH_ITEM* aParent ) :
|
2010-12-10 19:47:44 +00:00
|
|
|
SCH_ITEM( aParent, SCH_COMPONENT_T )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-10-16 17:18:23 +00:00
|
|
|
Init( aPos );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-02 19:20:40 +00:00
|
|
|
SCH_COMPONENT::SCH_COMPONENT( const LIB_PART& aPart, const LIB_ID& aLibId,
|
|
|
|
const SCH_SHEET_PATH* aSheet,
|
2019-05-01 09:24:43 +00:00
|
|
|
int unit, int convert, const wxPoint& pos ) :
|
2010-12-10 19:47:44 +00:00
|
|
|
SCH_ITEM( NULL, SCH_COMPONENT_T )
|
2008-10-06 05:44:29 +00:00
|
|
|
{
|
2009-10-16 17:18:23 +00:00
|
|
|
Init( pos );
|
2008-10-06 05:44:29 +00:00
|
|
|
|
2016-02-15 20:15:51 +00:00
|
|
|
m_unit = unit;
|
|
|
|
m_convert = convert;
|
2018-11-22 21:30:36 +00:00
|
|
|
m_lib_id = aLibId;
|
2019-12-31 13:05:52 +00:00
|
|
|
|
|
|
|
std::unique_ptr< LIB_PART > part;
|
|
|
|
|
|
|
|
part = aPart.Flatten();
|
|
|
|
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
|
|
|
|
2018-11-22 21:30:36 +00:00
|
|
|
// Copy fields from the library component
|
2017-08-25 13:27:06 +00:00
|
|
|
UpdateFields( true, true );
|
2009-10-21 20:02:25 +00:00
|
|
|
|
2018-11-22 21:30:36 +00:00
|
|
|
// Update the reference -- just the prefix for now.
|
2021-02-02 19:20:40 +00:00
|
|
|
if( aSheet )
|
|
|
|
SetRef( aSheet, m_part->GetReferenceField().GetText() + wxT( "?" ) );
|
2019-01-10 05:42:14 +00:00
|
|
|
else
|
2020-06-01 13:13:32 +00:00
|
|
|
m_prefix = m_part->GetReferenceField().GetText() + wxT( "?" );
|
2020-09-09 13:03:37 +00:00
|
|
|
|
|
|
|
// Inherit the include in bill of materials and board netlist settings from library symbol.
|
|
|
|
m_inBom = aPart.GetIncludeInBom();
|
|
|
|
m_onBoard = aPart.GetIncludeOnBoard();
|
2008-10-06 05:44:29 +00:00
|
|
|
}
|
|
|
|
|
2020-04-16 16:43:50 +00:00
|
|
|
|
2021-02-02 19:20:40 +00:00
|
|
|
SCH_COMPONENT::SCH_COMPONENT( const LIB_PART& aPart, const SCH_SHEET_PATH* aSheet,
|
|
|
|
const PICKED_SYMBOL& aSel, const wxPoint& pos ) :
|
2020-06-08 18:36:25 +00:00
|
|
|
SCH_COMPONENT( aPart, aSel.LibId, aSheet, aSel.Unit, aSel.Convert, pos )
|
2019-05-01 09:24:43 +00:00
|
|
|
{
|
|
|
|
// Set any fields that were modified as part of the component selection
|
|
|
|
for( auto const& i : aSel.Fields )
|
|
|
|
{
|
|
|
|
auto field = this->GetField( i.first );
|
|
|
|
|
|
|
|
if( field )
|
|
|
|
field->SetText( i.second );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-19 18:31:09 +00:00
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
SCH_COMPONENT::SCH_COMPONENT( const SCH_COMPONENT& aComponent ) :
|
|
|
|
SCH_ITEM( aComponent )
|
2008-10-19 18:31:09 +00:00
|
|
|
{
|
2020-11-14 18:11:28 +00:00
|
|
|
m_parent = aComponent.m_parent;
|
2020-11-16 13:15:54 +00:00
|
|
|
m_pos = aComponent.m_pos;
|
2020-01-12 13:00:42 +00:00
|
|
|
m_unit = aComponent.m_unit;
|
|
|
|
m_convert = aComponent.m_convert;
|
|
|
|
m_lib_id = aComponent.m_lib_id;
|
|
|
|
m_isInNetlist = aComponent.m_isInNetlist;
|
2020-06-03 12:30:57 +00:00
|
|
|
m_inBom = aComponent.m_inBom;
|
2020-06-09 16:50:05 +00:00
|
|
|
m_onBoard = aComponent.m_onBoard;
|
2019-11-06 19:15:42 +00:00
|
|
|
|
|
|
|
if( aComponent.m_part )
|
2020-04-16 16:43:50 +00:00
|
|
|
SetLibSymbol( new LIB_PART( *aComponent.m_part.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
|
|
|
|
2020-02-21 22:20:42 +00:00
|
|
|
const_cast<KIID&>( m_Uuid ) = aComponent.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
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
m_transform = aComponent.m_transform;
|
|
|
|
m_prefix = aComponent.m_prefix;
|
2020-02-22 21:39:59 +00:00
|
|
|
m_instanceReferences = aComponent.m_instanceReferences;
|
2020-11-16 13:15:54 +00:00
|
|
|
m_fields = aComponent.m_fields;
|
2010-12-21 15:13:09 +00:00
|
|
|
|
|
|
|
// Re-parent the fields, which before this had aComponent 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
|
|
|
|
2015-12-13 16:56:47 +00:00
|
|
|
m_fieldsAutoplaced = aComponent.m_fieldsAutoplaced;
|
2008-10-19 18:31:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-16 17:18:23 +00:00
|
|
|
void SCH_COMPONENT::Init( const wxPoint& pos )
|
|
|
|
{
|
2020-11-16 13:15:54 +00:00
|
|
|
m_pos = pos;
|
2019-04-15 13:59:36 +00:00
|
|
|
m_unit = 1; // In multi unit chip - which unit to draw.
|
|
|
|
m_convert = LIB_ITEM::LIB_CONVERT::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;
|
2020-06-03 12:30:57 +00:00
|
|
|
m_inBom = true;
|
2020-06-09 16:50:05 +00:00
|
|
|
m_onBoard = true;
|
2010-12-14 15:56:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 14:39:27 +00:00
|
|
|
EDA_ITEM* SCH_COMPONENT::Clone() const
|
2010-12-21 15:13:09 +00:00
|
|
|
{
|
|
|
|
return new SCH_COMPONENT( *this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-21 12:50:31 +00:00
|
|
|
void SCH_COMPONENT::ViewGetLayers( int aLayers[], int& aCount ) const
|
|
|
|
{
|
2019-07-30 01:57:41 +00:00
|
|
|
aCount = 3;
|
2018-10-21 12:50:31 +00:00
|
|
|
aLayers[0] = LAYER_DEVICE;
|
|
|
|
aLayers[1] = LAYER_DEVICE_BACKGROUND;
|
2019-07-30 01:57:41 +00:00
|
|
|
aLayers[2] = LAYER_SELECTION_SHADOWS;
|
2018-10-21 12:50:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-16 16:43:50 +00:00
|
|
|
void SCH_COMPONENT::SetLibId( const LIB_ID& aLibId )
|
2010-12-14 15:56:30 +00:00
|
|
|
{
|
2017-01-31 01:31:19 +00:00
|
|
|
if( m_lib_id != aLibId )
|
2010-12-14 15:56:30 +00:00
|
|
|
{
|
2017-01-31 01:31:19 +00:00
|
|
|
m_lib_id = aLibId;
|
2010-12-14 15:56:30 +00:00
|
|
|
SetModified();
|
2017-03-09 23:33:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-16 16:43:50 +00:00
|
|
|
wxString SCH_COMPONENT::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
|
|
|
|
return m_lib_id.Format().wx_str();
|
|
|
|
}
|
2017-09-01 20:42:20 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
|
2020-04-16 16:43:50 +00:00
|
|
|
void SCH_COMPONENT::SetLibSymbol( LIB_PART* aLibSymbol )
|
|
|
|
{
|
2020-05-05 14:55:54 +00:00
|
|
|
wxCHECK2( ( aLibSymbol == nullptr ) || ( aLibSymbol->IsRoot() ), aLibSymbol = nullptr );
|
|
|
|
|
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
|
|
|
|
2018-11-22 21:30:36 +00:00
|
|
|
wxString SCH_COMPONENT::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
|
|
|
|
2018-11-22 21:30:36 +00:00
|
|
|
wxString SCH_COMPONENT::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
|
|
|
|
2020-01-17 02:33:16 +00:00
|
|
|
void SCH_COMPONENT::UpdatePins()
|
2019-03-11 21:32:05 +00:00
|
|
|
{
|
2020-08-21 15:54:24 +00:00
|
|
|
std::map<wxString, wxString> altPinMap;
|
2021-01-25 22:01:49 +00:00
|
|
|
std::map<wxString, KIID> pinUuidMap;
|
2020-08-21 15:54:24 +00:00
|
|
|
|
|
|
|
for( const std::unique_ptr<SCH_PIN>& pin : m_pins )
|
|
|
|
{
|
2021-01-25 22:01:49 +00:00
|
|
|
pinUuidMap[ pin->GetNumber() ] = pin->m_Uuid;
|
|
|
|
|
2020-08-21 15:54:24 +00:00
|
|
|
if( !pin->GetAlt().IsEmpty() )
|
|
|
|
altPinMap[ pin->GetNumber() ] = pin->GetAlt();
|
|
|
|
}
|
|
|
|
|
2019-12-11 23:53:10 +00:00
|
|
|
m_pins.clear();
|
|
|
|
m_pinMap.clear();
|
|
|
|
|
2020-05-05 22:35:27 +00:00
|
|
|
if( !m_part )
|
|
|
|
return;
|
2019-04-03 09:14:36 +00:00
|
|
|
|
2020-05-05 22:35:27 +00:00
|
|
|
unsigned i = 0;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-05-05 22:35:27 +00:00
|
|
|
for( LIB_PIN* libPin = m_part->GetNextPin(); libPin; libPin = m_part->GetNextPin( libPin ) )
|
|
|
|
{
|
|
|
|
wxASSERT( libPin->Type() == LIB_PIN_T );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-05-05 22:35:27 +00:00
|
|
|
if( libPin->GetConvert() && m_convert && ( m_convert != libPin->GetConvert() ) )
|
|
|
|
continue;
|
2019-04-25 22:10:45 +00:00
|
|
|
|
2020-08-21 15:54:24 +00:00
|
|
|
m_pins.push_back( std::make_unique<SCH_PIN>( libPin, this ) );
|
2020-05-05 22:35:27 +00:00
|
|
|
|
2021-01-25 22:01:49 +00:00
|
|
|
auto ii = pinUuidMap.find( libPin->GetNumber() );
|
|
|
|
|
|
|
|
if( ii != pinUuidMap.end() )
|
|
|
|
const_cast<KIID&>( m_pins.back()->m_Uuid ) = ii->second;
|
|
|
|
|
|
|
|
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() )
|
|
|
|
m_pins.back()->SetAlt( iii->second );
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-08-21 15:54:24 +00:00
|
|
|
m_pinMap[ libPin ] = i;
|
2019-03-11 21:32:05 +00:00
|
|
|
|
2020-08-21 15:54:24 +00:00
|
|
|
++i;
|
|
|
|
}
|
2019-03-11 21:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-14 15:56:30 +00:00
|
|
|
void SCH_COMPONENT::SetUnit( int aUnit )
|
|
|
|
{
|
|
|
|
if( m_unit != aUnit )
|
|
|
|
{
|
|
|
|
m_unit = aUnit;
|
|
|
|
SetModified();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-27 15:22:25 +00:00
|
|
|
|
2013-07-05 17:48:01 +00:00
|
|
|
void SCH_COMPONENT::UpdateUnit( int aUnit )
|
|
|
|
{
|
|
|
|
m_unit = aUnit;
|
|
|
|
}
|
|
|
|
|
2010-12-14 15:56:30 +00:00
|
|
|
|
|
|
|
void SCH_COMPONENT::SetConvert( int aConvert )
|
|
|
|
{
|
|
|
|
if( m_convert != aConvert )
|
|
|
|
{
|
|
|
|
m_convert = aConvert;
|
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
|
|
|
SetModified();
|
|
|
|
}
|
2009-10-16 17:18:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-14 21:39:31 +00:00
|
|
|
void SCH_COMPONENT::SetTransform( const TRANSFORM& aTransform )
|
|
|
|
{
|
|
|
|
if( m_transform != aTransform )
|
|
|
|
{
|
|
|
|
m_transform = aTransform;
|
|
|
|
SetModified();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 SCH_COMPONENT::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
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-20 18:18:54 +00:00
|
|
|
void SCH_COMPONENT::Print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2020-04-14 12:25:00 +00:00
|
|
|
PART_DRAW_OPTIONS opts;
|
2017-02-19 18:40:26 +00:00
|
|
|
opts.transform = m_transform;
|
|
|
|
opts.draw_visible_fields = false;
|
|
|
|
opts.draw_hidden_fields = false;
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
if( m_part )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2020-11-16 13:15:54 +00:00
|
|
|
m_part->Print( aSettings, m_pos + aOffset, m_unit, m_convert, opts );
|
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.
|
|
|
|
{
|
2020-11-16 13:15:54 +00:00
|
|
|
dummy()->Print( aSettings, m_pos + aOffset, 0, 0, opts );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
|
2020-11-16 13:15:54 +00:00
|
|
|
for( SCH_FIELD& field : m_fields )
|
2020-04-14 12:25:00 +00:00
|
|
|
field.Print( aSettings, aOffset );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-22 21:39:59 +00:00
|
|
|
void SCH_COMPONENT::AddHierarchicalReference( const KIID_PATH& aPath, const wxString& aRef,
|
2020-08-29 13:41:47 +00:00
|
|
|
int aUnit, const wxString& aValue,
|
|
|
|
const wxString& aFootprint )
|
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
|
|
|
{
|
2020-08-29 13:41:47 +00:00
|
|
|
wxLogTrace( traceSchSheetPaths, "Removing symbol instance:\n"
|
|
|
|
" sheet path %s\n"
|
|
|
|
" reference %s, unit %d from symbol %s.",
|
|
|
|
aPath.AsString(),
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-15 17:03:27 +00:00
|
|
|
SYMBOL_INSTANCE_REFERENCE instance;
|
2020-02-22 21:39:59 +00:00
|
|
|
instance.m_Path = aPath;
|
|
|
|
instance.m_Reference = aRef;
|
|
|
|
instance.m_Unit = aUnit;
|
2020-08-29 13:41:47 +00:00
|
|
|
instance.m_Value = aValue;
|
|
|
|
instance.m_Footprint = aFootprint;
|
2020-04-26 20:53:29 +00:00
|
|
|
|
2020-08-29 13:41:47 +00:00
|
|
|
wxLogTrace( traceSchSheetPaths, "Adding symbol instance:\n"
|
|
|
|
" sheet path %s\n"
|
|
|
|
" reference %s, unit %d to symbol %s.",
|
|
|
|
aPath.AsString(),
|
|
|
|
aRef,
|
|
|
|
aUnit,
|
|
|
|
m_Uuid.AsString() );
|
2020-04-26 20:53:29 +00:00
|
|
|
|
2020-02-22 21:39:59 +00:00
|
|
|
m_instanceReferences.push_back( instance );
|
2008-02-12 21:12:46 +00:00
|
|
|
}
|
|
|
|
|
2008-02-21 12:21:01 +00:00
|
|
|
|
2020-08-29 13:41:47 +00:00
|
|
|
const wxString SCH_COMPONENT::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;
|
2008-02-21 12:21:01 +00:00
|
|
|
|
2020-11-15 17:03:27 +00:00
|
|
|
for( const SYMBOL_INSTANCE_REFERENCE& 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;
|
|
|
|
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
|
|
|
|
// the same component references, but perhaps this is best.
|
2020-11-12 21:31:41 +00:00
|
|
|
if( ref.IsEmpty() && !GetField( REFERENCE_FIELD )->GetText().IsEmpty() )
|
2008-02-21 12:21:01 +00:00
|
|
|
{
|
2020-11-12 21:31:41 +00:00
|
|
|
const_cast<SCH_COMPONENT*>( this )->SetRef( sheet, GetField( REFERENCE_FIELD )->GetText() );
|
|
|
|
ref = GetField( REFERENCE_FIELD )->GetText();
|
2008-02-21 12:21:01 +00:00
|
|
|
}
|
2011-12-07 18:47:59 +00:00
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
if( ref.IsEmpty() )
|
|
|
|
ref = m_prefix;
|
|
|
|
|
2020-04-11 19:11:29 +00:00
|
|
|
if( aIncludeUnit && GetUnitCount() > 1 )
|
2020-03-16 11:05:01 +00:00
|
|
|
ref += LIB_PART::SubReference( GetUnit() );
|
|
|
|
|
|
|
|
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
|
|
|
|
2011-12-14 17:25:42 +00:00
|
|
|
bool SCH_COMPONENT::IsReferenceStringValid( const wxString& aReferenceString )
|
2011-05-31 16:29:14 +00:00
|
|
|
{
|
|
|
|
wxString text = aReferenceString;
|
|
|
|
bool ok = true;
|
|
|
|
|
|
|
|
// Try to unannotate this reference
|
2019-03-04 19:40:23 +00:00
|
|
|
while( !text.IsEmpty() && ( text.Last() == '?' || wxIsdigit( text.Last() ) ) )
|
2011-05-31 16:29:14 +00:00
|
|
|
text.RemoveLast();
|
|
|
|
|
|
|
|
if( text.IsEmpty() )
|
|
|
|
ok = false;
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-02-15 20:18:32 +00:00
|
|
|
void SCH_COMPONENT::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();
|
|
|
|
bool notInArray = true;
|
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
|
2020-11-15 17:03:27 +00:00
|
|
|
for( SYMBOL_INSTANCE_REFERENCE& 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
|
|
|
{
|
2020-02-22 21:39:59 +00:00
|
|
|
instance.m_Reference = ref;
|
2008-02-21 12:21:01 +00:00
|
|
|
notInArray = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( notInArray )
|
2010-12-14 15:56:30 +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 );
|
|
|
|
|
2020-11-12 21:31:41 +00:00
|
|
|
SCH_FIELD* rf = GetField( REFERENCE_FIELD );
|
2008-10-06 05:44:29 +00:00
|
|
|
|
2019-12-30 18:28:00 +00:00
|
|
|
// @todo Should we really be checking for what is a "reasonable" position?
|
2013-03-18 19:36:07 +00:00
|
|
|
if( rf->GetText().IsEmpty()
|
2020-11-16 13:15:54 +00:00
|
|
|
|| ( abs( rf->GetTextPos().x - m_pos.x ) +
|
|
|
|
abs( rf->GetTextPos().y - m_pos.y ) > Mils2iu( 10000 ) ) )
|
2008-02-21 12:21:01 +00:00
|
|
|
{
|
2008-10-06 05:44:29 +00:00
|
|
|
// move it to a reasonable position
|
2020-11-16 13:15:54 +00:00
|
|
|
rf->SetTextPos( m_pos + wxPoint( Mils2iu( 50 ), Mils2iu( 50 ) ) );
|
2008-02-21 12:21:01 +00:00
|
|
|
}
|
2008-10-06 05:44:29 +00:00
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
rf->SetText( ref ); // for drawing.
|
2009-10-30 19:26:25 +00:00
|
|
|
|
2010-12-14 15:56:30 +00:00
|
|
|
// Reinit the m_prefix member if needed
|
2009-10-27 19:30:32 +00:00
|
|
|
wxString prefix = ref;
|
2011-12-07 18:47:59 +00:00
|
|
|
|
2011-05-31 16:29:14 +00:00
|
|
|
if( IsReferenceStringValid( prefix ) )
|
|
|
|
{
|
2019-03-04 19:40:23 +00:00
|
|
|
while( prefix.Last() == '?' || wxIsdigit( prefix.Last() ) )
|
2011-05-31 16:29:14 +00:00
|
|
|
prefix.RemoveLast();
|
|
|
|
}
|
|
|
|
else
|
2011-12-07 18:47:59 +00:00
|
|
|
{
|
2011-12-12 20:59:43 +00:00
|
|
|
prefix = wxT( "U" ); // Set to default ref prefix
|
2011-12-07 18:47:59 +00:00
|
|
|
}
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2010-12-14 15:56:30 +00:00
|
|
|
if( m_prefix != prefix )
|
|
|
|
m_prefix = prefix;
|
2019-04-09 01:54:41 +00:00
|
|
|
|
|
|
|
// Power components have references starting with # and are not included in netlists
|
|
|
|
m_isInNetlist = ! ref.StartsWith( wxT( "#" ) );
|
2008-02-12 21:12:46 +00:00
|
|
|
}
|
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2019-05-19 15:40:14 +00:00
|
|
|
bool SCH_COMPONENT::IsAnnotated( const SCH_SHEET_PATH* aSheet )
|
|
|
|
{
|
2020-02-22 21:39:59 +00:00
|
|
|
KIID_PATH path = aSheet->Path();
|
2019-05-19 15:40:14 +00:00
|
|
|
|
2020-11-15 17:03:27 +00:00
|
|
|
for( const SYMBOL_INSTANCE_REFERENCE& 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-17 02:33:16 +00:00
|
|
|
int SCH_COMPONENT::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
|
|
|
|
2020-11-15 17:03:27 +00:00
|
|
|
for( const SYMBOL_INSTANCE_REFERENCE& 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-17 02:33:16 +00:00
|
|
|
void SCH_COMPONENT::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
|
2020-11-15 17:03:27 +00:00
|
|
|
for( SYMBOL_INSTANCE_REFERENCE& 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
|
|
|
|
AddHierarchicalReference( path, m_prefix, aUnitSelection );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-21 20:00:09 +00:00
|
|
|
void SCH_COMPONENT::SetUnitSelection( int aUnitSelection )
|
|
|
|
{
|
|
|
|
for( SYMBOL_INSTANCE_REFERENCE& instance : m_instanceReferences )
|
|
|
|
instance.m_Unit = aUnitSelection;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-17 21:36:17 +00:00
|
|
|
const wxString SCH_COMPONENT::GetValue( const SCH_SHEET_PATH* sheet, bool aResolve ) const
|
2020-08-29 13:41:47 +00:00
|
|
|
{
|
|
|
|
KIID_PATH path = sheet->Path();
|
|
|
|
|
2020-11-15 17:03:27 +00:00
|
|
|
for( const SYMBOL_INSTANCE_REFERENCE& instance : m_instanceReferences )
|
2020-08-29 13:41:47 +00:00
|
|
|
{
|
2020-09-06 12:05:07 +00:00
|
|
|
if( instance.m_Path == path && !instance.m_Value.IsEmpty() )
|
2020-08-29 13:41:47 +00:00
|
|
|
{
|
2020-11-18 17:31:57 +00:00
|
|
|
// This can only be an override from an Update Schematic from PCB, and therefore
|
|
|
|
// will always be fully resolved.
|
|
|
|
return instance.m_Value;
|
2020-08-29 13:41:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-17 21:36:17 +00:00
|
|
|
if( !aResolve )
|
|
|
|
return GetField( VALUE_FIELD )->GetText();
|
|
|
|
|
2020-11-12 21:31:41 +00:00
|
|
|
return GetField( VALUE_FIELD )->GetShownText();
|
2020-08-29 13:41:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_COMPONENT::SetValue( const SCH_SHEET_PATH* sheet, const wxString& aValue )
|
|
|
|
{
|
2020-09-06 12:05:07 +00:00
|
|
|
if( sheet == nullptr )
|
|
|
|
{
|
|
|
|
// Clear instance overrides and set primary field value
|
2020-11-15 17:03:27 +00:00
|
|
|
for( SYMBOL_INSTANCE_REFERENCE& instance : m_instanceReferences )
|
2020-09-06 12:05:07 +00:00
|
|
|
instance.m_Value = wxEmptyString;
|
|
|
|
|
2020-11-16 13:15:54 +00:00
|
|
|
m_fields[ VALUE_FIELD ].SetText( aValue );
|
2020-09-06 12:05:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-29 13:41:47 +00:00
|
|
|
KIID_PATH path = sheet->Path();
|
|
|
|
|
|
|
|
// check to see if it is already there before inserting it
|
2020-11-15 17:03:27 +00:00
|
|
|
for( SYMBOL_INSTANCE_REFERENCE& instance : m_instanceReferences )
|
2020-08-29 13:41:47 +00:00
|
|
|
{
|
|
|
|
if( instance.m_Path == path )
|
|
|
|
{
|
|
|
|
instance.m_Value = aValue;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// didn't find it; better add it
|
|
|
|
AddHierarchicalReference( path, m_prefix, m_unit, aValue, wxEmptyString );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-17 21:36:17 +00:00
|
|
|
const wxString SCH_COMPONENT::GetFootprint( const SCH_SHEET_PATH* sheet, bool aResolve ) const
|
2020-08-29 13:41:47 +00:00
|
|
|
{
|
|
|
|
KIID_PATH path = sheet->Path();
|
|
|
|
|
2020-11-15 17:03:27 +00:00
|
|
|
for( const SYMBOL_INSTANCE_REFERENCE& instance : m_instanceReferences )
|
2020-08-29 13:41:47 +00:00
|
|
|
{
|
|
|
|
if( instance.m_Path == path && !instance.m_Footprint.IsEmpty() )
|
|
|
|
{
|
2020-11-18 17:31:57 +00:00
|
|
|
// This can only be an override from an Update Schematic from PCB, and therefore
|
|
|
|
// will always be fully resolved.
|
|
|
|
return instance.m_Footprint;
|
2020-08-29 13:41:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-17 21:36:17 +00:00
|
|
|
if( !aResolve )
|
|
|
|
return GetField( FOOTPRINT_FIELD )->GetText();
|
|
|
|
|
2020-11-12 21:31:41 +00:00
|
|
|
return GetField( FOOTPRINT_FIELD )->GetShownText();
|
2020-08-29 13:41:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_COMPONENT::SetFootprint( const SCH_SHEET_PATH* sheet, const wxString& aFootprint )
|
|
|
|
{
|
2020-09-06 12:05:07 +00:00
|
|
|
if( sheet == nullptr )
|
|
|
|
{
|
|
|
|
// Clear instance overrides and set primary field value
|
2020-11-15 17:03:27 +00:00
|
|
|
for( SYMBOL_INSTANCE_REFERENCE& instance : m_instanceReferences )
|
2020-09-08 10:01:13 +00:00
|
|
|
instance.m_Footprint = wxEmptyString;
|
2020-09-06 12:05:07 +00:00
|
|
|
|
2020-11-16 13:15:54 +00:00
|
|
|
m_fields[ FOOTPRINT_FIELD ].SetText( aFootprint );
|
2020-09-06 12:05:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-29 13:41:47 +00:00
|
|
|
KIID_PATH path = sheet->Path();
|
|
|
|
|
|
|
|
// check to see if it is already there before inserting it
|
2020-11-15 17:03:27 +00:00
|
|
|
for( SYMBOL_INSTANCE_REFERENCE& instance : m_instanceReferences )
|
2020-08-29 13:41:47 +00:00
|
|
|
{
|
|
|
|
if( instance.m_Path == path )
|
|
|
|
{
|
|
|
|
instance.m_Footprint = aFootprint;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// didn't find it; better add it
|
|
|
|
AddHierarchicalReference( path, m_prefix, m_unit, wxEmptyString, aFootprint );
|
2008-04-16 08:40:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-08 19:22:59 +00:00
|
|
|
SCH_FIELD* SCH_COMPONENT::GetField( int aFieldNdx )
|
2007-09-20 21:06:49 +00:00
|
|
|
{
|
2020-11-16 13:15:54 +00:00
|
|
|
if( (unsigned) aFieldNdx < m_fields.size() )
|
|
|
|
return &m_fields[aFieldNdx];
|
2020-05-08 19:22:59 +00:00
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
2008-02-21 12:21:01 +00:00
|
|
|
|
|
|
|
|
2020-05-08 19:22:59 +00:00
|
|
|
const SCH_FIELD* SCH_COMPONENT::GetField( int aFieldNdx ) const
|
|
|
|
{
|
2020-11-16 13:15:54 +00:00
|
|
|
if( (unsigned) aFieldNdx < m_fields.size() )
|
|
|
|
return &m_fields[aFieldNdx];
|
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
|
|
|
|
2018-05-29 21:46:13 +00:00
|
|
|
wxString SCH_COMPONENT::GetFieldText( const wxString& aFieldName, SCH_EDIT_FRAME* aFrame ) 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
|
|
|
{
|
2020-10-19 17:35:22 +00:00
|
|
|
if( aFieldName == field.GetName() || aFieldName == field.GetCanonicalName() )
|
2019-07-02 20:09:23 +00:00
|
|
|
return field.GetText();
|
2017-04-02 12:09:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return wxEmptyString;
|
|
|
|
}
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2015-12-13 16:56:47 +00:00
|
|
|
void SCH_COMPONENT::GetFields( std::vector<SCH_FIELD*>& aVector, bool aVisibleOnly )
|
|
|
|
{
|
2020-11-16 13:15:54 +00:00
|
|
|
for( SCH_FIELD& field : m_fields )
|
2015-12-13 16:56:47 +00:00
|
|
|
{
|
2019-07-02 20:09:23 +00:00
|
|
|
if( !aVisibleOnly || ( field.IsVisible() && !field.IsVoid() ) )
|
|
|
|
aVector.push_back( &field );
|
2015-12-13 16:56:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
SCH_FIELD* SCH_COMPONENT::AddField( const SCH_FIELD& aField )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2020-11-16 13:15:54 +00:00
|
|
|
int newNdx = m_fields.size();
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2020-11-16 13:15:54 +00:00
|
|
|
m_fields.push_back( aField );
|
|
|
|
return &m_fields[newNdx];
|
2010-06-17 16:30:10 +00:00
|
|
|
}
|
|
|
|
|
2017-06-27 15:22:25 +00:00
|
|
|
|
2018-07-31 21:59:43 +00:00
|
|
|
void SCH_COMPONENT::RemoveField( const wxString& aFieldName )
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-22 14:05:36 +00:00
|
|
|
SCH_FIELD* SCH_COMPONENT::FindField( const wxString& aFieldName, bool aIncludeDefaultFields )
|
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
|
|
|
{
|
2020-11-16 13:15:54 +00:00
|
|
|
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
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
return NULL;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-25 13:27:06 +00:00
|
|
|
void SCH_COMPONENT::UpdateFields( bool aResetStyle, bool aResetRef )
|
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
if( m_part )
|
2017-08-25 13:27:06 +00:00
|
|
|
{
|
2020-12-15 15:06:19 +00:00
|
|
|
wxString symbolName;
|
|
|
|
std::vector<LIB_FIELD*> fields;
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
m_part->GetFields( fields );
|
2017-08-25 13:27:06 +00:00
|
|
|
|
2020-12-15 15:06:19 +00:00
|
|
|
for( const LIB_FIELD* libField : fields )
|
2017-08-25 13:27:06 +00:00
|
|
|
{
|
2020-12-15 15:06:19 +00:00
|
|
|
int idx = libField->GetId();
|
2017-08-25 13:27:06 +00:00
|
|
|
SCH_FIELD* schField;
|
|
|
|
|
2020-11-12 21:31:41 +00:00
|
|
|
if( idx == REFERENCE_FIELD && !aResetRef )
|
2017-08-25 13:27:06 +00:00
|
|
|
continue;
|
2019-05-22 23:18:24 +00:00
|
|
|
|
2020-04-01 14:00:40 +00:00
|
|
|
if( idx >= 0 && idx < MANDATORY_FIELDS )
|
2020-06-01 13:13:32 +00:00
|
|
|
{
|
2017-08-25 13:27:06 +00:00
|
|
|
schField = GetField( idx );
|
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();
|
2020-04-18 20:04:41 +00:00
|
|
|
SCH_FIELD newField( wxPoint( 0, 0), GetFieldCount(), this, fieldName );
|
2020-03-26 11:02:59 +00:00
|
|
|
schField = AddField( newField );
|
|
|
|
}
|
2017-08-25 13:27:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( aResetStyle )
|
|
|
|
{
|
2020-12-15 15:06:19 +00:00
|
|
|
schField->ImportValues( *libField );
|
|
|
|
schField->SetTextPos( m_pos + libField->GetTextPos() );
|
2017-08-25 13:27:06 +00:00
|
|
|
}
|
|
|
|
|
2020-11-12 21:31:41 +00:00
|
|
|
if( idx == VALUE_FIELD )
|
2019-05-22 23:18:24 +00:00
|
|
|
{
|
2018-11-22 21:30:36 +00:00
|
|
|
schField->SetText( m_lib_id.GetLibItemName() ); // fetch alias-specific value
|
2019-05-22 23:18:24 +00:00
|
|
|
symbolName = m_lib_id.GetLibItemName();
|
|
|
|
}
|
2020-11-12 21:31:41 +00:00
|
|
|
else if( idx == DATASHEET_FIELD )
|
2019-05-22 23:18:24 +00:00
|
|
|
{
|
2018-11-22 21:30:36 +00:00
|
|
|
schField->SetText( GetDatasheet() ); // fetch alias-specific value
|
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
|
|
|
{
|
2020-12-15 15:06:19 +00:00
|
|
|
schField->SetText( libField->GetText() );
|
2019-05-22 23:18:24 +00:00
|
|
|
}
|
2017-08-25 13:27:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-17 16:02:47 +00:00
|
|
|
void SCH_COMPONENT::RunOnChildren( const std::function<void( SCH_ITEM* )>& aFunction )
|
|
|
|
{
|
|
|
|
for( const std::unique_ptr<SCH_PIN>& pin : m_pins )
|
|
|
|
aFunction( pin.get() );
|
|
|
|
|
|
|
|
for( SCH_FIELD& field : m_fields )
|
|
|
|
aFunction( &field );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-20 18:44:13 +00:00
|
|
|
SCH_PIN* SCH_COMPONENT::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
|
|
|
|
2020-12-20 18:44:13 +00:00
|
|
|
void SCH_COMPONENT::GetLibPins( std::vector<LIB_PIN*>& aPinsList ) const
|
2015-12-13 16:56:47 +00:00
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
if( m_part )
|
|
|
|
m_part->GetPins( aPinsList, m_unit, m_convert );
|
2015-12-13 16:56:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-21 15:54:24 +00:00
|
|
|
SCH_PIN* SCH_COMPONENT::GetPin( LIB_PIN* aLibPin )
|
2020-01-17 02:33:16 +00:00
|
|
|
{
|
2020-08-21 15:54:24 +00:00
|
|
|
wxASSERT( m_pinMap.count( aLibPin ) );
|
|
|
|
return m_pins[ m_pinMap.at( aLibPin ) ].get();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<SCH_PIN*> SCH_COMPONENT::GetPins( const SCH_SHEET_PATH* aSheet ) const
|
|
|
|
{
|
|
|
|
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
|
|
|
{
|
2020-08-21 15:54:24 +00:00
|
|
|
wxCHECK_MSG( Schematic(), pins, "Can't call GetPins on a component 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 );
|
|
|
|
|
|
|
|
for( const auto& p : m_pins )
|
|
|
|
{
|
|
|
|
if( unit && p->GetLibPin()->GetUnit() && ( p->GetLibPin()->GetUnit() != unit ) )
|
|
|
|
continue;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-08 17:41:52 +00:00
|
|
|
void SCH_COMPONENT::SwapData( SCH_ITEM* aItem )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-04-08 17:41:52 +00:00
|
|
|
wxCHECK_RET( (aItem != NULL) && (aItem->Type() == SCH_COMPONENT_T),
|
|
|
|
wxT( "Cannot swap data with invalid component." ) );
|
|
|
|
|
|
|
|
SCH_COMPONENT* component = (SCH_COMPONENT*) aItem;
|
|
|
|
|
2017-01-31 01:31:19 +00:00
|
|
|
std::swap( m_lib_id, component->m_lib_id );
|
2019-11-06 19:15:42 +00:00
|
|
|
|
|
|
|
LIB_PART* part = component->m_part.release();
|
|
|
|
component->m_part.reset( m_part.release() );
|
2019-12-11 23:53:10 +00:00
|
|
|
component->UpdatePins();
|
2019-11-06 19:15:42 +00:00
|
|
|
m_part.reset( part );
|
2019-12-11 23:53:10 +00:00
|
|
|
UpdatePins();
|
2019-11-06 19:15:42 +00:00
|
|
|
|
2020-11-16 13:15:54 +00:00
|
|
|
std::swap( m_pos, component->m_pos );
|
2015-06-26 13:41:56 +00:00
|
|
|
std::swap( m_unit, component->m_unit );
|
|
|
|
std::swap( m_convert, component->m_convert );
|
2008-10-06 05:44:29 +00:00
|
|
|
|
2020-11-16 13:15:54 +00:00
|
|
|
m_fields.swap( component->m_fields ); // std::vector's swap()
|
2008-10-18 13:42:21 +00:00
|
|
|
|
2020-11-16 13:15:54 +00:00
|
|
|
for( SCH_FIELD& field : component->m_fields )
|
2020-03-06 20:02:58 +00:00
|
|
|
field.SetParent( component );
|
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;
|
|
|
|
|
|
|
|
m_transform = component->m_transform;
|
|
|
|
component->m_transform = tmp;
|
|
|
|
|
2020-02-22 21:39:59 +00:00
|
|
|
std::swap( m_instanceReferences, component->m_instanceReferences );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-27 22:28:36 +00:00
|
|
|
void SCH_COMPONENT::GetContextualTextVars( wxArrayString* aVars ) const
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
aVars->push_back( wxT( "FOOTPRINT_LIBRARY" ) );
|
|
|
|
aVars->push_back( wxT( "FOOTPRINT_NAME" ) );
|
|
|
|
aVars->push_back( wxT( "UNIT" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-06 13:06:57 +00:00
|
|
|
bool SCH_COMPONENT::ResolveTextVar( wxString* token, int aDepth ) const
|
|
|
|
{
|
2020-08-29 13:41:47 +00:00
|
|
|
SCHEMATIC* schematic = Schematic();
|
|
|
|
|
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
|
|
|
{
|
2020-11-12 21:31:41 +00:00
|
|
|
if( i == REFERENCE_FIELD && schematic )
|
2020-08-29 13:41:47 +00:00
|
|
|
*token = GetRef( &schematic->CurrentSheet(), true );
|
2020-11-12 21:31:41 +00:00
|
|
|
else if( i == VALUE_FIELD && schematic )
|
2020-11-17 21:36:17 +00:00
|
|
|
*token = GetValue( &schematic->CurrentSheet(), true );
|
2020-11-12 21:31:41 +00:00
|
|
|
else if( i == FOOTPRINT_FIELD && schematic )
|
2020-11-17 21:36:17 +00:00
|
|
|
*token = GetFootprint( &schematic->CurrentSheet(), true );
|
2020-08-29 13:41:47 +00:00
|
|
|
else
|
2020-11-16 13:15:54 +00:00
|
|
|
*token = m_fields[ i ].GetShownText( 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
|
|
|
{
|
2020-11-16 13:15:54 +00:00
|
|
|
*token = m_fields[ i ].GetShownText( aDepth + 1 );
|
2020-04-06 13:06:57 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( token->IsSameAs( wxT( "FOOTPRINT_LIBRARY" ) ) )
|
|
|
|
{
|
2020-08-29 13:41:47 +00:00
|
|
|
wxString footprint;
|
|
|
|
|
|
|
|
if( schematic )
|
2020-11-17 21:36:17 +00:00
|
|
|
footprint = GetFootprint( &schematic->CurrentSheet(), true );
|
2020-08-29 13:41:47 +00:00
|
|
|
else
|
2020-11-16 13:15:54 +00:00
|
|
|
footprint = m_fields[ FOOTPRINT_FIELD ].GetShownText();
|
2020-08-29 13:41:47 +00:00
|
|
|
|
|
|
|
wxArrayString parts = wxSplit( footprint, ':' );
|
2020-04-06 13:06:57 +00:00
|
|
|
|
|
|
|
*token = parts[ 0 ];
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if( token->IsSameAs( wxT( "FOOTPRINT_NAME" ) ) )
|
|
|
|
{
|
2020-08-29 13:41:47 +00:00
|
|
|
wxString footprint;
|
|
|
|
|
|
|
|
if( schematic )
|
2020-11-17 21:36:17 +00:00
|
|
|
footprint = GetFootprint( &schematic->CurrentSheet(), true );
|
2020-08-29 13:41:47 +00:00
|
|
|
else
|
2020-11-16 13:15:54 +00:00
|
|
|
footprint = m_fields[ FOOTPRINT_FIELD ].GetShownText();
|
2020-08-29 13:41:47 +00:00
|
|
|
|
|
|
|
wxArrayString parts = wxSplit( footprint, ':' );
|
2020-04-06 13:06:57 +00:00
|
|
|
|
|
|
|
*token = parts[ std::min( 1, (int) parts.size() - 1 ) ];
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if( token->IsSameAs( wxT( "UNIT" ) ) )
|
|
|
|
{
|
2020-08-29 13:41:47 +00:00
|
|
|
int unit;
|
|
|
|
|
|
|
|
if( schematic )
|
|
|
|
unit = GetUnitSelection( &schematic->CurrentSheet() );
|
|
|
|
else
|
|
|
|
unit = GetUnit();
|
|
|
|
|
|
|
|
*token = LIB_PART::SubReference( unit );
|
2020-04-06 13:06:57 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-06 10:26:39 +00:00
|
|
|
void SCH_COMPONENT::ClearAnnotation( const SCH_SHEET_PATH* aSheetPath )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-05-31 16:29:14 +00:00
|
|
|
// Build a reference with no annotation,
|
|
|
|
// i.e. a reference ended by only one '?'
|
|
|
|
wxString defRef = m_prefix;
|
2011-12-07 18:47:59 +00:00
|
|
|
|
2018-06-08 04:34:17 +00:00
|
|
|
if( !IsReferenceStringValid( defRef ) )
|
2011-05-31 16:29:14 +00:00
|
|
|
{ // This is a malformed reference: reinit this reference
|
2016-02-15 20:22:45 +00:00
|
|
|
m_prefix = defRef = wxT("U"); // Set to default ref prefix
|
2011-05-31 16:29:14 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2018-06-08 04:34:17 +00:00
|
|
|
while( defRef.Last() == '?' )
|
|
|
|
defRef.RemoveLast();
|
|
|
|
|
2008-02-21 12:21:01 +00:00
|
|
|
defRef.Append( wxT( "?" ) );
|
2008-04-15 19:38:19 +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
|
|
|
|
2020-11-15 17:03:27 +00:00
|
|
|
for( SYMBOL_INSTANCE_REFERENCE& instance : m_instanceReferences )
|
2008-04-21 06:34:56 +00:00
|
|
|
{
|
2020-02-22 21:39:59 +00:00
|
|
|
if( instance.m_Path == path )
|
|
|
|
instance.m_Reference = defRef;
|
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
|
|
|
|
{
|
2020-11-15 17:03:27 +00:00
|
|
|
for( SYMBOL_INSTANCE_REFERENCE& instance : m_instanceReferences )
|
2020-02-22 21:39:59 +00:00
|
|
|
instance.m_Reference = defRef;
|
|
|
|
}
|
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.
|
2020-11-16 13:15:54 +00:00
|
|
|
m_fields[REFERENCE_FIELD].SetText( defRef ); //for drawing.
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2020-02-22 21:39:59 +00:00
|
|
|
bool SCH_COMPONENT::AddSheetPathReferenceEntryIfMissing( const KIID_PATH& aSheetPath )
|
2018-09-03 10:11:39 +00:00
|
|
|
{
|
2018-09-04 16:46:03 +00:00
|
|
|
// a empty sheet path is illegal:
|
2020-02-22 21:39:59 +00:00
|
|
|
wxCHECK( aSheetPath.size() > 0, false );
|
2018-09-03 10:11:39 +00:00
|
|
|
|
|
|
|
wxString reference_path;
|
|
|
|
|
2020-11-15 17:03:27 +00:00
|
|
|
for( const SYMBOL_INSTANCE_REFERENCE& 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-26 20:53:29 +00:00
|
|
|
bool SCH_COMPONENT::ReplaceInstanceSheetPath( const KIID_PATH& aOldSheetPath,
|
|
|
|
const KIID_PATH& aNewSheetPath )
|
|
|
|
{
|
|
|
|
auto it = std::find_if( m_instanceReferences.begin(), m_instanceReferences.end(),
|
2020-11-15 17:03:27 +00:00
|
|
|
[ aOldSheetPath ]( SYMBOL_INSTANCE_REFERENCE& r )->bool
|
2020-04-26 20:53:29 +00:00
|
|
|
{
|
|
|
|
return aOldSheetPath == r.m_Path;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
if( it != m_instanceReferences.end() )
|
|
|
|
{
|
|
|
|
wxLogTrace( traceSchSheetPaths,
|
|
|
|
"Replacing sheet path %s\n with sheet path %s\n for symbol %s.",
|
|
|
|
aOldSheetPath.AsString(), aNewSheetPath.AsString(), m_Uuid.AsString() );
|
|
|
|
|
|
|
|
it->m_Path = aNewSheetPath;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxLogTrace( traceSchSheetPaths,
|
|
|
|
"Could not find sheet path %s\n to replace with sheet path %s\n for symbol %s.",
|
|
|
|
aOldSheetPath.AsString(), aNewSheetPath.AsString(), m_Uuid.AsString() );
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-13 21:15:54 +00:00
|
|
|
void SCH_COMPONENT::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
|
|
|
{
|
|
|
|
case CMP_ORIENT_0:
|
2010-12-23 10:00:55 +00:00
|
|
|
case CMP_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;
|
|
|
|
|
2014-02-22 12:39:59 +00:00
|
|
|
case CMP_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;
|
|
|
|
|
2014-02-22 12:39:59 +00:00
|
|
|
case CMP_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;
|
|
|
|
|
2010-12-23 10:00:55 +00:00
|
|
|
case CMP_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;
|
|
|
|
|
2010-12-23 10:00:55 +00:00
|
|
|
case CMP_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;
|
|
|
|
|
|
|
|
case CMP_ORIENT_90:
|
2010-01-13 21:15:54 +00:00
|
|
|
SetOrientation( CMP_ORIENT_0 );
|
|
|
|
SetOrientation( CMP_ROTATE_COUNTERCLOCKWISE );
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CMP_ORIENT_180:
|
2010-01-13 21:15:54 +00:00
|
|
|
SetOrientation( CMP_ORIENT_0 );
|
|
|
|
SetOrientation( CMP_ROTATE_COUNTERCLOCKWISE );
|
|
|
|
SetOrientation( CMP_ROTATE_COUNTERCLOCKWISE );
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CMP_ORIENT_270:
|
2010-01-13 21:15:54 +00:00
|
|
|
SetOrientation( CMP_ORIENT_0 );
|
|
|
|
SetOrientation( CMP_ROTATE_CLOCKWISE );
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
2010-01-13 21:15:54 +00:00
|
|
|
case ( CMP_ORIENT_0 + CMP_MIRROR_X ):
|
|
|
|
SetOrientation( CMP_ORIENT_0 );
|
|
|
|
SetOrientation( CMP_MIRROR_X );
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
2010-01-13 21:15:54 +00:00
|
|
|
case ( CMP_ORIENT_0 + CMP_MIRROR_Y ):
|
|
|
|
SetOrientation( CMP_ORIENT_0 );
|
|
|
|
SetOrientation( CMP_MIRROR_Y );
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
2010-01-13 21:15:54 +00:00
|
|
|
case ( CMP_ORIENT_90 + CMP_MIRROR_X ):
|
|
|
|
SetOrientation( CMP_ORIENT_90 );
|
|
|
|
SetOrientation( CMP_MIRROR_X );
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
2010-01-13 21:15:54 +00:00
|
|
|
case ( CMP_ORIENT_90 + CMP_MIRROR_Y ):
|
|
|
|
SetOrientation( CMP_ORIENT_90 );
|
|
|
|
SetOrientation( CMP_MIRROR_Y );
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
2010-01-13 21:15:54 +00:00
|
|
|
case ( CMP_ORIENT_180 + CMP_MIRROR_X ):
|
|
|
|
SetOrientation( CMP_ORIENT_180 );
|
|
|
|
SetOrientation( CMP_MIRROR_X );
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
2010-01-13 21:15:54 +00:00
|
|
|
case ( CMP_ORIENT_180 + CMP_MIRROR_Y ):
|
|
|
|
SetOrientation( CMP_ORIENT_180 );
|
|
|
|
SetOrientation( CMP_MIRROR_Y );
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
2010-01-13 21:15:54 +00:00
|
|
|
case ( CMP_ORIENT_270 + CMP_MIRROR_X ):
|
|
|
|
SetOrientation( CMP_ORIENT_270 );
|
|
|
|
SetOrientation( CMP_MIRROR_X );
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
2010-01-13 21:15:54 +00:00
|
|
|
case ( CMP_ORIENT_270 + CMP_MIRROR_Y ):
|
|
|
|
SetOrientation( CMP_ORIENT_270 );
|
|
|
|
SetOrientation( CMP_MIRROR_Y );
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-13 21:15:54 +00:00
|
|
|
int SCH_COMPONENT::GetOrientation()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2018-09-01 23:29:19 +00:00
|
|
|
int rotate_values[] =
|
2007-09-20 21:06:49 +00:00
|
|
|
{
|
2018-09-01 23:29:19 +00:00
|
|
|
CMP_ORIENT_0,
|
|
|
|
CMP_ORIENT_90,
|
|
|
|
CMP_ORIENT_180,
|
2010-09-05 17:01:48 +00:00
|
|
|
CMP_ORIENT_270,
|
2018-09-01 23:29:19 +00:00
|
|
|
CMP_MIRROR_X + CMP_ORIENT_0,
|
|
|
|
CMP_MIRROR_X + CMP_ORIENT_90,
|
|
|
|
CMP_MIRROR_X + CMP_ORIENT_270,
|
|
|
|
CMP_MIRROR_Y,
|
|
|
|
CMP_MIRROR_Y + CMP_ORIENT_0,
|
|
|
|
CMP_MIRROR_Y + CMP_ORIENT_90,
|
|
|
|
CMP_MIRROR_Y + CMP_ORIENT_180,
|
|
|
|
CMP_MIRROR_Y + CMP_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;
|
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
|
|
|
{
|
2010-01-13 21:15:54 +00:00
|
|
|
SetOrientation( type_rotate );
|
2010-10-20 20:24:26 +00:00
|
|
|
|
2010-12-14 21:39:31 +00:00
|
|
|
if( transform == m_transform )
|
2009-04-09 11:34:41 +00:00
|
|
|
return type_rotate;
|
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-12-14 21:39:31 +00:00
|
|
|
m_transform = transform;
|
2010-10-20 20:24:26 +00:00
|
|
|
|
2009-04-09 11:34:41 +00:00
|
|
|
return CMP_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
|
|
|
|
2011-12-14 17:25:42 +00:00
|
|
|
void SCH_COMPONENT::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()
|
2011-03-25 19:16:05 +00:00
|
|
|
<< " ref=\"" << TO_UTF8( GetField( 0 )->GetName() )
|
2009-12-02 21:44:03 +00:00
|
|
|
<< '"' << " chipName=\""
|
2020-11-16 13:15:54 +00:00
|
|
|
<< GetLibId().Format() << '"' << 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
|
|
|
{
|
2013-03-18 19:36:07 +00:00
|
|
|
wxString value = GetField( 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=\""
|
2011-03-25 19:16:05 +00:00
|
|
|
<< TO_UTF8( GetField( 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
|
|
|
|
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT SCH_COMPONENT::GetBodyBoundingBox() const
|
2008-04-15 19:38:19 +00:00
|
|
|
{
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
EDA_RECT bBox;
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
if( m_part )
|
|
|
|
bBox = m_part->GetBodyBoundingBox( m_unit, m_convert );
|
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
|
|
|
|
bBox = dummy()->GetBodyBoundingBox( m_unit, m_convert );
|
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 );
|
2010-12-13 15:59:00 +00:00
|
|
|
return bBox;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
const EDA_RECT SCH_COMPONENT::GetBoundingBox() const
|
2010-12-13 15:59:00 +00:00
|
|
|
{
|
2012-03-12 10:04:40 +00:00
|
|
|
EDA_RECT bbox = GetBodyBoundingBox();
|
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-11-16 13:15:54 +00:00
|
|
|
for( const SCH_FIELD& field : m_fields )
|
2020-04-11 12:00:38 +00:00
|
|
|
bbox.Merge( field.GetBoundingBox() );
|
2012-03-12 10:04:40 +00:00
|
|
|
|
|
|
|
return bbox;
|
2008-04-12 18:39:20 +00:00
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
|
2020-08-13 06:50:41 +00:00
|
|
|
const EDA_RECT SCH_COMPONENT::GetBoundingBox( bool aIncludeInvisibleText ) const
|
|
|
|
{
|
|
|
|
EDA_RECT bbox = GetBodyBoundingBox();
|
|
|
|
|
2020-11-16 13:15:54 +00:00
|
|
|
for( const SCH_FIELD& field : m_fields )
|
2020-08-13 06:50:41 +00:00
|
|
|
{
|
|
|
|
if( field.IsVisible() || aIncludeInvisibleText )
|
|
|
|
bbox.Merge( field.GetBoundingBox() );
|
|
|
|
}
|
|
|
|
|
|
|
|
return bbox;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-24 13:36:10 +00:00
|
|
|
void SCH_COMPONENT::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, MSG_PANEL_ITEMS& 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
|
|
|
|
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
|
|
|
{
|
2020-11-18 15:36:47 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Reference" ), GetRef( currentSheet ) ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
msg = m_part->IsPower() ? _( "Power symbol" ) : _( "Value" );
|
2010-12-13 15:59:00 +00:00
|
|
|
|
2020-11-18 15:36:47 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( msg, GetValue( currentSheet, true ) ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2020-05-22 18:25:43 +00:00
|
|
|
#if 0 // Display component flags, for debug only
|
2020-11-18 15:36:47 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "flags" ), wxString::Format( "%X",
|
|
|
|
GetEditFlags() ) ) );
|
2020-05-22 18:25:43 +00:00
|
|
|
#endif
|
|
|
|
|
2017-08-01 19:34:34 +00:00
|
|
|
// Display component reference in library and library
|
2020-11-18 15:36:47 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Name" ), GetLibId().GetLibItemName() ) );
|
2010-12-13 15:59:00 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
if( !m_part->IsRoot() )
|
|
|
|
{
|
|
|
|
msg = _( "Missing parent" );
|
|
|
|
|
|
|
|
std::shared_ptr< LIB_PART > 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();
|
|
|
|
|
2020-11-18 15:36:47 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Alias of" ), 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
|
|
|
{
|
2020-11-18 15:36:47 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "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
|
|
|
{
|
2020-11-18 15:36:47 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "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.
|
2020-11-17 21:36:17 +00:00
|
|
|
msg = GetFootprint( currentSheet, true );
|
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
|
|
|
|
2020-11-18 15:36:47 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Footprint" ), msg ) );
|
2013-02-11 18:50:55 +00:00
|
|
|
|
2017-08-01 19:34:34 +00:00
|
|
|
// Display description of the component, and keywords found in lib
|
2019-11-06 19:15:42 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Description" ), m_part->GetDescription(),
|
2017-08-01 19:34:34 +00:00
|
|
|
DARKCYAN ) );
|
2020-11-18 15:36:47 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Keywords" ), m_part->GetKeyWords() ) );
|
2017-08-01 19:34:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-18 15:36:47 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Reference" ), GetRef( currentSheet ) ) );
|
2017-08-01 19:34:34 +00:00
|
|
|
|
2020-11-18 15:36:47 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Value" ), GetValue( currentSheet, true ) ) );
|
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Name" ), GetLibId().GetLibItemName() ) );
|
2017-10-22 00:48:25 +00:00
|
|
|
|
|
|
|
wxString libNickname = GetLibId().GetLibNickname();
|
|
|
|
|
|
|
|
if( libNickname.empty() )
|
|
|
|
{
|
2020-11-18 15:36:47 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Library" ), _( "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 );
|
2020-11-18 15:36:47 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Library" ), msg ) );
|
2017-10-22 00:48:25 +00:00
|
|
|
}
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
2009-07-27 14:32:40 +00:00
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2017-02-20 12:20:39 +00:00
|
|
|
BITMAP_DEF SCH_COMPONENT::GetMenuImage() const
|
|
|
|
{
|
|
|
|
return add_component_xpm;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-16 20:45:25 +00:00
|
|
|
void SCH_COMPONENT::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
|
|
|
|
2010-01-13 21:15:54 +00:00
|
|
|
SetOrientation( CMP_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
|
|
|
{
|
2013-03-18 19:36:07 +00:00
|
|
|
// Move the fields to the new position because the component itself has moved.
|
2020-03-06 20:02:58 +00:00
|
|
|
wxPoint 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-02-16 20:45:25 +00:00
|
|
|
void SCH_COMPONENT::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
|
|
|
|
|
|
|
SetOrientation( CMP_MIRROR_X );
|
2021-02-16 20:45:25 +00:00
|
|
|
MIRROR( m_pos.y, aCenter );
|
2020-11-16 13:15:54 +00:00
|
|
|
dy -= m_pos.y; // dy,0 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
|
|
|
{
|
2013-03-18 19:36:07 +00:00
|
|
|
// Move the fields to the new position because the component itself has moved.
|
2020-03-06 20:02:58 +00:00
|
|
|
wxPoint 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
void SCH_COMPONENT::Rotate( wxPoint aPosition )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2020-11-16 13:15:54 +00:00
|
|
|
wxPoint prev = m_pos;
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2020-11-16 13:15:54 +00:00
|
|
|
RotatePoint( &m_pos, aPosition, 900 );
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2014-02-22 12:39:59 +00:00
|
|
|
SetOrientation( CMP_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
|
|
|
{
|
2013-03-18 19:36:07 +00:00
|
|
|
// Move the fields to the new position because the component itself has moved.
|
2020-03-06 12:05:21 +00:00
|
|
|
wxPoint 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-20 18:27:51 +00:00
|
|
|
bool SCH_COMPONENT::Matches( const wxFindReplaceData& aSearchData, void* aAuxData ) const
|
2010-03-16 18:22:59 +00:00
|
|
|
{
|
2019-12-20 14:11:39 +00:00
|
|
|
wxLogTrace( traceFindItem, wxT( " item " ) + GetSelectMenuText( EDA_UNITS::MILLIMETRES ) );
|
2010-10-20 19:43:58 +00:00
|
|
|
|
2011-12-01 16:49:28 +00:00
|
|
|
// Components 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
|
|
|
|
|
|
|
|
|
|
|
void SCH_COMPONENT::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
|
|
|
|
{
|
2020-02-08 18:32:11 +00:00
|
|
|
for( auto& pin : m_pins )
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
2020-02-08 18:32:11 +00:00
|
|
|
LIB_PIN* lib_pin = pin->GetLibPin();
|
2010-11-03 14:13:15 +00:00
|
|
|
|
2020-02-08 18:32:11 +00:00
|
|
|
if( lib_pin->GetUnit() && m_unit && ( m_unit != lib_pin->GetUnit() ) )
|
|
|
|
continue;
|
2010-11-03 14:13:15 +00:00
|
|
|
|
2020-02-08 18:32:11 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-17 02:33:16 +00:00
|
|
|
bool SCH_COMPONENT::UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
|
|
|
|
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
|
|
|
|
2020-11-16 13:15:54 +00:00
|
|
|
wxPoint pos = m_transform.TransformCoordinate( pin->GetLocalPosition() ) + m_pos;
|
2015-06-08 00:07:42 +00:00
|
|
|
|
2017-12-11 03:28:34 +00:00
|
|
|
for( DANGLING_END_ITEM& each_item : aItemList )
|
|
|
|
{
|
|
|
|
// 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:
|
|
|
|
case WIRE_START_END:
|
|
|
|
case WIRE_END_END:
|
|
|
|
case NO_CONNECT_END:
|
|
|
|
case JUNCTION_END:
|
2015-06-08 00:07:42 +00:00
|
|
|
|
2017-12-11 03:28:34 +00:00
|
|
|
if( pos == each_item.GetPosition() )
|
2020-01-17 02:33:16 +00:00
|
|
|
pin->SetIsDangling( false );
|
2017-12-11 03:28:34 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-01-17 02:33:16 +00:00
|
|
|
if( !pin->IsDangling() )
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-12 16:10:22 +00:00
|
|
|
wxPoint SCH_COMPONENT::GetPinPhysicalPosition( const LIB_PIN* Pin ) const
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
wxCHECK_MSG( Pin != NULL && Pin->Type() == LIB_PIN_T, wxPoint( 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-08 13:27:13 +00:00
|
|
|
std::vector<wxPoint> SCH_COMPONENT::GetConnectionPoints() const
|
2017-12-11 03:28:34 +00:00
|
|
|
{
|
2020-09-08 13:27:13 +00:00
|
|
|
std::vector<wxPoint> retval;
|
|
|
|
|
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.
|
|
|
|
// others are not associated to this component instance
|
2020-04-11 12:00:38 +00:00
|
|
|
int pin_unit = pin->GetLibPin()->GetUnit();
|
|
|
|
int pin_convert = pin->GetLibPin()->GetConvert();
|
2020-04-03 15:40:59 +00:00
|
|
|
|
|
|
|
if( pin_unit > 0 && pin_unit != GetUnit() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( pin_convert > 0 && pin_convert != GetConvert() )
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LIB_ITEM* SCH_COMPONENT::GetDrawItem( const wxPoint& 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
|
|
|
{
|
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
|
|
|
// Calculate the position relative to the component.
|
2020-11-16 13:15:54 +00:00
|
|
|
wxPoint libPosition = aPosition - m_pos;
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
return m_part->LocateDrawItem( m_unit, m_convert, 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
|
|
|
|
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 NULL;
|
2010-12-13 15:59:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-20 14:11:39 +00:00
|
|
|
wxString SCH_COMPONENT::GetSelectMenuText( EDA_UNITS aUnits ) const
|
2011-03-25 19:16:05 +00:00
|
|
|
{
|
2020-09-19 16:12:00 +00:00
|
|
|
return wxString::Format( _( "Symbol %s [%s]" ),
|
2020-11-12 21:31:41 +00:00
|
|
|
GetField( REFERENCE_FIELD )->GetShownText(),
|
2020-09-19 16:12:00 +00:00
|
|
|
GetLibId().GetLibItemName().wx_str() );
|
2011-03-25 19:16:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-12 19:05:54 +00:00
|
|
|
SEARCH_RESULT SCH_COMPONENT::Visit( INSPECTOR aInspector, void* aTestData,
|
2011-03-25 19:16:05 +00:00
|
|
|
const KICAD_T aFilterTypes[] )
|
2010-12-13 15:59:00 +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
|
|
|
KICAD_T stype;
|
2010-12-13 15:59:00 +00:00
|
|
|
|
2012-12-08 17:24:49 +00:00
|
|
|
for( const KICAD_T* p = aFilterTypes; (stype = *p) != EOT; ++p )
|
2010-12-13 15:59:00 +00:00
|
|
|
{
|
2020-04-11 12:00:38 +00:00
|
|
|
if( stype == SCH_LOCATE_ANY_T
|
|
|
|
|| ( stype == SCH_COMPONENT_T )
|
|
|
|
|| ( stype == SCH_COMPONENT_LOCATE_POWER_T && m_part && m_part->IsPower() ) )
|
2010-12-13 15:59:00 +00:00
|
|
|
{
|
2019-12-28 00:55:11 +00:00
|
|
|
if( SEARCH_RESULT::QUIT == aInspector( this, aTestData ) )
|
|
|
|
return SEARCH_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
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
if( stype == SCH_LOCATE_ANY_T || stype == 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
|
|
|
{
|
2020-03-06 20:02:58 +00:00
|
|
|
if( SEARCH_RESULT::QUIT == aInspector( &field, (void*) this ) )
|
2019-12-28 00:55:11 +00:00
|
|
|
return SEARCH_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
|
|
|
|
2019-05-17 00:41:49 +00:00
|
|
|
if( stype == SCH_FIELD_LOCATE_REFERENCE_T )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2020-11-12 21:31:41 +00:00
|
|
|
if( SEARCH_RESULT::QUIT == aInspector( GetField( REFERENCE_FIELD ), (void*) this ) )
|
2019-12-28 00:55:11 +00:00
|
|
|
return SEARCH_RESULT::QUIT;
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
2012-12-08 17:24:49 +00:00
|
|
|
|
2020-04-11 20:55:49 +00:00
|
|
|
if( stype == SCH_FIELD_LOCATE_VALUE_T
|
|
|
|
|| ( stype == SCH_COMPONENT_LOCATE_POWER_T && m_part && m_part->IsPower() ) )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2020-11-12 21:31:41 +00:00
|
|
|
if( SEARCH_RESULT::QUIT == aInspector( GetField( VALUE_FIELD ), (void*) this ) )
|
2019-12-28 00:55:11 +00:00
|
|
|
return SEARCH_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
|
|
|
|
2019-05-17 00:41:49 +00:00
|
|
|
if( stype == SCH_FIELD_LOCATE_FOOTPRINT_T )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2020-11-12 21:31:41 +00:00
|
|
|
if( SEARCH_RESULT::QUIT == aInspector( GetField( FOOTPRINT_FIELD ), (void*) this ) )
|
2019-12-28 00:55:11 +00:00
|
|
|
return SEARCH_RESULT::QUIT;
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
2010-12-13 15:59:00 +00:00
|
|
|
|
2019-05-17 00:41:49 +00:00
|
|
|
if( stype == SCH_FIELD_LOCATE_DATASHEET_T )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2020-11-12 21:31:41 +00:00
|
|
|
if( SEARCH_RESULT::QUIT == aInspector( GetField( DATASHEET_FIELD ), (void*) this ) )
|
2019-12-28 00:55:11 +00:00
|
|
|
return SEARCH_RESULT::QUIT;
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
if( stype == SCH_LOCATE_ANY_T || stype == SCH_PIN_T )
|
|
|
|
{
|
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.
|
|
|
|
// others are not associated to this component instance
|
2020-04-11 12:00:38 +00:00
|
|
|
int pin_unit = pin->GetLibPin()->GetUnit();
|
|
|
|
int pin_convert = pin->GetLibPin()->GetConvert();
|
2020-04-03 14:34:37 +00:00
|
|
|
|
|
|
|
if( pin_unit > 0 && pin_unit != GetUnit() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( pin_convert > 0 && pin_convert != GetConvert() )
|
|
|
|
continue;
|
|
|
|
|
2020-01-17 02:33:16 +00:00
|
|
|
if( SEARCH_RESULT::QUIT == aInspector( pin.get(), (void*) this ) )
|
2019-12-28 00:55:11 +00:00
|
|
|
return SEARCH_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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-28 00:55:11 +00:00
|
|
|
return SEARCH_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
|
|
|
|
|
|
|
bool SCH_COMPONENT::operator <( const SCH_ITEM& aItem ) const
|
|
|
|
{
|
|
|
|
if( Type() != aItem.Type() )
|
|
|
|
return Type() < aItem.Type();
|
|
|
|
|
2020-01-28 15:42:42 +00:00
|
|
|
auto component = static_cast<const SCH_COMPONENT*>( &aItem );
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT rect = GetBodyBoundingBox();
|
2011-03-25 19:16:05 +00:00
|
|
|
|
|
|
|
if( rect.GetArea() != component->GetBodyBoundingBox().GetArea() )
|
|
|
|
return rect.GetArea() < component->GetBodyBoundingBox().GetArea();
|
|
|
|
|
2020-11-16 13:15:54 +00:00
|
|
|
if( m_pos.x != component->m_pos.x )
|
|
|
|
return m_pos.x < component->m_pos.x;
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2020-11-16 13:15:54 +00:00
|
|
|
if( m_pos.y != component->m_pos.y )
|
|
|
|
return m_pos.y < component->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
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-22 21:37:34 +00:00
|
|
|
bool SCH_COMPONENT::operator==( const SCH_COMPONENT& aComponent ) const
|
|
|
|
{
|
|
|
|
if( GetFieldCount() != aComponent.GetFieldCount() )
|
|
|
|
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
|
|
|
{
|
|
|
|
if( GetField( i )->GetText().Cmp( aComponent.GetField( i )->GetText() ) != 0 )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_COMPONENT::operator!=( const SCH_COMPONENT& aComponent ) const
|
|
|
|
{
|
|
|
|
return !( *this == aComponent );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-21 23:45:34 +00:00
|
|
|
SCH_COMPONENT& SCH_COMPONENT::operator=( const SCH_ITEM& aItem )
|
2012-01-09 20:26:55 +00:00
|
|
|
{
|
|
|
|
wxCHECK_MSG( Type() == aItem.Type(), *this,
|
|
|
|
wxT( "Cannot assign object type " ) + aItem.GetClass() + wxT( " to type " ) +
|
|
|
|
GetClass() );
|
|
|
|
|
|
|
|
if( &aItem != this )
|
|
|
|
{
|
|
|
|
SCH_ITEM::operator=( aItem );
|
|
|
|
|
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
|
|
|
SCH_COMPONENT* c = (SCH_COMPONENT*) &aItem;
|
2012-01-09 20:26:55 +00:00
|
|
|
|
2017-01-31 01:31:19 +00:00
|
|
|
m_lib_id = c->m_lib_id;
|
2019-11-06 19:15:42 +00:00
|
|
|
|
|
|
|
LIB_PART* libSymbol = c->m_part ? new LIB_PART( *c->m_part.get() ) : nullptr;
|
|
|
|
|
|
|
|
m_part.reset( libSymbol );
|
2020-11-16 13:15:54 +00:00
|
|
|
m_pos = c->m_pos;
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
m_unit = c->m_unit;
|
|
|
|
m_convert = c->m_convert;
|
|
|
|
m_transform = c->m_transform;
|
|
|
|
|
2020-02-22 21:39:59 +00:00
|
|
|
m_instanceReferences = c->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
|
|
|
|
2020-11-16 13:15:54 +00:00
|
|
|
m_fields = c->m_fields; // std::vector's assignment operator
|
2012-01-09 20:26:55 +00:00
|
|
|
|
|
|
|
// Reparent fields after assignment to new component.
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
bool SCH_COMPONENT::HitTest( const wxPoint& aPosition, int aAccuracy ) const
|
2011-03-25 19:16:05 +00:00
|
|
|
{
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT bBox = GetBodyBoundingBox();
|
2011-03-25 19:16:05 +00:00
|
|
|
bBox.Inflate( aAccuracy );
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
bool SCH_COMPONENT::HitTest( const EDA_RECT& 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;
|
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT rect = aRect;
|
2010-12-10 19:47:44 +00:00
|
|
|
|
|
|
|
rect.Inflate( aAccuracy );
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
bool SCH_COMPONENT::doIsConnected( const wxPoint& aPosition ) const
|
2010-12-13 15:59:00 +00:00
|
|
|
{
|
2020-11-16 13:15:54 +00:00
|
|
|
wxPoint new_pos = m_transform.InverseTransform().TransformCoordinate( aPosition - m_pos );
|
2019-04-03 09:14:36 +00:00
|
|
|
|
2020-01-17 02:33:16 +00:00
|
|
|
for( const auto& 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.
|
|
|
|
// others are not associated to this component instance
|
2020-04-24 13:36:10 +00:00
|
|
|
int pin_unit = pin->GetLibPin()->GetUnit();
|
|
|
|
int pin_convert = pin->GetLibPin()->GetConvert();
|
2020-04-03 15:40:59 +00:00
|
|
|
|
|
|
|
if( pin_unit > 0 && pin_unit != GetUnit() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( pin_convert > 0 && pin_convert != GetConvert() )
|
|
|
|
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
|
|
|
|
2013-09-27 17:58:58 +00:00
|
|
|
bool SCH_COMPONENT::IsInNetlist() const
|
|
|
|
{
|
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
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
void SCH_COMPONENT::Plot( PLOTTER* aPlotter )
|
2011-06-17 13:24:22 +00:00
|
|
|
{
|
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
|
|
|
{
|
2020-04-14 12:25:00 +00:00
|
|
|
TRANSFORM temp = GetTransform();
|
2019-01-27 00:58:33 +00:00
|
|
|
aPlotter->StartBlock( nullptr );
|
2011-06-17 13:24:22 +00:00
|
|
|
|
2020-11-16 13:15:54 +00:00
|
|
|
m_part->Plot( aPlotter, GetUnit(), GetConvert(), m_pos, temp );
|
2011-06-17 13:24:22 +00:00
|
|
|
|
2020-11-16 13:15:54 +00:00
|
|
|
for( SCH_FIELD field : m_fields )
|
2019-04-22 10:14:47 +00:00
|
|
|
field.Plot( aPlotter );
|
2019-01-27 00:58:33 +00:00
|
|
|
|
|
|
|
aPlotter->EndBlock( nullptr );
|
2011-06-17 13:24:22 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-24 11:17:35 +00:00
|
|
|
|
2018-12-31 12:54:26 +00:00
|
|
|
|
2019-03-08 00:16:59 +00:00
|
|
|
bool SCH_COMPONENT::HasBrightenedPins()
|
|
|
|
{
|
2020-01-17 02:33:16 +00:00
|
|
|
for( const auto& 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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_COMPONENT::ClearBrightenedPins()
|
|
|
|
{
|
2020-01-17 02:33:16 +00:00
|
|
|
for( auto& pin : m_pins )
|
|
|
|
pin->ClearBrightened();
|
2019-03-08 00:16:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-17 17:03:55 +00:00
|
|
|
bool SCH_COMPONENT::IsPointClickableAnchor( const wxPoint& aPos ) const
|
|
|
|
{
|
|
|
|
for( auto& pin : m_pins )
|
|
|
|
if( pin->IsPointClickableAnchor( aPos ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|