kicad/eeschema/delete.cpp

218 lines
6.1 KiB
C++
Raw Normal View History

2008-03-13 05:04:59 +00:00
/************************************/
/* delete.cpp */
2008-03-13 05:04:59 +00:00
/************************************/
#include "fctsys.h"
#include "gr_basic.h"
#include "common.h"
#include "class_sch_screen.h"
#include "wxEeschemaStruct.h"
#include "general.h"
#include "protos.h"
#include "sch_marker.h"
#include "sch_junction.h"
#include "sch_line.h"
#include "sch_sheet.h"
#include "sch_text.h"
/*
* Delete a connection, i.e wires or bus connected
* stop on a node (more than 2 wires (bus) connected)
2008-03-13 05:04:59 +00:00
*/
void SCH_EDIT_FRAME::DeleteConnection( bool DeleteFullConnection )
{
SCH_ITEM* item;
EDA_ITEM* tmp;
EDA_ITEMS list;
PICKED_ITEMS_LIST pickList;
SCH_SCREEN* screen = GetScreen();
wxPoint pos = screen->GetCrossHairPosition();
2008-03-13 05:04:59 +00:00
// Clear flags member for all items.
screen->ClearDrawingState();
screen->BreakSegmentsOnJunctions();
2008-03-13 05:04:59 +00:00
if( screen->GetNode( pos, list ) == 0 )
return;
for( size_t i = 0; i < list.size(); i++ )
2008-03-13 05:04:59 +00:00
{
item = (SCH_ITEM*) list[ i ];
item->SetFlags( SELECTEDNODE | STRUCT_DELETED );
2008-03-13 05:04:59 +00:00
/* Put this structure in the picked list: */
ITEM_PICKER picker( item, UR_DELETED );
pickList.PushItem( picker );
2008-03-13 05:04:59 +00:00
}
/* Mark all wires, junctions, .. connected to one of the item to delete
*/
if( DeleteFullConnection )
{
SCH_LINE* segment;
for( item = screen->GetDrawItems(); item != NULL; item = item->Next() )
2008-03-13 05:04:59 +00:00
{
if( !(item->GetFlags() & SELECTEDNODE) )
2008-03-13 05:04:59 +00:00
continue;
if( item->Type() != SCH_LINE_T )
2008-03-13 05:04:59 +00:00
continue;
screen->MarkConnections( (SCH_LINE*) item );
2008-03-13 05:04:59 +00:00
}
// Search all removable wires (i.e wire with one new dangling end )
for( item = screen->GetDrawItems(); item != NULL; item = item->Next() )
2008-03-13 05:04:59 +00:00
{
bool noconnect = false;
2008-03-13 05:04:59 +00:00
if( item->GetFlags() & STRUCT_DELETED )
continue; // Already seen
2008-03-13 05:04:59 +00:00
if( !(item->GetFlags() & CANDIDATE) )
continue; // Already seen
2008-03-13 05:04:59 +00:00
if( item->Type() != SCH_LINE_T )
2008-03-13 05:04:59 +00:00
continue;
item->SetFlags( SKIP_STRUCT );
segment = (SCH_LINE*) item;
2008-03-13 05:04:59 +00:00
/* Test the SEGM->m_Start point: if this point was connected to
* an STRUCT_DELETED wire, and now is not connected, the wire can
* be deleted */
SCH_LINE* testSegment = NULL;
for( tmp = screen->GetDrawItems(); tmp != NULL; tmp = tmp->Next() )
2008-03-13 05:04:59 +00:00
{
if( ( tmp->GetFlags() & STRUCT_DELETED ) == 0 )
2008-03-13 05:04:59 +00:00
continue;
if( tmp->Type() != SCH_LINE_T )
2008-03-13 05:04:59 +00:00
continue;
testSegment = (SCH_LINE*) tmp;
if( testSegment->IsEndPoint( segment->m_Start ) )
2008-03-13 05:04:59 +00:00
break;
}
if( testSegment && !screen->CountConnectedItems( segment->m_Start, true ) )
noconnect = true;
2008-03-13 05:04:59 +00:00
/* Test the SEGM->m_End point: if this point was connected to
* an STRUCT_DELETED wire, and now is not connected, the wire
* can be deleted */
for( tmp = screen->GetDrawItems(); tmp != NULL; tmp = tmp->Next() )
2008-03-13 05:04:59 +00:00
{
if( ( tmp->GetFlags() & STRUCT_DELETED ) == 0 )
2008-03-13 05:04:59 +00:00
continue;
if( tmp->Type() != SCH_LINE_T )
2008-03-13 05:04:59 +00:00
continue;
if( testSegment->IsEndPoint( segment->m_End ) )
2008-03-13 05:04:59 +00:00
break;
}
if( tmp && !screen->CountConnectedItems( segment->m_End, true ) )
noconnect = true;
2008-03-13 05:04:59 +00:00
item->ClearFlags( SKIP_STRUCT );
2008-03-13 05:04:59 +00:00
if( noconnect )
{
item->SetFlags( STRUCT_DELETED );
2008-03-13 05:04:59 +00:00
/* Put this structure in the picked list: */
ITEM_PICKER picker( item, UR_DELETED );
pickList.PushItem( picker );
2008-03-13 05:04:59 +00:00
item = screen->GetDrawItems();
2008-03-13 05:04:59 +00:00
}
}
// Delete redundant junctions (junctions which connect < 3 end wires
// and no pin are removed)
for( item = screen->GetDrawItems(); item != NULL; item = item->Next() )
2008-03-13 05:04:59 +00:00
{
if( item->GetFlags() & STRUCT_DELETED )
2008-03-13 05:04:59 +00:00
continue;
if( !(item->GetFlags() & CANDIDATE) )
2008-03-13 05:04:59 +00:00
continue;
if( item->Type() != SCH_JUNCTION_T )
continue;
SCH_JUNCTION* junction = (SCH_JUNCTION*) item;
if( screen->CountConnectedItems( junction->m_Pos, false ) <= 2 )
2008-03-13 05:04:59 +00:00
{
item->SetFlags( STRUCT_DELETED );
/* Put this structure in the picked list: */
ITEM_PICKER picker( item, UR_DELETED );
pickList.PushItem( picker );
2008-03-13 05:04:59 +00:00
}
}
for( item = screen->GetDrawItems(); item != NULL; item = item->Next() )
2008-03-13 05:04:59 +00:00
{
if( item->GetFlags() & STRUCT_DELETED )
2008-03-13 05:04:59 +00:00
continue;
if( item->Type() != SCH_LABEL_T )
2008-03-13 05:04:59 +00:00
continue;
tmp = screen->GetWireOrBus( ( (SCH_TEXT*) item )->m_Pos );
2008-03-13 05:04:59 +00:00
if( tmp && tmp->GetFlags() & STRUCT_DELETED )
2008-03-13 05:04:59 +00:00
{
item->SetFlags( STRUCT_DELETED );
2008-03-13 05:04:59 +00:00
/* Put this structure in the picked list: */
ITEM_PICKER picker( item, UR_DELETED );
pickList.PushItem( picker );
2008-03-13 05:04:59 +00:00
}
}
}
screen->ClearDrawingState();
2008-03-13 05:04:59 +00:00
if( pickList.GetCount() )
2008-03-13 05:04:59 +00:00
{
DeleteItemsInList( DrawPanel, pickList );
OnModify();
2008-03-13 05:04:59 +00:00
}
}
bool SCH_EDIT_FRAME::DeleteItemAtCrossHair( wxDC* DC )
{
SCH_ITEM* item;
SCH_SCREEN* screen = GetScreen();
2008-03-13 05:04:59 +00:00
item = LocateItem( screen->GetCrossHairPosition(), SCH_COLLECTOR::ParentItems );
2008-03-13 05:04:59 +00:00
if( item )
2008-03-13 05:04:59 +00:00
{
bool itemHasConnections = item->IsConnectable();
GetScreen()->SetCurItem( NULL );
SetRepeatItem( NULL );
DeleteItem( item );
if( itemHasConnections )
screen->TestDanglingEnds( DrawPanel, DC );
OnModify();
return true;
2008-03-13 05:04:59 +00:00
}
return false;
}