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