Browse Source

Enforce aspect ratio of square barcodes.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/21838
master
Jeff Young 3 days ago
parent
commit
ca09a8a2d4
  1. 2
      include/tool/edit_points.h
  2. 8
      pcbnew/pcb_barcode.h
  3. 25
      pcbnew/tools/pcb_point_editor.cpp

2
include/tool/edit_points.h

@ -125,7 +125,7 @@ public:
bool WithinPoint( const VECTOR2I& aPoint, unsigned int aSize ) const;
/**
* Set a constraint for and EDIT_POINT.
* Set a constraint for an EDIT_POINT.
*
* @param aConstraint is the constraint to be set.
*/

8
pcbnew/pcb_barcode.h

@ -62,7 +62,6 @@ DECLARE_ENUM_TO_WXANY( BARCODE_ECC_T );
class PCB_BARCODE : public BOARD_ITEM
{
public:
/**
* Construct a PCB_BARCODE.
@ -348,6 +347,13 @@ public:
void SetKind( BARCODE_T aKind );
void SetBarcodeKind( BARCODE_T aKind ); // Includes re-compute
bool KeepSquare() const
{
return m_kind == BARCODE_T::QR_CODE
|| m_kind == BARCODE_T::MICRO_QR_CODE
|| m_kind == BARCODE_T::DATA_MATRIX;
}
/**
* Set the error correction level used for QR codes.
*

25
pcbnew/tools/pcb_point_editor.cpp

@ -362,7 +362,7 @@ public:
}
/**
* Update the coordinates of 4 corners of a rectangle, according to pad constraints and the
* Update the coordinates of 4 corners of a rectangle, according to constraints and the
* moved corner
*
* @param aPoints the points list
@ -652,10 +652,27 @@ public:
void MakePoints( EDIT_POINTS& aPoints ) override
{
if( m_barcode.GetAngle().IsCardinal() )
RECTANGLE_POINT_EDIT_BEHAVIOR::MakePoints( makeDummyRect(), aPoints );
if( !m_barcode.GetAngle().IsCardinal() )
{
// Non-cardinal barcode point-editing isn't useful enough to support.
return;
}
auto set45Constraint =
[&]( int a, int b )
{
aPoints.Point( a ).SetConstraint( new EC_45DEGREE( aPoints.Point( a ), aPoints.Point( b ) ) );
};
RECTANGLE_POINT_EDIT_BEHAVIOR::MakePoints( makeDummyRect(), aPoints );
// Non-cardinal barcode point-editing isn't useful enough to support.
if( m_barcode.KeepSquare() )
{
set45Constraint( RECT_TOP_LEFT, RECT_BOT_RIGHT );
set45Constraint( RECT_TOP_RIGHT, RECT_BOT_LEFT );
set45Constraint( RECT_BOT_RIGHT, RECT_TOP_LEFT );
set45Constraint( RECT_BOT_LEFT, RECT_TOP_RIGHT );
}
}
bool UpdatePoints( EDIT_POINTS& aPoints ) override

Loading…
Cancel
Save