diff --git a/gerbview/class_aperture_macro.cpp b/gerbview/class_aperture_macro.cpp index 3bc52fd4fe..24b3c43860 100644 --- a/gerbview/class_aperture_macro.cpp +++ b/gerbview/class_aperture_macro.cpp @@ -116,14 +116,31 @@ void AM_PRIMITIVE::DrawBasicShape( GERBER_DRAW_ITEM* aParent, { /* Generated by an aperture macro declaration like: * "1,1,0.3,0.5, 1.0*" - * type (1), exposure, diameter, pos.x, pos.y + * type (1), exposure, diameter, pos.x, pos.y, + * is a optional parameter: rotation form origin * type is not stored in parameters list, so the first parameter is exposure */ - curPos += mapPt( params[2].GetValue( tool ), params[3].GetValue( tool ), m_GerbMetric ); - curPos = aParent->GetABPosition( curPos ); + wxPoint center = mapPt( params[2].GetValue( tool ), params[3].GetValue( tool ), m_GerbMetric ); int radius = scaletoIU( params[1].GetValue( tool ), m_GerbMetric ) / 2; - TransformCircleToPolygon( aShapeBuffer, curPos, radius, seg_per_circle ); + TransformCircleToPolygon( aShapeBuffer, center, radius, seg_per_circle ); + + SHAPE_LINE_CHAIN& poly = aShapeBuffer.Outline( aShapeBuffer.OutlineCount() - 1 ); + + // shape rotation (if any): + if( params.size() >= 5 ) + { + rotation = params[4].GetValue( tool ) * 10.0; + + if( rotation != 0) + { + for( int ii = 0; ii < poly.PointCount(); ii++ ) + RotatePoint( &poly.Point(ii).x, &poly.Point(ii).y, rotation ); + } + } + + // Move to current position: + poly.Move( aParent->GetABPosition( curPos ) ); } break; @@ -434,8 +451,8 @@ void AM_PRIMITIVE::ConvertShapeToPolygon( GERBER_DRAW_ITEM* aParent, wxPoint delta = end - start; int len = KiROUND( EuclideanNorm( delta ) ); - // To build the polygon, we must create a horizonta polygon starting to "start" - // and rotate it to have it end point to "end" + // To build the polygon, we must create a horizontal polygon starting to "start" + // and rotate it to have the end point to "end" wxPoint currpt; currpt.y += width / 2; // Upper left aBuffer.push_back( currpt ); @@ -443,7 +460,7 @@ void AM_PRIMITIVE::ConvertShapeToPolygon( GERBER_DRAW_ITEM* aParent, aBuffer.push_back( currpt ); currpt.y -= width; // lower right aBuffer.push_back( currpt ); - currpt.x = 0; // Upper left + currpt.x = 0; // lower left aBuffer.push_back( currpt ); // Rotate rectangle and move it to the actual start point diff --git a/gerbview/rs274x.cpp b/gerbview/rs274x.cpp index 2617383430..74aacfa530 100644 --- a/gerbview/rs274x.cpp +++ b/gerbview/rs274x.cpp @@ -1045,7 +1045,8 @@ bool GERBER_FILE_IMAGE::ReadApertureMacro( char *buff, if( *text == '%' ) break; // exit with text still pointing at % - int paramCount = 0; + int paramCount = 0; // will be set to the minimal parameters count, + // depending on the actual primitive int primitive_type = AMP_UNKNOWN; // Test for a valid symbol at the beginning of a description: // it can be: a parameter declaration like $1=$2/4 @@ -1084,7 +1085,7 @@ bool GERBER_FILE_IMAGE::ReadApertureMacro( char *buff, break; case AMP_CIRCLE: - paramCount = 4; + paramCount = 4; // minimal count. can have a optional parameter (rotation) break; case AMP_LINE2: @@ -1132,7 +1133,7 @@ bool GERBER_FILE_IMAGE::ReadApertureMacro( char *buff, prim.primitive_id = (AM_PRIMITIVE_ID) primitive_type; int ii; - for( ii = 0; ii < paramCount && *text && *text != '*'; ++ii ) + for( ii = 0; ii < *text && *text != '*'; ++ii ) { prim.params.push_back( AM_PARAM() );