Fix commit/view handling when dragging arcs

Fixes https://gitlab.com/kicad/code/kicad/-/issues/16145
This commit is contained in:
Jon Evans 2023-11-25 14:49:12 -05:00
parent 7e68da7f7f
commit f0988c3c5d
1 changed files with 96 additions and 70 deletions

View File

@ -528,7 +528,8 @@ int EDIT_TOOL::DragArcTrack( const TOOL_EVENT& aEvent )
if( theArc->GetAngle() + maxTangentDeviation >= ANGLE_180 )
{
wxString msg = wxString::Format( _( "Unable to resize arc tracks of %s or greater." ),
wxString msg = wxString::Format(
_( "Unable to resize arc tracks of %s or greater." ),
EDA_UNIT_UTILS::UI::MessageTextFromValue( ANGLE_180 - maxTangentDeviation ) );
frame()->ShowInfoBarError( msg );
@ -562,8 +563,10 @@ int EDIT_TOOL::DragArcTrack( const TOOL_EVENT& aEvent )
tanEnd.A = *tanIntersect;
tanEnd.B = theArc->GetEnd();
auto getUniqueTrackAtAnchorCollinear =
[&]( const VECTOR2I& aAnchor, const SEG& aCollinearSeg ) -> PCB_TRACK*
std::set<PCB_TRACK*> addedTracks;
auto getUniqueTrackAtAnchorCollinear = [&]( const VECTOR2I& aAnchor,
const SEG& aCollinearSeg ) -> PCB_TRACK*
{
std::shared_ptr<CONNECTIVITY_DATA> conn = board()->GetConnectivity();
@ -574,9 +577,8 @@ int EDIT_TOOL::DragArcTrack( const TOOL_EVENT& aEvent )
for( int i = 0; i < 3; i++ )
{
itemsOnAnchor = conn->GetConnectedItemsAtAnchor( theArc, aAnchor,
{ PCB_PAD_T, PCB_VIA_T,
PCB_TRACE_T, PCB_ARC_T },
itemsOnAnchor = conn->GetConnectedItemsAtAnchor(
theArc, aAnchor, { PCB_PAD_T, PCB_VIA_T, PCB_TRACE_T, PCB_ARC_T },
allowedDeviation );
allowedDeviation /= 2;
@ -609,7 +611,7 @@ int EDIT_TOOL::DragArcTrack( const TOOL_EVENT& aEvent )
track->SetLocked( theArc->IsLocked() );
track->SetFlags( IS_NEW );
getView()->Add( track );
commit.Added( track );
addedTracks.insert( track );
}
return track;
@ -634,8 +636,7 @@ int EDIT_TOOL::DragArcTrack( const TOOL_EVENT& aEvent )
if( tanIntersect = tanStart.IntersectLines( tanEnd ); !tanIntersect )
return 0;
auto isTrackStartClosestToArcStart =
[&]( PCB_TRACK* aTrack ) -> bool
auto isTrackStartClosestToArcStart = [&]( PCB_TRACK* aTrack ) -> bool
{
double trackStartToArcStart = GetLineLength( aTrack->GetStart(), theArc->GetStart() );
double trackEndToArcStart = GetLineLength( aTrack->GetEnd(), theArc->GetStart() );
@ -673,8 +674,7 @@ int EDIT_TOOL::DragArcTrack( const TOOL_EVENT& aEvent )
// * *
//
auto getFurthestPointToTanInterstect =
[&]( VECTOR2I& aPointA, VECTOR2I& aPointB ) -> VECTOR2I
auto getFurthestPointToTanInterstect = [&]( VECTOR2I& aPointA, VECTOR2I& aPointB ) -> VECTOR2I
{
if( ( aPointA - *tanIntersect ).EuclideanNorm()
> ( aPointB - *tanIntersect ).EuclideanNorm() )
@ -816,20 +816,46 @@ int EDIT_TOOL::DragArcTrack( const TOOL_EVENT& aEvent )
KiROUND( ADVANCED_CFG::GetCfg().m_MaxTrackLengthToKeep * pcbIUScale.IU_PER_MM );
if( trackOnStart->GetLength() <= maxLengthIU )
{
if( addedTracks.count( trackOnStart ) )
{
getView()->Remove( trackOnStart );
addedTracks.erase( trackOnStart );
delete trackOnStart;
}
else
{
commit.Remove( trackOnStart );
}
theArc->SetStart( newStart );
}
if( trackOnEnd->GetLength() <= maxLengthIU )
{
if( addedTracks.count( trackOnEnd ) )
{
getView()->Remove( trackOnEnd );
addedTracks.erase( trackOnEnd );
delete trackOnEnd;
}
else
{
commit.Remove( trackOnEnd );
}
theArc->SetEnd( newEnd );
}
if( theArc->GetLength() <= 0 )
commit.Remove( theArc );
for( PCB_TRACK* added : addedTracks )
{
getView()->Remove( added );
commit.Add( added );
}
// Should we commit?
if( restore_state )
commit.Revert();