Browse Source

eeschema: Remove UR_WIRE_IMAGE

The wire image undo/redo option required special handling and was only
used in a single location.  Replacing with single change handling
reduces the code complexity
pull/13/head
Seth Hillbrand 7 years ago
parent
commit
822cd9c6ef
  1. 14
      common/undo_redo_container.cpp
  2. 31
      eeschema/bus-wire-junction.cpp
  3. 5
      eeschema/sch_edit_frame.h
  4. 2
      eeschema/schedit.cpp
  5. 55
      eeschema/schematic_undo_redo.cpp
  6. 1
      include/undo_redo_container.h

14
common/undo_redo_container.cpp

@ -114,20 +114,6 @@ void PICKED_ITEMS_LIST::ClearListAndDeleteItems()
{ {
delete wrapper.GetItem(); delete wrapper.GetItem();
} }
else if( wrapper.GetStatus() == UR_WIRE_IMAGE )
{
// Specific to eeschema: a linked list of wires is stored. The wrapper picks only
// the first item (head of list), and is owner of all picked items.
EDA_ITEM* item = wrapper.GetItem();
while( item )
{
// Delete old copy of wires
EDA_ITEM* nextitem = item->Next();
delete item;
item = nextitem;
}
}
else if( wrapper.GetStatus() == UR_DELETED ) else if( wrapper.GetStatus() == UR_DELETED )
{ {
// This should really be replaced with UR_TRANSIENT, but currently many clients // This should really be replaced with UR_TRANSIENT, but currently many clients

31
eeschema/bus-wire-junction.cpp

@ -554,37 +554,6 @@ void SCH_EDIT_FRAME::DeleteCurrentSegment()
} }
void SCH_EDIT_FRAME::SaveWireImage()
{
PICKED_ITEMS_LIST oldItems;
oldItems.m_Status = UR_WIRE_IMAGE;
SCH_ITEM* item;
SCH_ITEM* next_item;
for( item = GetScreen()->GetDrawItems(); item; item = next_item )
{
next_item = item->Next();
if( item->Type() == SCH_JUNCTION_T || item->Type() == SCH_LINE_T )
{
GetScreen()->Remove( item );
GetCanvas()->GetView()->Remove( item );
oldItems.PushItem( ITEM_PICKER( item, UR_WIRE_IMAGE ) );
SCH_ITEM* item_copy = static_cast<SCH_ITEM*>( item->Clone() );
GetScreen()->GetDrawList().Insert( item_copy, next_item );
GetCanvas()->GetView()->Add( item_copy );
}
}
if( oldItems.GetCount() != 0 )
SaveCopyInUndoList( oldItems, UR_WIRE_IMAGE );
}
bool SCH_EDIT_FRAME::TrimWire( const wxPoint& aStart, const wxPoint& aEnd, bool aAppend ) bool SCH_EDIT_FRAME::TrimWire( const wxPoint& aStart, const wxPoint& aEnd, bool aAppend )
{ {
SCH_LINE* line; SCH_LINE* line;

5
eeschema/sch_edit_frame.h

@ -1001,11 +1001,6 @@ private:
bool aAppendToUndo = false, bool aAppendToUndo = false,
bool aFinal = true ); bool aFinal = true );
/**
* Save a copy of the current wire image in the undo list.
*/
void SaveWireImage();
/** /**
* Collects a unique list of all possible connection points in the schematic. * Collects a unique list of all possible connection points in the schematic.
* *

2
eeschema/schedit.cpp

@ -202,10 +202,8 @@ void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
break; break;
case ID_POPUP_SCH_BREAK_WIRE: case ID_POPUP_SCH_BREAK_WIRE:
SaveWireImage();
m_canvas->MoveCursorToCrossHair(); m_canvas->MoveCursorToCrossHair();
BreakSegments( GetCrossHairPosition() ); BreakSegments( GetCrossHairPosition() );
TestDanglingEnds(); TestDanglingEnds();
m_canvas->Refresh(); m_canvas->Refresh();

55
eeschema/schematic_undo_redo.cpp

@ -113,11 +113,7 @@ void SCH_EDIT_FRAME::SaveCopyInUndoList( SCH_ITEM* aItem,
{ {
PICKED_ITEMS_LIST* commandToUndo = NULL; PICKED_ITEMS_LIST* commandToUndo = NULL;
/* Does not save a null item or a UR_WIRE_IMAGE command type. UR_WIRE_IMAGE commands
* are handled by the overloaded version of SaveCopyInUndoList that takes a reference
* to a PICKED_ITEMS_LIST.
*/
if( aItem == NULL || aCommandType == UR_WIRE_IMAGE )
if( aItem == NULL )
return; return;
// Connectivity may change // Connectivity may change
@ -181,15 +177,8 @@ void SCH_EDIT_FRAME::SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList,
return; return;
// Can't append a WIRE IMAGE, so fail to a new undo point // Can't append a WIRE IMAGE, so fail to a new undo point
if( aAppend && ( aTypeCommand != UR_WIRE_IMAGE ) )
{
if( aAppend )
commandToUndo = GetScreen()->PopCommandFromUndoList(); commandToUndo = GetScreen()->PopCommandFromUndoList();
if( commandToUndo && commandToUndo->m_Status == UR_WIRE_IMAGE )
{
GetScreen()->PushCommandToUndoList( commandToUndo );
commandToUndo = NULL;
}
}
if( !commandToUndo ) if( !commandToUndo )
{ {
@ -246,7 +235,6 @@ void SCH_EDIT_FRAME::SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList,
case UR_NEW: case UR_NEW:
case UR_DELETED: case UR_DELETED:
case UR_EXCHANGE_T: case UR_EXCHANGE_T:
case UR_WIRE_IMAGE:
break; break;
default: default:
@ -255,7 +243,7 @@ void SCH_EDIT_FRAME::SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList,
} }
} }
if( commandToUndo->GetCount() || aTypeCommand == UR_WIRE_IMAGE )
if( commandToUndo->GetCount() )
{ {
/* Save the copy in undo list */ /* Save the copy in undo list */
GetScreen()->PushCommandToUndoList( commandToUndo ); GetScreen()->PushCommandToUndoList( commandToUndo );
@ -273,44 +261,8 @@ void SCH_EDIT_FRAME::SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList,
void SCH_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRedoCommand ) void SCH_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRedoCommand )
{ {
SCH_ITEM* item; SCH_ITEM* item;
SCH_ITEM* next_item;
SCH_ITEM* alt_item; SCH_ITEM* alt_item;
// Exchange the current wires, buses, and junctions with the copy save by the last edit.
if( aList->m_Status == UR_WIRE_IMAGE )
{
PICKED_ITEMS_LIST oldItems;
oldItems.m_Status = UR_WIRE_IMAGE;
// Remove all of the wires, buses, and junctions from the current screen.
for( item = GetScreen()->GetDrawItems(); item; item = next_item )
{
next_item = item->Next();
if( item->Type() == SCH_JUNCTION_T || item->Type() == SCH_LINE_T )
{
GetScreen()->Remove( item );
GetCanvas()->GetView()->Remove( item );
oldItems.PushItem( ITEM_PICKER( item, UR_WIRE_IMAGE ) );
}
}
// Copy the saved wires, buses, and junctions to the current screen.
for( unsigned int i = 0; i < aList->GetCount(); i++ )
{
item = static_cast<SCH_ITEM*>( aList->GetPickedItem( i ) );
AddToScreen( item );
}
// Copy the previous wires, buses, and junctions to the picked item list for the
// redo operation.
*aList = oldItems;
return;
}
// Undo in the reverse order of list creation: (this can allow stacked changes like the // Undo in the reverse order of list creation: (this can allow stacked changes like the
// same item can be changed and deleted in the same complex command). // same item can be changed and deleted in the same complex command).
for( int ii = aList->GetCount() - 1; ii >= 0; ii-- ) for( int ii = aList->GetCount() - 1; ii >= 0; ii-- )
@ -411,7 +363,6 @@ void SCH_EDIT_FRAME::GetSchematicFromUndoList( wxCommandEvent& event )
GetScreen()->PushCommandToRedoList( List ); GetScreen()->PushCommandToRedoList( List );
SetSheetNumberAndCount(); SetSheetNumberAndCount();
TestDanglingEnds(); TestDanglingEnds();
SyncView(); SyncView();

1
include/undo_redo_container.h

@ -68,7 +68,6 @@ enum UNDO_REDO_T {
UR_ROTATED, // Rotated item (counterclockwise), undo by rotating it UR_ROTATED, // Rotated item (counterclockwise), undo by rotating it
UR_ROTATED_CLOCKWISE, // Rotated item (clockwise), undo by rotating it UR_ROTATED_CLOCKWISE, // Rotated item (clockwise), undo by rotating it
UR_FLIPPED, // flipped (board items only), undo by flipping it UR_FLIPPED, // flipped (board items only), undo by flipping it
UR_WIRE_IMAGE, // Specific to Eeschema for handling wires changes.
UR_LIBEDIT, // Specific to the component editor (libedit creates a full copy UR_LIBEDIT, // Specific to the component editor (libedit creates a full copy
// of the current component when changed) // of the current component when changed)
UR_LIB_RENAME, // As UR_LIBEDIT, but old copy should be removed from library UR_LIB_RENAME, // As UR_LIBEDIT, but old copy should be removed from library

Loading…
Cancel
Save