Anchor a selected wire at the edge of a drag which is connected to a non-drag item.

Fixes: lp:1827846
* https://bugs.launchpad.net/kicad/+bug/1827846
This commit is contained in:
Jeff Young 2019-05-07 12:00:24 +01:00
parent f40408187e
commit cf046e0548
2 changed files with 36 additions and 18 deletions

View File

@ -440,35 +440,35 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
}
void SCH_MOVE_TOOL::getConnectedDragItems( SCH_ITEM* aItem, wxPoint aPoint, EDA_ITEMS& aList )
void SCH_MOVE_TOOL::getConnectedDragItems( SCH_ITEM* aOriginalItem, wxPoint aPoint,
EDA_ITEMS& aList )
{
for( SCH_ITEM* test = m_frame->GetScreen()->GetDrawItems(); test; test = test->Next() )
{
if( test->IsSelected() || !test->IsConnectable() || !test->CanConnect( aItem ) )
if( test->IsSelected() || !test->IsConnectable() || !test->CanConnect( aOriginalItem ) )
continue;
switch( test->Type() )
{
default:
case SCH_LINE_T:
{
// Select wires/busses that are connected at one end and/or the other. Any
// unconnected ends must be flagged (STARTPOINT or ENDPOINT).
SCH_LINE* line = (SCH_LINE*) test;
SCH_LINE* testLine = (SCH_LINE*) test;
if( line->GetStartPoint() == aPoint )
if( testLine->GetStartPoint() == aPoint )
{
if( !( line->GetFlags() & SELECTEDNODE ) )
aList.push_back( line );
if( !( testLine->GetFlags() & SELECTEDNODE ) )
aList.push_back( testLine );
line->SetFlags( STARTPOINT | SELECTEDNODE );
testLine->SetFlags( STARTPOINT | SELECTEDNODE );
}
else if( line->GetEndPoint() == aPoint )
else if( testLine->GetEndPoint() == aPoint )
{
if( !( line->GetFlags() & SELECTEDNODE ) )
aList.push_back( line );
if( !( testLine->GetFlags() & SELECTEDNODE ) )
aList.push_back( testLine );
line->SetFlags( ENDPOINT | SELECTEDNODE );
testLine->SetFlags( ENDPOINT | SELECTEDNODE );
}
break;
}
@ -481,10 +481,25 @@ void SCH_MOVE_TOOL::getConnectedDragItems( SCH_ITEM* aItem, wxPoint aPoint, EDA_
case SCH_COMPONENT_T:
case SCH_NO_CONNECT_T:
case SCH_JUNCTION_T:
// Select connected items that have no wire between them.
if( aItem->Type() != SCH_LINE_T && test->IsConnected( aPoint ) )
aList.push_back( test );
if( test->IsConnected( aPoint ) )
{
// Connected to a wire: anchor the wire
if( aOriginalItem->Type() == SCH_LINE_T )
{
SCH_LINE* originalLine = (SCH_LINE*) aOriginalItem;
if( originalLine->GetStartPoint() == aPoint )
originalLine->ClearFlags( STARTPOINT );
else if( originalLine->GetEndPoint() == aPoint )
originalLine->ClearFlags( ENDPOINT );
}
// Connected directly to something else with no wire to adjust: pick up the
// component/no-connect/junction
else
{
aList.push_back( test );
}
}
break;
case SCH_LABEL_T:
@ -493,18 +508,21 @@ void SCH_MOVE_TOOL::getConnectedDragItems( SCH_ITEM* aItem, wxPoint aPoint, EDA_
case SCH_BUS_WIRE_ENTRY_T:
case SCH_BUS_BUS_ENTRY_T:
// Select labels and bus entries that are connected to a wire being moved.
if( aItem->Type() == SCH_LINE_T )
if( aOriginalItem->Type() == SCH_LINE_T )
{
std::vector<wxPoint> connections;
test->GetConnectionPoints( connections );
for( wxPoint& point : connections )
{
if( aItem->HitTest( point ) )
if( aOriginalItem->HitTest( point ) )
aList.push_back( test );
}
}
break;
default:
break;
}
}
}

View File

@ -61,7 +61,7 @@ private:
///> Finds additional items for a drag operation.
///> Connected items with no wire are included (as there is no wire to adjust for the drag).
///> Connected wires are included with any un-connected ends flagged (STARTPOINT or ENDPOINT).
void getConnectedDragItems( SCH_ITEM* aItem, wxPoint aPoint, EDA_ITEMS& aList );
void getConnectedDragItems( SCH_ITEM* aOriginalItem, wxPoint aPoint, EDA_ITEMS& aList );
///> Adds junctions if needed to each item in the list after they have been
///> moved.