diff --git a/common/class_undoredo_container.cpp b/common/class_undoredo_container.cpp index 8e47dbc00b..0a2cb25091 100644 --- a/common/class_undoredo_container.cpp +++ b/common/class_undoredo_container.cpp @@ -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() ) { diff --git a/common/hotkeys_basic.cpp b/common/hotkeys_basic.cpp index dee4dde574..4f3613b180 100644 --- a/common/hotkeys_basic.cpp +++ b/common/hotkeys_basic.cpp @@ -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; } } diff --git a/common/sch_item_struct.cpp b/common/sch_item_struct.cpp index baab79e63e..6c88fed5af 100644 --- a/common/sch_item_struct.cpp +++ b/common/sch_item_struct.cpp @@ -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(), diff --git a/cvpcb/class_DisplayFootprintsFrame.h b/cvpcb/class_DisplayFootprintsFrame.h index ba01d28f54..8ce17327d0 100644 --- a/cvpcb/class_DisplayFootprintsFrame.h +++ b/cvpcb/class_DisplayFootprintsFrame.h @@ -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. diff --git a/eeschema/busentry.cpp b/eeschema/busentry.cpp index 3963f03eea..77afe18e9f 100644 --- a/eeschema/busentry.cpp +++ b/eeschema/busentry.cpp @@ -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; diff --git a/eeschema/edit_component_in_schematic.cpp b/eeschema/edit_component_in_schematic.cpp index 4d5a528377..2e2cac3f60 100644 --- a/eeschema/edit_component_in_schematic.cpp +++ b/eeschema/edit_component_in_schematic.cpp @@ -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; diff --git a/eeschema/edit_label.cpp b/eeschema/edit_label.cpp index 46392727aa..6d55c480f3 100644 --- a/eeschema/edit_label.cpp +++ b/eeschema/edit_label.cpp @@ -19,58 +19,87 @@ #include "eeschema_id.h" -static void ShowWhileMoving( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, - bool aErase ); -static void ExitMoveTexte( EDA_DRAW_PANEL* panel, wxDC* DC ); +static int lastGlobalLabelShape = (int) NET_INPUT; +static int lastTextOrientation = 0; +static bool lastTextBold = false; +static bool lastTextItalic = false; -static wxPoint ItemInitialPosition; -static int OldOrient; -static wxSize OldSize; -static int lastGlobalLabelShape = (int) NET_INPUT; -static int lastTextOrientation = 0; -static bool lastTextBold = false; -static bool lastTextItalic = false; - - -void SCH_EDIT_FRAME::StartMoveTexte( SCH_TEXT* aTextItem, wxDC* aDC ) +static void moveText( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, bool aErase ) { - if( aTextItem == NULL ) + SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen(); + SCH_TEXT* textItem = (SCH_TEXT*) screen->GetCurItem(); + + wxCHECK_RET( (textItem != NULL) && textItem->CanIncrementLabel(), + wxT( "Cannot move invalid text type." ) ); + + // Erase the current text at its current position. + if( aErase ) + textItem->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode ); + + textItem->m_Pos = screen->GetCrossHairPosition(); + + // Draw the text item at it's new position. + textItem->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode ); +} + + +static void abortMoveText( EDA_DRAW_PANEL* aPanel, wxDC* aDC ) +{ + SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen(); + SCH_ITEM* item = screen->GetCurItem(); + SCH_EDIT_FRAME* parent = ( SCH_EDIT_FRAME* ) aPanel->GetParent(); + + parent->SetRepeatItem( NULL ); + + if( item == NULL ) /* no current item */ return; + // Erase the text item and delete it if new (i.e. it was being just created). + item->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode ); + + if( item->IsNew() ) + { + SAFE_DELETE( item ); + } + else // Move command on an existing text item, restore the copy of the original. + { + screen->RemoveFromDrawList( item ); + delete item; + + item = parent->GetUndoItem(); + + wxCHECK_RET( item != NULL, wxT( "Cannot restore undefined last text item." ) ); + + screen->AddToDrawList( item ); + parent->SetUndoItem( NULL ); + item->Draw( aPanel, aDC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE ); + item->ClearFlags(); + } + + screen->SetCurItem( NULL ); +} + + +void SCH_EDIT_FRAME::MoveText( SCH_TEXT* aTextItem, wxDC* aDC ) +{ + wxCHECK_RET( (aTextItem != NULL) && aTextItem->CanIncrementLabel(), + wxT( "Cannot move invalid text item" ) ); + m_itemToRepeat = NULL; - if( !aTextItem->IsNew() ) - { - delete g_ItemToUndoCopy; - g_ItemToUndoCopy = aTextItem->Clone(); - } - aTextItem->SetFlags( IS_MOVED ); - switch( aTextItem->Type() ) - { - case SCH_LABEL_T: - case SCH_GLOBAL_LABEL_T: - case SCH_HIERARCHICAL_LABEL_T: - case SCH_TEXT_T: - ItemInitialPosition = aTextItem->m_Pos; - OldSize = aTextItem->m_Size; - OldOrient = aTextItem->GetOrientation(); - break; - - default: - break; - } + SetUndoItem( (SCH_ITEM*) aTextItem ); DrawPanel->CrossHairOff( aDC ); - GetScreen()->SetCrossHairPosition( ItemInitialPosition ); + GetScreen()->SetCrossHairPosition( aTextItem->m_Pos ); DrawPanel->MoveCursorToCrossHair(); OnModify(); - DrawPanel->SetMouseCapture( ShowWhileMoving, ExitMoveTexte ); + DrawPanel->SetMouseCapture( moveText, abortMoveText ); GetScreen()->SetCurItem( aTextItem ); - DrawPanel->m_mouseCaptureCallback( DrawPanel, aDC, wxDefaultPosition, true ); + moveText( DrawPanel, aDC, wxDefaultPosition, true ); DrawPanel->CrossHairOn( aDC ); } @@ -78,24 +107,10 @@ void SCH_EDIT_FRAME::StartMoveTexte( SCH_TEXT* aTextItem, wxDC* aDC ) void SCH_EDIT_FRAME::ChangeTextOrient( SCH_TEXT* aTextItem, wxDC* aDC ) { - wxCHECK_RET( aTextItem != NULL, wxT( "Invalid schematic text item." ) ); + wxCHECK_RET( (aTextItem != NULL) && aTextItem->CanIncrementLabel(), + wxT( "Invalid schematic text item." ) ); - int orient; - - switch( aTextItem->Type() ) - { - case SCH_LABEL_T: - case SCH_GLOBAL_LABEL_T: - case SCH_HIERARCHICAL_LABEL_T: - case SCH_TEXT_T: - orient = ( aTextItem->GetOrientation() + 1 ) & 3; - break; - - default: - wxFAIL_MSG( wxT( "Invalid schematic item <" ) + aTextItem->GetClass() + - wxT( "> passed to SCH_EDIT_FRAME::ChangeTextOrient()" ) ); - return; - } + int orient = ( aTextItem->GetOrientation() + 1 ) & 3; // Save current text orientation in undo list if is not already in edit. if( aTextItem->GetFlags() == 0 ) @@ -160,93 +175,19 @@ SCH_TEXT* SCH_EDIT_FRAME::CreateNewText( wxDC* aDC, int aType ) lastTextItalic = textItem->m_Italic; lastTextOrientation = textItem->GetOrientation(); - if( aType == LAYER_GLOBLABEL || aType == LAYER_HIERLABEL ) + if( (aType == SCH_GLOBAL_LABEL_T) || (aType == SCH_HIERARCHICAL_LABEL_T) ) { lastGlobalLabelShape = textItem->m_Shape; } textItem->Draw( DrawPanel, aDC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE ); - DrawPanel->SetMouseCapture( ShowWhileMoving, ExitMoveTexte ); + DrawPanel->SetMouseCapture( moveText, abortMoveText ); GetScreen()->SetCurItem( textItem ); return textItem; } -static void ShowWhileMoving( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, - bool aErase ) -{ - SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen(); - SCH_ITEM* textItem = screen->GetCurItem(); - - // Erase the current text at its current position. - if( aErase ) - textItem->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode ); - - // Draw the text item at it's new position. - switch( textItem->Type() ) - { - case SCH_LABEL_T: - case SCH_GLOBAL_LABEL_T: - case SCH_HIERARCHICAL_LABEL_T: - case SCH_TEXT_T: - ( (SCH_TEXT*) textItem )->m_Pos = screen->GetCrossHairPosition(); - break; - - default: - break; - } - - textItem->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode ); -} - - -/* Abort function for the command move text */ -static void ExitMoveTexte( EDA_DRAW_PANEL* aPanel, wxDC* aDC ) -{ - SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen(); - SCH_ITEM* item = screen->GetCurItem(); - SCH_EDIT_FRAME* parent = ( SCH_EDIT_FRAME* ) aPanel->GetParent(); - - parent->SetRepeatItem( NULL ); - - if( item == NULL ) /* no current item */ - return; - - // Erase the text item and delete it if new (i.e. it was being just created). - item->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode ); - - if( item->IsNew() ) - { - SAFE_DELETE( item ); - screen->SetCurItem( NULL ); - } - else // this was a move command on "old" text: restore its old settings. - { - switch( item->Type() ) - { - case SCH_LABEL_T: - case SCH_GLOBAL_LABEL_T: - case SCH_HIERARCHICAL_LABEL_T: - case SCH_TEXT_T: - { - SCH_TEXT* text = (SCH_TEXT*) item; - text->m_Pos = ItemInitialPosition; - text->m_Size = OldSize; - text->SetOrientation( OldOrient ); - } - break; - - default: - break; - } - - item->Draw( aPanel, aDC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE ); - item->ClearFlags(); - } -} - - void SCH_EDIT_FRAME::OnConvertTextType( wxCommandEvent& aEvent ) { SCH_SCREEN* screen = GetScreen(); @@ -314,6 +255,7 @@ void SCH_EDIT_FRAME::OnConvertTextType( wxCommandEvent& aEvent ) * they are not used in labels. Justifications will be set to default value in the new * text item type. */ + newtext->SetFlags( text->GetFlags() ); newtext->m_Shape = text->m_Shape; newtext->SetOrientation( text->GetOrientation() ); newtext->m_Size = text->m_Size; @@ -321,61 +263,38 @@ void SCH_EDIT_FRAME::OnConvertTextType( wxCommandEvent& aEvent ) newtext->m_Italic = text->m_Italic; newtext->m_Bold = text->m_Bold; - // save current text flag: - int flags = text->GetFlags(); - - /* add the new text in linked list if old text is in list */ - if( (flags & IS_NEW) == 0 ) - { - newtext->SetNext( GetScreen()->GetDrawItems() ); - GetScreen()->SetDrawItems( newtext ); - OnModify(); - } - - INSTALL_UNBUFFERED_DC( dc, DrawPanel ); - - /* Delete the old text item. If it is a text flagged as new it will be deleted by - * ending the mouse capture. - */ - if( DrawPanel->IsMouseCaptured() ) - DrawPanel->EndMouseCapture(); - - if( (flags & IS_NEW) == 0 ) // Remove old text from current list and save it in undo list - { - text->ClearFlags(); - DeleteItem( text ); // old text is really saved in undo list - GetScreen()->SetCurItem( NULL ); - m_itemToRepeat = NULL; - } - - GetScreen()->SetCurItem( NULL ); - - delete g_ItemToUndoCopy; - g_ItemToUndoCopy = NULL; - - DrawPanel->CrossHairOff( &dc ); // Erase schematic cursor - /* Save the new text in undo list if the old text was not itself a "new created text" * In this case, the old text is already in undo list as a deleted item. * Of course if the old text was a "new created text" the new text will be * put in undo list later, at the end of the current command (if not aborted) */ - if( (flags & IS_NEW) == 0 ) + + INSTALL_UNBUFFERED_DC( dc, DrawPanel ); + DrawPanel->CrossHairOff( &dc ); // Erase schematic cursor + text->Draw( DrawPanel, &dc, wxPoint( 0, 0 ), g_XorMode ); + + screen->RemoveFromDrawList( text ); + screen->AddToDrawList( newtext ); + GetScreen()->SetCurItem( newtext ); + OnModify(); + newtext->Draw( DrawPanel, &dc, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE ); + DrawPanel->CrossHairOn( &dc ); // redraw schematic cursor + + if( text->GetFlags() == 0 ) { - SaveCopyInUndoList( newtext, UR_NEW ); + m_itemToRepeat = NULL; + text->ClearFlags(); + text->SetNext( NULL ); + text->SetBack( NULL ); + newtext->ClearFlags(); + PICKED_ITEMS_LIST pickList; + ITEM_PICKER picker( newtext, UR_EXCHANGE_T ); + picker.SetLink( text ); + pickList.PushItem( picker ); + SaveCopyInUndoList( pickList, UR_EXCHANGE_T ); } else { - GetScreen()->SetCurItem( newtext ); - newtext->SetFlags( IS_NEW ); + delete text; } - - if( (flags & IS_MOVED) != 0 ) - { - GetScreen()->SetCurItem( newtext ); - StartMoveTexte( newtext, &dc ); - } - - newtext->Draw( DrawPanel, &dc, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE ); - DrawPanel->CrossHairOn( &dc ); // redraw schematic cursor } diff --git a/eeschema/eeschema.cpp b/eeschema/eeschema.cpp index 61715ee7c8..7b75331c46 100644 --- a/eeschema/eeschema.cpp +++ b/eeschema/eeschema.cpp @@ -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 ..) diff --git a/eeschema/events_called_functions_for_edit.cpp b/eeschema/events_called_functions_for_edit.cpp index 97c97f0e4a..bb220e1393 100644 --- a/eeschema/events_called_functions_for_edit.cpp +++ b/eeschema/events_called_functions_for_edit.cpp @@ -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 ); } diff --git a/eeschema/general.h b/eeschema/general.h index c2023f60ce..29f8370c1f 100644 --- a/eeschema/general.h +++ b/eeschema/general.h @@ -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. diff --git a/eeschema/getpart.cpp b/eeschema/getpart.cpp index 57d5ec4b68..33ebcf56fa 100644 --- a/eeschema/getpart.cpp +++ b/eeschema/getpart.cpp @@ -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 ); diff --git a/eeschema/onrightclick.cpp b/eeschema/onrightclick.cpp index 73762d43af..e2a73b9347 100644 --- a/eeschema/onrightclick.cpp +++ b/eeschema/onrightclick.cpp @@ -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; } diff --git a/eeschema/protos.h b/eeschema/protos.h index 9b3ffd77dc..bd8e6cd2d4 100644 --- a/eeschema/protos.h +++ b/eeschema/protos.h @@ -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 */ /***************/ diff --git a/eeschema/sch_component.cpp b/eeschema/sch_component.cpp index b8cc4e8a90..fd2bacee39 100644 --- a/eeschema/sch_component.cpp +++ b/eeschema/sch_component.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 ); } diff --git a/eeschema/sch_field.cpp b/eeschema/sch_field.cpp index 30fd43abe2..de3fa04d25 100644 --- a/eeschema/sch_field.cpp +++ b/eeschema/sch_field.cpp @@ -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 ); diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp index b95e29816d..9ebf772268 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -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 ); } diff --git a/eeschema/sch_sheet.cpp b/eeschema/sch_sheet.cpp index c51718dc44..725a7dce50 100644 --- a/eeschema/sch_sheet.cpp +++ b/eeschema/sch_sheet.cpp @@ -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(). diff --git a/eeschema/sch_sheet_pin.cpp b/eeschema/sch_sheet_pin.cpp index 1b9148b605..79887dfd95 100644 --- a/eeschema/sch_sheet_pin.cpp +++ b/eeschema/sch_sheet_pin.cpp @@ -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; diff --git a/eeschema/sch_text.cpp b/eeschema/sch_text.cpp index 5b71a941b4..545da8d9a0 100644 --- a/eeschema/sch_text.cpp +++ b/eeschema/sch_text.cpp @@ -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 ); + ClearFlags(); + PICKED_ITEMS_LIST pickList; + ITEM_PICKER picker( this, UR_EXCHANGE_T ); + SCH_ITEM* undoItem = frame->GetUndoItem(); - /* save in undo list */ - frame->SaveCopyInUndoList( this, UR_CHANGED ); + wxCHECK_RET( undoItem != NULL, wxT( "Invalid text undo item." ) ); - /* restore new values */ - SwapData( (SCH_TEXT*) g_ItemToUndoCopy ); - - SAFE_DELETE( g_ItemToUndoCopy ); + undoItem->ClearFlags(); + picker.SetLink( undoItem ); + frame->SetUndoItem( NULL ); + pickList.PushItem( picker ); + frame->SaveCopyInUndoList( pickList, UR_EXCHANGE_T ); } SCH_ITEM::Place( frame, DC ); diff --git a/eeschema/schedit.cpp b/eeschema/schedit.cpp index c1753caced..54511c3172 100644 --- a/eeschema/schedit.cpp +++ b/eeschema/schedit.cpp @@ -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: diff --git a/eeschema/schematic_undo_redo.cpp b/eeschema/schematic_undo_redo.cpp index 1a545fb784..f0f1668c71 100644 --- a/eeschema/schematic_undo_redo.cpp +++ b/eeschema/schematic_undo_redo.cpp @@ -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(); diff --git a/eeschema/schframe.cpp b/eeschema/schframe.cpp index 8595832ee5..08a59064e5 100644 --- a/eeschema/schframe.cpp +++ b/eeschema/schframe.cpp @@ -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 ); diff --git a/eeschema/sheet.cpp b/eeschema/sheet.cpp index 10ae33dc0c..67c7cdc60c 100644 --- a/eeschema/sheet.cpp +++ b/eeschema/sheet.cpp @@ -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 ); } diff --git a/eeschema/sheetlab.cpp b/eeschema/sheetlab.cpp index 475540c369..0877b9edff 100644 --- a/eeschema/sheetlab.cpp +++ b/eeschema/sheetlab.cpp @@ -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 ); diff --git a/gerbview/gerbview_frame.h b/gerbview/gerbview_frame.h index 0265c80e70..2bd3ad8ff5 100644 --- a/gerbview/gerbview_frame.h +++ b/gerbview/gerbview_frame.h @@ -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. diff --git a/include/class_undoredo_container.h b/include/class_undoredo_container.h index be1a86d36b..044311ce8e 100644 --- a/include/class_undoredo_container.h +++ b/include/class_undoredo_container.h @@ -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 diff --git a/include/sch_item_struct.h b/include/sch_item_struct.h index 793c0f0821..3d52fd0a02 100644 --- a/include/sch_item_struct.h +++ b/include/sch_item_struct.h @@ -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; } diff --git a/include/wxBasePcbFrame.h b/include/wxBasePcbFrame.h index 1dcb5dbe9e..5cd8d45c88 100644 --- a/include/wxBasePcbFrame.h +++ b/include/wxBasePcbFrame.h @@ -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: diff --git a/include/wxEeschemaStruct.h b/include/wxEeschemaStruct.h index 13e4efd062..7c197b58fd 100644 --- a/include/wxEeschemaStruct.h +++ b/include/wxEeschemaStruct.h @@ -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: /** diff --git a/include/wxPcbStruct.h b/include/wxPcbStruct.h index 7032edd22b..1f3bec8499 100644 --- a/include/wxPcbStruct.h +++ b/include/wxPcbStruct.h @@ -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 ) ); /** diff --git a/pcbnew/board_undo_redo.cpp b/pcbnew/board_undo_redo.cpp index 034df92198..74235fa451 100644 --- a/pcbnew/board_undo_redo.cpp +++ b/pcbnew/board_undo_redo.cpp @@ -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; diff --git a/pcbnew/modedit_undo_redo.cpp b/pcbnew/modedit_undo_redo.cpp index 33eb887a31..bdf404d9b6 100644 --- a/pcbnew/modedit_undo_redo.cpp +++ b/pcbnew/modedit_undo_redo.cpp @@ -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" ) ); diff --git a/pcbnew/module_editor_frame.h b/pcbnew/module_editor_frame.h index f00ee332f7..8a079bb016 100644 --- a/pcbnew/module_editor_frame.h +++ b/pcbnew/module_editor_frame.h @@ -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 ); diff --git a/pcbnew/zones_functions_for_undo_redo.cpp b/pcbnew/zones_functions_for_undo_redo.cpp index 3ebc8adc7e..0b822d15d0 100644 --- a/pcbnew/zones_functions_for_undo_redo.cpp +++ b/pcbnew/zones_functions_for_undo_redo.cpp @@ -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