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

View File

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