Explode pad to shapes command: Fix incorrect conversion of primitive to EDGE_MODULE (missing initialization)

This commit is contained in:
jean-pierre charras 2017-10-21 08:48:26 +02:00
parent 55bb35a582
commit 87821c1490
3 changed files with 36 additions and 15 deletions

View File

@ -50,6 +50,7 @@ class LINE_READER;
class EDA_3D_CANVAS;
class EDA_DRAW_PANEL;
class MODULE;
class EDGE_MODULE;
class TRACK;
class MSG_PANEL_INFO;
@ -114,6 +115,13 @@ public:
* @param aTarget is the DRAWSEGMENT to initialize
*/
void ExportTo( DRAWSEGMENT* aTarget );
/** Export the PAD_CS_PRIMITIVE parameters to a EDGE_MODULE
* useful to convert a primitive shape to a EDGE_MODULE shape for edition
* in footprint editor
* @param aTarget is the EDGE_MODULE to initialize
*/
void ExportTo( EDGE_MODULE* aTarget );
};

View File

@ -36,6 +36,7 @@
#include <class_pad.h>
#include <class_drawsegment.h>
#include <class_edge_mod.h>
#include <convert_basic_shapes_to_polygon.h>
#include <geometry/shape_rect.h>
#include <geometry/convex_hull.h>
@ -61,6 +62,15 @@ void PAD_CS_PRIMITIVE::ExportTo( DRAWSEGMENT* aTarget )
aTarget->SetPolyPoints( m_Poly );
}
void PAD_CS_PRIMITIVE::ExportTo( EDGE_MODULE* aTarget )
{
ExportTo( static_cast<DRAWSEGMENT*>( aTarget ) );
// Initialize coordinates specific to the EDGE_MODULE (m_Start0 and m_End0)
aTarget->SetLocalCoord();
}
/*
* Has meaning only for free shape pads.
* add a free shape to the shape list.

View File

@ -357,17 +357,10 @@ int MODULE_EDITOR_TOOLS::ExplodePadToShapes( const TOOL_EVENT& aEvent )
{
auto ds = new EDGE_MODULE( board()->m_Modules );
ds->SetLayer( pad->GetLayer() );
ds->SetShape( prim.m_Shape );
ds->SetStart( prim.m_Start + anchor );
ds->SetEnd( prim.m_End + anchor );
ds->SetWidth( prim.m_Thickness );
for( auto&p : prim.m_Poly )
p += anchor;
ds->SetPolyPoints( prim.m_Poly );
ds->SetAngle( prim.m_ArcAngle );
prim.ExportTo( ds ); // ExportTo exports to a DRAWSEGMENT
// Fix an arbitray draw layer for this EDGE_MODULE
ds->SetLayer( Dwgs_User ); //pad->GetLayer() );
ds->Move( anchor );
commit.Add( ds );
}
@ -442,13 +435,18 @@ int MODULE_EDITOR_TOOLS::CreatePadFromShapes( const TOOL_EVENT& aEvent )
if( multipleRefPadsFound )
{
DisplayErrorMessage( frame(), _("Cannot convert items to a custom-shaped pad: selection contains more than one reference pad. ") );
DisplayErrorMessage( frame(),
_( "Cannot convert items to a custom-shaped pad:\n"
"selection contains more than one reference pad." ) );
return 0;
}
if( illegalItemsFound )
{
DisplayErrorMessage( frame(), _("Cannot convert items to a custom-shaped pad: selection contains unsupported items. Only graphical lines, circles, arcs and polygons are allowed.") );
DisplayErrorMessage( frame(),
_( "Cannot convert items to a custom-shaped pad:\n"
"selection contains unsupported items.\n"
"Only graphical lines, circles, arcs and polygons are allowed." ) );
return 0;
}
@ -458,10 +456,12 @@ int MODULE_EDITOR_TOOLS::CreatePadFromShapes( const TOOL_EVENT& aEvent )
}
else
{
// Create a default pad anchor:
pad->SetAnchorPadShape( PAD_SHAPE_CIRCLE );
pad->SetAttribute( PAD_ATTRIB_SMD );
pad->SetLayerSet( D_PAD::SMDMask() );
pad->SetSize ( wxSize( 10000, 10000 ) );
int radius = Millimeter2iu( 0.2 );
pad->SetSize ( wxSize( radius, radius ) );
pad->IncrementPadName( true, true );
}
@ -483,7 +483,10 @@ int MODULE_EDITOR_TOOLS::CreatePadFromShapes( const TOOL_EVENT& aEvent )
if( !anchor )
{
DisplayErrorMessage( frame(), _("Cannot convert items to a custom-shaped pad: unable to determine the anchor point position. Consider adding a small anchor pad to the selection and try again.") );
DisplayErrorMessage( frame(),
_( "Cannot convert items to a custom-shaped pad:\n"
"unable to determine the anchor point position.\n"
"Consider adding a small anchor pad to the selection and try again.") );
return 0;
}