diff --git a/pcbnew/generators/pcb_tuning_pattern.cpp b/pcbnew/generators/pcb_tuning_pattern.cpp index 9fe3dcf04e..d9ee6d05e9 100644 --- a/pcbnew/generators/pcb_tuning_pattern.cpp +++ b/pcbnew/generators/pcb_tuning_pattern.cpp @@ -293,12 +293,11 @@ public: void Remove( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit ) override; - bool MakeEditPoints( std::shared_ptr points ) const override; + bool MakeEditPoints( EDIT_POINTS& points ) const override; - bool UpdateFromEditPoints( std::shared_ptr aEditPoints, - BOARD_COMMIT* aCommit ) override; + bool UpdateFromEditPoints( EDIT_POINTS& aEditPoints ) override; - bool UpdateEditPoints( std::shared_ptr aEditPoints ) override; + bool UpdateEditPoints( EDIT_POINTS& aEditPoints ) override; void Move( const VECTOR2I& aMoveVector ) override { @@ -1579,7 +1578,7 @@ void PCB_TUNING_PATTERN::EditRevert( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD } -bool PCB_TUNING_PATTERN::MakeEditPoints( std::shared_ptr points ) const +bool PCB_TUNING_PATTERN::MakeEditPoints( EDIT_POINTS& aPoints ) const { VECTOR2I centerlineOffset; VECTOR2I centerlineOffsetEnd; @@ -1590,8 +1589,8 @@ bool PCB_TUNING_PATTERN::MakeEditPoints( std::shared_ptr points ) c centerlineOffsetEnd = ( m_baseLineCoupled->CPoint( -1 ) - m_end ) / 2; } - points->AddPoint( m_origin + centerlineOffset ); - points->AddPoint( m_end + centerlineOffsetEnd ); + aPoints.AddPoint( m_origin + centerlineOffset ); + aPoints.AddPoint( m_end + centerlineOffsetEnd ); SEG base = m_baseLine && m_baseLine->SegmentCount() > 0 ? m_baseLine->CSegment( 0 ) : SEG( m_origin, m_end ); @@ -1609,21 +1608,20 @@ bool PCB_TUNING_PATTERN::MakeEditPoints( std::shared_ptr points ) c VECTOR2I widthHandleOffset = ( base.B - base.A ).Perpendicular().Resize( amplitude ); - points->AddPoint( base.A + widthHandleOffset ); - points->Point( 2 ).SetGridConstraint( IGNORE_GRID ); + aPoints.AddPoint( base.A + widthHandleOffset ); + aPoints.Point( 2 ).SetGridConstraint( IGNORE_GRID ); VECTOR2I spacingHandleOffset = widthHandleOffset + ( base.B - base.A ).Resize( KiROUND( m_settings.m_spacing * 1.5 ) ); - points->AddPoint( base.A + spacingHandleOffset ); - points->Point( 3 ).SetGridConstraint( IGNORE_GRID ); + aPoints.AddPoint( base.A + spacingHandleOffset ); + aPoints.Point( 3 ).SetGridConstraint( IGNORE_GRID ); return true; } -bool PCB_TUNING_PATTERN::UpdateFromEditPoints( std::shared_ptr aEditPoints, - BOARD_COMMIT* aCommit ) +bool PCB_TUNING_PATTERN::UpdateFromEditPoints( EDIT_POINTS& aEditPoints ) { VECTOR2I centerlineOffset; VECTOR2I centerlineOffsetEnd; @@ -1640,12 +1638,12 @@ bool PCB_TUNING_PATTERN::UpdateFromEditPoints( std::shared_ptr aEdi base.A += centerlineOffset; base.B += centerlineOffset; - m_origin = aEditPoints->Point( 0 ).GetPosition() - centerlineOffset; - m_end = aEditPoints->Point( 1 ).GetPosition() - centerlineOffsetEnd; + m_origin = aEditPoints.Point( 0 ).GetPosition() - centerlineOffset; + m_end = aEditPoints.Point( 1 ).GetPosition() - centerlineOffsetEnd; - if( aEditPoints->Point( 2 ).IsActive() ) + if( aEditPoints.Point( 2 ).IsActive() ) { - VECTOR2I wHandle = aEditPoints->Point( 2 ).GetPosition(); + VECTOR2I wHandle = aEditPoints.Point( 2 ).GetPosition(); int value = base.LineDistance( wHandle ); @@ -1664,10 +1662,10 @@ bool PCB_TUNING_PATTERN::UpdateFromEditPoints( std::shared_ptr aEdi m_settings.m_initialSide = PNS::MEANDER_SIDE_RIGHT; } - if( aEditPoints->Point( 3 ).IsActive() ) + if( aEditPoints.Point( 3 ).IsActive() ) { - VECTOR2I wHandle = aEditPoints->Point( 2 ).GetPosition(); - VECTOR2I sHandle = aEditPoints->Point( 3 ).GetPosition(); + VECTOR2I wHandle = aEditPoints.Point( 2 ).GetPosition(); + VECTOR2I sHandle = aEditPoints.Point( 3 ).GetPosition(); int value = KiROUND( SEG( base.A, wHandle ).LineDistance( sHandle ) / 1.5 ); @@ -1678,7 +1676,7 @@ bool PCB_TUNING_PATTERN::UpdateFromEditPoints( std::shared_ptr aEdi } -bool PCB_TUNING_PATTERN::UpdateEditPoints( std::shared_ptr aEditPoints ) +bool PCB_TUNING_PATTERN::UpdateEditPoints( EDIT_POINTS& aEditPoints ) { VECTOR2I centerlineOffset; VECTOR2I centerlineOffsetEnd; @@ -1705,15 +1703,15 @@ bool PCB_TUNING_PATTERN::UpdateEditPoints( std::shared_ptr aEditPoi VECTOR2I widthHandleOffset = ( base.B - base.A ).Perpendicular().Resize( amplitude ); - aEditPoints->Point( 0 ).SetPosition( m_origin + centerlineOffset ); - aEditPoints->Point( 1 ).SetPosition( m_end + centerlineOffsetEnd ); + aEditPoints.Point( 0 ).SetPosition( m_origin + centerlineOffset ); + aEditPoints.Point( 1 ).SetPosition( m_end + centerlineOffsetEnd ); - aEditPoints->Point( 2 ).SetPosition( base.A + widthHandleOffset ); + aEditPoints.Point( 2 ).SetPosition( base.A + widthHandleOffset ); VECTOR2I spacingHandleOffset = widthHandleOffset + ( base.B - base.A ).Resize( KiROUND( m_settings.m_spacing * 1.5 ) ); - aEditPoints->Point( 3 ).SetPosition( base.A + spacingHandleOffset ); + aEditPoints.Point( 3 ).SetPosition( base.A + spacingHandleOffset ); return true; } diff --git a/pcbnew/pcb_generator.cpp b/pcbnew/pcb_generator.cpp index c75b16fceb..0c4a31c9dd 100644 --- a/pcbnew/pcb_generator.cpp +++ b/pcbnew/pcb_generator.cpp @@ -95,20 +95,19 @@ std::vector PCB_GENERATOR::GetPreviewItems( GENERATOR_TOOL* aTool, } -bool PCB_GENERATOR::MakeEditPoints( std::shared_ptr aEditPoints ) const +bool PCB_GENERATOR::MakeEditPoints( EDIT_POINTS& aEditPoints ) const { return true; } -bool PCB_GENERATOR::UpdateFromEditPoints( std::shared_ptr aEditPoints, - BOARD_COMMIT* aCommit ) +bool PCB_GENERATOR::UpdateFromEditPoints( EDIT_POINTS& aEditPoints ) { return true; } -bool PCB_GENERATOR::UpdateEditPoints( std::shared_ptr aEditPoints ) +bool PCB_GENERATOR::UpdateEditPoints( EDIT_POINTS& aEditPoints ) { return true; } diff --git a/pcbnew/pcb_generator.h b/pcbnew/pcb_generator.h index 382da47cd9..7ad0194447 100644 --- a/pcbnew/pcb_generator.h +++ b/pcbnew/pcb_generator.h @@ -70,12 +70,11 @@ public: PCB_BASE_EDIT_FRAME* aFrame, bool aStatusItemsOnly = false ); - virtual bool MakeEditPoints( std::shared_ptr aEditPoints ) const; + virtual bool MakeEditPoints( EDIT_POINTS& aEditPoints ) const; - virtual bool UpdateFromEditPoints( std::shared_ptr aEditPoints, - BOARD_COMMIT* aCommit ); + virtual bool UpdateFromEditPoints( EDIT_POINTS& aEditPoints ); - virtual bool UpdateEditPoints( std::shared_ptr aEditPoints ); + virtual bool UpdateEditPoints( EDIT_POINTS& aEditPoints ); const BOX2I GetBoundingBox() const override; diff --git a/pcbnew/tools/pcb_point_editor.cpp b/pcbnew/tools/pcb_point_editor.cpp index 71c2149574..a83f252c0c 100644 --- a/pcbnew/tools/pcb_point_editor.cpp +++ b/pcbnew/tools/pcb_point_editor.cpp @@ -1489,6 +1489,36 @@ private: }; +/** + * Point editor behavior for the PCB_GENERATOR class. + * + * This just delegates to the PCB_GENERATOR's own methods. + */ +class GENERATOR_POINT_EDIT_BEHAVIOR : public POINT_EDIT_BEHAVIOR +{ +public: + GENERATOR_POINT_EDIT_BEHAVIOR( PCB_GENERATOR& aGenerator ) : m_generator( aGenerator ) {} + + void MakePoints( EDIT_POINTS& aPoints ) override + { + m_generator.MakeEditPoints( aPoints ); + } + + void UpdatePoints( EDIT_POINTS& aPoints ) override + { + m_generator.UpdateEditPoints( aPoints ); + } + + void UpdateItem( const EDIT_POINT& aEditedPoint, EDIT_POINTS& aPoints ) override + { + m_generator.UpdateFromEditPoints( aPoints ); + } + +private: + PCB_GENERATOR& m_generator; +}; + + PCB_POINT_EDITOR::PCB_POINT_EDITOR() : PCB_TOOL_BASE( "pcbnew.PointEditor" ), m_selectionTool( nullptr ), @@ -1619,8 +1649,8 @@ std::shared_ptr PCB_POINT_EDITOR::makePoints( EDA_ITEM* aItem ) case PCB_GENERATOR_T: { - const PCB_GENERATOR* generator = static_cast( aItem ); - generator->MakeEditPoints( points ); + PCB_GENERATOR* generator = static_cast( aItem ); + m_editorBehavior = std::make_unique( *generator ); break; } @@ -2244,7 +2274,6 @@ void PCB_POINT_EDITOR::updateItem( BOARD_COMMIT* aCommit ) GENERATOR_TOOL* generatorTool = m_toolMgr->GetTool(); PCB_GENERATOR* generatorItem = static_cast( item ); - generatorItem->UpdateFromEditPoints( m_editPoints, aCommit ); m_toolMgr->RunSynchronousAction( PCB_ACTIONS::genUpdateEdit, aCommit, generatorItem ); // Note: POINT_EDITOR::m_preview holds only the canvas-draw status "popup"; the meanders @@ -2560,13 +2589,6 @@ void PCB_POINT_EDITOR::updatePoints() break; } - case PCB_GENERATOR_T: - { - PCB_GENERATOR* generator = static_cast( item ); - generator->UpdateEditPoints( m_editPoints ); - break; - } - case PCB_DIM_ALIGNED_T: case PCB_DIM_ORTHOGONAL_T: {