Eeschema: Moving BreakSegment into SCH_EDIT_FRAME
BreakSegment now breaks a known segment and BreakSegments breaks all segments. This allows functions to break a segment without needing to iterate through the whole list.
This commit is contained in:
parent
e9a297de5b
commit
b5ec5f9a73
|
@ -228,9 +228,6 @@ bool SCH_EDIT_FRAME::HandleBlockEnd( wxDC* aDC )
|
|||
|
||||
case BLOCK_DRAG:
|
||||
case BLOCK_DRAG_ITEM: // Drag from a drag command
|
||||
GetScreen()->BreakSegmentsOnJunctions();
|
||||
// fall through
|
||||
|
||||
case BLOCK_MOVE:
|
||||
case BLOCK_DUPLICATE:
|
||||
if( block->GetCommand() == BLOCK_DRAG_ITEM &&
|
||||
|
|
|
@ -417,6 +417,30 @@ void SCH_EDIT_FRAME::DeleteCurrentSegment( wxDC* DC )
|
|||
}
|
||||
|
||||
|
||||
void SCH_EDIT_FRAME::SaveWireImage()
|
||||
{
|
||||
DLIST< SCH_ITEM > oldWires;
|
||||
|
||||
oldWires.SetOwnership( false ); // Prevent DLIST for deleting items in destructor.
|
||||
GetScreen()->ExtractWires( oldWires, true );
|
||||
|
||||
if( oldWires.GetCount() != 0 )
|
||||
{
|
||||
PICKED_ITEMS_LIST oldItems;
|
||||
|
||||
oldItems.m_Status = UR_WIRE_IMAGE;
|
||||
|
||||
while( oldWires.GetCount() != 0 )
|
||||
{
|
||||
ITEM_PICKER picker = ITEM_PICKER( oldWires.PopFront(), UR_WIRE_IMAGE );
|
||||
oldItems.PushItem( picker );
|
||||
}
|
||||
|
||||
SaveCopyInUndoList( oldItems, UR_WIRE_IMAGE );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool SCH_EDIT_FRAME::SchematicCleanUp()
|
||||
{
|
||||
bool modified = false;
|
||||
|
@ -465,6 +489,68 @@ bool SCH_EDIT_FRAME::SchematicCleanUp()
|
|||
return modified;
|
||||
}
|
||||
|
||||
bool SCH_EDIT_FRAME::BreakSegment( SCH_LINE *aSegment, const wxPoint& aPoint, bool aAppend )
|
||||
{
|
||||
if( !IsPointOnSegment( aSegment->GetStartPoint(), aSegment->GetEndPoint(), aPoint )
|
||||
|| aSegment->IsEndPoint( aPoint ) )
|
||||
return false;
|
||||
|
||||
SaveCopyInUndoList( aSegment, UR_CHANGED, aAppend );
|
||||
SCH_LINE* newSegment = new SCH_LINE( *aSegment );
|
||||
SaveCopyInUndoList( newSegment, UR_NEW, true );
|
||||
|
||||
newSegment->SetStartPoint( aPoint );
|
||||
aSegment->SetEndPoint( aPoint );
|
||||
GetScreen()->Append( newSegment );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool SCH_EDIT_FRAME::BreakSegments( const wxPoint& aPoint, bool aAppend )
|
||||
{
|
||||
bool brokenSegments = false;
|
||||
|
||||
for( SCH_ITEM* segment = GetScreen()->GetDrawItems(); segment; segment = segment->Next() )
|
||||
{
|
||||
if( ( segment->Type() != SCH_LINE_T ) || ( segment->GetLayer() == LAYER_NOTES ) )
|
||||
continue;
|
||||
|
||||
brokenSegments |= BreakSegment( (SCH_LINE*) segment, aPoint, aAppend || brokenSegments );
|
||||
}
|
||||
|
||||
return brokenSegments;
|
||||
}
|
||||
|
||||
|
||||
bool SCH_EDIT_FRAME::BreakSegmentsOnJunctions( bool aAppend )
|
||||
{
|
||||
bool brokenSegments = false;
|
||||
|
||||
for( SCH_ITEM* item = GetScreen()->GetDrawItems(); item; item = item->Next() )
|
||||
{
|
||||
if( item->Type() == SCH_JUNCTION_T )
|
||||
{
|
||||
SCH_JUNCTION* junction = ( SCH_JUNCTION* ) item;
|
||||
|
||||
if( BreakSegments( junction->GetPosition(), brokenSegments || aAppend ) )
|
||||
brokenSegments = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
SCH_BUS_ENTRY_BASE* busEntry = dynamic_cast<SCH_BUS_ENTRY_BASE*>( item );
|
||||
if( busEntry )
|
||||
{
|
||||
if( BreakSegments( busEntry->GetPosition(), brokenSegments || aAppend )
|
||||
|| BreakSegments( busEntry->m_End(), brokenSegments || aAppend ) )
|
||||
brokenSegments = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return brokenSegments;
|
||||
}
|
||||
|
||||
|
||||
SCH_JUNCTION* SCH_EDIT_FRAME::AddJunction( const wxPoint& aPosition,
|
||||
bool aPutInUndoList )
|
||||
|
|
|
@ -308,23 +308,6 @@ public:
|
|||
*/
|
||||
int GetConnection( const wxPoint& aPosition, PICKED_ITEMS_LIST& aList, bool aFullConnection );
|
||||
|
||||
/**
|
||||
* Checks every wire and bus for a intersection at \a aPoint and break into two segments
|
||||
* at \a aPoint if an intersection is found.
|
||||
*
|
||||
* @param aPoint Test this point for an intersection.
|
||||
* @return True if any wires or buses were broken.
|
||||
*/
|
||||
bool BreakSegment( const wxPoint& aPoint );
|
||||
|
||||
/**
|
||||
* Tests all junctions and bus entries in the schematic for intersections with wires and
|
||||
* buses and breaks any intersections into multiple segments.
|
||||
*
|
||||
* @return True if any wires or buses were broken.
|
||||
*/
|
||||
bool BreakSegmentsOnJunctions();
|
||||
|
||||
/* full undo redo management : */
|
||||
// use BASE_SCREEN::PushCommandToUndoList( PICKED_ITEMS_LIST* aItem )
|
||||
// use BASE_SCREEN::PushCommandToRedoList( PICKED_ITEMS_LIST* aItem )
|
||||
|
|
|
@ -845,64 +845,6 @@ bool SCH_SCREEN::TestDanglingEnds()
|
|||
}
|
||||
|
||||
|
||||
bool SCH_SCREEN::BreakSegment( const wxPoint& aPoint )
|
||||
{
|
||||
SCH_LINE* segment;
|
||||
SCH_LINE* newSegment;
|
||||
bool brokenSegments = false;
|
||||
|
||||
for( SCH_ITEM* item = m_drawList.begin(); item; item = item->Next() )
|
||||
{
|
||||
if( (item->Type() != SCH_LINE_T) || (item->GetLayer() == LAYER_NOTES) )
|
||||
continue;
|
||||
|
||||
segment = (SCH_LINE*) item;
|
||||
|
||||
if( !segment->HitTest( aPoint, 0 ) || segment->IsEndPoint( aPoint ) )
|
||||
continue;
|
||||
|
||||
// Break the segment at aPoint and create a new segment.
|
||||
newSegment = new SCH_LINE( *segment );
|
||||
newSegment->SetStartPoint( aPoint );
|
||||
segment->SetEndPoint( aPoint );
|
||||
m_drawList.Insert( newSegment, segment->Next() );
|
||||
item = newSegment;
|
||||
brokenSegments = true;
|
||||
}
|
||||
|
||||
return brokenSegments;
|
||||
}
|
||||
|
||||
|
||||
bool SCH_SCREEN::BreakSegmentsOnJunctions()
|
||||
{
|
||||
bool brokenSegments = false;
|
||||
|
||||
for( SCH_ITEM* item = m_drawList.begin(); item; item = item->Next() )
|
||||
{
|
||||
if( item->Type() == SCH_JUNCTION_T )
|
||||
{
|
||||
SCH_JUNCTION* junction = ( SCH_JUNCTION* ) item;
|
||||
|
||||
if( BreakSegment( junction->GetPosition() ) )
|
||||
brokenSegments = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
SCH_BUS_ENTRY_BASE* busEntry = dynamic_cast<SCH_BUS_ENTRY_BASE*>( item );
|
||||
if( busEntry )
|
||||
{
|
||||
if( BreakSegment( busEntry->GetPosition() )
|
||||
|| BreakSegment( busEntry->m_End() ) )
|
||||
brokenSegments = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return brokenSegments;
|
||||
}
|
||||
|
||||
|
||||
int SCH_SCREEN::GetNode( const wxPoint& aPosition, EDA_ITEMS& aList )
|
||||
{
|
||||
for( SCH_ITEM* item = m_drawList.begin(); item; item = item->Next() )
|
||||
|
@ -1047,7 +989,6 @@ int SCH_SCREEN::GetConnection( const wxPoint& aPosition, PICKED_ITEMS_LIST& aLis
|
|||
|
||||
// Clear flags member for all items.
|
||||
ClearDrawingState();
|
||||
BreakSegmentsOnJunctions();
|
||||
|
||||
if( GetNode( aPosition, list ) == 0 )
|
||||
return 0;
|
||||
|
|
|
@ -200,28 +200,9 @@ void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
|
|||
|
||||
case ID_POPUP_SCH_BREAK_WIRE:
|
||||
{
|
||||
DLIST< SCH_ITEM > oldWires;
|
||||
|
||||
oldWires.SetOwnership( false ); // Prevent DLIST for deleting items in destructor.
|
||||
SaveWireImage();
|
||||
m_canvas->MoveCursorToCrossHair();
|
||||
screen->ExtractWires( oldWires, true );
|
||||
screen->BreakSegment( GetCrossHairPosition() );
|
||||
|
||||
if( oldWires.GetCount() != 0 )
|
||||
{
|
||||
PICKED_ITEMS_LIST oldItems;
|
||||
|
||||
oldItems.m_Status = UR_WIRE_IMAGE;
|
||||
|
||||
while( oldWires.GetCount() != 0 )
|
||||
{
|
||||
ITEM_PICKER picker = ITEM_PICKER( oldWires.PopFront(), UR_WIRE_IMAGE );
|
||||
oldItems.PushItem( picker );
|
||||
}
|
||||
|
||||
SaveCopyInUndoList( oldItems, UR_WIRE_IMAGE );
|
||||
}
|
||||
|
||||
BreakSegments( GetCrossHairPosition() );
|
||||
if( screen->TestDanglingEnds() )
|
||||
m_canvas->Refresh();
|
||||
}
|
||||
|
|
|
@ -465,6 +465,35 @@ public:
|
|||
const wxString& aSearchText,
|
||||
bool aWarpMouse );
|
||||
|
||||
/**
|
||||
* Breaks a single segment into two at the specified point
|
||||
*
|
||||
* @param aSegment Line segment to break
|
||||
* @param aPoint Point at which to break the segment
|
||||
* @param aAppend Add the changes to the previous undo state
|
||||
* @return True if any wires or buses were broken.
|
||||
*/
|
||||
bool BreakSegment( SCH_LINE* aSegment, const wxPoint& aPoint, bool aAppend = false );
|
||||
|
||||
/**
|
||||
* Checks every wire and bus for a intersection at \a aPoint and break into two segments
|
||||
* at \a aPoint if an intersection is found.
|
||||
*
|
||||
* @param aPoint Test this point for an intersection.
|
||||
* @param aAppend Add the changes to the previous undo state
|
||||
* @return True if any wires or buses were broken.
|
||||
*/
|
||||
bool BreakSegments( const wxPoint& aPoint, bool aAppend = false );
|
||||
|
||||
/**
|
||||
* Tests all junctions and bus entries in the schematic for intersections with wires and
|
||||
* buses and breaks any intersections into multiple segments.
|
||||
*
|
||||
* @param aAppend Add the changes to the previous undo state
|
||||
* @return True if any wires or buses were broken.
|
||||
*/
|
||||
bool BreakSegmentsOnJunctions( bool aApped = false );
|
||||
|
||||
/**
|
||||
* Send a message to Pcbnew via a socket connection.
|
||||
*
|
||||
|
@ -907,6 +936,12 @@ private:
|
|||
*/
|
||||
SCH_JUNCTION* AddJunction( const wxPoint& aPosition, bool aPutInUndoList = false );
|
||||
|
||||
/**
|
||||
* Function SaveWireImage
|
||||
* saves a copy of the current wire image in the undo list
|
||||
*/
|
||||
void SaveWireImage();
|
||||
|
||||
/**
|
||||
* Function SchematicCleanUp
|
||||
* performs routine schematic cleaning including breaking wire and buses and
|
||||
|
|
Loading…
Reference in New Issue