Commit 5699ee3b authored by charras's avatar charras
Browse files

More about pcbnew undo/redo

parent d9ea63a8
Loading
Loading
Loading
Loading
+95 −13
Original line number Original line Diff line number Diff line
@@ -50,12 +50,20 @@ PICKED_ITEMS_LIST::~PICKED_ITEMS_LIST()
}
}




/** PushItem
 * push a picker to the top of the list
 * @param aItem = picker to push
 */
void PICKED_ITEMS_LIST::PushItem( ITEM_PICKER& aItem )
void PICKED_ITEMS_LIST::PushItem( ITEM_PICKER& aItem )
{
{
    m_ItemsList.push_back( aItem );
    m_ItemsList.push_back( aItem );
}
}




/** PopItem
 * @return the picker from the top of the list
 * the picker is removed from the list
 */
ITEM_PICKER PICKED_ITEMS_LIST::PICKED_ITEMS_LIST::PopItem()
ITEM_PICKER PICKED_ITEMS_LIST::PICKED_ITEMS_LIST::PopItem()
{
{
    ITEM_PICKER item;
    ITEM_PICKER item;
@@ -69,19 +77,87 @@ ITEM_PICKER PICKED_ITEMS_LIST::PICKED_ITEMS_LIST::PopItem()
}
}




void PICKED_ITEMS_LIST::PICKED_ITEMS_LIST::ClearItemsList()
/** Function ClearItemsList

 * delete only the list of pickers, NOT the picked data itself
/* delete only the list of EDA_BaseStruct * pointers, NOT the pointed data itself
 */
 */
void PICKED_ITEMS_LIST::PICKED_ITEMS_LIST::ClearItemsList()
{
{
    m_ItemsList.clear();
    m_ItemsList.clear();
}
}



/** Function ClearListAndDeleteItems
 * delete the list of pickers, AND the data pointed
 * by m_PickedItem or m_PickedItemLink, according to the type of undo/redo command recorded
 */
void PICKED_ITEMS_LIST::ClearListAndDeleteItems()
void PICKED_ITEMS_LIST::ClearListAndDeleteItems()
{
{
    for(unsigned ii = 0; ii < m_ItemsList.size(); ii++ )
    bool show_error_message = true;
        delete m_ItemsList[ii].m_PickedItem;

    m_ItemsList.clear();
    // Delete items is they are not flagged UR_NEW, or if this is a block operation
    while( GetCount() > 0 )
    {
        ITEM_PICKER wrapper = PopItem();
        if( wrapper.m_PickedItem == NULL ) // No more item in list.
            break;
        switch( wrapper.m_UndoRedoStatus )
        {
        case UR_UNSPECIFIED:
            if( show_error_message )
                wxMessageBox( wxT( "ClearUndoORRedoList() error: UR_UNSPECIFIED command type" ) );
            show_error_message = false;
            break;

        case UR_WIRE_IMAGE:
        {
            // Specific to eeschema: a linked list of wires is stored.
            // the wrapper picks only the first item (head of list), and is owner of all picked items
            EDA_BaseStruct* item = wrapper.m_PickedItem;
            while( item )
            {
                // Delete old copy of wires
                EDA_BaseStruct* nextitem = item->Next();
                delete item;
                item = nextitem;
            }
        }
        break;

        case UR_MOVED:
        case UR_FLIPPED:
        case UR_MIRRORED_X:
        case UR_MIRRORED_Y:
        case UR_ROTATED:
        case UR_ROTATED_CLOCKWISE:
        case UR_NEW:        // Do nothing, items are in use, the picker is not owner of items
            break;

        case UR_CHANGED:
            delete wrapper.m_Link;   //  the picker is owner of this item
            break;

        case UR_DELETED:            // the picker is owner of this item
        case UR_LIBEDIT:            /* Libedit save always a copy of the current item
                                     *  So, the picker is always owner of the picked item
                                     */
        case UR_MODEDIT:            /* Specific to the module editor
                                     *  (modedit creates a full copy of the current module when changed),
                                     *  and the picker is owner of this item
                                     */
            delete wrapper.m_PickedItem;
            break;

        default:
        {
            wxString msg;
            msg.Printf( wxT(
                            "ClearUndoORRedoList() error: unknown command type %d" ),
                        wrapper.m_UndoRedoStatus );
            wxMessageBox( msg );
        }
        break;
        }
    }
}
}




@@ -94,12 +170,14 @@ void PICKED_ITEMS_LIST::ClearListAndDeleteItems()
ITEM_PICKER PICKED_ITEMS_LIST::GetItemWrapper( unsigned int aIdx )
ITEM_PICKER PICKED_ITEMS_LIST::GetItemWrapper( unsigned int aIdx )
{
{
    ITEM_PICKER picker;
    ITEM_PICKER picker;

    if( aIdx < m_ItemsList.size() )
    if( aIdx < m_ItemsList.size() )
        picker = m_ItemsList[aIdx];
        picker = m_ItemsList[aIdx];


    return picker;
    return picker;
}
}



/** function GetPickedItem
/** function GetPickedItem
 * @return a pointer to the picked item, or null if does not exist
 * @return a pointer to the picked item, or null if does not exist
 * @param aIdx = index of the picked item in the picked list
 * @param aIdx = index of the picked item in the picked list
@@ -181,7 +259,9 @@ bool PICKED_ITEMS_LIST::SetPickedItemLink( EDA_BaseStruct* aLink, unsigned aIdx
 * @param aIdx = index of the picker in the picked list
 * @param aIdx = index of the picker in the picked list
 * @return true if the picker exists, or false if does not exist
 * @return true if the picker exists, or false if does not exist
 */
 */
bool PICKED_ITEMS_LIST::SetPickedItem( EDA_BaseStruct* aItem, UndoRedoOpType aStatus, unsigned aIdx )
bool PICKED_ITEMS_LIST::SetPickedItem( EDA_BaseStruct* aItem,
                                       UndoRedoOpType  aStatus,
                                       unsigned        aIdx )
{
{
    if( aIdx < m_ItemsList.size() )
    if( aIdx < m_ItemsList.size() )
    {
    {
@@ -225,6 +305,7 @@ bool PICKED_ITEMS_LIST::RemovePickedItem( unsigned aIdx )
    return true;
    return true;
}
}



/** Function CopyList
/** Function CopyList
 * copy all data from aSource
 * copy all data from aSource
 * Items picked are not copied. just pointer on them are copied
 * Items picked are not copied. just pointer on them are copied
@@ -232,6 +313,7 @@ bool PICKED_ITEMS_LIST::RemovePickedItem( unsigned aIdx )
void PICKED_ITEMS_LIST::CopyList( const PICKED_ITEMS_LIST& aSource )
void PICKED_ITEMS_LIST::CopyList( const PICKED_ITEMS_LIST& aSource )
{
{
    ITEM_PICKER picker;
    ITEM_PICKER picker;

    for( unsigned ii = 0; ii < aSource.GetCount(); ii++ )
    for( unsigned ii = 0; ii < aSource.GetCount(); ii++ )
    {
    {
        picker = aSource.m_ItemsList[ii];
        picker = aSource.m_ItemsList[ii];
+5 −53
Original line number Original line Diff line number Diff line
@@ -290,12 +290,13 @@ void WinEDA_SchematicFrame::SaveCopyInUndoList( PICKED_ITEMS_LIST& aItemsList,
        itemWrapper.m_PickedItem = item;
        itemWrapper.m_PickedItem = item;
        itemWrapper.m_PickedItemType = item->Type();
        itemWrapper.m_PickedItemType = item->Type();
        itemWrapper.m_UndoRedoStatus = command;
        itemWrapper.m_UndoRedoStatus = command;
        itemWrapper.m_Link = aItemsList.GetPickedItemLink( ii );
        switch( command )
        switch( command )
        {
        {
        case UR_CHANGED:        /* Create a copy of item */
        case UR_CHANGED:        /* Create a copy of item */
            CopyOfItem = DuplicateStruct( item );
            if( itemWrapper.m_Link == NULL )
            itemWrapper.m_Link = CopyOfItem;
                itemWrapper.m_Link = DuplicateStruct( item );
            if ( CopyOfItem )
            if ( itemWrapper.m_Link )
                commandToUndo->PushItem( itemWrapper );
                commandToUndo->PushItem( itemWrapper );
            break;
            break;


@@ -495,56 +496,7 @@ void SCH_SCREEN::ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount
        PICKED_ITEMS_LIST* curr_cmd = aList.m_CommandsList[0];
        PICKED_ITEMS_LIST* curr_cmd = aList.m_CommandsList[0];
        aList.m_CommandsList.erase( aList.m_CommandsList.begin() );
        aList.m_CommandsList.erase( aList.m_CommandsList.begin() );


        // Delete items is they are not flagged UR_NEW, or if this is a block operation
        curr_cmd->ClearListAndDeleteItems();
        while( 1 )
        {
            ITEM_PICKER     wrapper = curr_cmd->PopItem();
            EDA_BaseStruct* item    = wrapper.m_PickedItem;
            if( item == NULL ) // No more item in list.
                break;
            switch( wrapper.m_UndoRedoStatus )
            {
            case UR_WIRE_IMAGE:
                while( item )
                {   // Delete old copy of wires
                    EDA_BaseStruct* nextitem = item->Next();
                    delete          item;
                    item = nextitem;
                }

                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;

            case UR_LIBEDIT:    // Libedit save always a copy of the current item
                delete item;    // So, the picker is always owner of the picked item
                break;

            case UR_DELETED:
                delete item;    // Delete the picked item, because it was deleted from schematic
                break;

            case UR_CHANGED:
                delete wrapper.m_Link;  // Delete the copy of item (the item is itself in use)
                break;

            default:
            {
                wxString msg;
                msg.Printf(
                    wxT("ClearUndoORRedoList() error: unexpected undo/redo type %d"),
                    wrapper.m_UndoRedoStatus );
                wxMessageBox( msg );
                break;
            }
            }
        }

        delete curr_cmd;    // Delete command
        delete curr_cmd;    // Delete command
    }
    }
}
}
+18 −3
Original line number Original line Diff line number Diff line
@@ -58,7 +58,8 @@ enum UndoRedoOpType {
    UR_MOVED,               // moved item, undo by move it
    UR_MOVED,               // moved item, undo by move it
    UR_MIRRORED_X,          // mirrored item, undo by mirror X
    UR_MIRRORED_X,          // mirrored item, undo by mirror X
    UR_MIRRORED_Y,          // mirrored item, undo by mirror Y
    UR_MIRRORED_Y,          // mirrored item, undo by mirror Y
    UR_ROTATED,             // Rotated item, undo by rotating it
    UR_ROTATED,             // Rotated item (counterclockwise), undo by rotating it
    UR_ROTATED_CLOCKWISE,   // Rotated item (clockwise), undo by rotating it
    UR_FLIPPED,             // flipped (board items only), undo by flipping it
    UR_FLIPPED,             // flipped (board items only), undo by flipping it
    UR_WIRE_IMAGE,          // Specific to eeschema: handle wires changes
    UR_WIRE_IMAGE,          // Specific to eeschema: handle wires changes
    UR_MODEDIT,             // Specific to the module editor (modedit creates a full copy of the current module when changed)
    UR_MODEDIT,             // Specific to the module editor (modedit creates a full copy of the current module when changed)
@@ -104,19 +105,33 @@ private:
public:
public:
    PICKED_ITEMS_LIST();
    PICKED_ITEMS_LIST();
    ~PICKED_ITEMS_LIST();
    ~PICKED_ITEMS_LIST();

    /** PushItem
     * push a picker to the top of the list
     * @param aItem = picker to push
     */
    void        PushItem( ITEM_PICKER& aItem );
    void        PushItem( ITEM_PICKER& aItem );

    /** PopItem
     * @return the picker from the top of the list
     * the picker is removed from the list
     */
    ITEM_PICKER PopItem();
    ITEM_PICKER PopItem();


    /** Function ClearItemsList
    /** Function ClearItemsList
     * delete only the list of EDA_BaseStruct * pointers, NOT the pointed data itself
     * delete only the list of pickers, NOT the picked data itself
     */
     */
    void        ClearItemsList();
    void        ClearItemsList();


    /** Function ClearListAndDeleteItems
    /** Function ClearListAndDeleteItems
     * delete only the list of EDA_BaseStruct * pointers, AND the data pinted by m_Item
     * delete the list of pickers, AND the data pointed
     * by m_PickedItem or m_PickedItemLink, according to the type of undo/redo command recorded
     */
     */
    void        ClearListAndDeleteItems();
    void        ClearListAndDeleteItems();


    /** function GetCount()
     * @return the count of pickers stored in this list
     */
    unsigned        GetCount() const
    unsigned        GetCount() const
    {
    {
        return m_ItemsList.size();
        return m_ItemsList.size();
+0 −4
Original line number Original line Diff line number Diff line
@@ -178,9 +178,6 @@ public:
    // Gestion des modules
    // Gestion des modules
    void                     InstallModuleOptionsFrame( MODULE* Module, wxDC * DC );
    void                     InstallModuleOptionsFrame( MODULE* Module, wxDC * DC );
    MODULE*                  Copie_Module( MODULE* module );
    MODULE*                  Copie_Module( MODULE* module );
    MODULE*                  Exchange_Module( wxWindow* winaff,
                                              MODULE*   old_module,
                                              MODULE*   new_module );


    /** Function Save_Module_In_Library
    /** Function Save_Module_In_Library
     *  Save in an existing library a given footprint
     *  Save in an existing library a given footprint
@@ -207,7 +204,6 @@ public:
                                            int     angle,
                                            int     angle,
                                            bool    incremental );
                                            bool    incremental );
    void                     Place_Module( MODULE* module, wxDC* DC, bool aDoNotRecreateRatsnest = false );
    void                     Place_Module( MODULE* module, wxDC* DC, bool aDoNotRecreateRatsnest = false );
    void                     InstallExchangeModuleFrame( MODULE* ExchangeModuleModule );


    // Graphic items edition:
    // Graphic items edition:
    void                     InstallGraphicItemPropertiesDialog( DRAWSEGMENT* aItem, wxDC* aDC );
    void                     InstallGraphicItemPropertiesDialog( DRAWSEGMENT* aItem, wxDC* aDC );
+14 −0
Original line number Original line Diff line number Diff line
@@ -330,6 +330,20 @@ public:
    // Footprint edition (see also WinEDA_BasePcbFrame)
    // Footprint edition (see also WinEDA_BasePcbFrame)
    void             StartMove_Module( MODULE* module, wxDC* DC );
    void             StartMove_Module( MODULE* module, wxDC* DC );
    bool             Delete_Module( MODULE* module, wxDC* DC, bool aAskBeforeDeleting );
    bool             Delete_Module( MODULE* module, wxDC* DC, bool aAskBeforeDeleting );
    void            Change_Side_Module( MODULE* Module, wxDC* DC );

    void             InstallExchangeModuleFrame( MODULE* ExchangeModuleModule );
    /** function Exchange_Module
     * Replaces OldModule by NewModule, using OldModule settings:
     * position, orientation, pad netnames ...)
     * OldModule is deleted or put in undo list.
     * @param aOldModule = footprint to replace
     * @param aNewModule = footprint to put
     * @param aUndoPickList = the undo list used to save  OldModule. If null, OldModule is deleted
     */
    void            Exchange_Module( MODULE*   aOldModule,
                                                  MODULE*   aNewModule,
                                                PICKED_ITEMS_LIST* aUndoPickList);


    // loading modules: see WinEDA_BasePcbFrame
    // loading modules: see WinEDA_BasePcbFrame


Loading