Eeschema: fix broken instance data when adding new symbol.

Pass the current SCHEMATIC object pointer in SCH_SYMBOL ctor so that
newly created symbols will update the current instance data on creation
when the current sheet instance is being displayed.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/12190
This commit is contained in:
Wayne Stambaugh 2022-08-26 12:47:13 -04:00
parent 5606714952
commit 32a11e4df0
3 changed files with 19 additions and 17 deletions

View File

@ -95,21 +95,22 @@ static LIB_SYMBOL* dummy()
}
SCH_SYMBOL::SCH_SYMBOL( const wxPoint& aPos, SCH_ITEM* aParent ) :
SCH_SYMBOL::SCH_SYMBOL( const wxPoint& aPosition, EDA_ITEM* aParent ) :
SCH_ITEM( aParent, SCH_SYMBOL_T )
{
Init( aPos );
Init( aPosition );
}
SCH_SYMBOL::SCH_SYMBOL( const LIB_SYMBOL& aSymbol, const LIB_ID& aLibId,
const SCH_SHEET_PATH* aSheet, int unit, int convert, const wxPoint& pos ) :
SCH_ITEM( nullptr, SCH_SYMBOL_T )
const SCH_SHEET_PATH* aSheet, int aUnit, int aConvert,
const wxPoint& aPosition, EDA_ITEM* aParent ) :
SCH_ITEM( aParent, SCH_SYMBOL_T )
{
Init( pos );
Init( aPosition );
m_unit = unit;
m_convert = convert;
m_unit = aUnit;
m_convert = aConvert;
m_lib_id = aLibId;
std::unique_ptr< LIB_SYMBOL > part;
@ -146,8 +147,8 @@ SCH_SYMBOL::SCH_SYMBOL( const LIB_SYMBOL& aSymbol, const LIB_ID& aLibId,
SCH_SYMBOL::SCH_SYMBOL( const LIB_SYMBOL& aSymbol, const SCH_SHEET_PATH* aSheet,
const PICKED_SYMBOL& aSel, const wxPoint& pos ) :
SCH_SYMBOL( aSymbol, aSel.LibId, aSheet, aSel.Unit, aSel.Convert, pos )
const PICKED_SYMBOL& aSel, const wxPoint& aPosition, EDA_ITEM* aParent ) :
SCH_SYMBOL( aSymbol, aSel.LibId, aSheet, aSel.Unit, aSel.Convert, aPosition, aParent )
{
// Set any fields that were modified as part of the symbol selection
for( const std::pair<int, wxString>& i : aSel.Fields )

View File

@ -78,7 +78,7 @@ extern std::string toUTFTildaText( const wxString& txt );
class SCH_SYMBOL : public SCH_ITEM
{
public:
SCH_SYMBOL( const wxPoint& pos = wxPoint( 0, 0 ), SCH_ITEM* aParent = nullptr );
SCH_SYMBOL( const wxPoint& aPosition = wxPoint( 0, 0 ), EDA_ITEM* aParent = nullptr );
/**
* Create schematic symbol from library symbol object.
@ -86,16 +86,16 @@ public:
* @param aSymbol is the library symbol to create schematic symbol from.
* @param aLibId is the #LIB_ID of alias to create.
* @param aSheet is the schematic sheet the symbol is place into.
* @param unit is unit for symbols that have multiple parts per package.
* @param convert is the alternate body style for the schematic symbols.
* @param pos is the position of the symbol.
* @param setNewItemFlag is used to set the symbol #IS_NEW and #IS_MOVING flags.
* @param aUnit is unit for symbols that have multiple parts per package.
* @param aConvert is the alternate body style for the schematic symbols.
* @param aPositions is the position of the symbol.
*/
SCH_SYMBOL( const LIB_SYMBOL& aSymbol, const LIB_ID& aLibId, const SCH_SHEET_PATH* aSheet,
int unit, int convert = 0, const wxPoint& pos = wxPoint( 0, 0 ) );
int aUnit, int aConvert = 0, const wxPoint& aPosition = wxPoint( 0, 0 ),
EDA_ITEM* aParent = nullptr );
SCH_SYMBOL( const LIB_SYMBOL& aSymbol, const SCH_SHEET_PATH* aSheet, const PICKED_SYMBOL& aSel,
const wxPoint& pos = wxPoint( 0, 0 ) );
const wxPoint& aPosition = wxPoint( 0, 0 ), EDA_ITEM* aParent = nullptr );
/**
* Clone \a aSymbol into a new schematic symbol object.

View File

@ -269,7 +269,8 @@ int SCH_DRAWING_TOOLS::PlaceSymbol( const TOOL_EVENT& aEvent )
continue;
wxPoint pos( cursorPos );
symbol = new SCH_SYMBOL( *libSymbol, &m_frame->GetCurrentSheet(), sel, pos );
symbol = new SCH_SYMBOL( *libSymbol, &m_frame->GetCurrentSheet(), sel, pos,
&m_frame->Schematic() );
addSymbol( symbol );
// Update cursor now that we have a symbol