From fc0017fc950a540321fd4efb78838acf7782ee22 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 29 Oct 2023 11:23:52 +0000 Subject: [PATCH] Normalize rects higher up. We don't want to normalize footprint children to their board-relative coordinates. --- common/eda_shape.cpp | 19 ------------------- include/board_item.h | 5 +++++ .../drc/drc_test_provider_library_parity.cpp | 5 +---- pcbnew/pcb_shape.cpp | 2 +- pcbnew/pcb_shape.h | 8 ++++---- pcbnew/plugins/kicad/pcb_parser.cpp | 7 +++---- pcbnew/tools/drawing_tool.cpp | 2 +- pcbnew/tools/edit_tool.cpp | 4 ++++ 8 files changed, 19 insertions(+), 33 deletions(-) diff --git a/common/eda_shape.cpp b/common/eda_shape.cpp index e2d4f52f53..5c2149f2b2 100644 --- a/common/eda_shape.cpp +++ b/common/eda_shape.cpp @@ -351,14 +351,6 @@ void EDA_SHAPE::rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) { RotatePoint( m_start, aRotCentre, aAngle ); RotatePoint( m_end, aRotCentre, aAngle ); - - // Normalize - BOX2I bbox; - bbox.Merge( m_start ); - bbox.Merge( m_end ); - m_start = bbox.GetOrigin(); - m_end = bbox.GetEnd(); - break; } @@ -413,17 +405,6 @@ void EDA_SHAPE::flip( const VECTOR2I& aCentre, bool aFlipLeftRight ) } std::swap( m_start, m_end ); - - if( m_shape == SHAPE_T::RECTANGLE ) - { - // Normalize - BOX2I bbox; - bbox.Merge( m_start ); - bbox.Merge( m_end ); - m_start = bbox.GetOrigin(); - m_end = bbox.GetEnd(); - } - break; case SHAPE_T::CIRCLE: diff --git a/include/board_item.h b/include/board_item.h index c3fb34d8d7..e18bcbe3d3 100644 --- a/include/board_item.h +++ b/include/board_item.h @@ -327,6 +327,11 @@ public: */ virtual void Flip( const VECTOR2I& aCentre, bool aFlipLeftRight ); + /** + * Perform any normalization required after a user rotate and/or flip. + */ + virtual void Normalize() {} + /** * Return the #BOARD in which this #BOARD_ITEM resides, or NULL if none. */ diff --git a/pcbnew/drc/drc_test_provider_library_parity.cpp b/pcbnew/drc/drc_test_provider_library_parity.cpp index 778699822e..f1b8dbdac5 100644 --- a/pcbnew/drc/drc_test_provider_library_parity.cpp +++ b/pcbnew/drc/drc_test_provider_library_parity.cpp @@ -530,10 +530,7 @@ bool FOOTPRINT::FootprintNeedsUpdate( const FOOTPRINT* aLibFP, REPORTER* aReport temp->SetOrientation( ANGLE_0 ); for( BOARD_ITEM* item : temp->GraphicalItems() ) - { - if( item->Type() == PCB_SHAPE_T ) - static_cast( item )->NormalizeRect(); - } + item->Normalize(); diff = temp->FootprintNeedsUpdate( aLibFP, aReporter ); diff --git a/pcbnew/pcb_shape.cpp b/pcbnew/pcb_shape.cpp index a373e9e8cd..8993eb3216 100644 --- a/pcbnew/pcb_shape.cpp +++ b/pcbnew/pcb_shape.cpp @@ -244,7 +244,7 @@ void PCB_SHAPE::Scale( double aScale ) } -void PCB_SHAPE::NormalizeRect() +void PCB_SHAPE::Normalize() { if( m_shape == SHAPE_T::RECTANGLE ) { diff --git a/pcbnew/pcb_shape.h b/pcbnew/pcb_shape.h index cfec12a4e5..3705cb9e1c 100644 --- a/pcbnew/pcb_shape.h +++ b/pcbnew/pcb_shape.h @@ -121,13 +121,13 @@ public: return hitTest( aRect, aContained, aAccuracy ); } - void NormalizeRect(); + void Normalize() override; - virtual void Move( const VECTOR2I& aMoveVector ) override; + void Move( const VECTOR2I& aMoveVector ) override; - virtual void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) override; + void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) override; - virtual void Flip( const VECTOR2I& aCentre, bool aFlipLeftRight ) override; + void Flip( const VECTOR2I& aCentre, bool aFlipLeftRight ) override; virtual void Mirror( const VECTOR2I& aCentre, bool aMirrorAroundXAxis ); diff --git a/pcbnew/plugins/kicad/pcb_parser.cpp b/pcbnew/plugins/kicad/pcb_parser.cpp index 245c87b6f2..3dc408a5ef 100644 --- a/pcbnew/plugins/kicad/pcb_parser.cpp +++ b/pcbnew/plugins/kicad/pcb_parser.cpp @@ -2745,13 +2745,12 @@ PCB_SHAPE* PCB_PARSER::parsePCB_SHAPE( BOARD_ITEM* aParent ) if( aParent && aParent->Type() == PCB_FOOTPRINT_T ) { - // I'm not aware of any reason to skip normalization of footprint rects, except - // that that's what we've always done. (And, FWIW, the Alitum test gold files - // currently depend on this behaviour.) + // Footprint shapes are stored in board-relative coordinates, but we want the + // normalization to remain in footprint-relative coordinates. } else { - shape->NormalizeRect(); + shape->Normalize(); } NeedRIGHT(); diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index 0ce0fe744f..5c48b487cb 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -423,7 +423,7 @@ int DRAWING_TOOL::DrawRectangle( const TOOL_EVENT& aEvent ) } else { - rect->NormalizeRect(); + rect->Normalize(); commit.Add( rect ); commit.Push( isTextBox ? _( "Draw Text Box" ) : _( "Draw Rectangle" ) ); diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 191bb76a54..916e125e6a 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -1767,7 +1767,10 @@ int EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent ) } if( BOARD_ITEM* board_item = dynamic_cast( item ) ) + { board_item->Rotate( refPt, rotateAngle ); + board_item->Normalize(); + } } if( !localCommit.Empty() ) @@ -2054,6 +2057,7 @@ int EDIT_TOOL::Flip( const TOOL_EVENT& aEvent ) } boardItem->Flip( refPt, leftRight ); + boardItem->Normalize(); } }