Commit 3b246ca4 authored by jean-pierre charras's avatar jean-pierre charras

Pl_Editor: add undo/redo commands.

parent 1ef311cd
...@@ -102,7 +102,7 @@ void PICKED_ITEMS_LIST::ClearListAndDeleteItems() ...@@ -102,7 +102,7 @@ void PICKED_ITEMS_LIST::ClearListAndDeleteItems()
{ {
case UR_UNSPECIFIED: case UR_UNSPECIFIED:
if( show_error_message ) if( show_error_message )
wxMessageBox( wxT( "ClearUndoORRedoList() error: UR_UNSPECIFIED command type" ) ); wxMessageBox( wxT( "ClearListAndDeleteItems() error: UR_UNSPECIFIED command type" ) );
show_error_message = false; show_error_message = false;
break; break;
......
...@@ -638,6 +638,28 @@ void WORKSHEET_LAYOUT::SetDefaultLayout() ...@@ -638,6 +638,28 @@ void WORKSHEET_LAYOUT::SetDefaultLayout()
} }
} }
/**
* Populates the list from a S expr description stored in a string
* @param aPageLayout = the S expr string
*/
void WORKSHEET_LAYOUT::SetPageLayout( const char* aPageLayout, bool Append )
{
if( ! Append )
ClearList();
PAGE_LAYOUT_READER_PARSER lp_parser( aPageLayout, wxT( "Sexpr_string" ) );
try
{
lp_parser.Parse( this );
SetDefaultDescrFlag( true );
}
catch( IO_ERROR ioe )
{
wxLogMessage( ioe.errorText );
}
}
#include <wx/file.h> #include <wx/file.h>
// SetLayout() try to load a custom layout file, // SetLayout() try to load a custom layout file,
......
...@@ -134,6 +134,11 @@ enum KICAD_T { ...@@ -134,6 +134,11 @@ enum KICAD_T {
*/ */
TYPE_GERBER_DRAW_ITEM, TYPE_GERBER_DRAW_ITEM,
/*
* for Pl_Editor, in undo/redo commands
*/
TYPE_PL_EDITOR_LAYOUT,
// End value // End value
MAX_STRUCT_TYPE_ID MAX_STRUCT_TYPE_ID
}; };
......
...@@ -531,11 +531,17 @@ public: ...@@ -531,11 +531,17 @@ public:
void ClearList(); void ClearList();
/** /**
* Function Save: * Save the description in a file
* @param aFullFileName the filename of the file to created * @param aFullFileName the filename of the file to created
*/ */
void Save( const wxString& aFullFileName ); void Save( const wxString& aFullFileName );
/**
* Save the description in a buffer
* @param aOutputString = a wxString to store the S expr string
*/
void SaveInString( wxString& aOutputString );
/** /**
* Add an item to the list of items * Add an item to the list of items
*/ */
...@@ -591,6 +597,12 @@ public: ...@@ -591,6 +597,12 @@ public:
void SetPageLayout( const wxString& aFullFileName = wxEmptyString, void SetPageLayout( const wxString& aFullFileName = wxEmptyString,
bool Append = false ); bool Append = false );
/**
* Populates the list from a S expr description stored in a string
* @param aPageLayout = the S expr string
*/
void SetPageLayout( const char* aPageLayout, bool Append = false );
/** /**
* @return a short filename from a full filename: * @return a short filename from a full filename:
* if the path is the current path, or if the path * if the path is the current path, or if the path
......
...@@ -33,6 +33,7 @@ set(PL_EDITOR_SRCS ...@@ -33,6 +33,7 @@ set(PL_EDITOR_SRCS
pl_editor.cpp pl_editor.cpp
pl_editor_config.cpp pl_editor_config.cpp
pl_editor_frame.cpp pl_editor_frame.cpp
pl_editor_undo_redo.cpp
properties_frame.cpp properties_frame.cpp
hotkeys.cpp hotkeys.cpp
menubar.cpp menubar.cpp
......
...@@ -86,9 +86,27 @@ int PL_EDITOR_SCREEN::MilsToIuScalar() ...@@ -86,9 +86,27 @@ int PL_EDITOR_SCREEN::MilsToIuScalar()
/* Virtual function needed by classes derived from BASE_SCREEN /* Virtual function needed by classes derived from BASE_SCREEN
* this is a virtual pure function in BASE_SCREEN * this is a virtual pure function in BASE_SCREEN
* do nothing in GerbView
* could be removed later
*/ */
void PL_EDITOR_SCREEN::ClearUndoORRedoList( UNDO_REDO_CONTAINER&, int ) void PL_EDITOR_SCREEN::ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList,
int aItemCount )
{ {
if( aItemCount == 0 )
return;
unsigned icnt = aList.m_CommandsList.size();
if( aItemCount > 0 )
icnt = aItemCount;
for( unsigned ii = 0; ii < icnt; ii++ )
{
if( aList.m_CommandsList.size() == 0 )
break;
PICKED_ITEMS_LIST* curr_cmd = aList.m_CommandsList[0];
aList.m_CommandsList.erase( aList.m_CommandsList.begin() );
curr_cmd->ClearListAndDeleteItems();
delete curr_cmd; // Delete command
}
} }
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
*/ */
#include <wx/imaglist.h> #include <wx/imaglist.h>
#include <wx/wupdlock.h>
#include <fctsys.h> #include <fctsys.h>
#include <worksheet_shape_builder.h> #include <worksheet_shape_builder.h>
#include <class_worksheet_dataitem.h> #include <class_worksheet_dataitem.h>
...@@ -172,6 +173,8 @@ wxSize DESIGN_TREE_FRAME::GetMinSize() const ...@@ -172,6 +173,8 @@ wxSize DESIGN_TREE_FRAME::GetMinSize() const
void DESIGN_TREE_FRAME::ReCreateDesignTree() void DESIGN_TREE_FRAME::ReCreateDesignTree()
{ {
wxWindowUpdateLocker dummy(this); // Avoid flicker when rebuilding the tree
DeleteAllItems(); DeleteAllItems();
const WORKSHEET_LAYOUT& pglayout = WORKSHEET_LAYOUT::GetTheInstance(); const WORKSHEET_LAYOUT& pglayout = WORKSHEET_LAYOUT::GetTheInstance();
......
...@@ -68,8 +68,8 @@ PANEL_PROPERTIES_BASE::PANEL_PROPERTIES_BASE( wxWindow* parent, wxWindowID id, c ...@@ -68,8 +68,8 @@ PANEL_PROPERTIES_BASE::PANEL_PROPERTIES_BASE( wxWindow* parent, wxWindowID id, c
m_staticTextText->Wrap( -1 ); m_staticTextText->Wrap( -1 );
m_SizerTextOptions->Add( m_staticTextText, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); m_SizerTextOptions->Add( m_staticTextText, 0, wxTOP|wxRIGHT|wxLEFT, 5 );
m_textCtrlText = new wxTextCtrl( m_swItemProperties, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); m_textCtrlText = new wxTextCtrl( m_swItemProperties, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE );
m_SizerTextOptions->Add( m_textCtrlText, 0, wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND, 5 ); m_SizerTextOptions->Add( m_textCtrlText, 1, wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND, 5 );
wxBoxSizer* bSizerFontOpt; wxBoxSizer* bSizerFontOpt;
bSizerFontOpt = new wxBoxSizer( wxVERTICAL ); bSizerFontOpt = new wxBoxSizer( wxVERTICAL );
...@@ -515,6 +515,9 @@ PANEL_PROPERTIES_BASE::PANEL_PROPERTIES_BASE( wxWindow* parent, wxWindowID id, c ...@@ -515,6 +515,9 @@ PANEL_PROPERTIES_BASE::PANEL_PROPERTIES_BASE( wxWindow* parent, wxWindowID id, c
bSizerGeneralOpts->Add( bSizerGeneralOpts1, 0, 0, 5 ); bSizerGeneralOpts->Add( bSizerGeneralOpts1, 0, 0, 5 );
m_buttonDefault = new wxButton( m_swGeneralOpts, wxID_ANY, _("Set to Default"), wxDefaultPosition, wxDefaultSize, 0 );
bSizerGeneralOpts->Add( m_buttonDefault, 0, wxALL|wxEXPAND, 5 );
m_staticline9 = new wxStaticLine( m_swGeneralOpts, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); m_staticline9 = new wxStaticLine( m_swGeneralOpts, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
bSizerGeneralOpts->Add( m_staticline9, 0, wxEXPAND | wxALL, 5 ); bSizerGeneralOpts->Add( m_staticline9, 0, wxEXPAND | wxALL, 5 );
...@@ -592,16 +595,10 @@ PANEL_PROPERTIES_BASE::PANEL_PROPERTIES_BASE( wxWindow* parent, wxWindowID id, c ...@@ -592,16 +595,10 @@ PANEL_PROPERTIES_BASE::PANEL_PROPERTIES_BASE( wxWindow* parent, wxWindowID id, c
bSizerGeneralOpts->Add( bSizerGeneraMargins, 0, 0, 5 ); bSizerGeneralOpts->Add( bSizerGeneraMargins, 0, 0, 5 );
m_staticline10 = new wxStaticLine( m_swGeneralOpts, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
bSizerGeneralOpts->Add( m_staticline10, 0, wxEXPAND | wxALL, 5 );
m_buttonGeneralOptsOK = new wxButton( m_swGeneralOpts, wxID_ANY, _("Accept"), wxDefaultPosition, wxDefaultSize, 0 ); m_buttonGeneralOptsOK = new wxButton( m_swGeneralOpts, wxID_ANY, _("Accept"), wxDefaultPosition, wxDefaultSize, 0 );
m_buttonGeneralOptsOK->SetDefault(); m_buttonGeneralOptsOK->SetDefault();
bSizerGeneralOpts->Add( m_buttonGeneralOptsOK, 0, wxALL|wxEXPAND, 5 ); bSizerGeneralOpts->Add( m_buttonGeneralOptsOK, 0, wxALL|wxEXPAND, 5 );
m_buttonDefault = new wxButton( m_swGeneralOpts, wxID_ANY, _("Set to Default"), wxDefaultPosition, wxDefaultSize, 0 );
bSizerGeneralOpts->Add( m_buttonDefault, 0, wxALL|wxEXPAND, 5 );
m_swGeneralOpts->SetSizer( bSizerGeneralOpts ); m_swGeneralOpts->SetSizer( bSizerGeneralOpts );
m_swGeneralOpts->Layout(); m_swGeneralOpts->Layout();
...@@ -616,15 +613,15 @@ PANEL_PROPERTIES_BASE::PANEL_PROPERTIES_BASE( wxWindow* parent, wxWindowID id, c ...@@ -616,15 +613,15 @@ PANEL_PROPERTIES_BASE::PANEL_PROPERTIES_BASE( wxWindow* parent, wxWindowID id, c
// Connect Events // Connect Events
m_buttonOK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PROPERTIES_BASE::OnAcceptPrms ), NULL, this ); m_buttonOK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PROPERTIES_BASE::OnAcceptPrms ), NULL, this );
m_buttonGeneralOptsOK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PROPERTIES_BASE::OnAcceptPrms ), NULL, this );
m_buttonDefault->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PROPERTIES_BASE::OnSetDefaultValues ), NULL, this ); m_buttonDefault->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PROPERTIES_BASE::OnSetDefaultValues ), NULL, this );
m_buttonGeneralOptsOK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PROPERTIES_BASE::OnAcceptPrms ), NULL, this );
} }
PANEL_PROPERTIES_BASE::~PANEL_PROPERTIES_BASE() PANEL_PROPERTIES_BASE::~PANEL_PROPERTIES_BASE()
{ {
// Disconnect Events // Disconnect Events
m_buttonOK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PROPERTIES_BASE::OnAcceptPrms ), NULL, this ); m_buttonOK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PROPERTIES_BASE::OnAcceptPrms ), NULL, this );
m_buttonGeneralOptsOK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PROPERTIES_BASE::OnAcceptPrms ), NULL, this );
m_buttonDefault->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PROPERTIES_BASE::OnSetDefaultValues ), NULL, this ); m_buttonDefault->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PROPERTIES_BASE::OnSetDefaultValues ), NULL, this );
m_buttonGeneralOptsOK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PROPERTIES_BASE::OnAcceptPrms ), NULL, this );
} }
...@@ -113,6 +113,7 @@ class PANEL_PROPERTIES_BASE : public wxPanel ...@@ -113,6 +113,7 @@ class PANEL_PROPERTIES_BASE : public wxPanel
wxTextCtrl* m_textCtrlDefaultLineWidth; wxTextCtrl* m_textCtrlDefaultLineWidth;
wxStaticText* m_staticText22; wxStaticText* m_staticText22;
wxTextCtrl* m_textCtrlDefaultTextThickness; wxTextCtrl* m_textCtrlDefaultTextThickness;
wxButton* m_buttonDefault;
wxStaticLine* m_staticline9; wxStaticLine* m_staticline9;
wxStaticText* m_staticTextMargins; wxStaticText* m_staticTextMargins;
wxStaticText* m_staticTextLeftMargin; wxStaticText* m_staticTextLeftMargin;
...@@ -123,9 +124,7 @@ class PANEL_PROPERTIES_BASE : public wxPanel ...@@ -123,9 +124,7 @@ class PANEL_PROPERTIES_BASE : public wxPanel
wxTextCtrl* m_textCtrlTopMargin; wxTextCtrl* m_textCtrlTopMargin;
wxStaticText* m_staticTextBottomMargin; wxStaticText* m_staticTextBottomMargin;
wxTextCtrl* m_textCtrlDefaultBottomMargin; wxTextCtrl* m_textCtrlDefaultBottomMargin;
wxStaticLine* m_staticline10;
wxButton* m_buttonGeneralOptsOK; wxButton* m_buttonGeneralOptsOK;
wxButton* m_buttonDefault;
// Virtual event handlers, overide them in your derived class // Virtual event handlers, overide them in your derived class
virtual void OnAcceptPrms( wxCommandEvent& event ) { event.Skip(); } virtual void OnAcceptPrms( wxCommandEvent& event ) { event.Skip(); }
...@@ -134,7 +133,7 @@ class PANEL_PROPERTIES_BASE : public wxPanel ...@@ -134,7 +133,7 @@ class PANEL_PROPERTIES_BASE : public wxPanel
public: public:
PANEL_PROPERTIES_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 315,739 ), long style = wxTAB_TRAVERSAL ); PANEL_PROPERTIES_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 315,782 ), long style = wxTAB_TRAVERSAL );
~PANEL_PROPERTIES_BASE(); ~PANEL_PROPERTIES_BASE();
}; };
......
...@@ -61,8 +61,8 @@ BEGIN_EVENT_TABLE( PL_EDITOR_FRAME, EDA_DRAW_FRAME ) ...@@ -61,8 +61,8 @@ BEGIN_EVENT_TABLE( PL_EDITOR_FRAME, EDA_DRAW_FRAME )
EVT_MENU( wxID_ABOUT, EDA_DRAW_FRAME::GetKicadAbout ) EVT_MENU( wxID_ABOUT, EDA_DRAW_FRAME::GetKicadAbout )
EVT_TOOL( wxID_CUT, PL_EDITOR_FRAME::Process_Special_Functions ) EVT_TOOL( wxID_CUT, PL_EDITOR_FRAME::Process_Special_Functions )
EVT_TOOL( wxID_UNDO, PL_EDITOR_FRAME::Process_Special_Functions ) EVT_TOOL( wxID_UNDO, PL_EDITOR_FRAME::GetLayoutFromUndoList )
EVT_TOOL( wxID_REDO, PL_EDITOR_FRAME::Process_Special_Functions ) EVT_TOOL( wxID_REDO, PL_EDITOR_FRAME::GetLayoutFromRedoList )
EVT_TOOL( wxID_PRINT, PL_EDITOR_FRAME::ToPrinter ) EVT_TOOL( wxID_PRINT, PL_EDITOR_FRAME::ToPrinter )
EVT_TOOL( wxID_PREVIEW, PL_EDITOR_FRAME::ToPrinter ) EVT_TOOL( wxID_PREVIEW, PL_EDITOR_FRAME::ToPrinter )
EVT_TOOL( ID_SHEET_SET, PL_EDITOR_FRAME::Process_Special_Functions ) EVT_TOOL( ID_SHEET_SET, PL_EDITOR_FRAME::Process_Special_Functions )
...@@ -99,7 +99,6 @@ void PL_EDITOR_FRAME::Process_Special_Functions( wxCommandEvent& event ) ...@@ -99,7 +99,6 @@ void PL_EDITOR_FRAME::Process_Special_Functions( wxCommandEvent& event )
{ {
case ID_NO_TOOL_SELECTED: case ID_NO_TOOL_SELECTED:
SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString ); SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString );
break;
case ID_SELECT_PAGE_NUMBER: case ID_SELECT_PAGE_NUMBER:
m_canvas->Refresh(); m_canvas->Refresh();
...@@ -129,6 +128,7 @@ void PL_EDITOR_FRAME::Process_Special_Functions( wxCommandEvent& event ) ...@@ -129,6 +128,7 @@ void PL_EDITOR_FRAME::Process_Special_Functions( wxCommandEvent& event )
if( item == NULL ) if( item == NULL )
break; break;
SaveCopyInUndoList();
idx = pglayout.GetItemIndex( item ); idx = pglayout.GetItemIndex( item );
pglayout.Remove( item ); pglayout.Remove( item );
RebuildDesignTree(); RebuildDesignTree();
...@@ -147,10 +147,12 @@ void PL_EDITOR_FRAME::Process_Special_Functions( wxCommandEvent& event ) ...@@ -147,10 +147,12 @@ void PL_EDITOR_FRAME::Process_Special_Functions( wxCommandEvent& event )
break; break;
case ID_POPUP_ITEM_ADD_LINE: case ID_POPUP_ITEM_ADD_LINE:
SaveCopyInUndoList();
idx = m_treePagelayout->GetSelectedItemIndex(); idx = m_treePagelayout->GetSelectedItemIndex();
item = AddPageLayoutItem( WORKSHEET_DATAITEM::WS_SEGMENT, idx ); item = AddPageLayoutItem( WORKSHEET_DATAITEM::WS_SEGMENT, idx );
if( InvokeDialogNewItem( this, item ) == wxID_CANCEL ) if( InvokeDialogNewItem( this, item ) == wxID_CANCEL )
{ {
RemoveLastCommandInUndoList();
pglayout.Remove( item ); pglayout.Remove( item );
RebuildDesignTree(); RebuildDesignTree();
item = NULL; item = NULL;
...@@ -159,10 +161,12 @@ void PL_EDITOR_FRAME::Process_Special_Functions( wxCommandEvent& event ) ...@@ -159,10 +161,12 @@ void PL_EDITOR_FRAME::Process_Special_Functions( wxCommandEvent& event )
break; break;
case ID_POPUP_ITEM_ADD_RECT: case ID_POPUP_ITEM_ADD_RECT:
SaveCopyInUndoList();
idx = m_treePagelayout->GetSelectedItemIndex(); idx = m_treePagelayout->GetSelectedItemIndex();
item = AddPageLayoutItem( WORKSHEET_DATAITEM::WS_RECT, idx ); item = AddPageLayoutItem( WORKSHEET_DATAITEM::WS_RECT, idx );
if( InvokeDialogNewItem( this, item ) == wxID_CANCEL ) if( InvokeDialogNewItem( this, item ) == wxID_CANCEL )
{ {
RemoveLastCommandInUndoList();
pglayout.Remove( item ); pglayout.Remove( item );
RebuildDesignTree(); RebuildDesignTree();
item = NULL; item = NULL;
...@@ -171,10 +175,12 @@ void PL_EDITOR_FRAME::Process_Special_Functions( wxCommandEvent& event ) ...@@ -171,10 +175,12 @@ void PL_EDITOR_FRAME::Process_Special_Functions( wxCommandEvent& event )
break; break;
case ID_POPUP_ITEM_ADD_TEXT: case ID_POPUP_ITEM_ADD_TEXT:
SaveCopyInUndoList();
idx = m_treePagelayout->GetSelectedItemIndex(); idx = m_treePagelayout->GetSelectedItemIndex();
item = AddPageLayoutItem( WORKSHEET_DATAITEM::WS_TEXT, idx ); item = AddPageLayoutItem( WORKSHEET_DATAITEM::WS_TEXT, idx );
if( InvokeDialogNewItem( this, item ) == wxID_CANCEL ) if( InvokeDialogNewItem( this, item ) == wxID_CANCEL )
{ {
RemoveLastCommandInUndoList();
pglayout.Remove( item ); pglayout.Remove( item );
RebuildDesignTree(); RebuildDesignTree();
item = NULL; item = NULL;
...@@ -189,8 +195,7 @@ void PL_EDITOR_FRAME::Process_Special_Functions( wxCommandEvent& event ) ...@@ -189,8 +195,7 @@ void PL_EDITOR_FRAME::Process_Special_Functions( wxCommandEvent& event )
case ID_POPUP_ITEM_PLACE: case ID_POPUP_ITEM_PLACE:
item = GetScreen()->GetCurItem(); item = GetScreen()->GetCurItem();
m_canvas->SetMouseCapture( NULL, NULL ); PlaceItem( item );
GetScreen()->SetCurItem( NULL );
break; break;
case ID_POPUP_ITEM_PLACE_CANCEL: case ID_POPUP_ITEM_PLACE_CANCEL:
...@@ -245,18 +250,18 @@ static void moveItem( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPositio ...@@ -245,18 +250,18 @@ static void moveItem( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPositio
WORKSHEET_DATAITEM *item = screen->GetCurItem(); WORKSHEET_DATAITEM *item = screen->GetCurItem();
wxCHECK_RET( (item != NULL), wxT( "Cannot move NULL item." ) ); wxCHECK_RET( (item != NULL), wxT( "Cannot move NULL item." ) );
wxPoint position = screen->GetCrossHairPosition()
wxPoint newpos = screen->GetCrossHairPosition()
- ( initialCursorPosition - initialPositionUi ); - ( initialCursorPosition - initialPositionUi );
if( (item->GetFlags() & LOCATE_STARTPOINT) ) if( (item->GetFlags() & LOCATE_STARTPOINT) )
item->MoveStartPointToUi( newpos ); item->MoveStartPointToUi( position );
else if( (item->GetFlags() & LOCATE_ENDPOINT) ) else if( (item->GetFlags() & LOCATE_ENDPOINT) )
item->MoveEndPointToUi( newpos ); item->MoveEndPointToUi( position );
else else
item->MoveToUi( newpos ); item->MoveToUi( position );
// Draw the item item at it's new position. // Draw the item item at it's new position.
if( aPanel )
aPanel->Refresh(); aPanel->Refresh();
} }
...@@ -312,6 +317,38 @@ void PL_EDITOR_FRAME::MoveItem( WORKSHEET_DATAITEM* aItem ) ...@@ -312,6 +317,38 @@ void PL_EDITOR_FRAME::MoveItem( WORKSHEET_DATAITEM* aItem )
GetScreen()->SetCurItem( aItem ); GetScreen()->SetCurItem( aItem );
} }
/**
* Save in Undo list the layout, and place an item being moved.
* @param aItem is the item moved
*/
void PL_EDITOR_FRAME::PlaceItem( WORKSHEET_DATAITEM* aItem )
{
DPOINT currStartPos = aItem->GetStartPos();
DPOINT currEndPos = aItem->GetEndPos();
// Save the curren layout before changes
if( (aItem->GetFlags() & LOCATE_STARTPOINT) )
{
aItem->MoveStartPointTo( initialPosition );
}
else if( (aItem->GetFlags() & LOCATE_ENDPOINT) )
{
aItem->MoveEndPointTo( initialPosition );
}
else
aItem->MoveTo( initialPosition );
SaveCopyInUndoList();
// Re-place the item
aItem->MoveStartPointTo( currStartPos );
aItem->MoveEndPointTo( currEndPos );
m_canvas->SetMouseCapture( NULL, NULL );
GetScreen()->SetCurItem( NULL );
}
/* called when the user select one of the 4 page corner as corner /* called when the user select one of the 4 page corner as corner
* reference (or the left top paper corner) * reference (or the left top paper corner)
*/ */
......
...@@ -233,6 +233,7 @@ bool PL_EDITOR_FRAME::InsertPageLayoutDescrFile( const wxString& aFullFileName ) ...@@ -233,6 +233,7 @@ bool PL_EDITOR_FRAME::InsertPageLayoutDescrFile( const wxString& aFullFileName )
if( wxFileExists( aFullFileName ) ) if( wxFileExists( aFullFileName ) )
{ {
const bool append = true; const bool append = true;
SaveCopyInUndoList();
WORKSHEET_LAYOUT::GetTheInstance().SetPageLayout( aFullFileName, append ); WORKSHEET_LAYOUT::GetTheInstance().SetPageLayout( aFullFileName, append );
return true; return true;
} }
......
...@@ -75,8 +75,8 @@ static EDA_HOTKEY HkDeleteItem( wxT( "Move Item" ), HK_DELETE_ITEM, WXK_DELET ...@@ -75,8 +75,8 @@ static EDA_HOTKEY HkDeleteItem( wxT( "Move Item" ), HK_DELETE_ITEM, WXK_DELET
ID_POPUP_ITEM_DELETE ); ID_POPUP_ITEM_DELETE );
// Undo Redo // Undo Redo
//static EDA_HOTKEY HkUndo( wxT( "Undo" ), HK_UNDO, GR_KB_CTRL + 'Z', (int) wxID_UNDO ); static EDA_HOTKEY HkUndo( wxT( "Undo" ), HK_UNDO, GR_KB_CTRL + 'Z', (int) wxID_UNDO );
//static EDA_HOTKEY HkRedo( wxT( "Redo" ), HK_REDO, GR_KB_CTRL + 'Y', (int) wxID_REDO ); static EDA_HOTKEY HkRedo( wxT( "Redo" ), HK_REDO, GR_KB_CTRL + 'Y', (int) wxID_REDO );
// List of common hotkey descriptors // List of common hotkey descriptors
EDA_HOTKEY* s_Common_Hotkey_List[] = EDA_HOTKEY* s_Common_Hotkey_List[] =
...@@ -84,13 +84,15 @@ EDA_HOTKEY* s_Common_Hotkey_List[] = ...@@ -84,13 +84,15 @@ EDA_HOTKEY* s_Common_Hotkey_List[] =
&HkHelp, &HkHelp,
&HkZoomIn, &HkZoomOut, &HkZoomRedraw, &HkZoomCenter, &HkZoomIn, &HkZoomOut, &HkZoomRedraw, &HkZoomCenter,
&HkZoomAuto, &HkResetLocalCoord, &HkZoomAuto, &HkResetLocalCoord,
&HkUndo, &HkRedo,
NULL NULL
}; };
EDA_HOTKEY* s_PlEditor_Hotkey_List[] = EDA_HOTKEY* s_PlEditor_Hotkey_List[] =
{ {
&HkMoveItem, &HkMoveStartPoint, &HkMoveItem, &HkMoveStartPoint,
&HkMoveEndPoint, &HkDeleteItem &HkMoveEndPoint, &HkDeleteItem,
NULL
}; };
// list of sections and corresponding hotkey list for Pl_Editor // list of sections and corresponding hotkey list for Pl_Editor
...@@ -144,6 +146,14 @@ void PL_EDITOR_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, ...@@ -144,6 +146,14 @@ void PL_EDITOR_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode,
DisplayHotkeyList( this, s_PlEditor_Hokeys_Descr ); DisplayHotkeyList( this, s_PlEditor_Hokeys_Descr );
break; break;
case HK_UNDO:
case HK_REDO:
if( busy )
break;
cmd.SetId( HK_Descr->m_IdMenuEvent );
GetEventHandler()->ProcessEvent( cmd );
break;
case HK_ZOOM_IN: case HK_ZOOM_IN:
cmd.SetId( ID_POPUP_ZOOM_IN ); cmd.SetId( ID_POPUP_ZOOM_IN );
GetEventHandler()->ProcessEvent( cmd ); GetEventHandler()->ProcessEvent( cmd );
......
...@@ -49,9 +49,8 @@ void PL_EDITOR_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) ...@@ -49,9 +49,8 @@ void PL_EDITOR_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
if( item ) // An item is currently in edit: place it if( item ) // An item is currently in edit: place it
{ {
PlaceItem( item );
m_propertiesPagelayout->CopyPrmsFromItemToPanel( item ); m_propertiesPagelayout->CopyPrmsFromItemToPanel( item );
m_canvas->SetMouseCapture( NULL, NULL );
GetScreen()->SetCurItem( NULL );
m_canvas->Refresh(); m_canvas->Refresh();
return; return;
} }
......
...@@ -137,8 +137,8 @@ public: ...@@ -137,8 +137,8 @@ public:
} }
}; };
/** /*
* Function Save: aFullFileName = the filename of the file to created * Save the description in a file
*/ */
void WORKSHEET_LAYOUT::Save( const wxString& aFullFileName ) void WORKSHEET_LAYOUT::Save( const wxString& aFullFileName )
{ {
...@@ -146,6 +146,14 @@ void WORKSHEET_LAYOUT::Save( const wxString& aFullFileName ) ...@@ -146,6 +146,14 @@ void WORKSHEET_LAYOUT::Save( const wxString& aFullFileName )
writer.Format( this ); writer.Format( this );
} }
/* Save the description in a buffer
*/
void WORKSHEET_LAYOUT::SaveInString( wxString& aOutputString )
{
WORKSHEET_LAYOUT_STRINGIO writer( aOutputString );
writer.Format( this );
}
void WORKSHEET_LAYOUT_IO::Format( WORKSHEET_DATAITEM* aItem, int aNestLevel ) const void WORKSHEET_LAYOUT_IO::Format( WORKSHEET_DATAITEM* aItem, int aNestLevel ) const
throw( IO_ERROR ) throw( IO_ERROR )
......
...@@ -408,31 +408,22 @@ void PL_EDITOR_FRAME::UpdateStatusBar() ...@@ -408,31 +408,22 @@ void PL_EDITOR_FRAME::UpdateStatusBar()
double dXpos = To_User_Unit( g_UserUnit, coord.x*Xsign ); double dXpos = To_User_Unit( g_UserUnit, coord.x*Xsign );
double dYpos = To_User_Unit( g_UserUnit, coord.y*Ysign ); double dYpos = To_User_Unit( g_UserUnit, coord.y*Ysign );
wxString pagesizeformatter; wxString pagesizeformatter = wxT( "Page size: width %.4g height %.4g" );
wxString absformatter; wxString absformatter = wxT( "X %.4g Y %.4g" );
wxString locformatter; wxString locformatter = wxT( "dx %.4g dy %.4g" );
switch( g_UserUnit ) switch( g_UserUnit )
{ {
case INCHES: // Should not be used in page layout editor case INCHES: // Should not be used in page layout editor
SetStatusText( _("inches"), 5 ); SetStatusText( _("inches"), 5 );
pagesizeformatter = wxT( "Page size: width %4g height %4g" );
absformatter = wxT( "X %.4g Y %.4g" );
locformatter = wxT( "dx %.4g dy %.4g" );
break; break;
case MILLIMETRES: case MILLIMETRES:
SetStatusText( _("mm"), 5 ); SetStatusText( _("mm"), 5 );
pagesizeformatter = wxT( "Page size: width %3g height %3g" );
absformatter = wxT( "X %.3g Y %.3g" );
locformatter = wxT( "dx %.3g dy %.3g" );
break; break;
case UNSCALED_UNITS: case UNSCALED_UNITS:
SetStatusText( wxEmptyString, 5 ); SetStatusText( wxEmptyString, 5 );
pagesizeformatter = wxT( "Page size: width %g height %g" );
absformatter = wxT( "X %g Y %g" );
locformatter = wxT( "dx %g dy %g" );
break; break;
} }
...@@ -687,6 +678,7 @@ WORKSHEET_DATAITEM* PL_EDITOR_FRAME::Locate( const wxPoint& aPosition ) ...@@ -687,6 +678,7 @@ WORKSHEET_DATAITEM* PL_EDITOR_FRAME::Locate( const wxPoint& aPosition )
*/ */
void PL_EDITOR_FRAME::OnNewPageLayout() void PL_EDITOR_FRAME::OnNewPageLayout()
{ {
GetScreen()->ClearUndoRedoList();
GetScreen()->ClrModify(); GetScreen()->ClrModify();
m_propertiesPagelayout->CopyPrmsFromGeneralToPanel(); m_propertiesPagelayout->CopyPrmsFromGeneralToPanel();
RebuildDesignTree(); RebuildDesignTree();
......
...@@ -326,6 +326,12 @@ public: ...@@ -326,6 +326,12 @@ public:
*/ */
void MoveItem( WORKSHEET_DATAITEM* aItem ); void MoveItem( WORKSHEET_DATAITEM* aItem );
/**
* Save in Undo list the layout, and place an item being moved.
* @param aItem is the item moved
*/
void PlaceItem( WORKSHEET_DATAITEM* aItem );
/** /**
* Must be called after a change * Must be called after a change
* in order to set the "modify" flag of the current screen * in order to set the "modify" flag of the current screen
...@@ -335,6 +341,29 @@ public: ...@@ -335,6 +341,29 @@ public:
GetScreen()->SetModify(); GetScreen()->SetModify();
} }
/**
* Save a copy of the description (in a S expr string)
* for Undo/redo commands
*/
void SaveCopyInUndoList();
/** Redo the last edition:
* - Place the current edited layout in undo list
* - Get the previous version of the current edited layput
*/
void GetLayoutFromRedoList( wxCommandEvent& event );
/** Undo the last edition:
* - Place the current layout in Redo list
* - Get the previous version of the current edited layout
*/
void GetLayoutFromUndoList( wxCommandEvent& event );
/**
* Remove the last command in Undo List.
* Used to clean the Undo stack after a cancel command
*/
void RemoveLastCommandInUndoList();
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
......
...@@ -194,7 +194,9 @@ void PROPERTIES_FRAME::CopyPrmsFromItemToPanel( WORKSHEET_DATAITEM* aItem ) ...@@ -194,7 +194,9 @@ void PROPERTIES_FRAME::CopyPrmsFromItemToPanel( WORKSHEET_DATAITEM* aItem )
m_SizerTextIncrementLabel->Show( true ); m_SizerTextIncrementLabel->Show( true );
WORKSHEET_DATAITEM_TEXT* item = (WORKSHEET_DATAITEM_TEXT*) aItem; WORKSHEET_DATAITEM_TEXT* item = (WORKSHEET_DATAITEM_TEXT*) aItem;
m_textCtrlText->SetValue( item->m_TextBase ); wxString text = item->m_TextBase;
text.Replace(wxT("\\n"), wxT("\n") );
m_textCtrlText->SetValue( text );
msg.Printf( wxT("%d"), item->m_IncrementLabel ); msg.Printf( wxT("%d"), item->m_IncrementLabel );
m_textCtrlTextIncrement->SetValue( msg ); m_textCtrlTextIncrement->SetValue( msg );
...@@ -279,6 +281,8 @@ void PROPERTIES_FRAME::CopyPrmsFromItemToPanel( WORKSHEET_DATAITEM* aItem ) ...@@ -279,6 +281,8 @@ void PROPERTIES_FRAME::CopyPrmsFromItemToPanel( WORKSHEET_DATAITEM* aItem )
// Event function called by clicking on the OK button // Event function called by clicking on the OK button
void PROPERTIES_FRAME::OnAcceptPrms( wxCommandEvent& event ) void PROPERTIES_FRAME::OnAcceptPrms( wxCommandEvent& event )
{ {
m_parent->SaveCopyInUndoList();
WORKSHEET_DATAITEM* item = m_parent->GetSelectedItem(); WORKSHEET_DATAITEM* item = m_parent->GetSelectedItem();
if( item ) if( item )
CopyPrmsFromPanelToItem( item ); CopyPrmsFromPanelToItem( item );
...@@ -388,6 +392,7 @@ bool PROPERTIES_FRAME::CopyPrmsFromPanelToItem( WORKSHEET_DATAITEM* aItem ) ...@@ -388,6 +392,7 @@ bool PROPERTIES_FRAME::CopyPrmsFromPanelToItem( WORKSHEET_DATAITEM* aItem )
WORKSHEET_DATAITEM_TEXT* item = (WORKSHEET_DATAITEM_TEXT*) aItem; WORKSHEET_DATAITEM_TEXT* item = (WORKSHEET_DATAITEM_TEXT*) aItem;
item->m_TextBase = m_textCtrlText->GetValue(); item->m_TextBase = m_textCtrlText->GetValue();
item->m_TextBase.Replace( wxT("\n"), wxT("\\n") );
msg = m_textCtrlTextIncrement->GetValue(); msg = m_textCtrlTextIncrement->GetValue();
msg.ToLong( &itmp ); msg.ToLong( &itmp );
......
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