From 098b03e17a4c84b5143ba3ff15190eb69c9f0f9d Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Wed, 18 Jan 2023 16:35:09 +0100 Subject: [PATCH] gerbview: Cleanup code. Remove useless or not working code. --- gerbview/am_primitive.cpp | 173 ++-------------------------------- gerbview/am_primitive.h | 67 ++----------- gerbview/dcode.cpp | 15 +-- gerbview/gerber_draw_item.cpp | 16 +--- 4 files changed, 26 insertions(+), 245 deletions(-) diff --git a/gerbview/am_primitive.cpp b/gerbview/am_primitive.cpp index d5dcfec5ee..8835f184e6 100644 --- a/gerbview/am_primitive.cpp +++ b/gerbview/am_primitive.cpp @@ -93,7 +93,7 @@ bool AM_PRIMITIVE::IsAMPrimitiveExposureOn( const GERBER_DRAW_ITEM* aParent ) co const int seg_per_circle = 64; // Number of segments to approximate a circle -void AM_PRIMITIVE::DrawBasicShape( const GERBER_DRAW_ITEM* aParent, SHAPE_POLY_SET& aShapeBuffer, +void AM_PRIMITIVE::ConvertBasicShapeToPolygon( const GERBER_DRAW_ITEM* aParent, SHAPE_POLY_SET& aShapeBuffer, const VECTOR2I& aShapePos ) { #define TO_POLY_SHAPE \ @@ -694,124 +694,6 @@ void AM_PRIMITIVE::ConvertShapeToPolygon( const GERBER_DRAW_ITEM* aParent, } -int AM_PRIMITIVE::GetShapeDim( const GERBER_DRAW_ITEM* aParent ) -{ - int dim = -1; - D_CODE* tool = aParent->GetDcodeDescr(); - - switch( m_Primitive_id ) - { - case AMP_CIRCLE: - // m_Params = exposure, diameter, pos.x, pos.y - dim = scaletoIU( m_Params[1].GetValue( tool ), m_GerbMetric ); // Diameter - break; - - case AMP_LINE2: - case AMP_LINE20: // Line with rectangle ends. (Width, start and end pos + rotation) - dim = scaletoIU( m_Params[1].GetValue( tool ), m_GerbMetric ); // line width - break; - - case AMP_LINE_CENTER: - { - VECTOR2I size = - mapPt( m_Params[1].GetValue( tool ), m_Params[2].GetValue( tool ), m_GerbMetric ); - dim = std::min(size.x, size.y); - break; - } - - case AMP_LINE_LOWER_LEFT: - { - VECTOR2I size = - mapPt( m_Params[1].GetValue( tool ), m_Params[2].GetValue( tool ), m_GerbMetric ); - dim = std::min(size.x, size.y); - break; - } - - case AMP_THERMAL: - { - // Only 1/4 of the full shape is built, because the other 3 shapes will be draw from - // this first rotated by 90, 180 and 270 deg. - // m_Params = center.x (unused here), center.y (unused here), outside diam, inside diam, - // crosshair thickness. - dim = scaletoIU( m_Params[2].GetValue( tool ), m_GerbMetric ) / 2; // Outer diam - break; - } - - case AMP_MOIRE: // A cross hair with n concentric circles. - dim = scaletoIU( m_Params[7].GetValue( tool ), m_GerbMetric ); // = cross hair len - break; - - case AMP_OUTLINE: // a free polygon : - { - // dim = min side of the bounding box (this is a poor criteria, but what is a good - // criteria b?) - // exposure, corners count, corner1.x, corner.1y, ..., rotation - // note: corners count is the count of corners following corner1 - int numPoints = (int) m_Params[1].GetValue( tool ); - - // Read points. numPoints does not include the starting point, so add 1. - // and calculate the bounding box; - VECTOR2I pos_min, pos_max, pos; - int prm_idx = 2; // m_Params[2] is the first X coordinate - int last_prm = m_Params.size() - 1; - - for( int i = 0; i<= numPoints; ++i ) - { - pos.x = scaletoIU( m_Params[prm_idx].GetValue( tool ), m_GerbMetric ); - prm_idx++; - pos.y = scaletoIU( m_Params[prm_idx].GetValue( tool ), m_GerbMetric ); - prm_idx++; - - if( i == 0 ) - { - pos_min = pos_max = pos; - } - else - { - // upper right corner: - if( pos_min.x > pos.x ) - pos_min.x = pos.x; - - if( pos_min.y > pos.y ) - pos_min.y = pos.y; - - // lower left corner: - if( pos_max.x < pos.x ) - pos_max.x = pos.x; - - if( pos_max.y < pos.y ) - pos_max.y = pos.y; - } - - // Guard: ensure prm_idx < last_prm (last prm is orientation) - // I saw malformed gerber files with numCorners = number - // of coordinates instead of number of coordinates following the first point - if( prm_idx >= last_prm ) - break; - } - - // calculate dim - VECTOR2I size; - size.x = pos_max.x - pos_min.x; - size.y = pos_max.y - pos_min.y; - dim = std::min( size.x, size.y ); - break; - } - - case AMP_POLYGON: // Regular polygon - dim = scaletoIU( m_Params[4].GetValue( tool ), m_GerbMetric ) / 2; // Radius - break; - - case AMP_COMMENT: - case AMP_UNKNOWN: - case AMP_EOF: - break; - } - - return dim; -} - - SHAPE_POLY_SET* APERTURE_MACRO::GetApertureMacroShape( const GERBER_DRAW_ITEM* aParent, const VECTOR2I& aShapePos ) { @@ -819,19 +701,18 @@ SHAPE_POLY_SET* APERTURE_MACRO::GetApertureMacroShape( const GERBER_DRAW_ITEM* a m_shape.RemoveAllContours(); - for( AM_PRIMITIVES::iterator prim_macro = m_PrimitivesList.begin(); - prim_macro != m_PrimitivesList.end(); ++prim_macro ) + for( AM_PRIMITIVE& prim_macro : m_PrimitivesList ) { - if( prim_macro->m_Primitive_id == AMP_COMMENT ) + if( prim_macro.m_Primitive_id == AMP_COMMENT ) continue; - if( prim_macro->IsAMPrimitiveExposureOn( aParent ) ) + if( prim_macro.IsAMPrimitiveExposureOn( aParent ) ) { - prim_macro->DrawBasicShape( aParent, m_shape, aShapePos ); + prim_macro.ConvertBasicShapeToPolygon( aParent, m_shape, aShapePos ); } else { - prim_macro->DrawBasicShape( aParent, holeBuffer, aShapePos ); + prim_macro.ConvertBasicShapeToPolygon( aParent, holeBuffer, aShapePos ); if( holeBuffer.OutlineCount() ) // we have a new hole in shape: remove the hole { @@ -849,52 +730,10 @@ SHAPE_POLY_SET* APERTURE_MACRO::GetApertureMacroShape( const GERBER_DRAW_ITEM* a // (i.e link holes by overlapping edges) m_shape.Fracture( SHAPE_POLY_SET::PM_FAST ); - m_boundingBox = BOX2I( VECTOR2I( 0, 0 ), VECTOR2I( 1, 1 ) ); - - auto bb = m_shape.BBox(); - VECTOR2I center( bb.Centre().x, bb.Centre().y ); - - m_boundingBox.Move( aParent->GetABPosition( center ) ); - m_boundingBox.Inflate( bb.GetWidth() / 2, bb.GetHeight() / 2 ); - return &m_shape; } -void APERTURE_MACRO::DrawApertureMacroShape( const GERBER_DRAW_ITEM* aParent, wxDC* aDC, - const COLOR4D& aColor, const VECTOR2I& aShapePos, - bool aFilledShape ) -{ - SHAPE_POLY_SET* shapeBuffer = GetApertureMacroShape( aParent, aShapePos ); - - if( shapeBuffer->OutlineCount() == 0 ) - return; - - for( int ii = 0; ii < shapeBuffer->OutlineCount(); ii++ ) - { - SHAPE_LINE_CHAIN& poly = shapeBuffer->Outline( ii ); - GRClosedPoly( aDC, poly.PointCount(), (VECTOR2I*) &poly.CPoint( 0 ), aFilledShape, aColor ); - } -} - - -int APERTURE_MACRO::GetShapeDim( GERBER_DRAW_ITEM* aParent ) -{ - int dim = -1; - - for( AM_PRIMITIVES::iterator prim_macro = m_PrimitivesList.begin(); - prim_macro != m_PrimitivesList.end(); ++prim_macro ) - { - int pdim = prim_macro->GetShapeDim( aParent ); - - if( dim < pdim ) - dim = pdim; - } - - return dim; -} - - double APERTURE_MACRO::GetLocalParam( const D_CODE* aDcode, unsigned aParamId ) const { // find parameter descr. diff --git a/gerbview/am_primitive.h b/gerbview/am_primitive.h index 074458e489..e46cc79b7e 100644 --- a/gerbview/am_primitive.h +++ b/gerbview/am_primitive.h @@ -115,32 +115,17 @@ public: */ bool IsAMPrimitiveExposureOn( const GERBER_DRAW_ITEM* aParent ) const; - /* Draw functions: */ - /** - * Calculate a value that can be used to evaluate the size of text when displaying the - * D-Code of an item. - * - * Due to the complexity of the shape of some primitives one cannot calculate the "size" - * of a shape (only a bounding box) but here, the "dimension" of the shape is the diameter - * of the primitive or for lines the width of the line. - * - * @param aParent is the parent GERBER_DRAW_ITEM which is actually drawn - * @return a dimension, or -1 if no dim to calculate - */ - int GetShapeDim( const GERBER_DRAW_ITEM* aParent ); - - /** - * Draw (in fact generate the actual polygonal shape of) the primitive shape of an aperture + * Generate the polygonal shape of the primitive shape of an aperture * macro instance. * * @param aParent is the parent GERBER_DRAW_ITEM which is actually drawn. * @param aShapeBuffer is a SHAPE_POLY_SET to put the shape converted to a polygon. * @param aShapePos is the actual shape position. */ - void DrawBasicShape( const GERBER_DRAW_ITEM* aParent, - SHAPE_POLY_SET& aShapeBuffer, - const VECTOR2I& aShapePos ); + void ConvertBasicShapeToPolygon( const GERBER_DRAW_ITEM* aParent, + SHAPE_POLY_SET& aShapeBuffer, + const VECTOR2I& aShapePos ); private: /** @@ -157,8 +142,6 @@ private: }; -typedef std::vector AM_PRIMITIVES; - /** * Support the "aperture macro" defined within standard RS274X. */ @@ -191,44 +174,15 @@ public: SHAPE_POLY_SET* GetApertureMacroShape( const GERBER_DRAW_ITEM* aParent, const VECTOR2I& aShapePos ); - /** - * Draw the primitive shape for flashed items. - * - * When an item is flashed, this is the shape of the item. - * - * @param aParent is the parent GERBER_DRAW_ITEM which is actually drawn. - * @param aDC is the device context. - * @param aColor is the color of shape. - * @param aShapePos is the actual shape position. - * @param aFilledShape set to true to draw in filled mode, false to draw in sketch mode. + /** + * The name of the aperture macro as defined like %AMVB_RECTANGLE* (name is VB_RECTANGLE) */ - void DrawApertureMacroShape( const GERBER_DRAW_ITEM* aParent, wxDC* aDC, - const COLOR4D& aColor, - const VECTOR2I& aShapePos, bool aFilledShape ); + wxString m_AmName; /** - * Calculate a value that can be used to evaluate the size of text when displaying the - * D-Code of an item. - * - * Due to the complexity of a shape using many primitives one cannot calculate the "size" of - * a shape (only abounding box) but most of aperture macro are using one or few primitives - * and the "dimension" of the shape is the diameter of the primitive (or the max diameter of - * primitives). - * - * @param aParent is the parent #GERBER_DRAW_ITEM which is actually drawn. - * @return a dimension, or -1 if no dim to calculate. + * A sequence of AM_PRIMITIVEs */ - int GetShapeDim( GERBER_DRAW_ITEM* aParent ); - - /// Return the bounding box of the shape. - BOX2I GetBoundingBox() const - { - return m_boundingBox; - } - - wxString m_AmName; ///< The name of the aperture macro as defined - ///< like %AMVB_RECTANGLE* (name is VB_RECTANGLE) - AM_PRIMITIVES m_PrimitivesList; ///< A sequence of AM_PRIMITIVEs + std::vector m_PrimitivesList; /* A deferred parameter can be defined in aperture macro, * but outside aperture primitives. Example @@ -240,9 +194,6 @@ public: private: SHAPE_POLY_SET m_shape; ///< The shape of the item, calculated by GetApertureMacroShape - BOX2I m_boundingBox; ///< The bounding box of the item, calculated by - ///< GetApertureMacroShape. - }; diff --git a/gerbview/dcode.cpp b/gerbview/dcode.cpp index bd2a3e9182..5a7961881a 100644 --- a/gerbview/dcode.cpp +++ b/gerbview/dcode.cpp @@ -114,7 +114,7 @@ const wxChar* D_CODE::ShowApertureType( APERTURE_T aType ) int D_CODE::GetShapeDim( GERBER_DRAW_ITEM* aParent ) { - int dim = -1; + int dim = 0; switch( m_Shape ) { @@ -133,7 +133,13 @@ int D_CODE::GetShapeDim( GERBER_DRAW_ITEM* aParent ) case APT_MACRO: if( m_Macro ) - dim = m_Macro->GetShapeDim( aParent ); + { + if( m_Polygon.OutlineCount() == 0 ) + ConvertShapeToPolygon( aParent ); + + BOX2I bbox = m_Polygon.BBox(); + dim = std::min( bbox.GetWidth(), bbox.GetHeight() ); + } break; default: @@ -151,10 +157,6 @@ void D_CODE::DrawFlashedShape( const GERBER_DRAW_ITEM* aParent, wxDC* aDC, const switch( m_Shape ) { - case APT_MACRO: - GetMacro()->DrawApertureMacroShape( aParent, aDC, aColor, aShapePos, aFilledShape ); - break; - case APT_CIRCLE: radius = m_Size.x >> 1; @@ -250,6 +252,7 @@ void D_CODE::DrawFlashedShape( const GERBER_DRAW_ITEM* aParent, wxDC* aDC, const break; + case APT_MACRO: case APT_POLYGON: if( m_Polygon.OutlineCount() == 0 ) ConvertShapeToPolygon( aParent ); diff --git a/gerbview/gerber_draw_item.cpp b/gerbview/gerber_draw_item.cpp index 252d12338c..3aa8d7c664 100644 --- a/gerbview/gerber_draw_item.cpp +++ b/gerbview/gerber_draw_item.cpp @@ -318,6 +318,7 @@ const BOX2I GERBER_DRAW_ITEM::GetBoundingBox() const break; } + case GBR_SPOT_MACRO: case GBR_SPOT_POLY: { if( code ) @@ -331,19 +332,6 @@ const BOX2I GERBER_DRAW_ITEM::GetBoundingBox() const break; } - case GBR_SPOT_MACRO: - { - if( code ) - { - // Update the shape drawings and the bounding box coordinates: - code->GetMacro()->GetApertureMacroShape( this, m_Start ); - - // now the bounding box is valid: - bbox = code->GetMacro()->GetBoundingBox(); - } - - break; - } case GBR_SEGMENT: { @@ -955,7 +943,7 @@ double GERBER_DRAW_ITEM::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const switch( m_Shape ) { case GBR_SPOT_MACRO: - size = GetDcodeDescr()->GetMacro()->GetBoundingBox().GetWidth(); + size = GetDcodeDescr()->m_Polygon.BBox().GetWidth(); break; case GBR_ARC: