Commit f9be70f2 authored by charras's avatar charras
Browse files

pcbnew: work on undo/redo in progress Only delete commands are stored in undo/redo stack

parent 42022adb
Loading
Loading
Loading
Loading
+70 −13
Original line number Diff line number Diff line
@@ -30,6 +30,16 @@
#include "base_struct.h"
#include "class_undoredo_container.h"


ITEM_PICKER::ITEM_PICKER( EDA_BaseStruct* aItem, UndoRedoOpType aUndoRedoStatus )
{
    m_UndoRedoStatus = aUndoRedoStatus;
    m_PickedItem = aItem;
    m_PickedItemType = TYPE_NOT_INIT;
    m_Link = NULL;
}


PICKED_ITEMS_LIST::PICKED_ITEMS_LIST()
{
    m_Status = UR_UNSPECIFIED;
@@ -70,11 +80,17 @@ void PICKED_ITEMS_LIST::PICKED_ITEMS_LIST::ClearItemsList()
void PICKED_ITEMS_LIST::ClearListAndDeleteItems()
{
    for(unsigned ii = 0; ii < m_ItemsList.size(); ii++ )
        delete m_ItemsList[ii].m_Item;
        delete m_ItemsList[ii].m_PickedItem;
    m_ItemsList.clear();
}


/** function GetItemWrapper
 * @return the picker of a picked item
 * @param aIdx = index of the picker in the picked list
 * if this picker does not exist, a picker is returned,
 * with its members set to 0 or NULL
 */
ITEM_PICKER PICKED_ITEMS_LIST::GetItemWrapper( unsigned int aIdx )
{
    ITEM_PICKER picker;
@@ -84,16 +100,24 @@ ITEM_PICKER PICKED_ITEMS_LIST::GetItemWrapper( unsigned int aIdx )
    return picker;
}

EDA_BaseStruct* PICKED_ITEMS_LIST::GetItemData( unsigned int aIdx )
/** function GetPickedItem
 * @return a pointer to the picked item, or null if does not exist
 * @param aIdx = index of the picked item in the picked list
 */
EDA_BaseStruct* PICKED_ITEMS_LIST::GetPickedItem( unsigned int aIdx )
{
    if( aIdx < m_ItemsList.size() )
        return m_ItemsList[aIdx].m_Item;
        return m_ItemsList[aIdx].m_PickedItem;
    else
        return NULL;
}


EDA_BaseStruct* PICKED_ITEMS_LIST::GetImage( unsigned int aIdx )
/** function GetLink
 * @return link of the picked item, or null if does not exist
 * @param aIdx = index of the picked item in the picked list
 */
EDA_BaseStruct* PICKED_ITEMS_LIST::GetLink( unsigned int aIdx )
{
    if( aIdx < m_ItemsList.size() )
        return m_ItemsList[aIdx].m_Link;
@@ -102,7 +126,12 @@ EDA_BaseStruct* PICKED_ITEMS_LIST::GetImage( unsigned int aIdx )
}


UndoRedoOpType PICKED_ITEMS_LIST::GetItemStatus( unsigned int aIdx )
/** function GetPickedItemStatus
 * @return the type of undo/redo opertaion associated to the picked item,
 *   or UR_UNSPECIFIED if does not exist
 * @param aIdx = index of the picked item in the picked list
 */
UndoRedoOpType PICKED_ITEMS_LIST::GetPickedItemStatus( unsigned int aIdx )
{
    if( aIdx < m_ItemsList.size() )
        return m_ItemsList[aIdx].m_UndoRedoStatus;
@@ -111,11 +140,16 @@ UndoRedoOpType PICKED_ITEMS_LIST::GetItemStatus( unsigned int aIdx )
}


bool PICKED_ITEMS_LIST::SetItem( EDA_BaseStruct* aItem, unsigned aIdx )
/** function SetPickedItem
 * @param aItem = a pointer to the item to pick
 * @param aIdx = index of the picker in the picked list
 * @return true if the picker exists, or false if does not exist
 */
bool PICKED_ITEMS_LIST::SetPickedItem( EDA_BaseStruct* aItem, unsigned aIdx )
{
    if( aIdx < m_ItemsList.size() )
    {
        m_ItemsList[aIdx].m_Item = aItem;
        m_ItemsList[aIdx].m_PickedItem = aItem;
        return true;
    }
    else
@@ -123,11 +157,17 @@ bool PICKED_ITEMS_LIST::SetItem( EDA_BaseStruct* aItem, unsigned aIdx )
}


bool PICKED_ITEMS_LIST::SetLink( EDA_BaseStruct* aItem, unsigned aIdx )
/** function SetLink
 * Set the link associated to a given picked item
 * @param aLink = the link to the item associated to the picked item
 * @param aIdx = index of the picker in the picked list
 * @return true if the picker exists, or false if does not exist
 */
bool PICKED_ITEMS_LIST::SetLink( EDA_BaseStruct* aLink, unsigned aIdx )
{
    if( aIdx < m_ItemsList.size() )
    {
        m_ItemsList[aIdx].m_Link = aItem;
        m_ItemsList[aIdx].m_Link = aLink;
        return true;
    }
    else
@@ -135,11 +175,17 @@ bool PICKED_ITEMS_LIST::SetLink( EDA_BaseStruct* aItem, unsigned aIdx )
}


bool PICKED_ITEMS_LIST::SetItem( EDA_BaseStruct* aItem, UndoRedoOpType aStatus, unsigned aIdx )
/** function SetPickedItem
 * @param aItem = a pointer to the item to pick
 * @param aStatus = the type of undo/redo operation associated to the item to pick
 * @param aIdx = index of the picker in the picked list
 * @return true if the picker exists, or false if does not exist
 */
bool PICKED_ITEMS_LIST::SetPickedItem( EDA_BaseStruct* aItem, UndoRedoOpType aStatus, unsigned aIdx )
{
    if( aIdx < m_ItemsList.size() )
    {
        m_ItemsList[aIdx].m_Item = aItem;
        m_ItemsList[aIdx].m_PickedItem = aItem;
        m_ItemsList[aIdx].m_UndoRedoStatus = aStatus;
        return true;
    }
@@ -148,7 +194,13 @@ bool PICKED_ITEMS_LIST::SetItem( EDA_BaseStruct* aItem, UndoRedoOpType aStatus,
}


bool PICKED_ITEMS_LIST::SetItemStatus( UndoRedoOpType aStatus, unsigned aIdx )
/** function SetPickedItemStatus
 * Set the the type of undo/redo operation for a given picked item
 * @param aStatus = the type of undo/redo operation associated to the picked item
 * @param aIdx = index of the picker in the picked list
 * @return true if the picker exists, or false if does not exist
 */
bool PICKED_ITEMS_LIST::SetPickedItemStatus( UndoRedoOpType aStatus, unsigned aIdx )
{
    if( aIdx < m_ItemsList.size() )
    {
@@ -160,7 +212,12 @@ bool PICKED_ITEMS_LIST::SetItemStatus( UndoRedoOpType aStatus, unsigned aIdx )
}


bool PICKED_ITEMS_LIST::RemoveItem( unsigned aIdx )
/** function RemovePickedItem
 * remove one entry (one picker) from the list of picked items
 * @param aIdx = index of the picker in the picked list
 * @return true if ok, or false if did not exist
 */
bool PICKED_ITEMS_LIST::RemovePickedItem( unsigned aIdx )
{
    if( aIdx >= m_ItemsList.size() )
        return false;
+13 −18
Original line number Diff line number Diff line
@@ -479,7 +479,7 @@ static void DrawMovingBlockOutlines( WinEDA_DrawPanel* panel, wxDC* DC,
        block->Draw( panel, DC, block->m_MoveVector, g_XorMode, block->m_Color );
        for( unsigned ii = 0; ii < block->GetCount(); ii++ )
        {
            schitem = (SCH_ITEM*) block->m_ItemsSelection.GetItemData( ii );
            schitem = (SCH_ITEM*) block->m_ItemsSelection.GetPickedItem( ii );
            DrawStructsInGhost( panel, DC, schitem, block->m_MoveVector );
        }
    }
@@ -492,7 +492,7 @@ static void DrawMovingBlockOutlines( WinEDA_DrawPanel* panel, wxDC* DC,

    for( unsigned ii = 0; ii < block->GetCount(); ii++ )
    {
        schitem = (SCH_ITEM*) block->m_ItemsSelection.GetItemData( ii );
        schitem = (SCH_ITEM*) block->m_ItemsSelection.GetPickedItem( ii );
        DrawStructsInGhost( panel, DC, schitem, block->m_MoveVector );
    }
}
@@ -515,9 +515,9 @@ void SaveStructListForPaste( PICKED_ITEMS_LIST& aItemsList )
    for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
    {
        /* Make a copy of the original picked item. */
        SCH_ITEM* DrawStructCopy = DuplicateStruct( (SCH_ITEM*) aItemsList.GetItemData( ii ) );
        SCH_ITEM* DrawStructCopy = DuplicateStruct( (SCH_ITEM*) aItemsList.GetPickedItem( ii ) );
        DrawStructCopy->SetParent( NULL );
        item.m_Item = DrawStructCopy;
        item.m_PickedItem = DrawStructCopy;
        g_BlockSaveDataList.PushItem( item );
    }
}
@@ -543,8 +543,8 @@ void WinEDA_SchematicFrame::PasteListOfItems( wxDC* DC )
    ITEM_PICKER picker( NULL, UR_NEW );
    for( unsigned ii = 0; ii < g_BlockSaveDataList.GetCount(); ii++ )
    {
        Struct = DuplicateStruct( (SCH_ITEM*) g_BlockSaveDataList.m_ItemsSelection.GetItemData( ii ) );
        picker.m_Item = Struct;
        Struct = DuplicateStruct( (SCH_ITEM*) g_BlockSaveDataList.m_ItemsSelection.GetPickedItem( ii ) );
        picker.m_PickedItem = Struct;
        picklist.PushItem( picker );

        // Clear annotation and init new time stamp for the new components:
@@ -600,7 +600,7 @@ static void CollectStructsToDrag( SCH_SCREEN* screen )
    // Sel .m_Flags to selected for a wire or bus in selected area if there is only one item:
    if( pickedlist->GetCount() == 1 )
    {
        Struct = (SCH_ITEM*) pickedlist->GetItemData( 0 );
        Struct = (SCH_ITEM*) pickedlist->GetPickedItem( 0 );
        if( Struct->Type() == DRAW_SEGMENT_STRUCT_TYPE )
            Struct->m_Flags = SELECTED;
    }
@@ -609,7 +609,7 @@ static void CollectStructsToDrag( SCH_SCREEN* screen )
    {
        for( unsigned ii = 0; ii < pickedlist->GetCount(); ii++ )
        {
            Struct = (SCH_ITEM*)(SCH_ITEM*) pickedlist->GetItemData( ii );
            Struct = (SCH_ITEM*)(SCH_ITEM*) pickedlist->GetPickedItem( ii );
            Struct->m_Flags = SELECTED;
        }
    }
@@ -632,7 +632,7 @@ static void CollectStructsToDrag( SCH_SCREEN* screen )
     *  de selection */
    for( unsigned ii = 0; ii < pickedlist->GetCount(); ii++ )
    {
        Struct = (SCH_ITEM*)(SCH_ITEM*) pickedlist->GetItemData( ii );
        Struct = (SCH_ITEM*)(SCH_ITEM*) pickedlist->GetPickedItem( ii );
        if( Struct->Type() == DRAW_SEGMENT_STRUCT_TYPE )
        {
            SegmStruct = (EDA_DrawLineStruct*) Struct;
@@ -651,7 +651,7 @@ static void CollectStructsToDrag( SCH_SCREEN* screen )

    for( unsigned ii = 0; ii < pickedlist->GetCount(); ii++ )
    {
        Struct = (SCH_ITEM*)(SCH_ITEM*) pickedlist->GetItemData( ii );
        Struct = (SCH_ITEM*)(SCH_ITEM*) pickedlist->GetPickedItem( ii );
        if( Struct->Type() == TYPE_SCH_COMPONENT )
        {
            // Add all pins of the selected component to list
@@ -712,7 +712,7 @@ static void AddPickedItem( SCH_SCREEN* screen, wxPoint position )

    for( unsigned ii = 0; ii < pickedlist->GetCount(); ii++ )
    {
        Struct = (SCH_ITEM*) pickedlist->GetItemData( ii );
        Struct = (SCH_ITEM*) pickedlist->GetPickedItem( ii );

        switch( Struct->Type() )
        {
@@ -737,6 +737,8 @@ static void AddPickedItem( SCH_SCREEN* screen, wxPoint position )
    Struct = screen->EEDrawList;
    while( Struct )
    {
        picker.m_PickedItem    = Struct;
        picker.m_PickedItemType = Struct->Type();
        switch( Struct->Type() )
        {
        case TYPE_NOT_INIT:
@@ -754,7 +756,6 @@ static void AddPickedItem( SCH_SCREEN* screen, wxPoint position )
                break; /* Deja en liste */
            if( STRUCT->m_Pos != position )
                break;
            picker.m_Item = Struct;
            pickedlist->PushItem( picker );
            break;

@@ -767,14 +768,12 @@ static void AddPickedItem( SCH_SCREEN* screen, wxPoint position )
            {
                Struct->m_Flags  = SELECTED | ENDPOINT | STARTPOINT;
                Struct->m_Flags &= ~STARTPOINT;
                picker.m_Item    = Struct;
                pickedlist->PushItem( picker );
            }
            else if( STRUCT->m_End == position )
            {
                Struct->m_Flags  = SELECTED | ENDPOINT | STARTPOINT;
                Struct->m_Flags &= ~ENDPOINT;
                picker.m_Item    = Struct;
                pickedlist->PushItem( picker );
            }
            break;
@@ -793,7 +792,6 @@ static void AddPickedItem( SCH_SCREEN* screen, wxPoint position )
            if( STRUCT->m_Pos != position )
                break;
            Struct->m_Flags |= SELECTED;
            picker.m_Item    = Struct;
            pickedlist->PushItem( picker );
            break;

@@ -806,7 +804,6 @@ static void AddPickedItem( SCH_SCREEN* screen, wxPoint position )
            if( STRUCT->m_Pos != position )
                break;
            Struct->m_Flags |= SELECTED;
            picker.m_Item    = Struct;
            pickedlist->PushItem( picker );
            break;

@@ -823,7 +820,6 @@ static void AddPickedItem( SCH_SCREEN* screen, wxPoint position )
            if( STRUCT->m_Pos != position )
                break;
            Struct->m_Flags |= SELECTED;
            picker.m_Item    = Struct;
            pickedlist->PushItem( picker );
            break;

@@ -835,7 +831,6 @@ static void AddPickedItem( SCH_SCREEN* screen, wxPoint position )
            if( STRUCT->m_Pos != position )
                break;
            Struct->m_Flags |= SELECTED;
            picker.m_Item    = Struct;
            pickedlist->PushItem( picker );
            break;

+8 −4
Original line number Diff line number Diff line
@@ -149,7 +149,8 @@ void WinEDA_SchematicFrame::DeleteConnection( bool DeleteFullConnection )
        DelStruct->m_Flags = SELECTEDNODE | STRUCT_DELETED;

        /* Put this structure in the picked list: */
        picker.m_Item = DelStruct;
        picker.m_PickedItem = DelStruct;
        picker.m_PickedItemType = DelStruct->Type();
        pickList.PushItem(picker);

        DelStruct  = DelStruct->Next();
@@ -237,7 +238,8 @@ void WinEDA_SchematicFrame::DeleteConnection( bool DeleteFullConnection )
            {
                DelStruct->m_Flags |= STRUCT_DELETED;
                /* Put this structure in the picked list: */
                picker.m_Item = DelStruct;
                picker.m_PickedItem = DelStruct;
                picker.m_PickedItemType = DelStruct->Type();
                pickList.PushItem(picker);

                DelStruct  = GetScreen()->EEDrawList;
@@ -264,7 +266,8 @@ void WinEDA_SchematicFrame::DeleteConnection( bool DeleteFullConnection )
                    DelStruct->m_Flags |= STRUCT_DELETED;

                    /* Put this structure in the picked list: */
                    picker.m_Item = DelStruct;
                    picker.m_PickedItem = DelStruct;
                    picker.m_PickedItemType = DelStruct->Type();
                    pickList.PushItem(picker);
                }
                #undef JUNCTION
@@ -290,7 +293,8 @@ void WinEDA_SchematicFrame::DeleteConnection( bool DeleteFullConnection )
                DelStruct->m_Flags |= STRUCT_DELETED;

                /* Put this structure in the picked list: */
                picker.m_Item = DelStruct;
                picker.m_PickedItem = DelStruct;
                picker.m_PickedItemType = DelStruct->Type();
                pickList.PushItem(picker);
            }
        }
+4 −4
Original line number Diff line number Diff line
@@ -39,9 +39,9 @@ void WinEDA_LibeditFrame::SaveCopyInUndoList( EDA_BaseStruct* ItemToCopy,
        while ( 1 )
        {
            wrapper = lastcmd->PopItem();
            if ( wrapper.m_Item == NULL )
            if ( wrapper.m_PickedItem == NULL )
                break;      // All items are removed
            delete wrapper.m_Item;
            delete wrapper.m_PickedItem;
        }
        delete lastcmd;
    }
@@ -69,7 +69,7 @@ void WinEDA_LibeditFrame::GetComponentFromRedoList(wxCommandEvent& event)
    lastcmd = GetScreen()->PopCommandFromRedoList( );

    wrapper = lastcmd->PopItem();
    CurrentLibEntry = (EDA_LibComponentStruct*) wrapper.m_Item;
    CurrentLibEntry = (EDA_LibComponentStruct*) wrapper.m_PickedItem;
    if( CurrentLibEntry )
        CurrentLibEntry->SetNext( NULL );
    CurrentDrawItem = NULL;
@@ -102,7 +102,7 @@ void WinEDA_LibeditFrame::GetComponentFromUndoList(wxCommandEvent& event)
    lastcmd = GetScreen()->PopCommandFromUndoList( );

    wrapper = lastcmd->PopItem();
    CurrentLibEntry = (EDA_LibComponentStruct*) wrapper.m_Item;
    CurrentLibEntry = (EDA_LibComponentStruct*) wrapper.m_PickedItem;

    if( CurrentLibEntry )
        CurrentLibEntry->SetNext( NULL );
+2 −1
Original line number Diff line number Diff line
@@ -149,7 +149,8 @@ int PickItemsInBlock( BLOCK_SELECTOR& aBlock, BASE_SCREEN* aScreen )
        if( DrawStructInBox( OrigX, OrigY, x, y, DrawStruct ) )
        {
            /* Put this structure in the picked list: */
            picker.m_Item = DrawStruct;
            picker.m_PickedItem = DrawStruct;
            picker.m_PickedItemType = DrawStruct->Type();
            aBlock.PushItem(picker);
            itemcount++;
        }
Loading