Commit 83be1f8a authored by charras's avatar charras

Rework on undo/redo and block functions: more efficient code to undo/redo...

Rework on undo/redo and block functions: more efficient code to undo/redo block move and mirror operations
parent daceb2e0
......@@ -32,7 +32,7 @@
PICKED_ITEMS_LIST::PICKED_ITEMS_LIST()
{
m_UndoRedoType = 0;
m_Status = UR_UNSPECIFIED;
};
PICKED_ITEMS_LIST::~PICKED_ITEMS_LIST()
......@@ -102,12 +102,12 @@ EDA_BaseStruct* PICKED_ITEMS_LIST::GetImage( unsigned int aIdx )
}
int PICKED_ITEMS_LIST::GetItemStatus( unsigned int aIdx )
UndoRedoOpType PICKED_ITEMS_LIST::GetItemStatus( unsigned int aIdx )
{
if( aIdx < m_ItemsList.size() )
return m_ItemsList[aIdx].m_UndoRedoStatus;
else
return 0;
return UR_UNSPECIFIED;
}
......@@ -135,7 +135,7 @@ bool PICKED_ITEMS_LIST::SetLink( EDA_BaseStruct* aItem, unsigned aIdx )
}
bool PICKED_ITEMS_LIST::SetItem( EDA_BaseStruct* aItem, int aStatus, unsigned aIdx )
bool PICKED_ITEMS_LIST::SetItem( EDA_BaseStruct* aItem, UndoRedoOpType aStatus, unsigned aIdx )
{
if( aIdx < m_ItemsList.size() )
{
......@@ -148,7 +148,7 @@ bool PICKED_ITEMS_LIST::SetItem( EDA_BaseStruct* aItem, int aStatus, unsigned aI
}
bool PICKED_ITEMS_LIST::SetItemStatus( int aStatus, unsigned aIdx )
bool PICKED_ITEMS_LIST::SetItemStatus( UndoRedoOpType aStatus, unsigned aIdx )
{
if( aIdx < m_ItemsList.size() )
{
......
......@@ -45,7 +45,7 @@ void SCH_ITEM::Place( WinEDA_SchematicFrame* frame, wxDC* DC )
if( !screen->CheckIfOnDrawList( this ) ) //don't want a loop!
screen->AddToDrawList( this );
g_ItemToRepeat = this;
frame->SaveCopyInUndoList( this, IS_NEW );
frame->SaveCopyInUndoList( this, UR_NEW );
}
m_Flags = 0;
......
......@@ -73,6 +73,7 @@ set(EESCHEMA_SRCS
erc.cpp
files-io.cpp
find.cpp
geometric_transforms.cpp
getpart.cpp
hierarch.cpp
hotkeys.cpp
......
This diff is collapsed.
......@@ -357,7 +357,7 @@ void WinEDA_SchematicFrame::EndSegment( wxDC* DC )
DrawPanel->CursorOn( DC ); // Display schematic cursor
SaveCopyInUndoList( s_OldWiresList, IS_WIRE_IMAGE );
SaveCopyInUndoList( s_OldWiresList, UR_WIRE_IMAGE );
s_OldWiresList = NULL;
GetScreen()->SetModify();
......@@ -548,7 +548,7 @@ DrawJunctionStruct* WinEDA_SchematicFrame::CreateNewJunctionStruct(
GetScreen()->EEDrawList = NewJunction;
GetScreen()->SetModify();
if( PutInUndoList )
SaveCopyInUndoList( NewJunction, IS_NEW );
SaveCopyInUndoList( NewJunction, UR_NEW );
return NewJunction;
}
......@@ -572,7 +572,7 @@ DrawNoConnectStruct* WinEDA_SchematicFrame::CreateNewNoConnectStruct( wxDC* DC )
NewNoConnect->SetNext( GetScreen()->EEDrawList );
GetScreen()->EEDrawList = NewNoConnect;
GetScreen()->SetModify();
SaveCopyInUndoList( NewNoConnect, IS_NEW );
SaveCopyInUndoList( NewNoConnect, UR_NEW );
return NewNoConnect;
}
......@@ -734,7 +734,7 @@ void WinEDA_SchematicFrame::RepeatDrawItem( wxDC* DC )
GetScreen()->EEDrawList = g_ItemToRepeat;
TestDanglingEnds( GetScreen()->EEDrawList, NULL );
RedrawOneStruct( DrawPanel, DC, g_ItemToRepeat, GR_DEFAULT_DRAWMODE );
SaveCopyInUndoList( g_ItemToRepeat, IS_NEW );
SaveCopyInUndoList( g_ItemToRepeat, UR_NEW );
g_ItemToRepeat->m_Flags = 0;
// GetScreen()->Curseur = new_pos;
......
......@@ -145,7 +145,7 @@ void WinEDA_SchematicFrame::SetBusEntryShape( wxDC* DC,
/* Put old item in undo list if it is not currently in edit */
if( BusEntry->m_Flags == 0 )
SaveCopyInUndoList( BusEntry, IS_CHANGED );
SaveCopyInUndoList( BusEntry, UR_CHANGED );
RedrawOneStruct( DrawPanel, DC, BusEntry, g_XorMode );
......
......@@ -416,7 +416,7 @@ void SCH_CMP_FIELD::Place( WinEDA_SchematicFrame* frame, wxDC* DC )
if( g_ItemToUndoCopy && ( g_ItemToUndoCopy->Type() == component->Type()) )
{
component->SwapData( (SCH_COMPONENT*) g_ItemToUndoCopy );
frame->SaveCopyInUndoList( component, IS_CHANGED );
frame->SaveCopyInUndoList( component, UR_CHANGED );
component->SwapData( (SCH_COMPONENT*) g_ItemToUndoCopy );
}
......
......@@ -454,7 +454,7 @@ void SCH_TEXT::Place( WinEDA_SchematicFrame* frame, wxDC* DC )
SwapData( (SCH_TEXT*) g_ItemToUndoCopy );
/* save in undo list */
frame->SaveCopyInUndoList( this, IS_CHANGED );
frame->SaveCopyInUndoList( this, UR_CHANGED );
/* restore new values */
SwapData( (SCH_TEXT*) g_ItemToUndoCopy );
......
......@@ -155,7 +155,7 @@ void BreakSegment(SCH_SCREEN * aScreen, wxPoint aBreakpoint,
/* Ici il faut couper le segment en 2 */
if( aPicklist ) // First: put copy of the old segment in undo list
{
ITEM_PICKER picker((SCH_ITEM*) segment->GenCopy(), IS_CHANGED);
ITEM_PICKER picker((SCH_ITEM*) segment->GenCopy(), UR_CHANGED);
picker.m_Link = segment;
aPicklist->PushItem(picker);
}
......@@ -167,7 +167,7 @@ void BreakSegment(SCH_SCREEN * aScreen, wxPoint aBreakpoint,
DrawList = NewSegment;
if( aPicklist )
{
ITEM_PICKER picker(NewSegment, IS_NEW);
ITEM_PICKER picker(NewSegment, UR_NEW);
aPicklist->PushItem(picker);
}
}
......
......@@ -615,7 +615,7 @@ void SCH_COMPONENT::Place( WinEDA_SchematicFrame* frame, wxDC* DC )
SwapData( (SCH_COMPONENT*) g_ItemToUndoCopy );
/* save in undo list */
frame->SaveCopyInUndoList( this, IS_CHANGED );
frame->SaveCopyInUndoList( this, UR_CHANGED );
/* restore new values */
SwapData( (SCH_COMPONENT*) g_ItemToUndoCopy );
......
......@@ -138,7 +138,7 @@ void WinEDA_SchematicFrame::DeleteConnection( bool DeleteFullConnection )
/* Locate all the wires, bus or junction under the mouse cursor, and put them in a list
* of items to delete
*/
ITEM_PICKER picker(NULL, IS_DELETED);
ITEM_PICKER picker(NULL, UR_DELETED);
SCH_SCREEN* screen = (SCH_SCREEN*) GetScreen();
SCH_ITEM* savedEEDrawList = screen->EEDrawList; // Save the list entry point of this screen
DelStruct = GetScreen()->EEDrawList;
......
......@@ -243,7 +243,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnOKButtonClick( wxCommandEvent& event
/* save old cmp in undo list if not already in edit, or moving ... */
if( m_Cmp->m_Flags == 0 )
m_Parent->SaveCopyInUndoList( m_Cmp, IS_CHANGED );
m_Parent->SaveCopyInUndoList( m_Cmp, UR_CHANGED );
// change all field positions from relative to absolute
for( unsigned i = 0; i<m_FieldsBuf.size(); ++i )
......
......@@ -128,7 +128,7 @@ void WinEDA_SchematicFrame::EditCmpFieldText( SCH_CMP_FIELD* Field, wxDC* DC )
/* save old cmp in undo list if not already in edit, or moving ... */
if( Field->m_Flags == 0 )
SaveCopyInUndoList( Cmp, IS_CHANGED );
SaveCopyInUndoList( Cmp, UR_CHANGED );
wxString newtext = Field->m_Text;
DrawPanel->m_IgnoreMouseEvents = TRUE;
......@@ -270,7 +270,7 @@ void WinEDA_SchematicFrame::RotateCmpField( SCH_CMP_FIELD* Field, wxDC* DC )
/* save old cmp in undo list if not already in edit, or moving ... */
if( Field->m_Flags == 0 )
SaveCopyInUndoList( Cmp, IS_CHANGED );
SaveCopyInUndoList( Cmp, UR_CHANGED );
Field->m_AddExtraText = flag;
Field->Draw( DrawPanel, DC, wxPoint(0,0), g_XorMode );
......@@ -310,7 +310,7 @@ void WinEDA_SchematicFrame::EditComponentReference( SCH_COMPONENT* Cmp, wxDC* DC
{
/* save old cmp in undo list if not already in edit, or moving ... */
if( Cmp->m_Flags == 0 )
SaveCopyInUndoList( Cmp, IS_CHANGED );
SaveCopyInUndoList( Cmp, UR_CHANGED );
Cmp->SetRef(GetSheet(), ref);
Cmp->GetField( REFERENCE )->m_AddExtraText = flag;
......@@ -349,7 +349,7 @@ void WinEDA_SchematicFrame::EditComponentValue( SCH_COMPONENT* Cmp, wxDC* DC )
{
/* save old cmp in undo list if not already in edit, or moving ... */
if( Cmp->m_Flags == 0 )
SaveCopyInUndoList( Cmp, IS_CHANGED );
SaveCopyInUndoList( Cmp, UR_CHANGED );
TextField->Draw( DrawPanel, DC, wxPoint(0,0), g_XorMode );
TextField->m_Text = message;
......@@ -388,7 +388,7 @@ void WinEDA_SchematicFrame::EditComponentFootprint( SCH_COMPONENT* Cmp, wxDC* DC
// save old cmp in undo list if not already in edit, or moving ...
if( Cmp->m_Flags == 0 )
SaveCopyInUndoList( Cmp, IS_CHANGED );
SaveCopyInUndoList( Cmp, UR_CHANGED );
Cmp->GetField( FOOTPRINT )->Draw( DrawPanel, DC, wxPoint(0,0), g_XorMode );
// move the field if it was new.
......
......@@ -39,7 +39,7 @@ void DialogLabelEditor::TextPropertiesAccept( wxCommandEvent& event )
/* save old text in undo list if not already in edit */
if( m_CurrentText->m_Flags == 0 )
m_Parent->SaveCopyInUndoList( m_CurrentText, IS_CHANGED );
m_Parent->SaveCopyInUndoList( m_CurrentText, UR_CHANGED );
text = m_TextLabel->GetValue();
if( !text.IsEmpty() )
......@@ -162,7 +162,7 @@ void WinEDA_SchematicFrame::ChangeTextOrient( SCH_TEXT* TextStruct, wxDC* DC )
/* save old text in undo list if is not already in edit */
if( TextStruct->m_Flags == 0 )
SaveCopyInUndoList( TextStruct, IS_CHANGED );
SaveCopyInUndoList( TextStruct, UR_CHANGED );
/* Effacement du texte en cours */
DrawPanel->CursorOff( DC );
......@@ -432,7 +432,7 @@ void WinEDA_SchematicFrame::ConvertTextType( SCH_TEXT* Text,
*/
if( (flags & IS_NEW) == 0 )
{
SaveCopyInUndoList( newtext, IS_NEW );
SaveCopyInUndoList( newtext, UR_NEW );
}
else
{
......
......@@ -164,25 +164,23 @@ void RedrawOneStruct( WinEDA_DrawPanel* panel, wxDC* DC,
* de structures.
* Utilisee dans les deplacements de blocs
*/
void DrawStructsInGhost( WinEDA_DrawPanel* panel, wxDC* DC,
SCH_ITEM* DrawStruct, int dx, int dy )
void DrawStructsInGhost( WinEDA_DrawPanel * aPanel, wxDC * aDC, SCH_ITEM * aItem, const wxPoint & aOffset )
{
int DrawMode = g_XorMode;
int width = g_DrawDefaultLineThickness;
GRSetDrawMode( aDC, DrawMode );
GRSetDrawMode( DC, DrawMode );
switch( DrawStruct->Type() )
switch( aItem->Type() )
{
case DRAW_POLYLINE_STRUCT_TYPE:
{
DrawPolylineStruct* Struct = (DrawPolylineStruct*) DrawStruct;
GRMoveTo( Struct->m_PolyPoints[0].x + dx,
Struct->m_PolyPoints[0].y + dy );
DrawPolylineStruct* Struct = (DrawPolylineStruct*) aItem;
GRMoveTo( Struct->m_PolyPoints[0].x + aOffset.x,
Struct->m_PolyPoints[0].y + aOffset.y );
for( unsigned ii = 1; ii < Struct->GetCornerCount(); ii++ )
GRLineTo( &panel->m_ClipBox, DC, Struct->m_PolyPoints[ii].x + dx,
Struct->m_PolyPoints[ii].y + dy, width, g_GhostColor );
GRLineTo( &aPanel->m_ClipBox, aDC, Struct->m_PolyPoints[ii].x + aOffset.x,
Struct->m_PolyPoints[ii].y + aOffset.y, width, g_GhostColor );
break;
}
......@@ -190,10 +188,10 @@ void DrawStructsInGhost( WinEDA_DrawPanel* panel, wxDC* DC,
case DRAW_SEGMENT_STRUCT_TYPE:
{
EDA_DrawLineStruct* Struct;
Struct = (EDA_DrawLineStruct*) DrawStruct;
Struct = (EDA_DrawLineStruct*) aItem;
if( (Struct->m_Flags & STARTPOINT) == 0 )
{
GRMoveTo( Struct->m_Start.x + dx, Struct->m_Start.y + dy );
GRMoveTo( Struct->m_Start.x + aOffset.x, Struct->m_Start.y + aOffset.y );
}
else
{
......@@ -201,12 +199,12 @@ void DrawStructsInGhost( WinEDA_DrawPanel* panel, wxDC* DC,
}
if( (Struct->m_Flags & ENDPOINT) == 0 )
{
GRLineTo( &panel->m_ClipBox, DC, Struct->m_End.x + dx,
Struct->m_End.y + dy, width, g_GhostColor );
GRLineTo( &aPanel->m_ClipBox, aDC, Struct->m_End.x + aOffset.x,
Struct->m_End.y + aOffset.y, width, g_GhostColor );
}
else
{
GRLineTo( &panel->m_ClipBox, DC, Struct->m_End.x,
GRLineTo( &aPanel->m_ClipBox, aDC, Struct->m_End.x,
Struct->m_End.y, width, g_GhostColor );
}
break;
......@@ -214,27 +212,27 @@ void DrawStructsInGhost( WinEDA_DrawPanel* panel, wxDC* DC,
case DRAW_BUSENTRY_STRUCT_TYPE:
{
DrawBusEntryStruct* Struct = (DrawBusEntryStruct*) DrawStruct;
int xx = Struct->m_Pos.x + dx, yy = Struct->m_Pos.y + dy;
GRMoveTo( xx, yy );
GRLineTo( &panel->m_ClipBox, DC, Struct->m_Size.x + xx,
Struct->m_Size.y + yy, width, g_GhostColor );
DrawBusEntryStruct* Struct = (DrawBusEntryStruct*) aItem;
wxPoint start = Struct->m_Pos + aOffset;
GRMoveTo( start.x, start.y );
GRLineTo( &aPanel->m_ClipBox, aDC, Struct->m_Size.x + start.x,
Struct->m_Size.y + start.y, width, g_GhostColor );
break;
}
case DRAW_JUNCTION_STRUCT_TYPE:
{
DrawJunctionStruct* Struct;
Struct = (DrawJunctionStruct*) DrawStruct;
Struct->Draw( panel, DC, wxPoint(0,0), DrawMode, g_GhostColor );
Struct = (DrawJunctionStruct*) aItem;
Struct->Draw( aPanel, aDC, aOffset, DrawMode, g_GhostColor );
break;
}
case TYPE_SCH_TEXT:
{
SCH_TEXT* Struct;
Struct = (SCH_TEXT*) DrawStruct;
Struct->Draw( panel, DC, wxPoint( dx, dy ), DrawMode, g_GhostColor );
Struct = (SCH_TEXT*) aItem;
Struct->Draw( aPanel, aDC, aOffset, DrawMode, g_GhostColor );
break;
}
......@@ -243,16 +241,16 @@ void DrawStructsInGhost( WinEDA_DrawPanel* panel, wxDC* DC,
case TYPE_SCH_HIERLABEL:
{
SCH_LABEL* Struct;
Struct = (SCH_LABEL*) DrawStruct;
Struct->Draw( panel, DC, wxPoint( dx, dy ), DrawMode, g_GhostColor );
Struct = (SCH_LABEL*) aItem;
Struct->Draw( aPanel, aDC, aOffset, DrawMode, g_GhostColor );
break;
}
case DRAW_NOCONNECT_STRUCT_TYPE:
{
DrawNoConnectStruct* Struct;
Struct = (DrawNoConnectStruct*) DrawStruct;
Struct->Draw( panel, DC, wxPoint( dx, dy ), DrawMode, g_GhostColor );
Struct = (DrawNoConnectStruct*) aItem;
Struct->Draw( aPanel, aDC, aOffset, DrawMode, g_GhostColor );
break;
}
......@@ -260,23 +258,23 @@ void DrawStructsInGhost( WinEDA_DrawPanel* panel, wxDC* DC,
{
EDA_LibComponentStruct* LibEntry;
SCH_COMPONENT* Struct;
Struct = (SCH_COMPONENT*) DrawStruct;
Struct = (SCH_COMPONENT*) aItem;
LibEntry = FindLibPart( Struct->m_ChipName.GetData(), wxEmptyString,
FIND_ROOT );
if( LibEntry == NULL )
break;
DrawingLibInGhost( panel, DC, LibEntry, Struct, Struct->m_Pos.x + dx,
Struct->m_Pos.y + dy, Struct->m_Multi,
DrawingLibInGhost( aPanel, aDC, LibEntry, Struct, Struct->m_Pos.x + aOffset.x,
Struct->m_Pos.y + aOffset.y, Struct->m_Multi,
Struct->m_Convert, g_GhostColor, FALSE );
break;
}
case DRAW_SHEET_STRUCT_TYPE:
{
DrawSheetStruct* Struct = (DrawSheetStruct*) DrawStruct;
GRRect( &panel->m_ClipBox, DC, Struct->m_Pos.x + dx,
Struct->m_Pos.y + dy, Struct->m_Pos.x + Struct->m_Size.x + dx,
Struct->m_Pos.y + Struct->m_Size.y + dy, width, g_GhostColor );
DrawSheetStruct* Struct = (DrawSheetStruct*) aItem;
GRRect( &aPanel->m_ClipBox, aDC, Struct->m_Pos.x + aOffset.x,
Struct->m_Pos.y + aOffset.y, Struct->m_Pos.x + Struct->m_Size.x + aOffset.x,
Struct->m_Pos.y + Struct->m_Size.y + aOffset.y, width, g_GhostColor );
break;
}
......
This diff is collapsed.
......@@ -231,7 +231,7 @@ SCH_COMPONENT* WinEDA_SchematicFrame::Load_Component( wxDC* DC,
curr_field->m_Name = ( ii < FIELD1 ) ? ReturnDefaultFieldName( ii ) : EntryField->m_Name;
}
DrawStructsInGhost( DrawPanel, DC, Component, 0, 0 );
DrawStructsInGhost( DrawPanel, DC, Component, wxPoint(0,0) );
MsgPanel->EraseMsgBox();
Component->DisplayInfo( this );
......@@ -255,14 +255,14 @@ static void ShowWhileMoving( WinEDA_DrawPanel* panel, wxDC* DC, bool erase )
/* Effacement du composant */
if( erase )
{
DrawStructsInGhost( panel, DC, Component, 0, 0 );
DrawStructsInGhost( panel, DC, Component, wxPoint(0,0) );
}
move_vector.x = screen->m_Curseur.x - Component->m_Pos.x;
move_vector.y = screen->m_Curseur.y - Component->m_Pos.y;
MoveOneStruct( Component, move_vector );
DrawStructsInGhost( panel, DC, Component, 0, 0 );
DrawStructsInGhost( panel, DC, Component, wxPoint(0,0) );
}
......@@ -283,7 +283,7 @@ void WinEDA_SchematicFrame::CmpRotationMiroir(
{
DrawPanel->CursorOff( DC );
if( DrawComponent->m_Flags )
DrawStructsInGhost( DrawPanel, DC, DrawComponent, 0, 0 );
DrawStructsInGhost( DrawPanel, DC, DrawComponent, wxPoint(0,0) );
else
{
DrawPanel->PostDirtyRect( DrawComponent->GetBoundingBox() );
......@@ -296,7 +296,7 @@ void WinEDA_SchematicFrame::CmpRotationMiroir(
if( DC )
{
if( DrawComponent->m_Flags )
DrawStructsInGhost( DrawPanel, DC, DrawComponent, 0, 0 );
DrawStructsInGhost( DrawPanel, DC, DrawComponent, wxPoint(0,0) );
else
DrawComponent->Draw( DrawPanel, DC, wxPoint( 0,
0 ),
......@@ -378,7 +378,7 @@ void WinEDA_SchematicFrame::SelPartUnit( SCH_COMPONENT* DrawComponent,
/* Efface le trace precedent */
if( DrawComponent->m_Flags )
DrawStructsInGhost( DrawPanel, DC, DrawComponent, 0, 0 );
DrawStructsInGhost( DrawPanel, DC, DrawComponent, wxPoint(0,0) );
else
DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode );
......@@ -388,10 +388,9 @@ void WinEDA_SchematicFrame::SelPartUnit( SCH_COMPONENT* DrawComponent,
/* Redessine le composant dans la nouvelle position */
if( DrawComponent->m_Flags )
DrawStructsInGhost( DrawPanel, DC, DrawComponent, 0, 0 );
DrawStructsInGhost( DrawPanel, DC, DrawComponent, wxPoint(0,0) );
else
DrawComponent->Draw( DrawPanel, DC, wxPoint( 0,
0 ), GR_DEFAULT_DRAWMODE );
DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
TestDanglingEnds( GetScreen()->EEDrawList, DC );
GetScreen()->SetModify();
......@@ -421,7 +420,7 @@ void WinEDA_SchematicFrame::ConvertPart( SCH_COMPONENT* DrawComponent,
/* Efface le trace precedent */
if( DrawComponent->m_Flags )
DrawStructsInGhost( DrawPanel, DC, DrawComponent, 0, 0 );
DrawStructsInGhost( DrawPanel, DC, DrawComponent, wxPoint(0,0) );
else
DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode );
......@@ -431,10 +430,9 @@ void WinEDA_SchematicFrame::ConvertPart( SCH_COMPONENT* DrawComponent,
/* Redessine le composant dans la nouvelle position */
if( DrawComponent->m_Flags & IS_MOVED )
DrawStructsInGhost( DrawPanel, DC, DrawComponent, 0, 0 );
DrawStructsInGhost( DrawPanel, DC, DrawComponent, wxPoint(0,0) );
else
DrawComponent->Draw( DrawPanel, DC, wxPoint( 0,
0 ), GR_DEFAULT_DRAWMODE );
DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
TestDanglingEnds( GetScreen()->EEDrawList, DC );
GetScreen()->SetModify();
......@@ -508,7 +506,7 @@ void WinEDA_SchematicFrame::StartMovePart( SCH_COMPONENT* Component,
Component->m_Flags |= IS_MOVED; // omit redrawing the component, erase only
DrawPanel->PostDirtyRect( Component->GetBoundingBox() );
DrawStructsInGhost( DrawPanel, DC, Component, 0, 0 );
DrawStructsInGhost( DrawPanel, DC, Component, wxPoint(0,0) );
#else
......
......@@ -331,7 +331,7 @@ void WinEDA_SchematicFrame::OnHotKey( wxDC* DC, int hotkey,
case TYPE_SCH_COMPONENT:
if( DrawStruct->m_Flags == 0 )
{
SaveCopyInUndoList( (SCH_ITEM*) DrawStruct, IS_CHANGED );
SaveCopyInUndoList( (SCH_ITEM*) DrawStruct, UR_CHANGED );
RefreshToolBar = TRUE;
}
......@@ -345,7 +345,7 @@ void WinEDA_SchematicFrame::OnHotKey( wxDC* DC, int hotkey,
case TYPE_SCH_HIERLABEL:
if( DrawStruct->m_Flags == 0 )
{
SaveCopyInUndoList( (SCH_ITEM*) DrawStruct, IS_CHANGED );
SaveCopyInUndoList( (SCH_ITEM*) DrawStruct, UR_CHANGED );
RefreshToolBar = TRUE;
}
ChangeTextOrient( (SCH_TEXT*) DrawStruct, DC );
......@@ -364,7 +364,7 @@ void WinEDA_SchematicFrame::OnHotKey( wxDC* DC, int hotkey,
{
if( DrawStruct->m_Flags == 0 )
{
SaveCopyInUndoList( (SCH_ITEM*) DrawStruct, IS_CHANGED );
SaveCopyInUndoList( (SCH_ITEM*) DrawStruct, UR_CHANGED );
RefreshToolBar = TRUE;
}
CmpRotationMiroir( (SCH_COMPONENT*) DrawStruct, DC, CMP_MIROIR_Y );
......@@ -378,7 +378,7 @@ void WinEDA_SchematicFrame::OnHotKey( wxDC* DC, int hotkey,
{
if( DrawStruct->m_Flags == 0 )
{
SaveCopyInUndoList( (SCH_ITEM*) DrawStruct, IS_CHANGED );
SaveCopyInUndoList( (SCH_ITEM*) DrawStruct, UR_CHANGED );
RefreshToolBar = TRUE;
}
CmpRotationMiroir( (SCH_COMPONENT*) DrawStruct, DC, CMP_MIROIR_X );
......@@ -392,7 +392,7 @@ void WinEDA_SchematicFrame::OnHotKey( wxDC* DC, int hotkey,
{
if( DrawStruct->m_Flags == 0 )
{
SaveCopyInUndoList( (SCH_ITEM*) DrawStruct, IS_CHANGED );
SaveCopyInUndoList( (SCH_ITEM*) DrawStruct, UR_CHANGED );
RefreshToolBar = TRUE;
}
CmpRotationMiroir( (SCH_COMPONENT*) DrawStruct, DC, CMP_NORMAL );
......
......@@ -166,8 +166,7 @@ Hierarchical_PIN_Sheet_Struct * LocateAnyPinSheet(const wxPoint & RefPos,
void DrawDanglingSymbol(WinEDA_DrawPanel * panel,wxDC * DC,
const wxPoint & pos, int Color);
void DrawStructsInGhost(WinEDA_DrawPanel * panel, wxDC * DC,
SCH_ITEM * DrawStruct, int dx, int dy );
void DrawStructsInGhost(WinEDA_DrawPanel * aPanel, wxDC * aDC, SCH_ITEM * aItem, const wxPoint & aOffset );
void SetHighLightStruct(SCH_ITEM *HighLight);
void RedrawActiveWindow(WinEDA_DrawPanel * panel, wxDC * DC);
void RedrawStructList(WinEDA_DrawPanel * panel, wxDC * DC, SCH_ITEM *Structs, int DrawMode,
......
......@@ -341,7 +341,7 @@ void WinEDA_SchematicFrame::Process_Special_Functions( wxCommandEvent& event )
PICKED_ITEMS_LIST picklistForUndo;
BreakSegment( screen, screen->m_Curseur, &picklistForUndo );
if( picklistForUndo.GetCount() )
SaveCopyInUndoList( picklistForUndo, IS_NEW | IS_CHANGED );
SaveCopyInUndoList( picklistForUndo, UR_UNSPECIFIED );
TestDanglingEnds( screen->EEDrawList, &dc );
}
break;
......@@ -485,7 +485,7 @@ void WinEDA_SchematicFrame::Process_Special_Functions( wxCommandEvent& event )
DrawPanel->MouseToCursorSchema();
if( screen->GetCurItem()->m_Flags == 0 )
SaveCopyInUndoList( (SCH_ITEM*) screen->GetCurItem(), IS_CHANGED );
SaveCopyInUndoList( (SCH_ITEM*) screen->GetCurItem(), UR_CHANGED );
CmpRotationMiroir(
(SCH_COMPONENT*) screen->GetCurItem(),
......
......@@ -12,6 +12,10 @@
#include "protos.h"
#include "class_marker_sch.h"
// Imported functions
void MirrorOneStruct( SCH_ITEM* DrawStruct, wxPoint& aMirrorPoint );
/* Functions to undo and redo edit commands.
* commmands to undo are stored in CurrentScreen->m_UndoList
* commmands to redo are stored in CurrentScreen->m_RedoList
......@@ -173,19 +177,20 @@ void SwapData( EDA_BaseStruct* aItem, EDA_BaseStruct* aImage )
/***********************************************************************/
void WinEDA_SchematicFrame::SaveCopyInUndoList( SCH_ITEM* aItemToCopy,
int aCommandType )
UndoRedoOpType aCommandType,
const wxPoint& aTransformPoint )
/***********************************************************************/
/** function SaveCopyInUndoList
* Create a copy of the current schematic item, and put it in the undo list.
*
* flag_type_command =
* IS_CHANGED
* IS_NEW
* IS_DELETED
* IS_WIRE_IMAGE
* UR_CHANGED
* UR_NEW
* UR_DELETED
* UR_WIRE_IMAGE
*
* If it is a delete command, items are put on list with the .Flags member set to IS_DELETED.
* If it is a delete command, items are put on list with the .Flags member set to UR_DELETED.
* When it will be really deleted, the EEDrawList and the subhierarchy will be deleted.
* If it is only a copy, the EEDrawList and the subhierarchy must NOT be deleted.
*
......@@ -193,28 +198,29 @@ void WinEDA_SchematicFrame::SaveCopyInUndoList( SCH_ITEM* aItemToCopy,
* Edit wires and busses is a bit complex.
* because when a new wire is added, modifications in wire list
* (wire concatenation) there are modified items, deleted items and new items
* so flag_type_command is IS_WIRE_IMAGE: the struct ItemToCopy is a list of wires
* so flag_type_command is UR_WIRE_IMAGE: the struct ItemToCopy is a list of wires
* saved in Undo List (for Undo or Redo commands, saved wires will be exchanged with current wire list
*/
{
SCH_ITEM* CopyOfItem;
PICKED_ITEMS_LIST* commandToUndo = new PICKED_ITEMS_LIST();
commandToUndo->m_TransformPoint = aTransformPoint;
commandToUndo->m_UndoRedoType = aCommandType;
ITEM_PICKER itemWrapper( aItemToCopy, aCommandType );
switch( aCommandType )
{
case IS_CHANGED: /* Create a copy of schematic */
case UR_CHANGED: /* Create a copy of schematic */
CopyOfItem = DuplicateStruct( aItemToCopy );
itemWrapper.m_Item = CopyOfItem;
itemWrapper.m_Link = aItemToCopy;
commandToUndo->PushItem( itemWrapper );
break;
case IS_NEW:
case IS_WIRE_IMAGE:
case IS_DELETED:
case UR_NEW:
case UR_WIRE_IMAGE:
case UR_DELETED:
case UR_MOVED:
commandToUndo->PushItem( itemWrapper );
break;
......@@ -237,21 +243,23 @@ void WinEDA_SchematicFrame::SaveCopyInUndoList( SCH_ITEM* aItemToCopy,
/** function SaveCopyInUndoList
* @param aItemsList = a PICKED_ITEMS_LIST of items to save
* @param aTypeCommand = type of comand ( IS_CHANGED, IS_NEW, IS_DELETED ...
* @param aTypeCommand = type of comand ( UR_CHANGED, UR_NEW, UR_DELETED ...
*/
void WinEDA_SchematicFrame::SaveCopyInUndoList( PICKED_ITEMS_LIST& aItemsList, int aTypeCommand )
void WinEDA_SchematicFrame::SaveCopyInUndoList( PICKED_ITEMS_LIST& aItemsList,
UndoRedoOpType aTypeCommand,
const wxPoint& aTransformPoint )
{
SCH_ITEM* CopyOfItem;
PICKED_ITEMS_LIST* commandToUndo = new PICKED_ITEMS_LIST();
commandToUndo->m_TransformPoint = aTransformPoint;
commandToUndo->m_UndoRedoType = aTypeCommand;
ITEM_PICKER itemWrapper;
for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
{
SCH_ITEM* ItemToCopy = (SCH_ITEM*) aItemsList.GetItemData( ii );
int command = aItemsList.GetItemStatus( ii );
if( command == 0 )
UndoRedoOpType command = aItemsList.GetItemStatus( ii );
if( command == UR_UNSPECIFIED )
{
command = aTypeCommand;
}
......@@ -259,20 +267,21 @@ void WinEDA_SchematicFrame::SaveCopyInUndoList( PICKED_ITEMS_LIST& aItemsList, i
itemWrapper.m_UndoRedoStatus = command;
switch( command )
{
case IS_CHANGED: /* Create a copy of schematic */
case UR_CHANGED: /* Create a copy of schematic */
CopyOfItem = DuplicateStruct( ItemToCopy );
itemWrapper.m_Item = CopyOfItem;
itemWrapper.m_Link = ItemToCopy;
commandToUndo->PushItem( itemWrapper );
break;
case IS_NEW:
case IS_NEW | IS_CHANGED: // when more than one item, some are new, some are changed
case UR_MOVED:
case UR_MIRRORED_Y:
case UR_NEW:
commandToUndo->PushItem( itemWrapper );
break;
case IS_DELETED:
ItemToCopy->m_Flags = IS_DELETED;
case UR_DELETED:
ItemToCopy->m_Flags = UR_DELETED;
commandToUndo->PushItem( itemWrapper );
break;
......@@ -344,26 +353,38 @@ void WinEDA_SchematicFrame::PutDataInPreviousState( PICKED_ITEMS_LIST* aList )
SCH_ITEM* image = (SCH_ITEM*) itemWrapper.m_Link;
switch( itemWrapper.m_UndoRedoStatus )
{
case IS_CHANGED: /* Exchange old and new data for each item */
case UR_CHANGED: /* Exchange old and new data for each item */
SwapData( item, image );
break;
case IS_NEW: /* new items are deleted */
aList->m_UndoRedoType = IS_DELETED;
aList->SetItemStatus( IS_DELETED, ii );
case UR_NEW: /* new items are deleted */
aList->SetItemStatus( UR_DELETED, ii );
GetScreen()->RemoveFromDrawList( item );
item->m_Flags = IS_DELETED;
item->m_Flags = UR_DELETED;
break;
case IS_DELETED: /* deleted items are put in EEdrawList, as new items */
aList->m_UndoRedoType = IS_NEW;
aList->SetItemStatus( IS_NEW, ii );
case UR_DELETED: /* deleted items are put in EEdrawList, as new items */
aList->SetItemStatus( UR_NEW, ii );
item->SetNext( GetScreen()->EEDrawList );
GetScreen()->EEDrawList = item;
item->m_Flags = 0;
break;
case IS_WIRE_IMAGE:
case UR_MOVED:
{
wxPoint moveVector = - aList->m_TransformPoint;
MoveOneStruct( item, moveVector );
}
break;
case UR_MIRRORED_Y:
{
wxPoint mirrorPoint = aList->m_TransformPoint;
MirrorOneStruct( item, mirrorPoint );
}
break;
case UR_WIRE_IMAGE:
/* Exchange the current wires and the old wires */
alt_item = GetScreen()->ExtractWires( false );
aList->SetItem( alt_item, ii );
......@@ -422,14 +443,14 @@ bool WinEDA_SchematicFrame::GetSchematicFromUndoList()
}
/*********************************************************/
/***********************************************************************************/
void SCH_SCREEN::ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount )
/*********************************************************/
/**********************************************************************************/
/** Function ClearUndoORRedoList
* free the undo or redo list from List element
* Wrappers are deleted.
* datas pointed by wrappers are deleted if not flagged IS_NEW
* datas pointed by wrappers are deleted if not flagged UR_NEW
* because they are copy of used data or they are not in use (DELETED)
* @param aList = the UNDO_REDO_CONTAINER to clear
* @param aItemCount = the count of items to remove. < 0 for all items
......@@ -437,8 +458,6 @@ void SCH_SCREEN::ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount
* So this function can be called to remove old commands
*/
{
int CmdType;
if( aItemCount == 0 )
return;
......@@ -451,30 +470,36 @@ void SCH_SCREEN::ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount
break;
PICKED_ITEMS_LIST* curr_cmd = aList.m_CommandsList[0];
aList.m_CommandsList.erase( aList.m_CommandsList.begin() );
CmdType = curr_cmd->m_UndoRedoType;
// Delete items is they are not flagged IS_NEW
// Delete items is they are not flagged UR_NEW, or if this is a block operation
while( 1 )
{
ITEM_PICKER wrapper = curr_cmd->PopItem();
EDA_BaseStruct* item = wrapper.m_Item;
if( item == NULL ) // No more item in list.
break;
if( wrapper.m_UndoRedoStatus == IS_WIRE_IMAGE )
switch( wrapper.m_UndoRedoStatus )
{
case UR_WIRE_IMAGE:
while( item )
{
EDA_BaseStruct* nextitem = item->Next();
delete item;
item = nextitem;
}
}
else
{
if( (wrapper.m_UndoRedoStatus & IS_NEW) == 0 )
{
break;
case UR_MOVED:
case UR_MIRRORED_X:
case UR_MIRRORED_Y:
case UR_ROTATED:
case UR_NEW: // Do nothing, items are in use
break;
default:
delete item;
}
break;
}
}
......
......@@ -45,10 +45,26 @@
* and they are undo/redo by the same command
*/
/* Type of undo/redo operations
* each type must be redo/undoed by a specfic operation
*/
enum UndoRedoOpType {
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
UR_NEW, // new item, undo by changing in deleted
UR_DELETED, // deleted item, undo by changing in deleted
UR_MOVED, // moved item, undo by move it
UR_MIRRORED_X, // mirrored item, undo by mirror X
UR_MIRRORED_Y, // mirrored item, undo by mirror Y
UR_ROTATED, // Rotated item, undo by rotating it
UR_FLIPPED, // flipped (board items only), undo by flipping it
UR_WIRE_IMAGE // Specific to eeschema: handle wires changes
};
class ITEM_PICKER
{
public:
int m_UndoRedoStatus; // type of operation to undo/redo for this item
UndoRedoOpType m_UndoRedoStatus; /* type of operation to undo/redo for this item */
EDA_BaseStruct* m_Item; /* Pointer on the schematic or board item that is concerned,
* or in undo redo commands, the copy of an edited item.
*/
......@@ -60,7 +76,7 @@ public:
*/
public:
ITEM_PICKER( EDA_BaseStruct* aItem = NULL, int aUndoRedoStatus = 0 )
ITEM_PICKER( EDA_BaseStruct* aItem = NULL, UndoRedoOpType aUndoRedoStatus = UR_UNSPECIFIED )
{
m_UndoRedoStatus = aUndoRedoStatus;
m_Item = aItem;
......@@ -76,10 +92,10 @@ public:
class PICKED_ITEMS_LIST
{
public:
int m_UndoRedoType; // type of operation to undo/redo
// UNSPECIFIED (0), IS_NEW, IS_DELETED, IS_CHANGED
wxPoint m_TransformPoint; // used to undo redo command by the same command:
// we usually need to know the rotate point or the move vector
UndoRedoOpType 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:
* we usually need to know the rotate point or the move vector
*/
private:
std::vector <ITEM_PICKER> m_ItemsList;
......@@ -108,18 +124,18 @@ public:
ITEM_PICKER GetItemWrapper( unsigned int aIdx );
EDA_BaseStruct* GetItemData( unsigned int aIdx );
EDA_BaseStruct* GetImage( unsigned int aIdx );
int GetItemStatus( unsigned int aIdx );
UndoRedoOpType GetItemStatus( unsigned int aIdx );
bool SetItem( EDA_BaseStruct* aItem, unsigned aIdx );
bool SetItem( EDA_BaseStruct* aItem, int aStatus, unsigned aIdx );
bool SetItem( EDA_BaseStruct* aItem, UndoRedoOpType aStatus, unsigned aIdx );
bool SetLink( EDA_BaseStruct* aItem, unsigned aIdx );
bool SetItemStatus( int aStatus, unsigned aIdx );
bool SetItemStatus( UndoRedoOpType aStatus, unsigned aIdx );
bool RemoveItem( unsigned aIdx );
/** Function CopyList
* copy all data from aSource
* Items picked are not copied. just pointer on them are copied
*/
void CopyList(const PICKED_ITEMS_LIST & aSource);
void CopyList( const PICKED_ITEMS_LIST& aSource );
};
/**
......
......@@ -339,8 +339,6 @@ int ReturnValueFromTextCtrl( const wxTextCtrl& TextCtr,
int Internal_Unit );
/* return a String List from a string, whith a specific splitter*/
//WX_DECLARE_LIST( wxString, StringList );
//WX_DEFINE_LIST( StringList );
wxArrayString* wxStringSplit(wxString txt, wxChar splitter);
/**
......
......@@ -8,6 +8,7 @@
#include "wxstruct.h"
#include "param_config.h"
#include "class_undoredo_container.h"
class WinEDA_LibeditFrame;
......@@ -33,7 +34,7 @@ class LibDrawField;
class SCH_CMP_FIELD;
class LibDrawPin;
class DrawJunctionStruct;
class PICKED_ITEMS_LIST;
/*******************************/
/* class WinEDA_SchematicFrame */
......@@ -368,8 +369,26 @@ private:
/* Undo - redo */
public:
void SaveCopyInUndoList( SCH_ITEM* ItemToCopy, int aTypeCommand );
void SaveCopyInUndoList( PICKED_ITEMS_LIST& aItemsList, int aTypeCommand );
/** Function SaveCopyInUndoList.
* Creates a new entry in undo list of commands.
* add a picker to handle aItemToCopy
* @param aItemToCopy = the schematic item modified by the command to undo
* @param aTypeCommand = command type (see enum UndoRedoOpType)
* @param aTransformPoint = the reference point of the transformation, for commands like move
*/
void SaveCopyInUndoList( SCH_ITEM* aItemToCopy, UndoRedoOpType 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 aTransformPoint = the reference point of the transformation, for commands like move
*/
void SaveCopyInUndoList( PICKED_ITEMS_LIST& aItemsList, UndoRedoOpType aTypeCommand,
const wxPoint& aTransformPoint = wxPoint(0,0) );
private:
void PutDataInPreviousState( PICKED_ITEMS_LIST* aList );
......
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