Commit 32c54e49 authored by charras's avatar charras

More about undo/redo in pcbnew

parent a6fc1329
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
/* Routines Locales */ /* Routines Locales */
static void Show_MoveTexte_Module( WinEDA_DrawPanel* panel, wxDC* DC, bool erase ); static void Show_MoveTexte_Module( WinEDA_DrawPanel* panel, wxDC* DC, bool erase );
static void ExitTextModule( WinEDA_DrawPanel* Panel, wxDC* DC ); static void AbortMoveTextModule( WinEDA_DrawPanel* Panel, wxDC* DC );
/* local variables */ /* local variables */
wxPoint MoveVector; // Move vector for move edge, exported to dialog_edit mod_text.cpp wxPoint MoveVector; // Move vector for move edge, exported to dialog_edit mod_text.cpp
...@@ -129,9 +129,8 @@ void WinEDA_BasePcbFrame::DeleteTextModule( TEXTE_MODULE* Text ) ...@@ -129,9 +129,8 @@ void WinEDA_BasePcbFrame::DeleteTextModule( TEXTE_MODULE* Text )
/*************************************************************/ /*************************************************************/
static void ExitTextModule( WinEDA_DrawPanel* Panel, wxDC* DC ) static void AbortMoveTextModule( WinEDA_DrawPanel* Panel, wxDC* DC )
/*************************************************************/ /*************************************************************/
/* /*
* Routine de sortie du menu edit texte module * Routine de sortie du menu edit texte module
* Si un texte est selectionne, ses coord initiales sont regenerees * Si un texte est selectionne, ses coord initiales sont regenerees
...@@ -151,8 +150,12 @@ static void ExitTextModule( WinEDA_DrawPanel* Panel, wxDC* DC ) ...@@ -151,8 +150,12 @@ static void ExitTextModule( WinEDA_DrawPanel* Panel, wxDC* DC )
Text->Draw( Panel, DC, GR_XOR, MoveVector ); Text->Draw( Panel, DC, GR_XOR, MoveVector );
/* Redessin du Texte */ // If the text was moved (the move does not change internal data)
// Text->Draw( Panel, DC, GR_OR ); // it could be rotated while moving. So set old value for orientation
if ( (Text->m_Flags & IS_MOVED) )
Text->m_Orient = TextInitialOrientation;
/* Redraw the text */
Panel->PostDirtyRect( Text->GetBoundingBox() ); Panel->PostDirtyRect( Text->GetBoundingBox() );
// leave it at (0,0) so we can use it Rotate when not moving. // leave it at (0,0) so we can use it Rotate when not moving.
...@@ -191,7 +194,7 @@ void WinEDA_BasePcbFrame::StartMoveTexteModule( TEXTE_MODULE* Text, wxDC* DC ) ...@@ -191,7 +194,7 @@ void WinEDA_BasePcbFrame::StartMoveTexteModule( TEXTE_MODULE* Text, wxDC* DC )
SetCurItem( Text ); SetCurItem( Text );
DrawPanel->ManageCurseur = Show_MoveTexte_Module; DrawPanel->ManageCurseur = Show_MoveTexte_Module;
DrawPanel->ForceCloseManageCurseur = ExitTextModule; DrawPanel->ForceCloseManageCurseur = AbortMoveTextModule;
DrawPanel->ManageCurseur( DrawPanel, DC, TRUE ); DrawPanel->ManageCurseur( DrawPanel, DC, TRUE );
} }
...@@ -209,20 +212,19 @@ void WinEDA_BasePcbFrame::PlaceTexteModule( TEXTE_MODULE* Text, wxDC* DC ) ...@@ -209,20 +212,19 @@ void WinEDA_BasePcbFrame::PlaceTexteModule( TEXTE_MODULE* Text, wxDC* DC )
{ {
DrawPanel->PostDirtyRect( Text->GetBoundingBox() ); DrawPanel->PostDirtyRect( Text->GetBoundingBox() );
Text->m_Pos = GetScreen()->m_Curseur;
/* mise a jour des coordonnes relatives a l'ancre */ /* mise a jour des coordonnes relatives a l'ancre */
MODULE* Module = (MODULE*) Text->GetParent(); MODULE* Module = (MODULE*) Text->GetParent();
if( Module ) if( Module )
{ {
// Prepare undo command for Board Editor: // Prepare undo command (a rotation can be made while moving)
EXCHG(Text->m_Orient, TextInitialOrientation);
if( m_Ident == PCB_FRAME ) if( m_Ident == PCB_FRAME )
{
EXCHG(Text->m_Pos, TextInitialPosition);
EXCHG(Text->m_Orient, TextInitialOrientation);
SaveCopyInUndoList(Module, UR_CHANGED); SaveCopyInUndoList(Module, UR_CHANGED);
EXCHG(Text->m_Pos, TextInitialPosition); else
EXCHG(Text->m_Orient, TextInitialOrientation); SaveCopyInUndoList(Module, UR_MODEDIT);
} EXCHG(Text->m_Orient, TextInitialOrientation);
Text->m_Pos = GetScreen()->m_Curseur; // Set the new position for text
wxPoint textRelPos = Text->m_Pos - Module->m_Pos; wxPoint textRelPos = Text->m_Pos - Module->m_Pos;
RotatePoint( &textRelPos, -Module->m_Orient ); RotatePoint( &textRelPos, -Module->m_Orient );
Text->m_Pos0 = textRelPos; Text->m_Pos0 = textRelPos;
...@@ -234,6 +236,8 @@ void WinEDA_BasePcbFrame::PlaceTexteModule( TEXTE_MODULE* Text, wxDC* DC ) ...@@ -234,6 +236,8 @@ void WinEDA_BasePcbFrame::PlaceTexteModule( TEXTE_MODULE* Text, wxDC* DC )
/* Redessin du Texte */ /* Redessin du Texte */
DrawPanel->PostDirtyRect( Text->GetBoundingBox() ); DrawPanel->PostDirtyRect( Text->GetBoundingBox() );
} }
else
Text->m_Pos = GetScreen()->m_Curseur;
} }
// leave it at (0,0) so we can use it Rotate when not moving. // leave it at (0,0) so we can use it Rotate when not moving.
......
...@@ -33,7 +33,6 @@ void WinEDA_ModuleEditFrame::OnLeftClick( wxDC* DC, const wxPoint& MousePos ) ...@@ -33,7 +33,6 @@ void WinEDA_ModuleEditFrame::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
switch( DrawStruct->Type() ) switch( DrawStruct->Type() )
{ {
case TYPE_TEXTE_MODULE: case TYPE_TEXTE_MODULE:
SaveCopyInUndoList( GetBoard()->m_Modules, UR_MODEDIT );
PlaceTexteModule( (TEXTE_MODULE*) DrawStruct, DC ); PlaceTexteModule( (TEXTE_MODULE*) DrawStruct, DC );
break; break;
...@@ -64,9 +63,9 @@ void WinEDA_ModuleEditFrame::OnLeftClick( wxDC* DC, const wxPoint& MousePos ) ...@@ -64,9 +63,9 @@ void WinEDA_ModuleEditFrame::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
DrawStruct = GetCurItem(); DrawStruct = GetCurItem();
if( !DrawStruct || (DrawStruct->m_Flags == 0) ) if( !DrawStruct || (DrawStruct->m_Flags == 0) )
{ {
if( !wxGetKeyState(WXK_SHIFT) && !wxGetKeyState(WXK_ALT) && if( !wxGetKeyState( WXK_SHIFT ) && !wxGetKeyState( WXK_ALT )
!wxGetKeyState(WXK_CONTROL) ) && !wxGetKeyState( WXK_CONTROL ) )
DrawStruct = ModeditLocateAndDisplay(); DrawStruct = ModeditLocateAndDisplay();
SetCurItem( DrawStruct ); SetCurItem( DrawStruct );
} }
...@@ -90,7 +89,7 @@ void WinEDA_ModuleEditFrame::OnLeftClick( wxDC* DC, const wxPoint& MousePos ) ...@@ -90,7 +89,7 @@ void WinEDA_ModuleEditFrame::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
shape = S_ARC; shape = S_ARC;
SetCurItem( SetCurItem(
Begin_Edge_Module( (EDGE_MODULE*) NULL, DC, shape ) ); Begin_Edge_Module( (EDGE_MODULE*) NULL, DC, shape ) );
} }
else if( (DrawStruct->m_Flags & IS_NEW) ) else if( (DrawStruct->m_Flags & IS_NEW) )
{ {
...@@ -120,7 +119,7 @@ void WinEDA_ModuleEditFrame::OnLeftClick( wxDC* DC, const wxPoint& MousePos ) ...@@ -120,7 +119,7 @@ void WinEDA_ModuleEditFrame::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
DrawStruct = ModeditLocateAndDisplay(); DrawStruct = ModeditLocateAndDisplay();
if( DrawStruct == NULL || (DrawStruct->m_Flags != 0) ) if( DrawStruct == NULL || (DrawStruct->m_Flags != 0) )
break; break;
if( DrawStruct->Type() != TYPE_MODULE) //GetBoard()->m_Modules ) // Cannot delete the module itself if( DrawStruct->Type() != TYPE_MODULE ) //GetBoard()->m_Modules ) // Cannot delete the module itself
{ {
SaveCopyInUndoList( GetBoard()->m_Modules, UR_MODEDIT ); SaveCopyInUndoList( GetBoard()->m_Modules, UR_MODEDIT );
RemoveStruct( DrawStruct ); RemoveStruct( DrawStruct );
...@@ -131,19 +130,20 @@ void WinEDA_ModuleEditFrame::OnLeftClick( wxDC* DC, const wxPoint& MousePos ) ...@@ -131,19 +130,20 @@ void WinEDA_ModuleEditFrame::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
case ID_MODEDIT_PLACE_ANCHOR: case ID_MODEDIT_PLACE_ANCHOR:
{ {
MODULE * module = GetBoard()->m_Modules; MODULE* module = GetBoard()->m_Modules;
module->m_Flags = 0; module->m_Flags = 0;
SaveCopyInUndoList( module, UR_MODEDIT ); SaveCopyInUndoList( module, UR_MODEDIT );
Place_Ancre( module ); // set the new relatives internal coordinates of items Place_Ancre( module ); // set the new relatives internal coordinates of items
GetScreen()->m_Curseur = wxPoint( 0, 0 ); GetScreen()->m_Curseur = wxPoint( 0, 0 );
Recadre_Trace( TRUE ); Recadre_Trace( TRUE );
// Replace the module in position 0, to recalculate absolutes coordinates of items // Replace the module in position 0, to recalculate absolutes coordinates of items
module->SetPosition( wxPoint(0,0) ); module->SetPosition( wxPoint( 0, 0 ) );
SetToolID( 0, wxCURSOR_ARROW, wxEmptyString ); SetToolID( 0, wxCURSOR_ARROW, wxEmptyString );
SetCurItem( NULL ); SetCurItem( NULL );
DrawPanel->Refresh(); DrawPanel->Refresh();
} }
break; break;
case ID_TEXT_COMMENT_BUTT: case ID_TEXT_COMMENT_BUTT:
SaveCopyInUndoList( GetBoard()->m_Modules, UR_MODEDIT ); SaveCopyInUndoList( GetBoard()->m_Modules, UR_MODEDIT );
...@@ -179,10 +179,10 @@ bool WinEDA_ModuleEditFrame::OnRightClick( const wxPoint& MousePos, ...@@ -179,10 +179,10 @@ bool WinEDA_ModuleEditFrame::OnRightClick( const wxPoint& MousePos,
* After this menu is built, the standart ZOOM menu is added * After this menu is built, the standart ZOOM menu is added
*/ */
{ {
BOARD_ITEM* DrawStruct = GetCurItem(); BOARD_ITEM* DrawStruct = GetCurItem();
wxString msg; wxString msg;
bool append_set_width = FALSE; bool append_set_width = FALSE;
bool BlockActive = (GetScreen()->m_BlockLocate.m_Command != BLOCK_IDLE); bool BlockActive = (GetScreen()->m_BlockLocate.m_Command != BLOCK_IDLE);
// Simple localisation des elements si possible // Simple localisation des elements si possible
if( (DrawStruct == NULL) || (DrawStruct->m_Flags == 0) ) if( (DrawStruct == NULL) || (DrawStruct->m_Flags == 0) )
...@@ -290,11 +290,14 @@ bool WinEDA_ModuleEditFrame::OnRightClick( const wxPoint& MousePos, ...@@ -290,11 +290,14 @@ bool WinEDA_ModuleEditFrame::OnRightClick( const wxPoint& MousePos,
} }
ADD_MENUITEM( PopMenu, ID_POPUP_PCB_ROTATE_TEXTMODULE, ADD_MENUITEM( PopMenu, ID_POPUP_PCB_ROTATE_TEXTMODULE,
_( "Rotate Text Mod." ), rotate_field_xpm ); _( "Rotate Text Mod." ), rotate_field_xpm );
ADD_MENUITEM( PopMenu, ID_POPUP_PCB_EDIT_TEXTMODULE, if( !flags )
_( "Edit Text Mod." ), edit_text_xpm ); {
if( ( (TEXTE_MODULE*) DrawStruct )->m_Type == TEXT_is_DIVERS ) ADD_MENUITEM( PopMenu, ID_POPUP_PCB_EDIT_TEXTMODULE,
ADD_MENUITEM( PopMenu, ID_POPUP_PCB_DELETE_TEXTMODULE, _( "Edit Text Mod." ), edit_text_xpm );
_( "Delete Text Mod." ), delete_text_xpm ); if( ( (TEXTE_MODULE*) DrawStruct )->m_Type == TEXT_is_DIVERS )
ADD_MENUITEM( PopMenu, ID_POPUP_PCB_DELETE_TEXTMODULE,
_( "Delete Text Mod." ), delete_text_xpm );
}
break; break;
case TYPE_EDGE_MODULE: case TYPE_EDGE_MODULE:
...@@ -323,7 +326,7 @@ bool WinEDA_ModuleEditFrame::OnRightClick( const wxPoint& MousePos, ...@@ -323,7 +326,7 @@ bool WinEDA_ModuleEditFrame::OnRightClick( const wxPoint& MousePos,
_( "Delete edge" ), delete_xpm ); _( "Delete edge" ), delete_xpm );
append_set_width = TRUE; append_set_width = TRUE;
} }
break; break;
case TYPE_DRAWSEGMENT: case TYPE_DRAWSEGMENT:
case TYPE_TEXTE: case TYPE_TEXTE:
...@@ -376,9 +379,9 @@ void WinEDA_ModuleEditFrame::OnLeftDClick( wxDC* DC, const wxPoint& MousePos ) ...@@ -376,9 +379,9 @@ void WinEDA_ModuleEditFrame::OnLeftDClick( wxDC* DC, const wxPoint& MousePos )
* If the double clicked item is editable: call the corresponding editor. * If the double clicked item is editable: call the corresponding editor.
*/ */
{ {
BOARD_ITEM* DrawStruct = GetCurItem(); BOARD_ITEM* DrawStruct = GetCurItem();
wxPoint pos = GetPosition(); wxPoint pos = GetPosition();
wxClientDC dc( DrawPanel ); wxClientDC dc( DrawPanel );
DrawPanel->PrepareGraphicContext( &dc ); DrawPanel->PrepareGraphicContext( &dc );
...@@ -414,7 +417,7 @@ void WinEDA_ModuleEditFrame::OnLeftDClick( wxDC* DC, const wxPoint& MousePos ) ...@@ -414,7 +417,7 @@ void WinEDA_ModuleEditFrame::OnLeftDClick( wxDC* DC, const wxPoint& MousePos )
if( ret > 0 ) if( ret > 0 )
DrawPanel->Refresh(); DrawPanel->Refresh();
} }
break; break;
case TYPE_TEXTE_MODULE: case TYPE_TEXTE_MODULE:
InstallTextModOptionsFrame( (TEXTE_MODULE*) DrawStruct, &dc ); InstallTextModOptionsFrame( (TEXTE_MODULE*) DrawStruct, &dc );
......
...@@ -176,10 +176,11 @@ bool WinEDA_PcbFrame::OnRightClick( const wxPoint& aMousePos, wxMenu* aPopMenu ) ...@@ -176,10 +176,11 @@ bool WinEDA_PcbFrame::OnRightClick( const wxPoint& aMousePos, wxMenu* aPopMenu )
ADD_MENUITEM( aPopMenu, ID_POPUP_PCB_MOVE_DRAWING_REQUEST, ADD_MENUITEM( aPopMenu, ID_POPUP_PCB_MOVE_DRAWING_REQUEST,
_( "Move Drawing" ), move_xpm ); _( "Move Drawing" ), move_xpm );
ADD_MENUITEM( aPopMenu, ID_POPUP_PCB_EDIT_DRAWING, _( "Edit Drawing" ), edit_xpm ); ADD_MENUITEM( aPopMenu, ID_POPUP_PCB_EDIT_DRAWING, _( "Edit Drawing" ), edit_xpm );
ADD_MENUITEM( aPopMenu, ID_POPUP_PCB_DELETE_DRAWING, _( "Delete Drawing" ), delete_xpm ); ADD_MENUITEM( aPopMenu, ID_POPUP_PCB_DELETE_DRAWING, _(
"Delete Drawing" ), delete_xpm );
if( item->GetLayer() > LAST_COPPER_LAYER ) if( item->GetLayer() > LAST_COPPER_LAYER )
ADD_MENUITEM( aPopMenu, ID_POPUP_PCB_DELETE_DRAWING_LAYER, ADD_MENUITEM( aPopMenu, ID_POPUP_PCB_DELETE_DRAWING_LAYER,
_( "Delete All Drawing on Layer" ), delete_body_xpm ); _( "Delete All Drawing on Layer" ), delete_body_xpm );
} }
break; break;
...@@ -220,7 +221,7 @@ bool WinEDA_PcbFrame::OnRightClick( const wxPoint& aMousePos, wxMenu* aPopMenu ) ...@@ -220,7 +221,7 @@ bool WinEDA_PcbFrame::OnRightClick( const wxPoint& aMousePos, wxMenu* aPopMenu )
ADD_MENUITEM( aPopMenu, ID_POPUP_PCB_EDIT_COTATION, ADD_MENUITEM( aPopMenu, ID_POPUP_PCB_EDIT_COTATION,
_( "Edit Dimension" ), edit_xpm ); _( "Edit Dimension" ), edit_xpm );
ADD_MENUITEM( aPopMenu, ID_POPUP_PCB_DELETE_COTATION, ADD_MENUITEM( aPopMenu, ID_POPUP_PCB_DELETE_COTATION,
_( "Delete Dimension" ), delete_xpm ); _( "Delete Dimension" ), delete_xpm );
} }
break; break;
...@@ -707,8 +708,9 @@ void WinEDA_PcbFrame::createPopUpMenuForFpTexts( TEXTE_MODULE* FpText, wxMenu* m ...@@ -707,8 +708,9 @@ void WinEDA_PcbFrame::createPopUpMenuForFpTexts( TEXTE_MODULE* FpText, wxMenu* m
ADD_MENUITEM( sub_menu_Fp_text, ID_POPUP_PCB_ROTATE_TEXTMODULE, ADD_MENUITEM( sub_menu_Fp_text, ID_POPUP_PCB_ROTATE_TEXTMODULE,
_( "Rotate" ), rotate_field_xpm ); _( "Rotate" ), rotate_field_xpm );
ADD_MENUITEM( sub_menu_Fp_text, ID_POPUP_PCB_EDIT_TEXTMODULE, if( !flags )
_( "Edit" ), edit_text_xpm ); ADD_MENUITEM( sub_menu_Fp_text, ID_POPUP_PCB_EDIT_TEXTMODULE,
_( "Edit" ), edit_text_xpm );
if( !flags && FpText->m_Type == TEXT_is_DIVERS ) // Graphic texts can be deleted only if are not currently edited if( !flags && FpText->m_Type == TEXT_is_DIVERS ) // Graphic texts can be deleted only if are not currently edited
{ {
...@@ -891,4 +893,3 @@ static wxMenu* Append_Track_Width_List() ...@@ -891,4 +893,3 @@ static wxMenu* Append_Track_Width_List()
return trackwidth_menu; return trackwidth_menu;
} }
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