Push schematic get connection code into schematic screen object.

This commit is contained in:
Wayne Stambaugh 2011-04-15 08:40:56 -04:00
parent 14e3507e16
commit ce983218f8
5 changed files with 214 additions and 220 deletions

View File

@ -25,7 +25,6 @@ set(EESCHEMA_SRCS
cross-probing.cpp
dangling_ends.cpp
database.cpp
delete.cpp
delsheet.cpp
dialogs/dialog_color_config.cpp
dialogs/dialog_plot_schematic_DXF.cpp

View File

@ -1,217 +0,0 @@
/************************************/
/* delete.cpp */
/************************************/
#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)
*/
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();
// Clear flags member for all items.
screen->ClearDrawingState();
screen->BreakSegmentsOnJunctions();
if( screen->GetNode( pos, list ) == 0 )
return;
for( size_t i = 0; i < list.size(); i++ )
{
item = (SCH_ITEM*) list[ i ];
item->SetFlags( SELECTEDNODE | STRUCT_DELETED );
/* Put this structure in the picked list: */
ITEM_PICKER picker( item, UR_DELETED );
pickList.PushItem( picker );
}
/* 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() )
{
if( !(item->GetFlags() & SELECTEDNODE) )
continue;
if( item->Type() != SCH_LINE_T )
continue;
screen->MarkConnections( (SCH_LINE*) item );
}
// Search all removable wires (i.e wire with one new dangling end )
for( item = screen->GetDrawItems(); item != NULL; item = item->Next() )
{
bool noconnect = false;
if( item->GetFlags() & STRUCT_DELETED )
continue; // Already seen
if( !(item->GetFlags() & CANDIDATE) )
continue; // Already seen
if( item->Type() != SCH_LINE_T )
continue;
item->SetFlags( SKIP_STRUCT );
segment = (SCH_LINE*) item;
/* 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() )
{
if( ( tmp->GetFlags() & STRUCT_DELETED ) == 0 )
continue;
if( tmp->Type() != SCH_LINE_T )
continue;
testSegment = (SCH_LINE*) tmp;
if( testSegment->IsEndPoint( segment->m_Start ) )
break;
}
if( testSegment && !screen->CountConnectedItems( segment->m_Start, true ) )
noconnect = true;
/* 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() )
{
if( ( tmp->GetFlags() & STRUCT_DELETED ) == 0 )
continue;
if( tmp->Type() != SCH_LINE_T )
continue;
if( testSegment->IsEndPoint( segment->m_End ) )
break;
}
if( tmp && !screen->CountConnectedItems( segment->m_End, true ) )
noconnect = true;
item->ClearFlags( SKIP_STRUCT );
if( noconnect )
{
item->SetFlags( STRUCT_DELETED );
/* Put this structure in the picked list: */
ITEM_PICKER picker( item, UR_DELETED );
pickList.PushItem( picker );
item = screen->GetDrawItems();
}
}
// Delete redundant junctions (junctions which connect < 3 end wires
// and no pin are removed)
for( item = screen->GetDrawItems(); item != NULL; item = item->Next() )
{
if( item->GetFlags() & STRUCT_DELETED )
continue;
if( !(item->GetFlags() & CANDIDATE) )
continue;
if( item->Type() != SCH_JUNCTION_T )
continue;
SCH_JUNCTION* junction = (SCH_JUNCTION*) item;
if( screen->CountConnectedItems( junction->m_Pos, false ) <= 2 )
{
item->SetFlags( STRUCT_DELETED );
/* Put this structure in the picked list: */
ITEM_PICKER picker( item, UR_DELETED );
pickList.PushItem( picker );
}
}
for( item = screen->GetDrawItems(); item != NULL; item = item->Next() )
{
if( item->GetFlags() & STRUCT_DELETED )
continue;
if( item->Type() != SCH_LABEL_T )
continue;
tmp = screen->GetWireOrBus( ( (SCH_TEXT*) item )->m_Pos );
if( tmp && tmp->GetFlags() & STRUCT_DELETED )
{
item->SetFlags( STRUCT_DELETED );
/* Put this structure in the picked list: */
ITEM_PICKER picker( item, UR_DELETED );
pickList.PushItem( picker );
}
}
}
screen->ClearDrawingState();
if( pickList.GetCount() )
{
DeleteItemsInList( DrawPanel, pickList );
OnModify();
}
}
bool SCH_EDIT_FRAME::DeleteItemAtCrossHair( wxDC* DC )
{
SCH_ITEM* item;
SCH_SCREEN* screen = GetScreen();
item = LocateItem( screen->GetCrossHairPosition(), SCH_COLLECTOR::ParentItems );
if( item )
{
bool itemHasConnections = item->IsConnectable();
GetScreen()->SetCurItem( NULL );
SetRepeatItem( NULL );
DeleteItem( item );
if( itemHasConnections )
screen->TestDanglingEnds( DrawPanel, DC );
OnModify();
return true;
}
return false;
}

View File

@ -1044,6 +1044,165 @@ bool SCH_SCREEN::SetComponentFootprint( SCH_SHEET_PATH* aSheetPath, const wxStri
}
int SCH_SCREEN::GetConnection( const wxPoint& aPosition, PICKED_ITEMS_LIST& aList,
bool aFullConnection )
{
SCH_ITEM* item;
EDA_ITEM* tmp;
EDA_ITEMS list;
// Clear flags member for all items.
ClearDrawingState();
BreakSegmentsOnJunctions();
if( GetNode( aPosition, list ) == 0 )
return 0;
for( size_t i = 0; i < list.size(); i++ )
{
item = (SCH_ITEM*) list[ i ];
item->SetFlags( SELECTEDNODE | STRUCT_DELETED );
/* Put this structure in the picked list: */
ITEM_PICKER picker( item, UR_DELETED );
aList.PushItem( picker );
}
// Mark all wires, junctions, .. connected to the item(s) found.
if( aFullConnection )
{
SCH_LINE* segment;
for( item = GetDrawItems(); item != NULL; item = item->Next() )
{
if( !(item->GetFlags() & SELECTEDNODE) )
continue;
if( item->Type() != SCH_LINE_T )
continue;
MarkConnections( (SCH_LINE*) item );
}
// Search all attached wires (i.e wire with one new dangling end )
for( item = GetDrawItems(); item != NULL; item = item->Next() )
{
bool noconnect = false;
if( item->GetFlags() & STRUCT_DELETED )
continue; // Already seen
if( !(item->GetFlags() & CANDIDATE) )
continue; // Already seen
if( item->Type() != SCH_LINE_T )
continue;
item->SetFlags( SKIP_STRUCT );
segment = (SCH_LINE*) item;
/* If the wire start point is connected to a wire that has already been found
* and now is not connected, add the wire to the list. */
SCH_LINE* testSegment = NULL;
for( tmp = GetDrawItems(); tmp != NULL; tmp = tmp->Next() )
{
if( ( tmp->GetFlags() & STRUCT_DELETED ) == 0 )
continue;
if( tmp->Type() != SCH_LINE_T )
continue;
testSegment = (SCH_LINE*) tmp;
if( testSegment->IsEndPoint( segment->m_Start ) )
break;
}
if( testSegment && !CountConnectedItems( segment->m_Start, true ) )
noconnect = true;
/* If the wire end point is connected to a wire that has already been found
* and now is not connected, add the wire to the list. */
for( tmp = GetDrawItems(); tmp != NULL; tmp = tmp->Next() )
{
if( ( tmp->GetFlags() & STRUCT_DELETED ) == 0 )
continue;
if( tmp->Type() != SCH_LINE_T )
continue;
if( testSegment->IsEndPoint( segment->m_End ) )
break;
}
if( tmp && !CountConnectedItems( segment->m_End, true ) )
noconnect = true;
item->ClearFlags( SKIP_STRUCT );
if( noconnect )
{
item->SetFlags( STRUCT_DELETED );
ITEM_PICKER picker( item, UR_DELETED );
aList.PushItem( picker );
item = GetDrawItems();
}
}
// Get redundant junctions (junctions which connect < 3 end wires
// and no pin)
for( item = GetDrawItems(); item != NULL; item = item->Next() )
{
if( item->GetFlags() & STRUCT_DELETED )
continue;
if( !(item->GetFlags() & CANDIDATE) )
continue;
if( item->Type() != SCH_JUNCTION_T )
continue;
SCH_JUNCTION* junction = (SCH_JUNCTION*) item;
if( CountConnectedItems( junction->m_Pos, false ) <= 2 )
{
item->SetFlags( STRUCT_DELETED );
ITEM_PICKER picker( item, UR_DELETED );
aList.PushItem( picker );
}
}
for( item = GetDrawItems(); item != NULL; item = item->Next() )
{
if( item->GetFlags() & STRUCT_DELETED )
continue;
if( item->Type() != SCH_LABEL_T )
continue;
tmp = GetWireOrBus( ( (SCH_TEXT*) item )->m_Pos );
if( tmp && tmp->GetFlags() & STRUCT_DELETED )
{
item->SetFlags( STRUCT_DELETED );
ITEM_PICKER picker( item, UR_DELETED );
aList.PushItem( picker );
}
}
}
ClearDrawingState();
return aList.GetCount();
}
/******************************************************************/
/* Class SCH_SCREENS to handle the list of screens in a hierarchy */
/******************************************************************/

View File

@ -176,7 +176,7 @@ void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
case ID_POPUP_SCH_DELETE_NODE:
case ID_POPUP_SCH_DELETE_CONNECTION:
DrawPanel->MoveCursorToCrossHair();
DeleteConnection( id == ID_POPUP_SCH_DELETE_CONNECTION ? true : false );
DeleteConnection( id == ID_POPUP_SCH_DELETE_CONNECTION );
screen->SetCurItem( NULL );
m_itemToRepeat = NULL;
screen->TestDanglingEnds( DrawPanel, &dc );
@ -627,3 +627,43 @@ void SCH_EDIT_FRAME::OnUpdateSelectTool( wxUpdateUIEvent& aEvent )
if( aEvent.GetEventObject() == m_VToolBar )
aEvent.Check( GetToolId() == aEvent.GetId() );
}
void SCH_EDIT_FRAME::DeleteConnection( bool aFullConnection )
{
PICKED_ITEMS_LIST pickList;
SCH_SCREEN* screen = GetScreen();
wxPoint pos = screen->GetCrossHairPosition();
if( screen->GetConnection( pos, pickList, aFullConnection ) != 0 )
{
DeleteItemsInList( DrawPanel, pickList );
OnModify();
}
}
bool SCH_EDIT_FRAME::DeleteItemAtCrossHair( wxDC* DC )
{
SCH_ITEM* item;
SCH_SCREEN* screen = GetScreen();
item = LocateItem( screen->GetCrossHairPosition(), SCH_COLLECTOR::ParentItems );
if( item )
{
bool itemHasConnections = item->IsConnectable();
screen->SetCurItem( NULL );
SetRepeatItem( NULL );
DeleteItem( item );
if( itemHasConnections )
screen->TestDanglingEnds( DrawPanel, DC );
OnModify();
return true;
}
return false;
}

View File

@ -179,13 +179,26 @@ public:
void ReplaceWires( SCH_ITEM* aWireList );
/**
* Functions MarkConnections
* Function MarkConnections
* add all wires and junctions connected to \a aSegment which are not connected any
* component pin to \a aItemList.
* @param aSegment The segment to test for connections.
*/
void MarkConnections( SCH_LINE* aSegment );
/**
* Functions GetConnection
* adds all of the wires and junctions to \a aList that make up a connection to the
* object at \a aPosition.
* @param aPosition The position of the first connection object in drawing units.
* @param aList The pick list to add the connect item to.
* @param aFullConnection If true all the objects that make up this connection are
* add to \aList. Otherwise, only the objects up to the first
* node are added.
* @return The number of items added to \a aList.
*/
int GetConnection( const wxPoint& aPosition, PICKED_ITEMS_LIST& aList, bool aFullConnection );
/**
* Function BreakSegment
* checks every wire and bus for a intersection at \a aPoint and break into two segments