From e454595348e5f09c224a13be69f9cbc20a5af127 Mon Sep 17 00:00:00 2001 From: Mike Williams Date: Mon, 11 Jul 2022 13:55:54 -0400 Subject: [PATCH] Eeschema: Changing pin length adjusts offset according to orientation ADDED: When pin length is changed now, the pin position is adjusted according to its orientation such that the connection point for wires moves instead of the other side of the stem base. For pins coming out of component boxes, etc. this keeps them attached to the box while the length is changed. --- .../dialogs/dialog_lib_edit_pin_table.cpp | 2 +- eeschema/dialogs/dialog_pin_properties.cpp | 2 +- eeschema/lib_pin.cpp | 27 +++++++++++++++++++ eeschema/lib_pin.h | 7 +++++ eeschema/tools/symbol_editor_pin_tool.cpp | 4 +-- 5 files changed, 38 insertions(+), 4 deletions(-) diff --git a/eeschema/dialogs/dialog_lib_edit_pin_table.cpp b/eeschema/dialogs/dialog_lib_edit_pin_table.cpp index 986022d536..d1d2c49efc 100644 --- a/eeschema/dialogs/dialog_lib_edit_pin_table.cpp +++ b/eeschema/dialogs/dialog_lib_edit_pin_table.cpp @@ -355,7 +355,7 @@ public: break; case COL_LENGTH: - pin->SetLength( ValueFromString( m_frame->GetUserUnits(), aValue ) ); + pin->ChangeLength( ValueFromString( m_frame->GetUserUnits(), aValue ) ); break; case COL_POSX: diff --git a/eeschema/dialogs/dialog_pin_properties.cpp b/eeschema/dialogs/dialog_pin_properties.cpp index 1dc32f84e1..d7905b75c4 100644 --- a/eeschema/dialogs/dialog_pin_properties.cpp +++ b/eeschema/dialogs/dialog_pin_properties.cpp @@ -345,8 +345,8 @@ bool DIALOG_PIN_PROPERTIES::TransferDataFromWindow() m_pin->SetNameTextSize( m_nameSize.GetValue() ); m_pin->SetNumberTextSize( m_numberSize.GetValue() ); m_pin->SetOrientation( PinOrientationCode( m_choiceOrientation->GetSelection() ) ); - m_pin->SetLength( m_pinLength.GetValue() ); m_pin->SetPosition( newPos ); + m_pin->ChangeLength( m_pinLength.GetValue() ); m_pin->SetType( m_choiceElectricalType->GetPinTypeSelection() ); m_pin->SetShape( m_choiceStyle->GetPinShapeSelection() ); m_pin->SetConvert( m_checkApplyToAllConversions->GetValue() ? 0 : m_frame->GetConvert() ); diff --git a/eeschema/lib_pin.cpp b/eeschema/lib_pin.cpp index 436fb440b8..c1225880fd 100644 --- a/eeschema/lib_pin.cpp +++ b/eeschema/lib_pin.cpp @@ -963,6 +963,33 @@ int LIB_PIN::compare( const LIB_ITEM& aOther, int aCompareFlags ) const return 0; } +void LIB_PIN::ChangeLength( int aLength ) +{ + int lengthChange = m_length - aLength; + int offsetX = 0; + int offsetY = 0; + + switch( m_orientation ) + { + case PIN_RIGHT: + offsetX = lengthChange; + break; + case PIN_LEFT: + offsetX = -1 * lengthChange; + break; + case PIN_UP: + offsetY = lengthChange; + break; + case PIN_DOWN: + offsetY = -1 * lengthChange; + break; + } + + wxPoint offset = wxPoint( offsetX, offsetY ); + Offset( offset ); + + m_length = aLength; +} void LIB_PIN::Offset( const VECTOR2I& aOffset ) { diff --git a/eeschema/lib_pin.h b/eeschema/lib_pin.h index 5639363107..e442e8beb9 100644 --- a/eeschema/lib_pin.h +++ b/eeschema/lib_pin.h @@ -81,6 +81,13 @@ public: int GetLength() const { return m_length; } void SetLength( int aLength ) { m_length = aLength; } + /** + * Change the length of a pin and adjust its position based on orientation. + * + * @param aLength New length of pin + */ + void ChangeLength( int aLength ); + ELECTRICAL_PINTYPE GetType() const { return m_type; } void SetType( ELECTRICAL_PINTYPE aType ) { m_type = aType; } diff --git a/eeschema/tools/symbol_editor_pin_tool.cpp b/eeschema/tools/symbol_editor_pin_tool.cpp index cfc18f7911..705f810215 100644 --- a/eeschema/tools/symbol_editor_pin_tool.cpp +++ b/eeschema/tools/symbol_editor_pin_tool.cpp @@ -171,7 +171,7 @@ bool SYMBOL_EDITOR_PIN_TOOL::EditPinProperties( LIB_PIN* aPin ) else if( other->GetConvert() == aPin->GetConvert() ) { other->SetPosition( aPin->GetPosition() ); - other->SetLength( aPin->GetLength() ); + other->ChangeLength( aPin->GetLength() ); other->SetShape( aPin->GetShape() ); } @@ -392,7 +392,7 @@ int SYMBOL_EDITOR_PIN_TOOL::PushPinProperties( const TOOL_EVENT& aEvent ) if( aEvent.IsAction( &EE_ACTIONS::pushPinLength ) ) { if( !pin->GetConvert() || pin->GetConvert() == m_frame->GetConvert() ) - pin->SetLength( sourcePin->GetLength() ); + pin->ChangeLength( sourcePin->GetLength() ); } else if( aEvent.IsAction( &EE_ACTIONS::pushPinNameSize ) ) {