Explode/Combine in terms of visible elements

When generating a complex pad, this allows the user to combine with a
rotated pad and explode rotated pads without needing to rotate elements
to 0 orientation first.

Fixes: lp:1808137
* https://bugs.launchpad.net/kicad/+bug/1808137
This commit is contained in:
Seth Hillbrand 2019-07-11 01:48:11 -07:00
parent c86b4928a7
commit f2f2b4bcf9
4 changed files with 58 additions and 3 deletions

View File

@ -116,6 +116,13 @@ public:
*/
void Move( wxPoint aMoveVector );
/**
* Rotates the primitive about a point
* @param aRotCentre center of rotation
* @param aAngle angle in tenths of degree
*/
void Rotate( const wxPoint& aRotCentre, double aAngle );
/** Export the PAD_CS_PRIMITIVE parameters to a DRAWSEGMENT
* useful to draw a primitive shape
* @param aTarget is the DRAWSEGMENT to initialize

View File

@ -34,6 +34,7 @@
#include <bezier_curves.h>
#include <class_board.h>
#include <class_board_item.h>
#include <class_drawsegment.h>
#include <class_edge_mod.h>
#include <class_pad.h>
@ -88,6 +89,42 @@ void PAD_CS_PRIMITIVE::Move( wxPoint aMoveVector )
}
void PAD_CS_PRIMITIVE::Rotate( const wxPoint& aRotCentre, double aAngle )
{
switch( m_Shape )
{
case S_ARC:
case S_SEGMENT:
case S_CIRCLE:
// these can all be done by just rotating the start and end points
RotatePoint( &m_Start, aRotCentre, aAngle );
RotatePoint( &m_End, aRotCentre, aAngle );
break;
case S_POLYGON:
for( auto& pt : m_Poly )
RotatePoint( &pt, aRotCentre, aAngle );
break;
case S_CURVE:
RotatePoint( &m_Start, aRotCentre, aAngle );
RotatePoint( &m_End, aRotCentre, aAngle );
RotatePoint( &m_Ctrl1, aRotCentre, aAngle );
RotatePoint( &m_Ctrl2, aRotCentre, aAngle );
break;
case S_RECT:
default:
// un-handled edge transform
wxASSERT_MSG( false, wxT( "PAD_CS_PRIMITIVE::Rotate not implemented for "
+ BOARD_ITEM::ShowShape( m_Shape ) ) );
break;
}
}
/*
* Has meaning only for free shape pads.
* add a free shape to the shape list.

View File

@ -485,6 +485,8 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent )
int step = SET_ORIGIN;
// Prime the pump
m_toolMgr->RunAction( ACTIONS::refreshPreview );
if( aEvent.HasPosition() )
m_toolMgr->RunAction( ACTIONS::cursorClick );
@ -891,6 +893,8 @@ bool DRAWING_TOOL::drawSegment( int aShape, DRAWSEGMENT*& aGraphic, OPT<VECTOR2D
VECTOR2I cursorPos = m_controls->GetMousePosition();
// Prime the pump
m_toolMgr->RunAction( ACTIONS::refreshPreview );
if( aStartingPoint )
m_toolMgr->RunAction( ACTIONS::cursorClick );
@ -1152,6 +1156,8 @@ bool DRAWING_TOOL::drawArc( DRAWSEGMENT*& aGraphic, bool aImmediateMode )
bool cancelled = false;
// Prime the pump
m_toolMgr->RunAction( ACTIONS::refreshPreview );
if( aImmediateMode )
m_toolMgr->RunAction( ACTIONS::cursorClick );

View File

@ -350,6 +350,7 @@ int MODULE_EDITOR_TOOLS::ExplodePadToShapes( const TOOL_EVENT& aEvent )
// Fix an arbitray draw layer for this EDGE_MODULE
ds->SetLayer( Dwgs_User ); //pad->GetLayer() );
ds->Move( anchor );
ds->Rotate( anchor, pad->GetOrientation() );
commit.Add( ds );
}
@ -446,6 +447,8 @@ int MODULE_EDITOR_TOOLS::CreatePadFromShapes( const TOOL_EVENT& aEvent )
return 0;
}
double refOrientation = 0.0;
if( refPad )
{
pad.reset( static_cast<D_PAD*>( refPad->Clone() ) );
@ -453,9 +456,10 @@ int MODULE_EDITOR_TOOLS::CreatePadFromShapes( const TOOL_EVENT& aEvent )
if( refPad->GetShape() == PAD_SHAPE_RECT )
pad->SetAnchorPadShape( PAD_SHAPE_RECT );
// ignore the pad orientation and offset for the moment. Makes more trouble than it's worth.
pad->SetOrientation( 0 );
// ignore the pad offset for the moment. Makes more trouble than it's worth.
pad->SetOffset( wxPoint( 0, 0 ) );
refOrientation = pad->GetOrientation();
pad->SetOrientation( 0.0 );
}
else
{
@ -497,14 +501,15 @@ int MODULE_EDITOR_TOOLS::CreatePadFromShapes( const TOOL_EVENT& aEvent )
for( auto& shape : shapes )
{
shape.Move( wxPoint( -anchor->x, -anchor->y ) );
shape.Rotate( wxPoint( 0, 0 ), -refOrientation );
}
pad->SetPosition( wxPoint( anchor->x, anchor->y ) );
pad->AddPrimitives( shapes );
pad->ClearFlags();
bool result = pad->MergePrimitivesAsPolygon();
pad->Rotate( wxPoint( anchor->x, anchor->y ), refOrientation );
if( !result )
{