Fix incorrect handling of Aperture Macros, especially when using exposure OFF in macros.

Aperture macro shapes are now drawn using polygons.
This commit is contained in:
jean-pierre charras 2016-06-03 18:42:24 +02:00
parent b4ad18a3ea
commit 2b459acfe9
6 changed files with 144 additions and 203 deletions

View File

@ -41,7 +41,7 @@
* @param aRadius = the radius of the circle * @param aRadius = the radius of the circle
* @param aCircleToSegmentsCount = the number of segments to approximate a circle * @param aCircleToSegmentsCount = the number of segments to approximate a circle
* Note: the polygon is inside the circle, so if you want to have the polygon * Note: the polygon is inside the circle, so if you want to have the polygon
* outside the circle, you should give aRadius calculated with a corrrection factor * outside the circle, you should give aRadius calculated with a correction factor
*/ */
void TransformCircleToPolygon( SHAPE_POLY_SET& aCornerBuffer, void TransformCircleToPolygon( SHAPE_POLY_SET& aCornerBuffer,
wxPoint aCenter, int aRadius, wxPoint aCenter, int aRadius,

View File

@ -31,6 +31,7 @@
#include <common.h> #include <common.h>
#include <macros.h> #include <macros.h>
#include <trigo.h> #include <trigo.h>
#include <convert_basic_shapes_to_polygon.h>
#include <gr_basic.h> #include <gr_basic.h>
#include <gerbview.h> #include <gerbview.h>
@ -57,22 +58,17 @@ static wxPoint mapPt( double x, double y, bool isMetric )
return ret; return ret;
} }
/**
* Function mapExposure bool AM_PRIMITIVE::IsAMPrimitiveExposureOn(GERBER_DRAW_ITEM* aParent) const
* translates the first parameter from an aperture macro into a current
* exposure setting.
* @param aParent = a GERBER_DRAW_ITEM that handle:
* ** m_Exposure A dynamic setting which can change throughout the
* reading of the gerber file, and it indicates whether the current tool
* is lit or not.
* ** m_ImageNegative A dynamic setting which can change throughout the reading
* of the gerber file, and it indicates whether the current D codes are to
* be interpreted as erasures or not.
* @return true to draw with current color, false to draw with alt color (erase)
*/
bool AM_PRIMITIVE::mapExposure( GERBER_DRAW_ITEM* aParent )
{ {
bool exposure; /*
* Some but not all primitives use the first parameter as an exposure control.
* Others are always ON.
* In a aperture macro shape, a basic primitive with exposure off is a hole in the shape
* it is NOT a negative shape
*/
wxASSERT( params.size() && params[0].IsImmediate() );
switch( primitive_id ) switch( primitive_id )
{ {
case AMP_CIRCLE: case AMP_CIRCLE:
@ -81,70 +77,38 @@ bool AM_PRIMITIVE::mapExposure( GERBER_DRAW_ITEM* aParent )
case AMP_LINE_CENTER: case AMP_LINE_CENTER:
case AMP_LINE_LOWER_LEFT: case AMP_LINE_LOWER_LEFT:
case AMP_OUTLINE: case AMP_OUTLINE:
case AMP_THERMAL:
case AMP_POLYGON: case AMP_POLYGON:
// All have an exposure parameter and can return true or false // All have an exposure parameter and can return a value (0 or 1)
switch( GetExposure(aParent) ) return params[0].GetValue( aParent->GetDcodeDescr() ) != 0;
{
case 0: // exposure always OFF
exposure = false;
break;
default:
case 1: // exposure always ON
exposure = true;
break;
case 2: // reverse exposure
exposure = !aParent->GetLayerPolarity();
}
break; break;
case AMP_MOIRE: case AMP_THERMAL: // Exposure is always on
case AMP_MOIRE: // Exposure is always on
case AMP_EOF: case AMP_EOF:
case AMP_UNKNOWN: case AMP_UNKNOWN:
default: default:
return true; // All have no exposure parameter and must return true (no change for exposure) return 1; // All have no exposure parameter and are always 0N return true
break; break;
} }
return exposure ^ aParent->m_GerberImageFile->m_ImageNegative;
} }
/**
* Function GetExposure
* returns the first parameter in integer form. Some but not all primitives
* use the first parameter as an exposure control.
*/
int AM_PRIMITIVE::GetExposure(GERBER_DRAW_ITEM* aParent) const
{
// No D_CODE* for GetValue()
wxASSERT( params.size() && params[0].IsImmediate() );
return (int) params[0].GetValue( aParent->GetDcodeDescr() );
}
/**
* Function DrawBasicShape
* Draw the primitive shape for flashed items.
*/
void AM_PRIMITIVE::DrawBasicShape( GERBER_DRAW_ITEM* aParent, void AM_PRIMITIVE::DrawBasicShape( GERBER_DRAW_ITEM* aParent,
EDA_RECT* aClipBox, SHAPE_POLY_SET& aShapeBuffer,
wxDC* aDC, wxPoint aShapePos )
EDA_COLOR_T aColor, EDA_COLOR_T aAltColor,
wxPoint aShapePos,
bool aFilledShape )
{ {
#define TO_POLY_SHAPE { aShapeBuffer.NewOutline(); \
for( unsigned jj = 0; jj < polybuffer.size(); jj++ )\
aShapeBuffer.Append( polybuffer[jj].x, polybuffer[jj].y );}
const int seg_per_circle = 64; // Number of segments to approximate a circle
// Draw the primitive shape for flashed items.
static std::vector<wxPoint> polybuffer; // create a static buffer to avoid a lot of memory reallocation static std::vector<wxPoint> polybuffer; // create a static buffer to avoid a lot of memory reallocation
polybuffer.clear(); polybuffer.clear();
wxPoint curPos = aShapePos; wxPoint curPos = aShapePos;
D_CODE* tool = aParent->GetDcodeDescr(); D_CODE* tool = aParent->GetDcodeDescr();
double rotation; double rotation;
if( mapExposure( aParent ) == false )
{
std::swap( aColor, aAltColor );
}
switch( primitive_id ) switch( primitive_id )
{ {
@ -158,16 +122,18 @@ void AM_PRIMITIVE::DrawBasicShape( GERBER_DRAW_ITEM* aParent,
curPos += mapPt( params[2].GetValue( tool ), params[3].GetValue( tool ), m_GerbMetric ); curPos += mapPt( params[2].GetValue( tool ), params[3].GetValue( tool ), m_GerbMetric );
curPos = aParent->GetABPosition( curPos ); curPos = aParent->GetABPosition( curPos );
int radius = scaletoIU( params[1].GetValue( tool ), m_GerbMetric ) / 2; int radius = scaletoIU( params[1].GetValue( tool ), m_GerbMetric ) / 2;
if( !aFilledShape )
GRCircle( aClipBox, aDC, curPos, radius, 0, aColor ); TransformCircleToPolygon( aShapeBuffer, curPos, radius, seg_per_circle );
else
GRFilledCircle( aClipBox, aDC, curPos, radius, aColor );
} }
break; break;
case AMP_LINE2: case AMP_LINE2:
case AMP_LINE20: // Line with rectangle ends. (Width, start and end pos + rotation) case AMP_LINE20: // Line with rectangle ends. (Width, start and end pos + rotation)
{ {
/* Vector Line, Primitive Code 20.
* A vector line is a rectangle defined by its line width, start and end points.
* The line ends are rectangular.
*/
/* Generated by an aperture macro declaration like: /* Generated by an aperture macro declaration like:
* "2,1,0.3,0,0, 0.5, 1.0,-135*" * "2,1,0.3,0,0, 0.5, 1.0,-135*"
* type (2), exposure, width, start.x, start.y, end.x, end.y, rotation * type (2), exposure, width, start.x, start.y, end.x, end.y, rotation
@ -190,13 +156,15 @@ void AM_PRIMITIVE::DrawBasicShape( GERBER_DRAW_ITEM* aParent,
polybuffer[ii] = aParent->GetABPosition( polybuffer[ii] ); polybuffer[ii] = aParent->GetABPosition( polybuffer[ii] );
} }
GRClosedPoly( aClipBox, aDC, TO_POLY_SHAPE;
polybuffer.size(), &polybuffer[0], aFilledShape, aColor, aColor );
} }
break; break;
case AMP_LINE_CENTER: case AMP_LINE_CENTER:
{ {
/* Center Line, Primitive Code 21
* A center line primitive is a rectangle defined by its width, height, and center point
*/
/* Generated by an aperture macro declaration like: /* Generated by an aperture macro declaration like:
* "21,1,0.3,0.03,0,0,-135*" * "21,1,0.3,0.03,0,0,-135*"
* type (21), exposure, ,width, height, center pos.x, center pos.y, rotation * type (21), exposure, ,width, height, center pos.x, center pos.y, rotation
@ -206,6 +174,7 @@ void AM_PRIMITIVE::DrawBasicShape( GERBER_DRAW_ITEM* aParent,
// shape rotation: // shape rotation:
rotation = params[5].GetValue( tool ) * 10.0; rotation = params[5].GetValue( tool ) * 10.0;
if( rotation != 0 ) if( rotation != 0 )
{ {
for( unsigned ii = 0; ii < polybuffer.size(); ii++ ) for( unsigned ii = 0; ii < polybuffer.size(); ii++ )
@ -219,8 +188,7 @@ void AM_PRIMITIVE::DrawBasicShape( GERBER_DRAW_ITEM* aParent,
polybuffer[ii] = aParent->GetABPosition( polybuffer[ii] ); polybuffer[ii] = aParent->GetABPosition( polybuffer[ii] );
} }
GRClosedPoly( aClipBox, aDC, TO_POLY_SHAPE;
polybuffer.size(), &polybuffer[0], aFilledShape, aColor, aColor );
} }
break; break;
@ -248,8 +216,7 @@ void AM_PRIMITIVE::DrawBasicShape( GERBER_DRAW_ITEM* aParent,
polybuffer[ii] = aParent->GetABPosition( polybuffer[ii] ); polybuffer[ii] = aParent->GetABPosition( polybuffer[ii] );
} }
GRClosedPoly( aClipBox, aDC, TO_POLY_SHAPE;
polybuffer.size(), &polybuffer[0], aFilledShape, aColor, aColor );
} }
break; break;
@ -259,39 +226,44 @@ void AM_PRIMITIVE::DrawBasicShape( GERBER_DRAW_ITEM* aParent,
* "7, 0,0,1.0,0.3,0.01,-13*" * "7, 0,0,1.0,0.3,0.01,-13*"
* type (7), center.x , center.y, outside diam, inside diam, crosshair thickness, rotation * type (7), center.x , center.y, outside diam, inside diam, crosshair thickness, rotation
* type is not stored in parameters list, so the first parameter is center.x * type is not stored in parameters list, so the first parameter is center.x
*
* The thermal primitive is a ring (annulus) interrupted by four gaps. Exposure is always on.
*/ */
std::vector<wxPoint> subshape_poly;
curPos += mapPt( params[0].GetValue( tool ), params[1].GetValue( tool ), m_GerbMetric ); curPos += mapPt( params[0].GetValue( tool ), params[1].GetValue( tool ), m_GerbMetric );
ConvertShapeToPolygon( aParent, polybuffer ); ConvertShapeToPolygon( aParent, subshape_poly );
// shape rotation: // shape rotation:
rotation = params[5].GetValue( tool ) * 10.0; rotation = params[5].GetValue( tool ) * 10.0;
// Because a thermal shape has 4 identical sub-shapes, only one is created in polybuffer. // Because a thermal shape has 4 identical sub-shapes, only one is created in subshape_poly.
// We must draw 4 sub-shapes rotated by 90 deg // We must draw 4 sub-shapes rotated by 90 deg
std::vector<wxPoint> subshape_poly;
for( int ii = 0; ii < 4; ii++ ) for( int ii = 0; ii < 4; ii++ )
{ {
subshape_poly = polybuffer; polybuffer = subshape_poly;
double sub_rotation = rotation + 900 * ii; double sub_rotation = rotation + 900 * ii;
for( unsigned jj = 0; jj < subshape_poly.size(); jj++ )
RotatePoint( &subshape_poly[jj], -sub_rotation ); for( unsigned jj = 0; jj < polybuffer.size(); jj++ )
RotatePoint( &polybuffer[jj], -sub_rotation );
// Move to current position: // Move to current position:
for( unsigned jj = 0; jj < subshape_poly.size(); jj++ ) for( unsigned jj = 0; jj < polybuffer.size(); jj++ )
{ {
subshape_poly[jj] += curPos; polybuffer[jj] += curPos;
subshape_poly[jj] = aParent->GetABPosition( subshape_poly[jj] ); polybuffer[jj] = aParent->GetABPosition( polybuffer[jj] );
} }
GRClosedPoly( aClipBox, aDC, TO_POLY_SHAPE;
subshape_poly.size(), &subshape_poly[0], true, aAltColor,
aAltColor );
} }
} }
break; break;
case AMP_MOIRE: // A cross hair with n concentric circles case AMP_MOIRE:
{ {
/* Moiré, Primitive Code 6
* The moiré primitive is a cross hair centered on concentric rings (annuli).
* Exposure is always on.
*/
curPos += mapPt( params[0].GetValue( tool ), params[1].GetValue( tool ), curPos += mapPt( params[0].GetValue( tool ), params[1].GetValue( tool ),
m_GerbMetric ); m_GerbMetric );
@ -309,21 +281,14 @@ void AM_PRIMITIVE::DrawBasicShape( GERBER_DRAW_ITEM* aParent,
wxPoint center = aParent->GetABPosition( curPos ); wxPoint center = aParent->GetABPosition( curPos );
// adjust outerDiam by this on each nested circle // adjust outerDiam by this on each nested circle
int diamAdjust = (gap + penThickness); //*2; //Should we use * 2 ? int diamAdjust = (gap + penThickness); //*2; //Should we use * 2 ?
for( int i = 0; i < numCircles; ++i, outerDiam -= diamAdjust ) for( int i = 0; i < numCircles; ++i, outerDiam -= diamAdjust )
{ {
if( outerDiam <= 0 ) if( outerDiam <= 0 )
break; break;
if( !aFilledShape )
{ TransformRingToPolygon( aShapeBuffer, center,
// draw the border of the pen's path using two circles, each as narrow as possible (outerDiam - penThickness) / 2, seg_per_circle, penThickness );
GRCircle( aClipBox, aDC, center, outerDiam / 2, 0, aColor );
GRCircle( aClipBox, aDC, center, outerDiam / 2 - penThickness, 0, aColor );
}
else // Filled mode
{
GRCircle( aClipBox, aDC, center,
(outerDiam - penThickness) / 2, penThickness, aColor );
}
} }
// Draw the cross: // Draw the cross:
@ -339,13 +304,21 @@ void AM_PRIMITIVE::DrawBasicShape( GERBER_DRAW_ITEM* aParent,
polybuffer[ii] = aParent->GetABPosition( polybuffer[ii] ); polybuffer[ii] = aParent->GetABPosition( polybuffer[ii] );
} }
GRClosedPoly( aClipBox, aDC, TO_POLY_SHAPE;
polybuffer.size(), &polybuffer[0], aFilledShape, aColor, aColor );
} }
break; break;
case AMP_OUTLINE: case AMP_OUTLINE:
{ {
/* Outline, Primitive Code 4
* An outline primitive is an area enclosed by an n-point polygon defined by its start point and n
* subsequent points. The outline must be closed, i.e. the last point must be equal to the start
* point. There must be at least one subsequent point (to close the outline).
* The outline of the primitive is actually the contour (see 2.6) that consists of linear segments
* only, so it must conform to all the requirements described for contours.
* Warning: Make no mistake: n is the number of subsequent points, being the number of
* vertices of the outline or one less than the number of coordinate pairs.
*/
/* Generated by an aperture macro declaration like: /* Generated by an aperture macro declaration like:
* "4,1,3,0.0,0.0,0.0,0.5,0.5,0.5,0.5,0.0,-25" * "4,1,3,0.0,0.0,0.0,0.5,0.5,0.5,0.5,0.0,-25"
* type(4), exposure, corners count, corner1.x, corner.1y, ..., rotation * type(4), exposure, corners count, corner1.x, corner.1y, ..., rotation
@ -376,12 +349,15 @@ void AM_PRIMITIVE::DrawBasicShape( GERBER_DRAW_ITEM* aParent,
polybuffer[ii] = aParent->GetABPosition( polybuffer[ii] ); polybuffer[ii] = aParent->GetABPosition( polybuffer[ii] );
} }
GRClosedPoly( aClipBox, aDC, TO_POLY_SHAPE;
polybuffer.size(), &polybuffer[0], aFilledShape, aColor, aColor );
} }
break; break;
case AMP_POLYGON: // Is a regular polygon case AMP_POLYGON:
/* Polygon, Primitive Code 5
* A polygon primitive is a regular polygon defined by the number of vertices n, the center point
* and the diameter of the circumscribed circle
*/
/* Generated by an aperture macro declaration like: /* Generated by an aperture macro declaration like:
* "5,1,0.6,0,0,0.5,25" * "5,1,0.6,0,0,0.5,25"
* type(5), exposure, vertices count, pox.x, pos.y, diameter, rotation * type(5), exposure, vertices count, pox.x, pos.y, diameter, rotation
@ -399,8 +375,9 @@ void AM_PRIMITIVE::DrawBasicShape( GERBER_DRAW_ITEM* aParent,
polybuffer[ii] += curPos; polybuffer[ii] += curPos;
polybuffer[ii] = aParent->GetABPosition( polybuffer[ii] ); polybuffer[ii] = aParent->GetABPosition( polybuffer[ii] );
} }
GRClosedPoly( aClipBox, aDC,
polybuffer.size(), &polybuffer[0], aFilledShape, aColor, aColor ); TO_POLY_SHAPE;
break; break;
case AMP_EOF: case AMP_EOF:
@ -718,44 +695,55 @@ int AM_PRIMITIVE::GetShapeDim( GERBER_DRAW_ITEM* aParent )
} }
/** /*
* Function DrawApertureMacroShape * Function DrawApertureMacroShape
* Draw the primitive shape for flashed items. * Draw the primitive shape for flashed items.
* When an item is flashed, this is the shape of the item * When an item is flashed, this is the shape of the item
*/ */
void APERTURE_MACRO::DrawApertureMacroShape( GERBER_DRAW_ITEM* aParent, void APERTURE_MACRO::DrawApertureMacroShape( GERBER_DRAW_ITEM* aParent,
EDA_RECT* aClipBox, wxDC* aDC, EDA_RECT* aClipBox, wxDC* aDC,
EDA_COLOR_T aColor, EDA_COLOR_T aAltColor, EDA_COLOR_T aColor,
wxPoint aShapePos, bool aFilledShape ) wxPoint aShapePos, bool aFilledShape )
{ {
SHAPE_POLY_SET shapeBuffer;
SHAPE_POLY_SET holeBuffer;
bool hasHole = false;
for( AM_PRIMITIVES::iterator prim_macro = primitives.begin(); for( AM_PRIMITIVES::iterator prim_macro = primitives.begin();
prim_macro != primitives.end(); ++prim_macro ) prim_macro != primitives.end(); ++prim_macro )
{ {
prim_macro->DrawBasicShape( aParent, aClipBox, aDC, if( prim_macro->IsAMPrimitiveExposureOn( aParent ) )
aColor, aAltColor, prim_macro->DrawBasicShape( aParent, shapeBuffer, aShapePos );
aShapePos, else
aFilledShape ); {
} prim_macro->DrawBasicShape( aParent, holeBuffer, aShapePos );
}
/* Function HasNegativeItems if( holeBuffer.OutlineCount() ) // we have a new hole in shape: remove the hole
* return true if this macro has at least one aperture primitives {
* that must be drawn in background color shapeBuffer.BooleanSubtract( holeBuffer, SHAPE_POLY_SET::PM_FAST );
* used to optimize screen refresh holeBuffer.RemoveAllContours();
*/ hasHole = true;
bool APERTURE_MACRO::HasNegativeItems( GERBER_DRAW_ITEM* aParent ) }
{ }
for( AM_PRIMITIVES::iterator prim_macro = primitives.begin(); }
prim_macro != primitives.end(); ++prim_macro )
if( shapeBuffer.OutlineCount() == 0 )
return;
// If a hole is defined inside a polygon, we must fracture the polygon
// to be able to drawn it (i.e link holes by overlapping edges)
if( hasHole )
shapeBuffer.Fracture( SHAPE_POLY_SET::PM_FAST );
for( int ii = 0; ii < shapeBuffer.OutlineCount(); ii++ )
{ {
if( prim_macro->mapExposure( aParent ) == false ) // = is negative SHAPE_LINE_CHAIN& poly = shapeBuffer.Outline( ii );
return true;
GRClosedPoly( aClipBox, aDC,
poly.PointCount(), (wxPoint*)&poly.Point( 0 ), aFilledShape, aColor, aColor );
} }
return false;
} }
/** GetShapeDim /** GetShapeDim
* Calculate a value that can be used to evaluate the size of text * Calculate a value that can be used to evaluate the size of text
* when displaying the D-Code of an item * when displaying the D-Code of an item

View File

@ -36,6 +36,8 @@
#include <base_struct.h> #include <base_struct.h>
#include <class_am_param.h> #include <class_am_param.h>
class SHAPE_POLY_SET;
/* /*
* An aperture macro defines a complex shape and is a list of aperture primitives. * An aperture macro defines a complex shape and is a list of aperture primitives.
* Each aperture primitive defines a simple shape (circle, rect, regular polygon...) * Each aperture primitive defines a simple shape (circle, rect, regular polygon...)
@ -52,6 +54,10 @@
* 21,1,$1-$3,$2-$3,0-$1/2-$4,0-$2/2-$4,0* * 21,1,$1-$3,$2-$3,0-$1/2-$4,0-$2/2-$4,0*
* For the aperture primitive, parameters $1 to $3 will be defined in ADD command, * For the aperture primitive, parameters $1 to $3 will be defined in ADD command,
* and $4 is defined inside the macro * and $4 is defined inside the macro
*
* Each basic shape can be a positive shape or a negative shape.
* a negative shape is "local" to the whole shape.
* It must be seen like a hole in the shape, and not like a standard negative object.
*/ */
/** /**
@ -100,43 +106,17 @@ public: AM_PRIMITIVE( bool aGerbMetric, AM_PRIMITIVE_ID aId = AMP_UNKNOWN )
~AM_PRIMITIVE() {} ~AM_PRIMITIVE() {}
/** /**
* Function GetExposure * Function IsAMPrimitiveExposureOn
* returns the first parameter in integer form. Some but not all primitives * @return true if the first parameter is not 0 (it can be only 0 or 1).
* use the first parameter as an exposure control. * Some but not all primitives use the first parameter as an exposure control.
* Others are always ON.
* In a aperture macro shape, a basic primitive with exposure off is a hole in the shape
* it is NOT a negative shape
*/ */
int GetExposure( GERBER_DRAW_ITEM* aParent ) const; bool IsAMPrimitiveExposureOn( GERBER_DRAW_ITEM* aParent ) const;
/**
* Function mapExposure
* translates the first parameter from an aperture macro into a current
* exposure setting.
* @param aParent = a GERBER_DRAW_ITEM that handle:
* ** m_Exposure A dynamic setting which can change throughout the
* reading of the gerber file, and it indicates whether the current tool
* is lit or not.
* ** m_ImageNegative A dynamic setting which can change throughout the reading
* of the gerber file, and it indicates whether the current D codes are to
* be interpreted as erasures or not.
* @return true to draw with current color, false to draw with alt color (erase)
*/
bool mapExposure( GERBER_DRAW_ITEM* aParent );
/* Draw functions: */ /* Draw functions: */
/**
* Function DrawBasicShape
* Draw the primitive shape for flashed items.
* @param aParent = the parent GERBER_DRAW_ITEM which is actually drawn
* @param aClipBox = DC clip box (NULL is no clip)
* @param aDC = device context
* @param aColor = the normal color to use
* @param aAltColor = the color used to draw with "reverse" exposure mode (used in aperture macros only)
* @param aShapePos = the actual shape position
* @param aFilledShape = true to draw in filled mode, false to draw in skecth mode
*/
void DrawBasicShape( GERBER_DRAW_ITEM* aParent, EDA_RECT* aClipBox, wxDC* aDC,
EDA_COLOR_T aColor, EDA_COLOR_T aAltColor, wxPoint aShapePos, bool aFilledShape );
/** GetShapeDim /** GetShapeDim
* Calculate a value that can be used to evaluate the size of text * Calculate a value that can be used to evaluate the size of text
* when displaying the D-Code of an item * when displaying the D-Code of an item
@ -149,6 +129,15 @@ public: AM_PRIMITIVE( bool aGerbMetric, AM_PRIMITIVE_ID aId = AMP_UNKNOWN )
*/ */
int GetShapeDim( GERBER_DRAW_ITEM* aParent ); int GetShapeDim( GERBER_DRAW_ITEM* aParent );
/**
* Function drawBasicShape
* Draw (in fact generate the actual polygonal shape of) the primitive shape of an aperture macro instance.
* @param aParent = the parent GERBER_DRAW_ITEM which is actually drawn
* @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,
wxPoint aShapePos );
private: private:
/** /**
@ -201,13 +190,12 @@ struct APERTURE_MACRO
* @param aParent = the parent GERBER_DRAW_ITEM which is actually drawn * @param aParent = the parent GERBER_DRAW_ITEM which is actually drawn
* @param aClipBox = DC clip box (NULL is no clip) * @param aClipBox = DC clip box (NULL is no clip)
* @param aDC = device context * @param aDC = device context
* @param aColor = the normal color to use * @param aColor = the color of shape
* @param aAltColor = the color used to draw with "reverse" exposure mode (used in aperture macros only)
* @param aShapePos = the actual shape position * @param aShapePos = the actual shape position
* @param aFilledShape = true to draw in filled mode, false to draw in skecth mode * @param aFilledShape = true to draw in filled mode, false to draw in skecth mode
*/ */
void DrawApertureMacroShape( GERBER_DRAW_ITEM* aParent, EDA_RECT* aClipBox, wxDC* aDC, void DrawApertureMacroShape( GERBER_DRAW_ITEM* aParent, EDA_RECT* aClipBox, wxDC* aDC,
EDA_COLOR_T aColor, EDA_COLOR_T aAltColor, wxPoint aShapePos, bool aFilledShape ); EDA_COLOR_T aColor, wxPoint aShapePos, bool aFilledShape );
/** /**
* Function GetShapeDim * Function GetShapeDim
@ -222,16 +210,6 @@ struct APERTURE_MACRO
* @return a dimension, or -1 if no dim to calculate * @return a dimension, or -1 if no dim to calculate
*/ */
int GetShapeDim( GERBER_DRAW_ITEM* aParent ); int GetShapeDim( GERBER_DRAW_ITEM* aParent );
/**
* Function HasNegativeItems
* @param aParent = the parent GERBER_DRAW_ITEM which is actually drawn
* @return true if this macro has at least one shape (using aperture primitives)
* must be drawn in background color
* used to optimize screen refresh (when no items are in background color
* refresh can be faster)
*/
bool HasNegativeItems( GERBER_DRAW_ITEM* aParent );
}; };

View File

@ -242,26 +242,7 @@ bool GERBER_DRAW_ITEM::HasNegativeItems()
bool isClear = m_LayerNegative ^ m_GerberImageFile->m_ImageNegative; bool isClear = m_LayerNegative ^ m_GerberImageFile->m_ImageNegative;
// if isClear is true, this item has negative shape // if isClear is true, this item has negative shape
// but if isClear is true, and if this item use an aperture macro definition, return isClear;
// we must see if this aperture macro uses a negative shape.
if( isClear )
return true;
// see for a macro def
D_CODE* dcodeDescr = GetDcodeDescr();
if( dcodeDescr == NULL )
return false;
if( m_Shape == GBR_SPOT_MACRO )
{
APERTURE_MACRO* macro = dcodeDescr->GetMacro();
if( macro ) // macro == NULL should not occurs
return macro->HasNegativeItems( this );
}
return false;
} }
@ -270,7 +251,6 @@ void GERBER_DRAW_ITEM::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, GR_DRAWMODE aDra
{ {
// used when a D_CODE is not found. default D_CODE to draw a flashed item // used when a D_CODE is not found. default D_CODE to draw a flashed item
static D_CODE dummyD_CODE( 0 ); static D_CODE dummyD_CODE( 0 );
EDA_COLOR_T color, alt_color;
bool isFilled; bool isFilled;
int radius; int radius;
int halfPenWidth; int halfPenWidth;
@ -280,15 +260,13 @@ void GERBER_DRAW_ITEM::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, GR_DRAWMODE aDra
if( d_codeDescr == NULL ) if( d_codeDescr == NULL )
d_codeDescr = &dummyD_CODE; d_codeDescr = &dummyD_CODE;
color = m_GerberImageFile->GetPositiveDrawColor(); EDA_COLOR_T color = m_GerberImageFile->GetPositiveDrawColor();
if( aDrawMode & GR_HIGHLIGHT ) if( aDrawMode & GR_HIGHLIGHT )
ColorChangeHighlightFlag( &color, !(aDrawMode & GR_AND) ); ColorChangeHighlightFlag( &color, !(aDrawMode & GR_AND) );
ColorApplyHighlightFlag( &color ); ColorApplyHighlightFlag( &color );
alt_color = aDrawOptions->m_NegativeDrawColor;
/* isDark is true if flash is positive and should use a drawing /* isDark is true if flash is positive and should use a drawing
* color other than the background color, else use the background color * color other than the background color, else use the background color
* when drawing so that an erasure happens. * when drawing so that an erasure happens.
@ -298,7 +276,7 @@ void GERBER_DRAW_ITEM::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, GR_DRAWMODE aDra
if( !isDark ) if( !isDark )
{ {
// draw in background color ("negative" color) // draw in background color ("negative" color)
std::swap( color, alt_color ); color = aDrawOptions->m_NegativeDrawColor;
} }
GRSetDrawMode( aDC, aDrawMode ); GRSetDrawMode( aDC, aDrawMode );
@ -368,7 +346,7 @@ void GERBER_DRAW_ITEM::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, GR_DRAWMODE aDra
case GBR_SPOT_POLY: case GBR_SPOT_POLY:
case GBR_SPOT_MACRO: case GBR_SPOT_MACRO:
isFilled = aDrawOptions->m_DisplayFlashedItemsFill; isFilled = aDrawOptions->m_DisplayFlashedItemsFill;
d_codeDescr->DrawFlashedShape( this, aPanel->GetClipBox(), aDC, color, alt_color, d_codeDescr->DrawFlashedShape( this, aPanel->GetClipBox(), aDC, color,
m_Start, isFilled ); m_Start, isFilled );
break; break;

View File

@ -152,7 +152,6 @@ int D_CODE::GetShapeDim( GERBER_DRAW_ITEM* aParent )
void D_CODE::DrawFlashedShape( GERBER_DRAW_ITEM* aParent, void D_CODE::DrawFlashedShape( GERBER_DRAW_ITEM* aParent,
EDA_RECT* aClipBox, wxDC* aDC, EDA_COLOR_T aColor, EDA_RECT* aClipBox, wxDC* aDC, EDA_COLOR_T aColor,
EDA_COLOR_T aAltColor,
wxPoint aShapePos, bool aFilledShape ) wxPoint aShapePos, bool aFilledShape )
{ {
int radius; int radius;
@ -160,7 +159,7 @@ void D_CODE::DrawFlashedShape( GERBER_DRAW_ITEM* aParent,
switch( m_Shape ) switch( m_Shape )
{ {
case APT_MACRO: case APT_MACRO:
GetMacro()->DrawApertureMacroShape( aParent, aClipBox, aDC, aColor, aAltColor, GetMacro()->DrawApertureMacroShape( aParent, aClipBox, aDC, aColor,
aShapePos, aFilledShape); aShapePos, aFilledShape);
break; break;

View File

@ -165,13 +165,11 @@ public:
* @param aClipBox = DC clip box (NULL is no clip) * @param aClipBox = DC clip box (NULL is no clip)
* @param aDC = device context * @param aDC = device context
* @param aColor = the normal color to use * @param aColor = the normal color to use
* @param aAltColor = the color used to draw with "reverse" exposure mode (used in
* aperture macros only)
* @param aShapePos = the actual shape position * @param aShapePos = the actual shape position
* @param aFilledShape = true to draw in filled mode, false to draw in sketch mode * @param aFilledShape = true to draw in filled mode, false to draw in sketch mode
*/ */
void DrawFlashedShape( GERBER_DRAW_ITEM* aParent, EDA_RECT* aClipBox, void DrawFlashedShape( GERBER_DRAW_ITEM* aParent, EDA_RECT* aClipBox,
wxDC* aDC, EDA_COLOR_T aColor, EDA_COLOR_T aAltColor, wxDC* aDC, EDA_COLOR_T aColor,
wxPoint aShapePos, bool aFilledShape ); wxPoint aShapePos, bool aFilledShape );
/** /**