libedit_undo_redo.cpp 2.91 KB
Newer Older
1 2 3
/********************************************/
/*  library editor: undo and redo functions */
/********************************************/
4

5 6
#include <fctsys.h>
#include <class_drawpanel.h>
7

8 9 10 11
#include <general.h>
#include <protos.h>
#include <libeditframe.h>
#include <class_libentry.h>
12 13


14
void LIB_EDIT_FRAME::SaveCopyInUndoList( EDA_ITEM* ItemToCopy, int unused_flag )
15
{
16
    LIB_COMPONENT*     CopyItem;
charras's avatar
charras committed
17
    PICKED_ITEMS_LIST* lastcmd;
18

19
    CopyItem = new LIB_COMPONENT( *( (LIB_COMPONENT*) ItemToCopy ) );
20

21 22
    // Clear current flags (which can be temporary set by a current edit command).
    CopyItem->ClearStatus();
charras's avatar
charras committed
23 24

    lastcmd = new PICKED_ITEMS_LIST();
25
    ITEM_PICKER wrapper( CopyItem, UR_LIBEDIT );
charras's avatar
charras committed
26 27
    lastcmd->PushItem(wrapper);
    GetScreen()->PushCommandToUndoList( lastcmd );
28 29

    // Clear redo list, because after new save there is no redo to do.
30
    GetScreen()->ClearUndoORRedoList( GetScreen()->m_RedoList );
31 32
}

33

34
/* Redo the last edition:
35 36
 * - Place the current edited library component in undo list
 * - Get old version of the current edited library component
37
 */
38
void LIB_EDIT_FRAME::GetComponentFromRedoList( wxCommandEvent& event )
39
{
charras's avatar
charras committed
40
    if ( GetScreen()->GetRedoCommandCount() <= 0 )
41
        return;
charras's avatar
charras committed
42 43

    PICKED_ITEMS_LIST* lastcmd = new PICKED_ITEMS_LIST();
44 45
    ITEM_PICKER wrapper( m_component, UR_LIBEDIT );
    lastcmd->PushItem( wrapper );
charras's avatar
charras committed
46 47
    GetScreen()->PushCommandToUndoList( lastcmd );

48
    lastcmd = GetScreen()->PopCommandFromRedoList();
49

charras's avatar
charras committed
50
    wrapper = lastcmd->PopItem();
51
    m_component = (LIB_COMPONENT*) wrapper.GetItem();
52 53 54 55 56 57 58

    if( m_component == NULL )
        return;

    if( !m_aliasName.IsEmpty() && !m_component->HasAlias( m_aliasName ) )
        m_aliasName = m_component->GetName();

59
    m_drawItem = NULL;
60 61
    UpdateAliasSelectList();
    UpdatePartSelectList();
62
    SetShowDeMorgan( m_component->HasConversion() );
63 64
    DisplayLibInfos();
    DisplayCmpDoc();
65 66
    OnModify();
    m_canvas->Refresh();
plyatov's avatar
plyatov committed
67
}
68

69

70
/** Undo the last edition:
71 72
 * - Place the current edited library component in Redo list
 * - Get old version of the current edited library component
73
 */
74
void LIB_EDIT_FRAME::GetComponentFromUndoList( wxCommandEvent& event )
75
{
charras's avatar
charras committed
76
    if ( GetScreen()->GetUndoCommandCount() <= 0 )
77
        return;
charras's avatar
charras committed
78 79

    PICKED_ITEMS_LIST* lastcmd = new PICKED_ITEMS_LIST();
80 81
    ITEM_PICKER wrapper( m_component, UR_LIBEDIT );
    lastcmd->PushItem( wrapper );
charras's avatar
charras committed
82 83
    GetScreen()->PushCommandToRedoList( lastcmd );

84
    lastcmd = GetScreen()->PopCommandFromUndoList();
85

charras's avatar
charras committed
86
    wrapper = lastcmd->PopItem();
87
    m_component = (LIB_COMPONENT*) wrapper.GetItem();
88

89 90 91 92 93 94
    if( m_component == NULL )
        return;

    if( !m_aliasName.IsEmpty() && !m_component->HasAlias( m_aliasName ) )
        m_aliasName = m_component->GetName();

95
    m_drawItem = NULL;
96 97
    UpdateAliasSelectList();
    UpdatePartSelectList();
98
    SetShowDeMorgan( m_component->HasConversion() );
99 100
    DisplayLibInfos();
    DisplayCmpDoc();
101
    OnModify();
102
    m_canvas->Refresh();
plyatov's avatar
plyatov committed
103
}