Fixes for length tuning patterns.

This commit is contained in:
Alex Shvartzkop 2023-11-12 12:17:03 +03:00
parent bcde7c59c9
commit 05e954ad5d
6 changed files with 119 additions and 54 deletions

View File

@ -128,23 +128,32 @@ public:
m_origin += aMoveVector;
m_end += aMoveVector;
PCB_GROUP::Move( aMoveVector );
if( !this->HasFlag( IN_EDIT ) )
{
PCB_GROUP::Move( aMoveVector );
if( m_baseLine )
m_baseLine->Move( aMoveVector );
if( m_baseLineCoupled )
m_baseLineCoupled->Move( aMoveVector );
}
}
void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) override
{
// Not supported for tuning patterns
#if 0
RotatePoint( m_origin, aRotCentre, aAngle );
RotatePoint( m_end, aRotCentre, aAngle );
PCB_GROUP::Rotate( aRotCentre, aAngle );
if( !this->HasFlag( IN_EDIT ) )
{
RotatePoint( m_origin, aRotCentre, aAngle );
RotatePoint( m_end, aRotCentre, aAngle );
PCB_GROUP::Rotate( aRotCentre, aAngle );
if( m_baseLine )
m_baseLine->Rotate( aAngle, aRotCentre );
if( m_baseLine )
m_baseLine->Rotate( aAngle, aRotCentre );
if( m_baseLineCoupled )
m_baseLineCoupled->Rotate( aAngle, aRotCentre );*/
#endif
if( m_baseLineCoupled )
m_baseLineCoupled->Rotate( aAngle, aRotCentre );
}
}
const BOX2I GetBoundingBox() const override
@ -510,7 +519,7 @@ void PCB_TUNING_PATTERN::EditStart( GENERATOR_TOOL* aTool, BOARD* aBoard,
aCommit->Modify( this );
}
SetFlags( IS_MOVING );
SetFlags( IN_EDIT );
int layer = GetLayer();
PNS::ROUTER* router = aTool->Router();
@ -1007,6 +1016,7 @@ bool PCB_TUNING_PATTERN::Update( GENERATOR_TOOL* aTool, BOARD* aBoard, PCB_BASE_
PNS::MEANDER_PLACER_BASE* placer = static_cast<PNS::MEANDER_PLACER_BASE*>( router->Placer() );
m_settings.m_keepEndpoints = true; // Required for re-grouping
placer->UpdateSettings( m_settings );
router->Move( m_end, nullptr );
@ -1038,6 +1048,8 @@ void PCB_TUNING_PATTERN::EditPush( GENERATOR_TOOL* aTool, BOARD* aBoard,
PCB_BASE_EDIT_FRAME* aFrame, BOARD_COMMIT* aCommit,
const wxString& aCommitMsg, int aCommitFlags )
{
ClearFlags( IN_EDIT );
PNS::ROUTER* router = aTool->Router();
SHAPE_LINE_CHAIN bounds = getRectShape();
PICKED_ITEMS_LIST groupUndoList;
@ -1066,13 +1078,14 @@ void PCB_TUNING_PATTERN::EditPush( GENERATOR_TOOL* aTool, BOARD* aBoard,
for( BOARD_ITEM* item : routerAddedItems )
{
PCB_TRACK* track = dynamic_cast<PCB_TRACK*>( item );
if( track && bounds.PointInside( track->GetPosition(), epsilon )
&& bounds.PointInside( track->GetEnd(), epsilon ) )
if( PCB_TRACK* track = dynamic_cast<PCB_TRACK*>( item ) )
{
AddItem( item );
groupUndoList.PushItem( ITEM_PICKER( nullptr, item, UNDO_REDO::REGROUP ) );
if( bounds.PointInside( track->GetPosition(), epsilon )
&& bounds.PointInside( track->GetEnd(), epsilon ) )
{
AddItem( item );
groupUndoList.PushItem( ITEM_PICKER( nullptr, item, UNDO_REDO::REGROUP ) );
}
}
aCommit->Add( item );
@ -1091,6 +1104,8 @@ void PCB_TUNING_PATTERN::EditPush( GENERATOR_TOOL* aTool, BOARD* aBoard,
void PCB_TUNING_PATTERN::EditRevert( GENERATOR_TOOL* aTool, BOARD* aBoard,
PCB_BASE_EDIT_FRAME* aFrame, BOARD_COMMIT* aCommit )
{
ClearFlags( IN_EDIT );
for( BOARD_ITEM* item : m_removedItems )
aFrame->GetCanvas()->GetView()->Hide( item, false );
@ -1299,19 +1314,21 @@ void PCB_TUNING_PATTERN::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
return;
KIGFX::PREVIEW::DRAW_CONTEXT ctx( *aView );
int size = KiROUND( aView->ToWorld( EDIT_POINT::POINT_SIZE ) * 0.8 );
size = std::max( size, pcbIUScale.mmToIU( 0.05 ) );
if( m_baseLine )
{
for( int i = 0; i < m_baseLine->SegmentCount(); i++ )
{
SEG seg = m_baseLine->CSegment( i );
ctx.DrawLine( seg.A, seg.B, false );
ctx.DrawLineDashed( seg.A, seg.B, size, size / 6, true );
}
}
else
{
ctx.DrawLine( m_origin, m_end, false );
ctx.DrawLineDashed( m_origin, m_end, size, size / 6, false );
}
if( m_tuningMode == DIFF_PAIR && m_baseLineCoupled )
@ -1319,7 +1336,7 @@ void PCB_TUNING_PATTERN::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
for( int i = 0; i < m_baseLineCoupled->SegmentCount(); i++ )
{
SEG seg = m_baseLineCoupled->CSegment( i );
ctx.DrawLine( seg.A, seg.B, false );
ctx.DrawLineDashed( seg.A, seg.B, size, size / 6, true );
}
}

View File

@ -352,16 +352,38 @@ bool DP_MEANDER_PLACER::Move( const VECTOR2I& aP, ITEM* aEndItem )
}
m_finalShapeP.Clear();
m_finalShapeP.Append( preP );
m_finalShapeP.Append( tunedP );
m_finalShapeP.Append( postP );
m_finalShapeP.Simplify();
m_finalShapeN.Clear();
m_finalShapeN.Append( preN );
m_finalShapeN.Append( tunedN );
m_finalShapeN.Append( postN );
m_finalShapeN.Simplify();
if( m_settings.m_keepEndpoints )
{
preP.Simplify();
tunedP.Simplify();
postP.Simplify();
m_finalShapeP.Append( preP );
m_finalShapeP.Append( tunedP );
m_finalShapeP.Append( postP );
preN.Simplify();
tunedN.Simplify();
postN.Simplify();
m_finalShapeN.Append( preN );
m_finalShapeN.Append( tunedN );
m_finalShapeN.Append( postN );
}
else
{
m_finalShapeP.Append( preP );
m_finalShapeP.Append( tunedP );
m_finalShapeP.Append( postP );
m_finalShapeP.Simplify();
m_finalShapeN.Append( preN );
m_finalShapeN.Append( tunedN );
m_finalShapeN.Append( postN );
m_finalShapeN.Simplify();
}
return true;
}

View File

@ -1163,7 +1163,7 @@ std::unique_ptr<PNS::SEGMENT> PNS_KICAD_IFACE_BASE::syncTrack( PCB_TRACK* aTrack
if( PCB_GENERATOR* generator = dynamic_cast<PCB_GENERATOR*>( aTrack->GetParentGroup() ) )
{
if( !generator->IsMoving() )
if( !generator->HasFlag( IN_EDIT ) )
segment->Mark( PNS::MK_LOCKED );
}
@ -1185,7 +1185,7 @@ std::unique_ptr<PNS::ARC> PNS_KICAD_IFACE_BASE::syncArc( PCB_ARC* aArc )
if( PCB_GENERATOR* generator = dynamic_cast<PCB_GENERATOR*>( aArc->GetParentGroup() ) )
{
if( !generator->IsMoving() )
if( !generator->HasFlag( IN_EDIT ) )
arc->Mark( PNS::MK_LOCKED );
}
@ -1212,7 +1212,7 @@ std::unique_ptr<PNS::VIA> PNS_KICAD_IFACE_BASE::syncVia( PCB_VIA* aVia )
if( PCB_GENERATOR* generator = dynamic_cast<PCB_GENERATOR*>( aVia->GetParentGroup() ) )
{
if( !generator->IsMoving() )
if( !generator->HasFlag( IN_EDIT ) )
via->Mark( PNS::MK_LOCKED );
}

View File

@ -85,6 +85,7 @@ public:
m_singleSided = false;
m_initialSide = MEANDER_SIDE_LEFT;
m_lengthTolerance = 0;
m_keepEndpoints = false;
}
void SetTargetLength( long long int aOpt )
@ -160,6 +161,9 @@ public:
///< Allowable tuning error.
int m_lengthTolerance;
///< Keep vertices between pre, tuned and post parts of the line.
bool m_keepEndpoints;
};
/**

View File

@ -199,10 +199,24 @@ bool MEANDER_PLACER::doMove( const VECTOR2I& aP, ITEM* aEndItem, long long int a
}
m_finalShape.Clear();
m_finalShape.Append( pre );
m_finalShape.Append( tuned );
m_finalShape.Append( post );
m_finalShape.Simplify();
if( m_settings.m_keepEndpoints )
{
pre.Simplify();
tuned.Simplify();
post.Simplify();
m_finalShape.Append( pre );
m_finalShape.Append( tuned );
m_finalShape.Append( post );
}
else
{
m_finalShape.Append( pre );
m_finalShape.Append( tuned );
m_finalShape.Append( post );
m_finalShape.Simplify();
}
return true;
}

View File

@ -230,17 +230,11 @@ int EDIT_TOOL::Move( const TOOL_EVENT& aEvent )
if( doMoveSelection( aEvent, &localCommit ) )
{
if( PCB_GENERATOR* genItem = dynamic_cast<PCB_GENERATOR*>( localCommit.GetFirst() ) )
m_toolMgr->RunSynchronousAction( PCB_ACTIONS::genPushEdit, &localCommit, genItem );
else
localCommit.Push( _( "Move" ) );
localCommit.Push( _( "Move" ) );
}
else
{
if( PCB_GENERATOR* genItem = dynamic_cast<PCB_GENERATOR*>( localCommit.GetFirst() ) )
m_toolMgr->RunSynchronousAction( PCB_ACTIONS::genRevertEdit, &localCommit, genItem );
else
localCommit.Revert();
localCommit.Revert();
}
}
@ -590,15 +584,15 @@ bool EDIT_TOOL::doMoveSelection( const TOOL_EVENT& aEvent, BOARD_COMMIT* aCommit
else
{
aCommit->Modify( item );
item->SetFlags( IS_MOVING );
static_cast<BOARD_ITEM*>( item )->RunOnDescendants(
[&]( BOARD_ITEM* bItem )
{
item->SetFlags( IS_MOVING );
} );
}
item->SetFlags( IS_MOVING );
static_cast<BOARD_ITEM*>( item )->RunOnDescendants(
[&]( BOARD_ITEM* bItem )
{
item->SetFlags( IS_MOVING );
} );
}
}
@ -789,8 +783,22 @@ bool EDIT_TOOL::doMoveSelection( const TOOL_EVENT& aEvent, BOARD_COMMIT* aCommit
// items.
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear );
if( !restore_state )
if( restore_state )
{
if( sel_items.size() == 1 && sel_items.back()->Type() == PCB_GENERATOR_T )
{
m_toolMgr->RunSynchronousAction( PCB_ACTIONS::genRevertEdit, aCommit,
static_cast<PCB_GENERATOR*>( sel_items.back() ) );
}
}
else
{
if( sel_items.size() == 1 && sel_items.back()->Type() == PCB_GENERATOR_T )
{
m_toolMgr->RunSynchronousAction( PCB_ACTIONS::genPushEdit, aCommit,
static_cast<PCB_GENERATOR*>( sel_items.back() ) );
}
EDA_ITEMS oItems( orig_items.begin(), orig_items.end() );
m_toolMgr->RunAction<EDA_ITEMS*>( PCB_ACTIONS::selectItems, &oItems );
}