7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-20 00:21:31 +00:00

Pcbnew: Fix issue when flipping a graphic segment (SHAPE_T::SEGMENT).

PCB_SHAPE::Normalize() normalized a graphic segment by (sometimes) swapping
start and end points. But it creates an issue when flipping a segment: the
reference point can be changed.
This normalization was made for DRC purpose when comparing 2 footprints.
Now, PCB_SHAPE::Normalize() does not change end points of a segment, and a
specific PCB_SHAPE::NormalizeForCompare() normalize fct is used for DRC compare.
This commit is contained in:
jean-pierre charras 2024-09-28 17:22:22 +02:00
parent 016b9deec2
commit 9979b4849e
4 changed files with 39 additions and 18 deletions

View File

@ -367,6 +367,13 @@ public:
*/
virtual void Normalize() {}
/**
* Perform any normalization required to compare 2 graphics, especially
* if the can be rotated and/or flipped.
* Similar to Normalize(), but more changes can be made
*/
virtual void NormalizeForCompare() { Normalize(); }
/**
* Return the #BOARD in which this #BOARD_ITEM resides, or NULL if none.
*/

View File

@ -562,7 +562,7 @@ bool FOOTPRINT::FootprintNeedsUpdate( const FOOTPRINT* aLibFP, int aCompareFlags
temp->SetPosition( GetPosition() );
for( BOARD_ITEM* item : temp->GraphicalItems() )
item->Normalize();
item->NormalizeForCompare();
// This temporary footprint must not have a parent when it goes out of scope because it
// must not trigger the IncrementTimestamp call in ~FOOTPRINT.
@ -689,7 +689,7 @@ bool FOOTPRINT::FootprintNeedsUpdate( const FOOTPRINT* aLibFP, int aCompareFlags
dummy.SetParent( nullptr );
for( BOARD_ITEM* item : dummy.GraphicalItems() )
item->Normalize();
item->NormalizeForCompare();
std::set<BOARD_ITEM*, FOOTPRINT::cmp_drawings> aShapes;
std::copy_if( dummy.GraphicalItems().begin(), dummy.GraphicalItems().end(),

View File

@ -479,22 +479,7 @@ void PCB_SHAPE::Scale( double aScale )
void PCB_SHAPE::Normalize()
{
if( m_shape == SHAPE_T::SEGMENT )
{
// we want start point the top left point and end point the bottom right
// (more easy to compare 2 segments: we are seeing them as equivalent if
// they have the same end points, not necessary the same order)
VECTOR2I start = GetStart();
VECTOR2I end = GetEnd();
if( ( start.x > end.x )
|| ( start.x == end.x && start.y < end.y ) )
{
SetStart( end );
SetEnd( start );
}
}
else if( m_shape == SHAPE_T::RECTANGLE )
if( m_shape == SHAPE_T::RECTANGLE )
{
VECTOR2I start = GetStart();
VECTOR2I end = GetEnd();
@ -551,6 +536,28 @@ void PCB_SHAPE::Normalize()
}
void PCB_SHAPE::NormalizeForCompare()
{
if( m_shape == SHAPE_T::SEGMENT )
{
// we want start point the top left point and end point the bottom right
// (more easy to compare 2 segments: we are seeing them as equivalent if
// they have the same end points, not necessary the same order)
VECTOR2I start = GetStart();
VECTOR2I end = GetEnd();
if( ( start.x > end.x )
|| ( start.x == end.x && start.y < end.y ) )
{
SetStart( end );
SetEnd( start );
}
}
else
Normalize();
}
void PCB_SHAPE::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle )
{
rotate( aRotCentre, aAngle );

View File

@ -125,6 +125,13 @@ public:
void Normalize() override;
/**
* Normalize coordinates to compare 2 similar PCB_SHAPES
* similat to Normalize(), but also normalize SEGMENT end points
* needed only for graphic comparisons
*/
void NormalizeForCompare() override;
void Move( const VECTOR2I& aMoveVector ) override;
void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) override;