kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #18003
Re: Inserting new pins based on pin orientation in eeschema
I just re-implemented the calculations for pin offsets when inserting pins
in the library editor in eeschema. They are no longer dependent on global
settings. They are only dependent on the currently selected grid size and
the size of the text. The direction of the offset is determined by the
orientation of the pin.
This is a very minor change to an already implemented feature. Could
someone look this over, and if it passes muster, could it be applied to the
current code base? :)
Thanks.
-Ed
On Tue, Apr 21, 2015 at 4:25 PM, Ed Johns <edwardgjohns3@xxxxxxxxx> wrote:
> I just updated the eeschema code to insert new pins based on orientation.
> I have a few questions and wasn't able to find the answers in the code:
>
> 1. Where is the global variable g_RepeatStep set? It is used to determine
> horizontal and vertical step distances?
>
> 2. Am I using this global as it is intended? It seems like the insert
> function was half-implemented. It currently applies a -100 mil offset when
> you press the INSERT key. There is no implementation in the X direction.
>
> 3. If this is the correct usage, how would I set the default
> g_RepeatStep.x value to 100 mils as well?
>
> 4. Why is g_RepeatStep not initialized when running eeschema from the
> command line?
>
> Thanks.
>
> -Ed
>
> For context, I have added my patch below.
>
> === modified file 'eeschema/pinedit.cpp'
> --- eeschema/pinedit.cpp 2015-03-03 10:50:50 +0000
> +++ eeschema/pinedit.cpp 2015-04-21 20:15:06 +0000
> @@ -572,7 +572,26 @@
>
> pin->ClearFlags();
> pin->SetFlags( IS_NEW );
> - pin->Move( pin->GetPosition() + wxPoint( g_RepeatStep.x,
> -g_RepeatStep.y ) );
> +
> + switch( pin->GetOrientation() )
> + {
> + case PIN_UP:
> + pin->Move( pin->GetPosition() + wxPoint( g_RepeatStep.x, 0 ) );
> + break;
> +
> + case PIN_DOWN:
> + pin->Move( pin->GetPosition() + wxPoint( -g_RepeatStep.x, 0 ) );
> + break;
> +
> + case PIN_LEFT:
> + pin->Move( pin->GetPosition() + wxPoint( 0, g_RepeatStep.y ) );
> + break;
> +
> + case PIN_RIGHT:
> + pin->Move( pin->GetPosition() + wxPoint( 0, -g_RepeatStep.y ) );
> + break;
> + }
> +
> wxString nextName = pin->GetName();
> IncrementLabelMember( nextName );
> pin->SetName( nextName );
>
>
=== modified file 'eeschema/pinedit.cpp'
--- eeschema/pinedit.cpp 2015-03-03 10:50:50 +0000
+++ eeschema/pinedit.cpp 2015-04-22 01:56:45 +0000
@@ -558,6 +558,47 @@
}
+/**
+ * Returns the offset for a new pin based on the text size and current
+ * grid size.
+ * @param aPin is a pin instance to be moved.
+ * @return the x-offset to be applied.
+ */
+wxPoint CalculatePinOffset(LIB_PIN* aPin, int aXGridSize, int aYGridSize)
+{
+ int maxTextHeight = ( aPin->GetNumberTextSize() > aPin->GetNameTextSize() )
+ ? aPin->GetNumberTextSize() : aPin->GetNameTextSize();
+
+ // The following integer math calculates the minimum spacing on the
+ // grid that will fit the pin name and number text.
+ int xOffset = aXGridSize * ( ( aXGridSize + maxTextHeight ) / aXGridSize );
+ int yOffset = aYGridSize * ( ( aYGridSize + maxTextHeight ) / aYGridSize );
+
+ switch( aPin->GetOrientation() )
+ {
+ case PIN_UP:
+ yOffset = 0;
+ break;
+
+ case PIN_DOWN:
+ xOffset = -xOffset;
+ yOffset = 0;
+ break;
+
+ case PIN_LEFT:
+ xOffset = 0;
+ break;
+
+ case PIN_RIGHT:
+ xOffset = 0;
+ yOffset = -yOffset;
+ break;
+ }
+
+ return wxPoint( xOffset, yOffset );
+}
+
+
// Create a new pin based on the previous pin with an incremented pin number.
void LIB_EDIT_FRAME::RepeatPinItem( wxDC* DC, LIB_PIN* SourcePin )
{
@@ -572,7 +613,11 @@
pin->ClearFlags();
pin->SetFlags( IS_NEW );
- pin->Move( pin->GetPosition() + wxPoint( g_RepeatStep.x, -g_RepeatStep.y ) );
+
+ wxPoint pinOffset = CalculatePinOffset( pin, GetScreen()->GetGrid().m_Size.x,
+ GetScreen()->GetGrid().m_Size.y );
+
+ pin->Move( pin->GetPosition() + pinOffset );
wxString nextName = pin->GetName();
IncrementLabelMember( nextName );
pin->SetName( nextName );
Follow ups
References