Fix aperture macro hit testing (partial fix of lp:1730249)

Also update various things in class_aperture_macro.cpp to take a const
parent argument so that it is callable from within GERBER_DRAW_ITEM
This commit is contained in:
Jon Evans 2017-11-11 17:20:19 -05:00 committed by jean-pierre charras
parent f3908bd87c
commit a1acf705e8
4 changed files with 16 additions and 14 deletions

View File

@ -7,7 +7,7 @@
*
* Copyright (C) 1992-2017 Jean-Pierre Charras <jp.charras at wanadoo.fr>
* Copyright (C) 2010 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 1992-2017 KiCad Developers, see change_log.txt for contributors.
* Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License

View File

@ -59,7 +59,7 @@ static wxPoint mapPt( double x, double y, bool isMetric )
}
bool AM_PRIMITIVE::IsAMPrimitiveExposureOn(GERBER_DRAW_ITEM* aParent) const
bool AM_PRIMITIVE::IsAMPrimitiveExposureOn( const GERBER_DRAW_ITEM* aParent ) const
{
/*
* Some but not all primitives use the first parameter as an exposure control.
@ -94,7 +94,7 @@ bool AM_PRIMITIVE::IsAMPrimitiveExposureOn(GERBER_DRAW_ITEM* aParent) const
const int seg_per_circle = 64; // Number of segments to approximate a circle
void AM_PRIMITIVE::DrawBasicShape( GERBER_DRAW_ITEM* aParent,
void AM_PRIMITIVE::DrawBasicShape( const GERBER_DRAW_ITEM* aParent,
SHAPE_POLY_SET& aShapeBuffer,
wxPoint aShapePos )
{
@ -448,7 +448,7 @@ void AM_PRIMITIVE::DrawBasicShape( GERBER_DRAW_ITEM* aParent,
* because circles are very easy to draw (no rotation problem) so convert them in polygons,
* and draw them as polygons is not a good idea.
*/
void AM_PRIMITIVE::ConvertShapeToPolygon( GERBER_DRAW_ITEM* aParent,
void AM_PRIMITIVE::ConvertShapeToPolygon( const GERBER_DRAW_ITEM* aParent,
std::vector<wxPoint>& aBuffer )
{
D_CODE* tool = aParent->GetDcodeDescr();
@ -668,7 +668,7 @@ void AM_PRIMITIVE::ConvertShapeToPolygon( GERBER_DRAW_ITEM* aParent,
* @param aParent = the parent GERBER_DRAW_ITEM which is actually drawn
* @return a dimension, or -1 if no dim to calculate
*/
int AM_PRIMITIVE::GetShapeDim( GERBER_DRAW_ITEM* aParent )
int AM_PRIMITIVE::GetShapeDim( const GERBER_DRAW_ITEM* aParent )
{
int dim = -1;
D_CODE* tool = aParent->GetDcodeDescr();
@ -773,7 +773,7 @@ int AM_PRIMITIVE::GetShapeDim( GERBER_DRAW_ITEM* aParent )
}
SHAPE_POLY_SET* APERTURE_MACRO::GetApertureMacroShape( GERBER_DRAW_ITEM* aParent,
SHAPE_POLY_SET* APERTURE_MACRO::GetApertureMacroShape( const GERBER_DRAW_ITEM* aParent,
wxPoint aShapePos )
{
SHAPE_POLY_SET holeBuffer;

View File

@ -114,7 +114,7 @@ public: AM_PRIMITIVE( bool aGerbMetric, AM_PRIMITIVE_ID aId = AMP_UNKNOWN )
* In a aperture macro shape, a basic primitive with exposure off is a hole in the shape
* it is NOT a negative shape
*/
bool IsAMPrimitiveExposureOn( GERBER_DRAW_ITEM* aParent ) const;
bool IsAMPrimitiveExposureOn( const GERBER_DRAW_ITEM* aParent ) const;
/* Draw functions: */
@ -128,7 +128,7 @@ public: AM_PRIMITIVE( bool aGerbMetric, AM_PRIMITIVE_ID aId = AMP_UNKNOWN )
* @param aParent = the parent GERBER_DRAW_ITEM which is actually drawn
* @return a dimension, or -1 if no dim to calculate
*/
int GetShapeDim( GERBER_DRAW_ITEM* aParent );
int GetShapeDim( const GERBER_DRAW_ITEM* aParent );
/**
* Function drawBasicShape
@ -137,7 +137,8 @@ public: AM_PRIMITIVE( bool aGerbMetric, AM_PRIMITIVE_ID aId = AMP_UNKNOWN )
* @param aShapeBuffer = a SHAPE_POLY_SET to put the shape converted to a polygon
* @param aShapePos = the actual shape position
*/
void DrawBasicShape( GERBER_DRAW_ITEM* aParent, SHAPE_POLY_SET& aShapeBuffer,
void DrawBasicShape( const GERBER_DRAW_ITEM* aParent,
SHAPE_POLY_SET& aShapeBuffer,
wxPoint aShapePos );
private:
@ -148,7 +149,8 @@ private:
* Useful when a shape is not a graphic primitive (shape with hole,
* rotated shape ... ) and cannot be easily drawn.
*/
void ConvertShapeToPolygon( GERBER_DRAW_ITEM* aParent, std::vector<wxPoint>& aBuffer );
void ConvertShapeToPolygon( const GERBER_DRAW_ITEM* aParent,
std::vector<wxPoint>& aBuffer );
};
@ -195,7 +197,7 @@ struct APERTURE_MACRO
* @param aParent = the parent GERBER_DRAW_ITEM which is actually drawn
* @return The shape of the item
*/
SHAPE_POLY_SET* GetApertureMacroShape( GERBER_DRAW_ITEM* aParent, wxPoint aShapePos );
SHAPE_POLY_SET* GetApertureMacroShape( const GERBER_DRAW_ITEM* aParent, wxPoint aShapePos );
/**
* Function DrawApertureMacroShape

View File

@ -703,10 +703,10 @@ bool GERBER_DRAW_ITEM::HitTest( const wxPoint& aRefPos ) const
case GBR_SPOT_MACRO:
// Aperture macro polygons are already in absolute coordinates
poly = GetDcodeDescr()->GetMacro()->m_shape;
for( int i = 0; i < poly.OutlineCount(); ++i )
auto p = GetDcodeDescr()->GetMacro()->GetApertureMacroShape( this, m_Start );
for( int i = 0; i < p->OutlineCount(); ++i )
{
if( poly.Contains( VECTOR2I( aRefPos ), i ) )
if( p->Contains( VECTOR2I( aRefPos ), i ) )
return true;
}
return false;