mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-04-11 09:00:13 +00:00
Pcbnew: point editor: use behavior class for generators
This also changes the interface on the GENERATOR classes to no longer take a shared_ptr - these methods are synchronous and don't store (shared) ownership of the EDIT_POINTs.
This commit is contained in:
parent
d12ad6820b
commit
90e49a42e7
pcbnew
@ -293,12 +293,11 @@ public:
|
||||
|
||||
void Remove( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit ) override;
|
||||
|
||||
bool MakeEditPoints( std::shared_ptr<EDIT_POINTS> points ) const override;
|
||||
bool MakeEditPoints( EDIT_POINTS& points ) const override;
|
||||
|
||||
bool UpdateFromEditPoints( std::shared_ptr<EDIT_POINTS> aEditPoints,
|
||||
BOARD_COMMIT* aCommit ) override;
|
||||
bool UpdateFromEditPoints( EDIT_POINTS& aEditPoints ) override;
|
||||
|
||||
bool UpdateEditPoints( std::shared_ptr<EDIT_POINTS> 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<EDIT_POINTS> 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<EDIT_POINTS> 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<EDIT_POINTS> 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<EDIT_POINTS> 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<EDIT_POINTS> 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<EDIT_POINTS> 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<EDIT_POINTS> aEdi
|
||||
}
|
||||
|
||||
|
||||
bool PCB_TUNING_PATTERN::UpdateEditPoints( std::shared_ptr<EDIT_POINTS> 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<EDIT_POINTS> 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;
|
||||
}
|
||||
|
@ -95,20 +95,19 @@ std::vector<EDA_ITEM*> PCB_GENERATOR::GetPreviewItems( GENERATOR_TOOL* aTool,
|
||||
}
|
||||
|
||||
|
||||
bool PCB_GENERATOR::MakeEditPoints( std::shared_ptr<EDIT_POINTS> aEditPoints ) const
|
||||
bool PCB_GENERATOR::MakeEditPoints( EDIT_POINTS& aEditPoints ) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool PCB_GENERATOR::UpdateFromEditPoints( std::shared_ptr<EDIT_POINTS> aEditPoints,
|
||||
BOARD_COMMIT* aCommit )
|
||||
bool PCB_GENERATOR::UpdateFromEditPoints( EDIT_POINTS& aEditPoints )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool PCB_GENERATOR::UpdateEditPoints( std::shared_ptr<EDIT_POINTS> aEditPoints )
|
||||
bool PCB_GENERATOR::UpdateEditPoints( EDIT_POINTS& aEditPoints )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -70,12 +70,11 @@ public:
|
||||
PCB_BASE_EDIT_FRAME* aFrame,
|
||||
bool aStatusItemsOnly = false );
|
||||
|
||||
virtual bool MakeEditPoints( std::shared_ptr<EDIT_POINTS> aEditPoints ) const;
|
||||
virtual bool MakeEditPoints( EDIT_POINTS& aEditPoints ) const;
|
||||
|
||||
virtual bool UpdateFromEditPoints( std::shared_ptr<EDIT_POINTS> aEditPoints,
|
||||
BOARD_COMMIT* aCommit );
|
||||
virtual bool UpdateFromEditPoints( EDIT_POINTS& aEditPoints );
|
||||
|
||||
virtual bool UpdateEditPoints( std::shared_ptr<EDIT_POINTS> aEditPoints );
|
||||
virtual bool UpdateEditPoints( EDIT_POINTS& aEditPoints );
|
||||
|
||||
const BOX2I GetBoundingBox() const override;
|
||||
|
||||
|
@ -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<EDIT_POINTS> PCB_POINT_EDITOR::makePoints( EDA_ITEM* aItem )
|
||||
|
||||
case PCB_GENERATOR_T:
|
||||
{
|
||||
const PCB_GENERATOR* generator = static_cast<const PCB_GENERATOR*>( aItem );
|
||||
generator->MakeEditPoints( points );
|
||||
PCB_GENERATOR* generator = static_cast<PCB_GENERATOR*>( aItem );
|
||||
m_editorBehavior = std::make_unique<GENERATOR_POINT_EDIT_BEHAVIOR>( *generator );
|
||||
break;
|
||||
}
|
||||
|
||||
@ -2244,7 +2274,6 @@ void PCB_POINT_EDITOR::updateItem( BOARD_COMMIT* aCommit )
|
||||
GENERATOR_TOOL* generatorTool = m_toolMgr->GetTool<GENERATOR_TOOL>();
|
||||
PCB_GENERATOR* generatorItem = static_cast<PCB_GENERATOR*>( 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<PCB_GENERATOR*>( item );
|
||||
generator->UpdateEditPoints( m_editPoints );
|
||||
break;
|
||||
}
|
||||
|
||||
case PCB_DIM_ALIGNED_T:
|
||||
case PCB_DIM_ORTHOGONAL_T:
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user