Merges a line after manually removing its junction.
Fixes: lp:1746998 * https://bugs.launchpad.net/kicad/+bug/1746998
This commit is contained in:
parent
1858852f57
commit
fddd5abef1
|
@ -658,6 +658,71 @@ bool SCH_EDIT_FRAME::BreakSegmentsOnJunctions( bool aAppend )
|
|||
}
|
||||
|
||||
|
||||
void SCH_EDIT_FRAME::DeleteJunction( SCH_ITEM* aJunction, bool aAppend )
|
||||
{
|
||||
SCH_SCREEN* screen = GetScreen();
|
||||
PICKED_ITEMS_LIST itemList;
|
||||
|
||||
auto remove_item = [ & ]( SCH_ITEM* aItem ) -> void
|
||||
{
|
||||
aItem->SetFlags( STRUCT_DELETED );
|
||||
itemList.PushItem( ITEM_PICKER( aItem, UR_DELETED ) );
|
||||
screen->Remove( aItem );
|
||||
};
|
||||
|
||||
remove_item( aJunction );
|
||||
|
||||
for( SCH_ITEM* item = screen->GetDrawItems(); item; item = item->Next() )
|
||||
{
|
||||
SCH_LINE* firstLine = dynamic_cast<SCH_LINE*>( item );
|
||||
|
||||
if( !firstLine || !firstLine->IsEndPoint( aJunction->GetPosition() )
|
||||
|| ( firstLine->GetFlags() & STRUCT_DELETED ) )
|
||||
continue;
|
||||
|
||||
for( SCH_ITEM* secondItem = item->Next(); secondItem; secondItem = secondItem->Next() )
|
||||
{
|
||||
SCH_LINE* secondLine = dynamic_cast<SCH_LINE*>( secondItem );
|
||||
|
||||
if( !secondLine || !secondLine->IsEndPoint( aJunction->GetPosition() )
|
||||
|| ( secondItem->GetFlags() & STRUCT_DELETED )
|
||||
|| !secondLine->IsParallel( firstLine ) )
|
||||
continue;
|
||||
|
||||
|
||||
// Remove identical lines
|
||||
if( firstLine->IsEndPoint( secondLine->GetStartPoint() )
|
||||
&& firstLine->IsEndPoint( secondLine->GetEndPoint() ) )
|
||||
{
|
||||
remove_item( secondItem );
|
||||
continue;
|
||||
}
|
||||
|
||||
// Try to merge the remaining lines
|
||||
if( SCH_LINE* line = (SCH_LINE*) secondLine->MergeOverlap( firstLine ) )
|
||||
{
|
||||
remove_item( item );
|
||||
remove_item( secondItem );
|
||||
itemList.PushItem( ITEM_PICKER( line, UR_NEW ) );
|
||||
screen->Append( (SCH_ITEM*) line );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SaveCopyInUndoList( itemList, UR_DELETED, aAppend );
|
||||
|
||||
SCH_ITEM* nextitem;
|
||||
for( SCH_ITEM* item = screen->GetDrawItems(); item; item = nextitem )
|
||||
{
|
||||
nextitem = item->Next();
|
||||
|
||||
if( item->GetFlags() & STRUCT_DELETED )
|
||||
screen->Remove( item );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SCH_JUNCTION* SCH_EDIT_FRAME::AddJunction( const wxPoint& aPosition, bool aAppend )
|
||||
{
|
||||
SCH_JUNCTION* junction = new SCH_JUNCTION( aPosition );
|
||||
|
|
|
@ -207,34 +207,25 @@ void SCH_EDIT_FRAME::DeleteItem( SCH_ITEM* aItem, bool aAppend )
|
|||
sheet->RemovePin( (SCH_SHEET_PIN*) aItem );
|
||||
m_canvas->RefreshDrawingRect( sheet->GetBoundingBox() );
|
||||
}
|
||||
else if( aItem->Type() == SCH_JUNCTION_T )
|
||||
{
|
||||
DeleteJunction( aItem, aAppend );
|
||||
}
|
||||
else
|
||||
{
|
||||
PICKED_ITEMS_LIST itemsList;
|
||||
ITEM_PICKER picker( aItem, UR_DELETED );
|
||||
|
||||
aItem->SetFlags( STRUCT_DELETED );
|
||||
itemsList.PushItem( picker );
|
||||
SaveCopyInUndoList( aItem, UR_DELETED, aAppend );
|
||||
screen->Remove( aItem );
|
||||
|
||||
if( aItem->IsConnectable() && aItem->Type() != SCH_JUNCTION_T )
|
||||
std::vector< wxPoint > pts;
|
||||
aItem->GetConnectionPoints( pts );
|
||||
for( auto point : pts )
|
||||
{
|
||||
std::vector< wxPoint > pts;
|
||||
aItem->GetConnectionPoints( pts );
|
||||
for( auto point : pts )
|
||||
{
|
||||
SCH_ITEM* junction;
|
||||
if( !screen->IsJunctionNeeded( point )
|
||||
&& ( junction = screen->GetItem( point, 0, SCH_JUNCTION_T ) ) )
|
||||
{
|
||||
ITEM_PICKER picker_juction( junction, UR_DELETED );
|
||||
junction->SetFlags( STRUCT_DELETED );
|
||||
itemsList.PushItem( picker_juction );
|
||||
screen->Remove( junction );
|
||||
}
|
||||
}
|
||||
SCH_ITEM* junction = screen->GetItem( point, 0, SCH_JUNCTION_T );
|
||||
if( junction && !screen->IsJunctionNeeded( point ) )
|
||||
DeleteJunction( junction, true );
|
||||
}
|
||||
|
||||
SaveCopyInUndoList( itemsList, UR_DELETED, aAppend );
|
||||
m_canvas->RefreshDrawingRect( aItem->GetBoundingBox() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1157,6 +1157,14 @@ public:
|
|||
*/
|
||||
void DeleteItemsInList( PICKED_ITEMS_LIST& aItemsList, bool aAppend = false );
|
||||
|
||||
/**
|
||||
* Removes a given junction and heals any wire segments under the junction
|
||||
*
|
||||
* @param aItem The junction to delete
|
||||
* @param aAppend True if we are updating an ongoing commit
|
||||
*/
|
||||
void DeleteJunction( SCH_ITEM* aItem, bool aAppend = false );
|
||||
|
||||
/**
|
||||
* Adds junctions if needed to each item in the list after they have been
|
||||
* moved.
|
||||
|
|
Loading…
Reference in New Issue