From 7c6d9f67f951066cf468baaba9fa4163ef5c8564 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Fri, 26 Aug 2022 13:34:46 -0400 Subject: [PATCH] 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. This is a better fix for the master branch and cherry-picking from 6.0 was a mess. Fixes https://gitlab.com/kicad/code/kicad/-/issues/12190 --- eeschema/sch_symbol.cpp | 9 +++++---- eeschema/sch_symbol.h | 12 ++++++------ eeschema/tools/sch_drawing_tools.cpp | 17 +++++++++++++++-- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/eeschema/sch_symbol.cpp b/eeschema/sch_symbol.cpp index 50bbecf7a3..3070d2c745 100644 --- a/eeschema/sch_symbol.cpp +++ b/eeschema/sch_symbol.cpp @@ -105,8 +105,8 @@ SCH_SYMBOL::SCH_SYMBOL() : SCH_SYMBOL::SCH_SYMBOL( const LIB_SYMBOL& aSymbol, const LIB_ID& aLibId, const SCH_SHEET_PATH* aSheet, int aUnit, int aConvert, - const VECTOR2I& aPosition ) : - SCH_ITEM( nullptr, SCH_SYMBOL_T ) + const VECTOR2I& aPosition, EDA_ITEM* aParent ) : + SCH_ITEM( aParent, SCH_SYMBOL_T ) { Init( aPosition ); @@ -151,8 +151,9 @@ 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 VECTOR2I& aPosition ) : - SCH_SYMBOL( aSymbol, aSel.LibId, aSheet, aSel.Unit, aSel.Convert, aPosition ) + const PICKED_SYMBOL& aSel, const VECTOR2I& 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& i : aSel.Fields ) diff --git a/eeschema/sch_symbol.h b/eeschema/sch_symbol.h index 9116ea9c70..609857c810 100644 --- a/eeschema/sch_symbol.h +++ b/eeschema/sch_symbol.h @@ -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 aPosition 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 VECTOR2I& pos = VECTOR2I( 0, 0 ) ); + int aUnit, int aConvert = 0, const VECTOR2I& aPosition = VECTOR2I( 0, 0 ), + EDA_ITEM* aParent = nullptr ); SCH_SYMBOL( const LIB_SYMBOL& aSymbol, const SCH_SHEET_PATH* aSheet, const PICKED_SYMBOL& aSel, - const VECTOR2I& pos = VECTOR2I( 0, 0 ) ); + const VECTOR2I& aPosition = VECTOR2I( 0, 0 ), EDA_ITEM* aParent = nullptr ); /** * Clone \a aSymbol into a new schematic symbol object. diff --git a/eeschema/tools/sch_drawing_tools.cpp b/eeschema/tools/sch_drawing_tools.cpp index e385d53ffd..b7a31b7e97 100644 --- a/eeschema/tools/sch_drawing_tools.cpp +++ b/eeschema/tools/sch_drawing_tools.cpp @@ -216,8 +216,10 @@ int SCH_DRAWING_TOOLS::PlaceSymbol( const TOOL_EVENT& aEvent ) }; Activate(); + // Must be done after Activate() so that it gets set into the correct context getViewControls()->ShowCursor( true ); + // Set initial cursor setCursor(); @@ -226,7 +228,7 @@ int SCH_DRAWING_TOOLS::PlaceSymbol( const TOOL_EVENT& aEvent ) { addSymbol( symbol ); annotate(); - getViewControls()->WarpMouseCursor( getViewControls()->GetMousePosition( false )); + getViewControls()->WarpMouseCursor( getViewControls()->GetMousePosition( false ) ); } else if( aEvent.HasPosition() ) { @@ -324,7 +326,8 @@ int SCH_DRAWING_TOOLS::PlaceSymbol( const TOOL_EVENT& aEvent ) cursorPos = getViewControls()->GetMousePosition(); } - symbol = new SCH_SYMBOL( *libSymbol, &m_frame->GetCurrentSheet(), sel, cursorPos ); + symbol = new SCH_SYMBOL( *libSymbol, &m_frame->GetCurrentSheet(), sel, cursorPos, + &m_frame->Schematic() ); addSymbol( symbol ); annotate(); @@ -482,8 +485,10 @@ int SCH_DRAWING_TOOLS::PlaceImage( const TOOL_EVENT& aEvent ) }; Activate(); + // Must be done after Activate() so that it gets set into the correct context getViewControls()->ShowCursor( true ); + // Set initial cursor setCursor(); @@ -756,8 +761,10 @@ int SCH_DRAWING_TOOLS::SingleClickPlace( const TOOL_EVENT& aEvent ) }; Activate(); + // Must be done after Activate() so that it gets set into the correct context getViewControls()->ShowCursor( true ); + // Set initial cursor setCursor(); @@ -1173,8 +1180,10 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent ) }; Activate(); + // Must be done after Activate() so that it gets set into the correct context controls->ShowCursor( true ); + // Set initial cursor setCursor(); @@ -1501,8 +1510,10 @@ int SCH_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent ) }; Activate(); + // Must be done after Activate() so that it gets set into the correct context getViewControls()->ShowCursor( true ); + // Set initial cursor setCursor(); @@ -1708,8 +1719,10 @@ int SCH_DRAWING_TOOLS::DrawSheet( const TOOL_EVENT& aEvent ) }; Activate(); + // Must be done after Activate() so that it gets set into the correct context getViewControls()->ShowCursor( true ); + // Set initial cursor setCursor();