Commit df8f7d1e authored by Wayne Stambaugh's avatar Wayne Stambaugh

EESchema remove global variable and fix text object change type undo/redo.

* Move undo item copy global variable into schematic editor frame object
  member variable.
* Add helper methods for accessing the undo item copy member variable.
* Fix undetected bug when changing a text type.
* Added an exchange command to the undo/redo base class for handling undoing
  a changed item type which cannot be undone by swapping out the variables.
* Revert change to common/hotkeys_basic.cpp that broke hot key behavior.
* Lots of coding policy changes while making the changes above.
parent fb475361
......@@ -31,7 +31,7 @@
#include "class_undoredo_container.h"
ITEM_PICKER::ITEM_PICKER( EDA_ITEM* aItem, UndoRedoOpType aUndoRedoStatus )
ITEM_PICKER::ITEM_PICKER( EDA_ITEM* aItem, UNDO_REDO_T aUndoRedoStatus )
{
m_UndoRedoStatus = aUndoRedoStatus;
m_PickedItem = aItem;
......@@ -134,6 +134,7 @@ void PICKED_ITEMS_LIST::ClearListAndDeleteItems()
break;
case UR_CHANGED:
case UR_EXCHANGE_T:
delete wrapper.m_Link; // the picker is owner of this item
break;
......@@ -149,13 +150,9 @@ void PICKED_ITEMS_LIST::ClearListAndDeleteItems()
break;
default:
{
wxString msg;
msg.Printf( wxT( "ClearUndoORRedoList() error: unknown command type %d" ),
wrapper.m_UndoRedoStatus );
wxMessageBox( msg );
}
break;
wxFAIL_MSG( wxString::Format( wxT( "Cannot clear unknown undo/redo command %d" ),
wrapper.m_UndoRedoStatus ) );
break;
}
}
}
......@@ -190,7 +187,7 @@ EDA_ITEM* PICKED_ITEMS_LIST::GetPickedItemLink( unsigned int aIdx )
}
UndoRedoOpType PICKED_ITEMS_LIST::GetPickedItemStatus( unsigned int aIdx )
UNDO_REDO_T PICKED_ITEMS_LIST::GetPickedItemStatus( unsigned int aIdx )
{
if( aIdx < m_ItemsList.size() )
return m_ItemsList[aIdx].m_UndoRedoStatus;
......@@ -232,7 +229,7 @@ bool PICKED_ITEMS_LIST::SetPickedItemLink( EDA_ITEM* aLink, unsigned aIdx )
}
bool PICKED_ITEMS_LIST::SetPickedItem( EDA_ITEM* aItem, UndoRedoOpType aStatus, unsigned aIdx )
bool PICKED_ITEMS_LIST::SetPickedItem( EDA_ITEM* aItem, UNDO_REDO_T aStatus, unsigned aIdx )
{
if( aIdx < m_ItemsList.size() )
{
......@@ -245,7 +242,7 @@ bool PICKED_ITEMS_LIST::SetPickedItem( EDA_ITEM* aItem, UndoRedoOpType aStatus,
}
bool PICKED_ITEMS_LIST::SetPickedItemStatus( UndoRedoOpType aStatus, unsigned aIdx )
bool PICKED_ITEMS_LIST::SetPickedItemStatus( UNDO_REDO_T aStatus, unsigned aIdx )
{
if( aIdx < m_ItemsList.size() )
{
......
......@@ -189,8 +189,12 @@ wxString AddHotkeyName( const wxString& aText, Ki_HotkeyInfo** aList,
keyname = ReturnKeyNameFromCommandId( aList, aCommandId );
if( !keyname.IsEmpty() )
{
if( aIsShortCut )
msg << wxT( "\t" ) << keyname;
else
msg << wxT( " <" ) << keyname << wxT( ">" );
}
return msg;
}
......@@ -219,10 +223,12 @@ wxString AddHotkeyName( const wxString& aText,
{
List = aDescList->m_HK_InfoList;
keyname = ReturnKeyNameFromCommandId( List, aCommandId );
if( !keyname.IsEmpty() )
{
msg << wxT( "\t" ) << keyname;
if( aIsShortCut )
msg << wxT( "\t" ) << keyname;
else
msg << wxT( " <" ) << keyname << wxT( ">" );
break;
}
}
......
......@@ -116,6 +116,12 @@ bool SCH_ITEM::IsConnected( const wxPoint& aPosition ) const
}
void SCH_ITEM::SwapData( SCH_ITEM* aItem )
{
wxFAIL_MSG( wxT( "SwapData() method not implemented for class " ) + GetClass() );
}
bool SCH_ITEM::operator < ( const SCH_ITEM& aItem ) const
{
wxCHECK_MSG( false, this->Type() < aItem.Type(),
......
......@@ -60,7 +60,7 @@ public:
* but but be defined because it is a pure virtual in PCB_BASE_FRAME
*/
virtual void SaveCopyInUndoList( BOARD_ITEM* aItemToCopy,
UndoRedoOpType aTypeCommand = UR_UNSPECIFIED,
UNDO_REDO_T aTypeCommand = UR_UNSPECIFIED,
const wxPoint& aTransformPoint = wxPoint( 0, 0 ) )
{
}
......@@ -71,12 +71,12 @@ public:
* Creates a new entry in undo list of commands.
* add a list of pickers to handle a list of items
* @param aItemsList = the list of items modified by the command to undo
* @param aTypeCommand = command type (see enum UndoRedoOpType)
* @param aTypeCommand = command type (see enum UNDO_REDO_T)
* @param aTransformPoint = the reference point of the transformation,
* for commands like move
*/
virtual void SaveCopyInUndoList( PICKED_ITEMS_LIST& aItemsList,
UndoRedoOpType aTypeCommand,
UNDO_REDO_T aTypeCommand,
const wxPoint& aTransformPoint = wxPoint( 0, 0 ) )
{
// currently: do nothing in cvpcb.
......
......@@ -86,12 +86,9 @@ void SCH_EDIT_FRAME::StartMoveBusEntry( SCH_BUS_ENTRY* BusEntry, wxDC* DC )
return;
if( !BusEntry->IsNew() ) // not already in edit, save shape
{
delete g_ItemToUndoCopy;
g_ItemToUndoCopy = BusEntry->Clone();
}
SetUndoItem( BusEntry );
BusEntry->m_Flags |= IS_MOVED;
BusEntry->SetFlags( IS_MOVED );
ItemInitialPosition = BusEntry->m_Pos;
......
......@@ -70,8 +70,6 @@ static void abortMoveField( EDA_DRAW_PANEL* aPanel, wxDC* aDC )
}
frame->SetCurrentField( NULL );
SAFE_DELETE( g_ItemToUndoCopy );
}
......@@ -85,9 +83,7 @@ void SCH_EDIT_FRAME::MoveField( SCH_FIELD* aField, wxDC* aDC )
SCH_COMPONENT* comp = (SCH_COMPONENT*) aField->GetParent();
SetCurrentField( aField );
SAFE_DELETE( g_ItemToUndoCopy );
g_ItemToUndoCopy = new SCH_COMPONENT( *comp );
SetUndoItem( comp );
pos = comp->m_Pos;
......
This diff is collapsed.
......@@ -29,10 +29,6 @@ bool g_OptNetListUseNames; /* TRUE to use names rather than net
wxSize g_RepeatStep;
int g_RepeatDeltaLabel;
SCH_ITEM* g_ItemToUndoCopy; /* copy of last modified schematic item
* before it is modified (used for undo
* managing to restore old values ) */
bool g_HVLines = true; // Bool: force H or V
// directions (Wires, Bus ..)
......
......@@ -52,8 +52,8 @@ void SCH_EDIT_FRAME::OnCopySchematicItemRequest( wxCommandEvent& event )
case SCH_HIERARCHICAL_LABEL_T:
{
SCH_TEXT* newitem = (SCH_TEXT*) curr_item->Clone();
newitem->m_Flags = IS_NEW;
StartMoveTexte( newitem, &dc );
newitem->SetFlags( IS_NEW );
MoveText( newitem, &dc );
/* Redraw the original part in XOR mode */
curr_item->Draw( DrawPanel, &dc, wxPoint( 0, 0 ), g_XorMode );
}
......
......@@ -109,15 +109,11 @@ public:
int Flags;
};
extern wxSize g_RepeatStep;
extern int g_RepeatDeltaLabel;
extern SCH_ITEM* g_ItemToUndoCopy; /* copy of last modified schematic item
* before it is modified (used for undo
* managing to restore old values ) */
extern wxSize g_RepeatStep;
extern int g_RepeatDeltaLabel;
// Management options.
extern bool g_HVLines;
extern bool g_HVLines;
// Management variables, option ... to be stored. Reset to 0 during a
// project reload.
......
......@@ -455,14 +455,7 @@ void SCH_EDIT_FRAME::StartMovePart( SCH_COMPONENT* Component, wxDC* DC )
return;
if( Component->m_Flags == 0 )
{
if( g_ItemToUndoCopy )
{
SAFE_DELETE( g_ItemToUndoCopy );
}
g_ItemToUndoCopy = Component->Clone();
}
SetUndoItem( Component );
DrawPanel->CrossHairOff( DC );
GetScreen()->SetCrossHairPosition( Component->m_Pos );
......
......@@ -102,6 +102,7 @@ bool SCH_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu )
{
if( GetSheet()->Last() != g_RootSheet )
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_LEAVE_SHEET, _( "Leave Sheet" ), leave_sheet_xpm );
PopMenu->AppendSeparator();
return true;
}
......@@ -191,10 +192,8 @@ bool SCH_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu )
break;
default:
wxString msg;
msg.Printf( wxT( "SCH_EDIT_FRAME::OnRightClick Error: unknown DrawType %d" ),
item->Type() );
DisplayError( this, msg );
wxFAIL_MSG( wxString::Format( wxT( "Cannot create context menu for unknown type %d" ),
item->Type() ) );
break;
}
......
......@@ -2,13 +2,14 @@
#ifndef __PROTOS_H__
#define __PROTOS_H__
#include "class_undoredo_container.h"
//#include "class_undoredo_container.h"
#include "colors.h"
class EDA_DRAW_PANEL;
class EDA_DRAW_FRAME;
class PICKED_ITEMS_LIST;
class SCH_EDIT_FRAME;
class LIB_EDIT_FRAME;
class CMP_LIBRARY;
......@@ -20,39 +21,30 @@ class SCH_SHEET;
class NETLIST_OBJECT;
wxString ReturnDefaultFieldName( int aFieldNdx );
/****************/
/* DATABASE.CPP */
/****************/
void DisplayCmpDoc( wxString& Name );
wxString DataBaseGetName( EDA_DRAW_FRAME* frame, wxString& Keys, wxString& BufName );
/*********************/
/* DANGLING_ENDS.CPP */
/*********************/
bool SegmentIntersect( wxPoint aSegStart, wxPoint aSegEnd, wxPoint aTestPoint );
/****************/
/* BUS_WIRE_JUNCTION.CPP */
/****************/
void IncrementLabelMember( wxString& name );
/****************/
/* EDITPART.CPP */
/****************/
void InstallCmpeditFrame( SCH_EDIT_FRAME* aParent, SCH_COMPONENT* aComponent );
void SnapLibItemPoint( int OrigX,
int OrigY,
int* ClosestX,
int* ClosestY,
SCH_COMPONENT* DrawLibItem );
bool LibItemInBox( int x1, int y1, int x2, int y2, SCH_COMPONENT* DrawLibItem );
// operations_on_item_lists.cpp
void DeleteItemsInList( EDA_DRAW_PANEL* panel, PICKED_ITEMS_LIST& aItemsList );
......@@ -72,7 +64,6 @@ SCH_ITEM* DuplicateStruct( SCH_ITEM* DrawStruct, bool aClone = false );
/* EEREDRAW.CPP */
/***************/
void DrawDanglingSymbol( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& pos, int Color );
void RedrawActiveWindow( EDA_DRAW_PANEL* panel, wxDC* DC );
/**************/
......@@ -87,11 +78,13 @@ EDA_Colors ReturnLayerColor( int Layer );
/**************/
int IsBusLabel( const wxString& LabelDrawList );
/************/
/* PLOT.CPP */
/************/
void PlotDrawlist( PLOTTER* plotter, SCH_ITEM* drawlist );
/***************/
/* DELSHEET.CPP */
/***************/
......
......@@ -586,19 +586,8 @@ void SCH_COMPONENT::SwapData( SCH_COMPONENT* copyitem )
void SCH_COMPONENT::Place( SCH_EDIT_FRAME* frame, wxDC* DC )
{
/* save old text in undo list */
if( g_ItemToUndoCopy && ( g_ItemToUndoCopy->Type() == Type() ) && !IsNew() )
{
/* restore old values and save new ones */
SwapData( (SCH_COMPONENT*) g_ItemToUndoCopy );
/* save in undo list */
frame->SaveCopyInUndoList( this, UR_CHANGED );
/* restore new values */
SwapData( (SCH_COMPONENT*) g_ItemToUndoCopy );
SAFE_DELETE( g_ItemToUndoCopy );
}
if( !IsNew() )
frame->SaveUndoItemInUndoList( this );
SCH_ITEM::Place( frame, DC );
}
......
......@@ -371,12 +371,7 @@ void SCH_FIELD::Place( SCH_EDIT_FRAME* frame, wxDC* DC )
SCH_COMPONENT* component = (SCH_COMPONENT*) GetParent();
// save old cmp in undo list
if( g_ItemToUndoCopy && ( g_ItemToUndoCopy->Type() == component->Type() ) )
{
component->SwapData( (SCH_COMPONENT*) g_ItemToUndoCopy );
frame->SaveCopyInUndoList( component, UR_CHANGED );
component->SwapData( (SCH_COMPONENT*) g_ItemToUndoCopy );
}
frame->SaveUndoItemInUndoList( component );
fieldNdx = m_FieldId;
m_AddExtraText = 0;
......@@ -393,7 +388,7 @@ void SCH_FIELD::Place( SCH_EDIT_FRAME* frame, wxDC* DC )
}
Draw( frame->DrawPanel, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
m_Flags = 0;
ClearFlags();
frame->GetScreen()->SetCurItem( NULL );
frame->OnModify();
frame->SetCurrentField( NULL );
......
......@@ -121,22 +121,22 @@ void SCH_SCREEN::DecRefCount()
void SCH_SCREEN::FreeDrawList()
{
SCH_ITEM* DrawStruct;
SCH_ITEM* item;
while( GetDrawItems() != NULL )
{
DrawStruct = GetDrawItems();
item = GetDrawItems();
SetDrawItems( GetDrawItems()->Next() );
SAFE_DELETE( DrawStruct );
SAFE_DELETE( item );
}
SetDrawItems( NULL );
}
void SCH_SCREEN::RemoveFromDrawList( SCH_ITEM * DrawStruct )
void SCH_SCREEN::RemoveFromDrawList( SCH_ITEM* aItem )
{
if( DrawStruct == GetDrawItems() )
if( aItem == GetDrawItems() )
{
SetDrawItems( GetDrawItems()->Next() );
}
......@@ -146,7 +146,7 @@ void SCH_SCREEN::RemoveFromDrawList( SCH_ITEM * DrawStruct )
while( DrawList && DrawList->Next() )
{
if( DrawList->Next() == DrawStruct )
if( DrawList->Next() == aItem )
{
DrawList->SetNext( DrawList->Next()->Next() );
break;
......@@ -201,13 +201,13 @@ void SCH_SCREEN::DeleteItem( SCH_ITEM* aItem )
}
bool SCH_SCREEN::CheckIfOnDrawList( SCH_ITEM* st )
bool SCH_SCREEN::CheckIfOnDrawList( SCH_ITEM* aItem )
{
SCH_ITEM * itemList = GetDrawItems();
SCH_ITEM* itemList = GetDrawItems();
while( itemList )
{
if( itemList == st )
if( itemList == aItem )
return true;
itemList = itemList->Next();
......@@ -217,10 +217,10 @@ bool SCH_SCREEN::CheckIfOnDrawList( SCH_ITEM* st )
}
void SCH_SCREEN::AddToDrawList( SCH_ITEM* st )
void SCH_SCREEN::AddToDrawList( SCH_ITEM* aItem )
{
st->SetNext( GetDrawItems() );
SetDrawItems( st );
aItem->SetNext( GetDrawItems() );
SetDrawItems( aItem );
}
......
......@@ -418,19 +418,7 @@ void SCH_SHEET::Place( SCH_EDIT_FRAME* frame, wxDC* DC )
}
else /* save old text in undo list */
{
if( g_ItemToUndoCopy && ( g_ItemToUndoCopy->Type() == Type() ) )
{
/* restore old values and save new ones */
SwapData( (SCH_SHEET*) g_ItemToUndoCopy );
/* save in undo list */
frame->SaveCopyInUndoList( this, UR_CHANGED );
/* restore new values */
SwapData( (SCH_SHEET*) g_ItemToUndoCopy );
SAFE_DELETE( g_ItemToUndoCopy );
}
frame->SaveUndoItemInUndoList( this );
}
SCH_ITEM::Place( frame, DC ); //puts it on the GetDrawItems().
......
......@@ -120,8 +120,6 @@ void SCH_SHEET_PIN::Place( SCH_EDIT_FRAME* aFrame, wxDC* aDC )
wxCHECK_RET( (sheet != NULL) && (sheet->Type() == SCH_SHEET_T),
wxT( "Cannot place sheet pin in invalid schematic sheet object." ) );
SAFE_DELETE( g_ItemToUndoCopy );
int flags = m_Flags;
m_Flags = 0;
......
......@@ -326,18 +326,20 @@ void SCH_TEXT::SwapData( SCH_TEXT* copyitem )
void SCH_TEXT::Place( SCH_EDIT_FRAME* frame, wxDC* DC )
{
/* save old text in undo list */
if( g_ItemToUndoCopy && !IsNew() )
if( !IsNew() )
{
/* restore old values and save new ones */
SwapData( (SCH_TEXT*) g_ItemToUndoCopy );
/* save in undo list */
frame->SaveCopyInUndoList( this, UR_CHANGED );
/* restore new values */
SwapData( (SCH_TEXT*) g_ItemToUndoCopy );
SAFE_DELETE( g_ItemToUndoCopy );
ClearFlags();
PICKED_ITEMS_LIST pickList;
ITEM_PICKER picker( this, UR_EXCHANGE_T );
SCH_ITEM* undoItem = frame->GetUndoItem();
wxCHECK_RET( undoItem != NULL, wxT( "Invalid text undo item." ) );
undoItem->ClearFlags();
picker.SetLink( undoItem );
frame->SetUndoItem( NULL );
pickList.PushItem( picker );
frame->SaveCopyInUndoList( pickList, UR_EXCHANGE_T );
}
SCH_ITEM::Place( frame, DC );
......
......@@ -476,7 +476,7 @@ void SCH_EDIT_FRAME::Process_Move_Item( SCH_ITEM* DrawStruct, wxDC* DC )
case SCH_GLOBAL_LABEL_T:
case SCH_HIERARCHICAL_LABEL_T:
case SCH_TEXT_T:
StartMoveTexte( (SCH_TEXT*) DrawStruct, DC );
MoveText( (SCH_TEXT*) DrawStruct, DC );
break;
case SCH_COMPONENT_T:
......
......@@ -188,7 +188,7 @@ void SwapData( EDA_ITEM* aItem, EDA_ITEM* aImage )
void SCH_EDIT_FRAME::SaveCopyInUndoList( SCH_ITEM* aItem,
UndoRedoOpType aCommandType,
UNDO_REDO_T aCommandType,
const wxPoint& aTransformPoint )
{
/* Does not save a null item.
......@@ -252,7 +252,7 @@ void SCH_EDIT_FRAME::SaveCopyInUndoList( SCH_ITEM* aItem,
void SCH_EDIT_FRAME::SaveCopyInUndoList( PICKED_ITEMS_LIST& aItemsList,
UndoRedoOpType aTypeCommand,
UNDO_REDO_T aTypeCommand,
const wxPoint& aTransformPoint )
{
PICKED_ITEMS_LIST* commandToUndo = new PICKED_ITEMS_LIST();
......@@ -265,10 +265,11 @@ void SCH_EDIT_FRAME::SaveCopyInUndoList( PICKED_ITEMS_LIST& aItemsList,
// Verify list, and creates data if needed
for( unsigned ii = 0; ii < commandToUndo->GetCount(); ii++ )
{
SCH_ITEM* item = (SCH_ITEM*) commandToUndo->GetPickedItem( ii );
SCH_ITEM* item = (SCH_ITEM*) commandToUndo->GetPickedItem( ii );
wxASSERT( item );
UndoRedoOpType command = commandToUndo->GetPickedItemStatus( ii );
UNDO_REDO_T command = commandToUndo->GetPickedItemStatus( ii );
if( command == UR_UNSPECIFIED )
{
command = aTypeCommand;
......@@ -294,15 +295,12 @@ void SCH_EDIT_FRAME::SaveCopyInUndoList( PICKED_ITEMS_LIST& aItemsList,
case UR_ROTATED:
case UR_NEW:
case UR_DELETED:
case UR_EXCHANGE_T:
break;
default:
{
wxString msg;
msg.Printf( wxT( "SaveCopyInUndoList() error (unknown code %X)" ), command );
wxMessageBox( msg );
}
break;
wxFAIL_MSG( wxString::Format( wxT( "Unknown undo/redo command %d" ), command ) );
break;
}
}
......@@ -399,14 +397,19 @@ void SCH_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed
break;
case UR_EXCHANGE_T:
GetScreen()->AddToDrawList( (SCH_ITEM*) aList->GetPickedItemLink( ii ) );
GetScreen()->RemoveFromDrawList( item );
item->SetNext( NULL );
item->SetBack( NULL );
aList->SetPickedItem( aList->GetPickedItemLink( ii ), ii );
aList->SetPickedItemLink( item, ii );
break;
default:
{
wxString msg;
msg.Printf( wxT( "PutDataInPreviousState() error (unknown code %X)" ),
aList->GetPickedItemStatus( ii ) );
wxMessageBox( msg );
}
break;
wxFAIL_MSG( wxString::Format( wxT( "Unknown undo/redo command %d" ),
aList->GetPickedItemStatus( ii ) ) );
break;
}
}
}
......@@ -429,7 +432,6 @@ void SCH_EDIT_FRAME::GetSchematicFromUndoList( wxCommandEvent& event )
OnModify();
SetSheetNumberAndCount();
ReCreateHToolbar();
GetScreen()->TestDanglingEnds();
DrawPanel->Refresh();
......@@ -441,7 +443,6 @@ void SCH_EDIT_FRAME::GetSchematicFromRedoList( wxCommandEvent& event )
if( GetScreen()->GetRedoCommandCount() == 0 )
return;
/* Get the old list */
PICKED_ITEMS_LIST* List = GetScreen()->PopCommandFromRedoList();
......@@ -454,7 +455,6 @@ void SCH_EDIT_FRAME::GetSchematicFromRedoList( wxCommandEvent& event )
OnModify();
SetSheetNumberAndCount();
ReCreateHToolbar();
GetScreen()->TestDanglingEnds();
DrawPanel->Refresh();
......
......@@ -175,6 +175,7 @@ SCH_EDIT_FRAME::SCH_EDIT_FRAME( wxWindow* father,
m_HotkeysZoomAndGridList = s_Schematic_Hokeys_Descr;
m_dlgFindReplace = NULL;
m_findReplaceData = new wxFindReplaceData( wxFR_DOWN );
m_undoItem = NULL;
CreateScreens();
......@@ -249,6 +250,7 @@ SCH_EDIT_FRAME::~SCH_EDIT_FRAME()
{
SetScreen( NULL );
SAFE_DELETE( m_CurrentSheet ); // a SCH_SHEET_PATH, on the heap.
SAFE_DELETE( m_undoItem );
SAFE_DELETE( g_RootSheet );
SAFE_DELETE( m_findReplaceData );
CMP_LIBRARY::RemoveAllLibraries();
......@@ -344,6 +346,31 @@ void SCH_EDIT_FRAME::CreateScreens()
}
void SCH_EDIT_FRAME::SetUndoItem( const SCH_ITEM* aItem )
{
if( (aItem != NULL) && (m_undoItem != NULL) )
{
delete m_undoItem;
}
m_undoItem = NULL;
if( aItem )
m_undoItem = aItem->Clone();
}
void SCH_EDIT_FRAME::SaveUndoItemInUndoList( SCH_ITEM* aItem )
{
wxCHECK_RET( aItem != NULL && m_undoItem != NULL && (aItem->Type() == m_undoItem->Type() ),
wxT( "Cannot swap undo item structures. Bad programmer!." ) );
aItem->SwapData( m_undoItem );
SaveCopyInUndoList( aItem, UR_CHANGED );
aItem->SwapData( m_undoItem );
}
void SCH_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event )
{
if( m_LibeditFrame && !m_LibeditFrame->Close() ) // Can close component editor?
......@@ -354,7 +381,7 @@ void SCH_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event )
if( SheetList.IsModified() )
{
wxMessageDialog dialog( this,
_( "Schematic modified, Save before exit ?" ),
_( "Schematic modified, Save before exit?" ),
_( "Confirmation" ), wxYES_NO | wxCANCEL |
wxICON_EXCLAMATION | wxYES_DEFAULT );
......
......@@ -276,7 +276,6 @@ static void ExitSheet( EDA_DRAW_PANEL* aPanel, wxDC* aDC )
}
screen->SetCurItem( NULL );
SAFE_DELETE( g_ItemToUndoCopy );
}
......@@ -288,11 +287,10 @@ static void ExitSheet( EDA_DRAW_PANEL* aPanel, wxDC* aDC )
SCH_SHEET* SCH_EDIT_FRAME::CreateSheet( wxDC* aDC )
{
m_itemToRepeat = NULL;
SAFE_DELETE( g_ItemToUndoCopy );
SCH_SHEET* sheet = new SCH_SHEET( GetScreen()->GetCrossHairPosition() );
sheet->m_Flags = IS_NEW | IS_RESIZED;
sheet->SetFlags( IS_NEW | IS_RESIZED );
sheet->m_TimeStamp = GetTimeStamp();
sheet->SetParent( GetScreen() );
sheet->SetScreen( NULL );
......@@ -341,10 +339,7 @@ void SCH_EDIT_FRAME::ReSizeSheet( SCH_SHEET* aSheet, wxDC* aDC )
DrawPanel->m_mouseCaptureCallback( DrawPanel, aDC, wxDefaultPosition, true );
if( aSheet->IsNew() ) // not already in edit, save a copy for undo/redo
{
delete g_ItemToUndoCopy;
g_ItemToUndoCopy = DuplicateStruct( aSheet, true );
}
SetUndoItem( aSheet );
}
......@@ -364,8 +359,5 @@ void SCH_EDIT_FRAME::StartMoveSheet( SCH_SHEET* aSheet, wxDC* aDC )
DrawPanel->CrossHairOn( aDC );
if( !aSheet->IsNew() ) // not already in edit, save a copy for undo/redo
{
delete g_ItemToUndoCopy;
g_ItemToUndoCopy = DuplicateStruct( aSheet, true );
}
SetUndoItem( aSheet );
}
......@@ -192,7 +192,6 @@ SCH_SHEET_PIN* SCH_EDIT_FRAME::ImportSheetPin( SCH_SHEET* aSheet, wxDC* aDC )
}
OnModify();
SAFE_DELETE( g_ItemToUndoCopy );
SaveCopyInUndoList( aSheet, UR_CHANGED );
sheetPin = new SCH_SHEET_PIN( aSheet, wxPoint( 0, 0 ), label->m_Text );
......
......@@ -470,7 +470,7 @@ public: GERBVIEW_FRAME( wxWindow* father, const wxString& title,
* but must be defined because it is a pure virtual in PCB_BASE_FRAME
*/
virtual void SaveCopyInUndoList( BOARD_ITEM* aItemToCopy,
UndoRedoOpType aTypeCommand = UR_UNSPECIFIED,
UNDO_REDO_T aTypeCommand = UR_UNSPECIFIED,
const wxPoint& aTransformPoint = wxPoint( 0, 0 ) ) { }
/**
......@@ -478,12 +478,12 @@ public: GERBVIEW_FRAME( wxWindow* father, const wxString& title,
* Creates a new entry in undo list of commands.
* add a list of pickers to handle a list of items
* @param aItemsList = the list of items modified by the command to undo
* @param aTypeCommand = command type (see enum UndoRedoOpType)
* @param aTypeCommand = command type (see enum UNDO_REDO_T)
* @param aTransformPoint = the reference point of the transformation,
* for commands like move
*/
virtual void SaveCopyInUndoList( PICKED_ITEMS_LIST& aItemsList,
UndoRedoOpType aTypeCommand,
UNDO_REDO_T aTypeCommand,
const wxPoint& aTransformPoint = wxPoint( 0, 0 ) )
{
// currently: do nothing in gerbview.
......
......@@ -56,7 +56,7 @@ class PICKED_ITEMS_LIST;
/* Type of undo/redo operations
* each type must be redo/undone by a specific operation
*/
enum UndoRedoOpType {
enum UNDO_REDO_T {
UR_UNSPECIFIED = 0, // illegal
UR_CHANGED, // params of items have a value changed: undo is made by exchange
// values with a copy of these values
......@@ -71,8 +71,10 @@ enum UndoRedoOpType {
UR_WIRE_IMAGE, // Specific to eeschema: handle wires changes
UR_MODEDIT, // Specific to the module editor (modedit creates a full copy of
// the current module when changed)
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)
UR_EXCHANGE_T ///< Use for changing the schematic text type where swapping
///< data structure is insufficient to restor the change.
};
......@@ -81,7 +83,7 @@ class ITEM_PICKER
friend class PICKED_ITEMS_LIST;
public:
UndoRedoOpType m_UndoRedoStatus; /* type of operation to undo/redo for this item */
UNDO_REDO_T m_UndoRedoStatus; /* type of operation to undo/redo for this item */
EDA_ITEM* m_PickedItem; /* Pointer on the schematic or board item that is concerned
* (picked), or in undo redo commands, the copy of an
* edited item. */
......@@ -96,7 +98,7 @@ public:
* copy of an active item) and m_Link points the active
* item in schematic */
ITEM_PICKER( EDA_ITEM* aItem = NULL, UndoRedoOpType aUndoRedoStatus = UR_UNSPECIFIED );
ITEM_PICKER( EDA_ITEM* aItem = NULL, UNDO_REDO_T aUndoRedoStatus = UR_UNSPECIFIED );
EDA_ITEM* GetItem() const { return m_PickedItem; }
......@@ -105,6 +107,10 @@ public:
KICAD_T GetItemType() const { return m_PickedItemType; }
void SetItemType( KICAD_T aType ) { m_PickedItemType = aType; }
void SetLink( EDA_ITEM* aItem ) { m_Link = aItem; }
EDA_ITEM* GetLink() const { return m_Link; }
};
......@@ -116,7 +122,7 @@ public:
class PICKED_ITEMS_LIST
{
public:
UndoRedoOpType m_Status; /* info about operation to undo/redo for this item. can be
UNDO_REDO_T m_Status; /* info about operation to undo/redo for this item. can be
* UR_UNSPECIFIED */
wxPoint m_TransformPoint; /* used to undo redo command by the same command: usually
* need to know the rotate point or the move vector */
......@@ -208,7 +214,7 @@ public:
* or UR_UNSPECIFIED if does not exist
* @param aIdx Index of the picked item in the picked list
*/
UndoRedoOpType GetPickedItemStatus( unsigned int aIdx );
UNDO_REDO_T GetPickedItemStatus( unsigned int aIdx );
/**
* Function GetPickerFlags
......@@ -233,7 +239,7 @@ public:
* @param aIdx Index of the picker in the picked list
* @return True if the picker exists or false if does not exist
*/
bool SetPickedItem( EDA_ITEM* aItem, UndoRedoOpType aStatus, unsigned aIdx );
bool SetPickedItem( EDA_ITEM* aItem, UNDO_REDO_T aStatus, unsigned aIdx );
/**
* Function SetPickedItemLink
......@@ -251,7 +257,7 @@ public:
* @param aIdx Index of the picker in the picked list
* @return True if the picker exists or false if does not exist
*/
bool SetPickedItemStatus( UndoRedoOpType aStatus, unsigned aIdx );
bool SetPickedItemStatus( UNDO_REDO_T aStatus, unsigned aIdx );
/**
* Function SetPickerFlags
......
......@@ -88,6 +88,14 @@ public:
SCH_ITEM* Clone() const { return ( SCH_ITEM* ) EDA_ITEM::Clone(); }
/**
* Function SwapDate
* swap the internal data structures \a aItem with the schematic item.
*
* @param aItem The item to swap the data structures with.
*/
virtual void SwapData( SCH_ITEM* aItem );
SCH_ITEM* Next() { return (SCH_ITEM*) Pnext; }
SCH_ITEM* Back() { return (SCH_ITEM*) Pback; }
......
......@@ -436,28 +436,26 @@ public:
* Creates a new entry in undo list of commands.
* add a picker to handle aItemToCopy
* @param aItemToCopy = the board item modified by the command to undo
* @param aTypeCommand = command type (see enum UndoRedoOpType)
* @param aTypeCommand = command type (see enum UNDO_REDO_T)
* @param aTransformPoint = the reference point of the transformation, for
* commands like move
*/
virtual void SaveCopyInUndoList( BOARD_ITEM* aItemToCopy,
UndoRedoOpType aTypeCommand,
const wxPoint& aTransformPoint =
wxPoint( 0, 0 ) ) = 0;
UNDO_REDO_T aTypeCommand,
const wxPoint& aTransformPoint = wxPoint( 0, 0 ) ) = 0;
/**
* Function SaveCopyInUndoList (virtual pure, overloaded).
* Creates a new entry in undo list of commands.
* add a list of pickers to handle a list of items
* @param aItemsList = the list of items modified by the command to undo
* @param aTypeCommand = command type (see enum UndoRedoOpType)
* @param aTypeCommand = command type (see enum UNDO_REDO_T)
* @param aTransformPoint = the reference point of the transformation,
* for commands like move
*/
virtual void SaveCopyInUndoList( PICKED_ITEMS_LIST& aItemsList,
UndoRedoOpType aTypeCommand,
const wxPoint& aTransformPoint =
wxPoint( 0, 0 ) ) = 0;
UNDO_REDO_T aTypeCommand,
const wxPoint& aTransformPoint = wxPoint( 0, 0 ) ) = 0;
// layerhandling:
......
......@@ -96,6 +96,7 @@ private:
SCH_ITEM* m_itemToRepeat; ///< Last item to insert by the repeat command.
int m_repeatLabelDelta; ///< Repeat label number increment step.
SCH_COLLECTOR m_collectedItems; ///< List of collected items.
SCH_ITEM* m_undoItem; ///< Copy of the current item being edited.
static int m_lastSheetPinType; ///< Last sheet pin type.
static wxSize m_lastSheetPinTextSize; ///< Last sheet pin text size.
......@@ -498,11 +499,11 @@ private:
// Junction
SCH_JUNCTION* AddJunction( wxDC* aDC, const wxPoint& aPosition, bool aPutInUndoList = FALSE );
// Text ,label, glabel
// Text, label, glabel
SCH_TEXT* CreateNewText( wxDC* aDC, int aType );
void EditSchematicText( SCH_TEXT* TextStruct );
void ChangeTextOrient( SCH_TEXT* aTextItem, wxDC* aDC );
void StartMoveTexte( SCH_TEXT* aTextItem, wxDC* aDC );
void MoveText( SCH_TEXT* aTextItem, wxDC* aDC );
/**
* Function OnCovertTextType
......@@ -640,12 +641,12 @@ public:
* wires saved in Undo List (for Undo or Redo commands, saved wires will be
* exchanged with current wire list
* @param aItemToCopy = the schematic item modified by the command to undo
* @param aTypeCommand = command type (see enum UndoRedoOpType)
* @param aTypeCommand = command type (see enum UNDO_REDO_T)
* @param aTransformPoint = the reference point of the transformation,
* for commands like move
*/
void SaveCopyInUndoList( SCH_ITEM* aItemToCopy,
UndoRedoOpType aTypeCommand,
UNDO_REDO_T aTypeCommand,
const wxPoint& aTransformPoint = wxPoint( 0, 0 ) );
/**
......@@ -653,12 +654,12 @@ public:
* Creates a new entry in undo list of commands.
* add a list of pickers to handle a list of items
* @param aItemsList = the list of items modified by the command to undo
* @param aTypeCommand = command type (see enum UndoRedoOpType)
* @param aTypeCommand = command type (see enum UNDO_REDO_T)
* @param aTransformPoint = the reference point of the transformation,
* for commands like move
*/
void SaveCopyInUndoList( PICKED_ITEMS_LIST& aItemsList,
UndoRedoOpType aTypeCommand,
UNDO_REDO_T aTypeCommand,
const wxPoint& aTransformPoint = wxPoint( 0, 0 ) );
private:
......@@ -739,6 +740,28 @@ public:
void SetRepeatItem( SCH_ITEM* aItem ) { m_itemToRepeat = aItem; }
/**
* Function SetUndoItem
* clones \a aItem which can be used to restore the state of the item being edited
* when the user cancels the editing in progress.
*
* @param aItem The item to make a clone of for undoing the last change. Set to
* NULL to free the current undo item.
*/
void SetUndoItem( const SCH_ITEM* aItem );
SCH_ITEM* GetUndoItem() const { return m_undoItem; }
/**
* Function SaveUndoItemInUndoList
* swaps the cloned item in #m_undoItem with \a aItem and saves it to the undo list
* then swap the data back. This swaps the internal structure of the item with the
* cloned item. It does not swap the actual item pointers themselves.
*
* @param aItem The item to swap with the current undo item.
*/
void SaveUndoItemInUndoList( SCH_ITEM* aItem );
// ERC:
/**
......
......@@ -411,12 +411,12 @@ public:
* Creates a new entry in undo list of commands.
* add a picker to handle aItemToCopy
* @param aItemToCopy = the board item modified by the command to undo
* @param aTypeCommand = command type (see enum UndoRedoOpType)
* @param aTypeCommand = command type (see enum UNDO_REDO_T)
* @param aTransformPoint = the reference point of the transformation, for
* commands like move
*/
virtual void SaveCopyInUndoList( BOARD_ITEM* aItemToCopy,
UndoRedoOpType aTypeCommand,
UNDO_REDO_T aTypeCommand,
const wxPoint& aTransformPoint = wxPoint( 0, 0 ) );
/**
......@@ -424,12 +424,12 @@ public:
* Creates a new entry in undo list of commands.
* add a list of pickers to handle a list of items
* @param aItemsList = the list of items modified by the command to undo
* @param aTypeCommand = command type (see enum UndoRedoOpType)
* @param aTypeCommand = command type (see enum UNDO_REDO_T)
* @param aTransformPoint = the reference point of the transformation, for
* commands like move
*/
virtual void SaveCopyInUndoList( PICKED_ITEMS_LIST& aItemsList,
UndoRedoOpType aTypeCommand,
UNDO_REDO_T aTypeCommand,
const wxPoint& aTransformPoint = wxPoint( 0, 0 ) );
/**
......
......@@ -339,7 +339,7 @@ BOARD_ITEM* DuplicateStruct( BOARD_ITEM* aItem )
* UR_ROTATED
*/
void PCB_EDIT_FRAME::SaveCopyInUndoList( BOARD_ITEM* aItem,
UndoRedoOpType aCommandType,
UNDO_REDO_T aCommandType,
const wxPoint& aTransformPoint )
{
if( aItem == NULL ) // Nothing to save
......@@ -399,7 +399,7 @@ void PCB_EDIT_FRAME::SaveCopyInUndoList( BOARD_ITEM* aItem,
* @param aTransformPoint - Transform items around this point.
*/
void PCB_EDIT_FRAME::SaveCopyInUndoList( PICKED_ITEMS_LIST& aItemsList,
UndoRedoOpType aTypeCommand,
UNDO_REDO_T aTypeCommand,
const wxPoint& aTransformPoint )
{
PICKED_ITEMS_LIST* commandToUndo = new PICKED_ITEMS_LIST();
......@@ -412,8 +412,8 @@ void PCB_EDIT_FRAME::SaveCopyInUndoList( PICKED_ITEMS_LIST& aItemsList,
// Verify list, and creates data if needed
for( unsigned ii = 0; ii < commandToUndo->GetCount(); ii++ )
{
BOARD_ITEM* item = (BOARD_ITEM*) commandToUndo->GetPickedItem( ii );
UndoRedoOpType command = commandToUndo->GetPickedItemStatus( ii );
BOARD_ITEM* item = (BOARD_ITEM*) commandToUndo->GetPickedItem( ii );
UNDO_REDO_T command = commandToUndo->GetPickedItemStatus( ii );
if( command == UR_UNSPECIFIED )
{
command = aTypeCommand;
......
......@@ -18,11 +18,11 @@
* Creates a new entry in undo list of commands.
* add a picker to handle aItemToCopy
* @param aItem = the board item modified by the command to undo
* @param aTypeCommand = command type (see enum UndoRedoOpType)
* @param aTypeCommand = command type (see enum UNDO_REDO_T)
* @param aTransformPoint = the reference point of the transformation, for commands like move
*/
void WinEDA_ModuleEditFrame::SaveCopyInUndoList( BOARD_ITEM* aItem,
UndoRedoOpType aTypeCommand,
UNDO_REDO_T aTypeCommand,
const wxPoint& aTransformPoint )
{
EDA_ITEM* item;
......@@ -52,12 +52,12 @@ void WinEDA_ModuleEditFrame::SaveCopyInUndoList( BOARD_ITEM* aItem,
* Creates a new entry in undo list of commands.
* add a list of pickers to handle a list of items
* @param aItemsList = the list of items modified by the command to undo
* @param aTypeCommand = command type (see enum UndoRedoOpType)
* @param aTypeCommand = command type (see enum UNDO_REDO_T)
* @param aTransformPoint = the reference point of the transformation, for commands like move
*/
void WinEDA_ModuleEditFrame::SaveCopyInUndoList( PICKED_ITEMS_LIST& aItemsList,
UndoRedoOpType aTypeCommand,
const wxPoint& aTransformPoint )
UNDO_REDO_T aTypeCommand,
const wxPoint& aTransformPoint )
{
// Currently unused in modedit, because the module itself is saved for each change
wxMessageBox( wxT( "SaveCopyInUndoList( PICKED_ITEMS_LIST& aItemsList..) not yet in use" ) );
......
......@@ -114,28 +114,26 @@ public:
* Creates a new entry in undo list of commands.
* add a picker to handle aItemToCopy
* @param aItem = the board item modified by the command to undo
* @param aTypeCommand = command type (see enum UndoRedoOpType)
* @param aTypeCommand = command type (see enum UNDO_REDO_T)
* @param aTransformPoint = the reference point of the transformation, for
* commands like move
*/
virtual void SaveCopyInUndoList( BOARD_ITEM* aItem,
UndoRedoOpType aTypeCommand,
const wxPoint& aTransformPoint =
wxPoint( 0, 0 ) );
UNDO_REDO_T aTypeCommand,
const wxPoint& aTransformPoint = wxPoint( 0, 0 ) );
/**
* Function SaveCopyInUndoList (overloaded).
* Creates a new entry in undo list of commands.
* add a list of pickers to handle a list of items
* @param aItemsList = the list of items modified by the command to undo
* @param aTypeCommand = command type (see enum UndoRedoOpType)
* @param aTypeCommand = command type (see enum UNDO_REDO_T)
* @param aTransformPoint = the reference point of the transformation, for
* commands like move
*/
virtual void SaveCopyInUndoList( PICKED_ITEMS_LIST& aItemsList,
UndoRedoOpType aTypeCommand,
const wxPoint& aTransformPoint =
wxPoint( 0, 0 ) );
UNDO_REDO_T aTypeCommand,
const wxPoint& aTransformPoint = wxPoint( 0, 0 ) );
private:
void GetComponentFromUndoList( wxCommandEvent& event );
......
......@@ -165,7 +165,7 @@ void UpdateCopyOfZonesList( PICKED_ITEMS_LIST& aPickList,
{
for( unsigned kk = 0; kk < aPickList.GetCount(); kk++ )
{
UndoRedoOpType status = aPickList.GetPickedItemStatus( kk );
UNDO_REDO_T status = aPickList.GetPickedItemStatus( kk );
ZONE_CONTAINER* ref = (ZONE_CONTAINER*) aPickList.GetPickedItem( kk );
for( unsigned ii = 0; ; ii++ ) // analyse the main picked list
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment