Commit c7187652 authored by charras's avatar charras
Browse files

More about undo/redo in pcbnew

parent 5699ee3b
Loading
Loading
Loading
Loading
+4 −10
Original line number Original line Diff line number Diff line
@@ -292,12 +292,12 @@ bool PICKED_ITEMS_LIST::SetPickedItemStatus( UndoRedoOpType aStatus, unsigned aI
}
}




/** function RemovePickedItem
/** function RemovePicker
 * remove one entry (one picker) from the list of picked items
 * remove one entry (one picker) from the list of picked items
 * @param aIdx = index of the picker in the picked list
 * @param aIdx = index of the picker in the picked list
 * @return true if ok, or false if did not exist
 * @return true if ok, or false if did not exist
 */
 */
bool PICKED_ITEMS_LIST::RemovePickedItem( unsigned aIdx )
bool PICKED_ITEMS_LIST::RemovePicker( unsigned aIdx )
{
{
    if( aIdx >= m_ItemsList.size() )
    if( aIdx >= m_ItemsList.size() )
        return false;
        return false;
@@ -308,17 +308,11 @@ bool PICKED_ITEMS_LIST::RemovePickedItem( unsigned aIdx )


/** 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
 * Picked items are not copied. just pointers on them are copied
 */
 */
void PICKED_ITEMS_LIST::CopyList( const PICKED_ITEMS_LIST& aSource )
void PICKED_ITEMS_LIST::CopyList( const PICKED_ITEMS_LIST& aSource )
{
{
    ITEM_PICKER picker;
    m_ItemsList = aSource.m_ItemsList;  // Vector's copy

    for( unsigned ii = 0; ii < aSource.GetCount(); ii++ )
    {
        picker = aSource.m_ItemsList[ii];
        PushItem( picker );
    }
}
}




+18 −17
Original line number Original line Diff line number Diff line
@@ -274,37 +274,38 @@ void WinEDA_SchematicFrame::SaveCopyInUndoList( PICKED_ITEMS_LIST& aItemsList,
    SCH_ITEM*          CopyOfItem;
    SCH_ITEM*          CopyOfItem;
    PICKED_ITEMS_LIST* commandToUndo = new PICKED_ITEMS_LIST();
    PICKED_ITEMS_LIST* commandToUndo = new PICKED_ITEMS_LIST();
    commandToUndo->m_TransformPoint = aTransformPoint;
    commandToUndo->m_TransformPoint = aTransformPoint;
    // Copy picker list:
    commandToUndo->CopyList( aItemsList );


    ITEM_PICKER        itemWrapper;
    // Verify list, and creates data if needed

    for( unsigned ii = 0; ii < commandToUndo->GetCount(); ii++ )
    for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
    {
    {
        SCH_ITEM*      item = (SCH_ITEM*) aItemsList.GetPickedItem( ii );
        SCH_ITEM*      item = (SCH_ITEM*) commandToUndo->GetPickedItem( ii );
        if( item == NULL )
        wxASSERT( item );
            continue;

        UndoRedoOpType command    = aItemsList.GetPickedItemStatus( ii );
        UndoRedoOpType command    = commandToUndo->GetPickedItemStatus( ii );
        if( command == UR_UNSPECIFIED )
        if( command == UR_UNSPECIFIED )
        {
        {
            command = aTypeCommand;
            command = aTypeCommand;
            commandToUndo->SetPickedItemStatus(command, ii );
        }
        }
        itemWrapper.m_PickedItem = item;

        itemWrapper.m_PickedItemType = item->Type();
        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 */
            if( itemWrapper.m_Link == NULL )
            /* If needed, create a copy of item, and put in undo list
                itemWrapper.m_Link = DuplicateStruct( item );
             * in the picker, as link
            if ( itemWrapper.m_Link )
             * If this link is not null, the copy is already done
                commandToUndo->PushItem( itemWrapper );
             */
            if( commandToUndo->GetPickedItemLink(ii) == NULL )
                commandToUndo->SetPickedItemLink( DuplicateStruct( item ), ii );
            wxASSERT( commandToUndo->GetPickedItemLink(ii) );
            break;
            break;


        case UR_MOVED:
        case UR_MOVED:
        case UR_MIRRORED_Y:
        case UR_MIRRORED_Y:
        case UR_NEW:
        case UR_NEW:
        case UR_DELETED:
        case UR_DELETED:
            commandToUndo->PushItem( itemWrapper );
            break;
            break;


        default:
        default:
@@ -325,7 +326,7 @@ void WinEDA_SchematicFrame::SaveCopyInUndoList( PICKED_ITEMS_LIST& aItemsList,
        /* Clear redo list, because after new save there is no redo to do */
        /* Clear redo list, because after new save there is no redo to do */
        GetScreen()->ClearUndoORRedoList( GetScreen()->m_RedoList );
        GetScreen()->ClearUndoORRedoList( GetScreen()->m_RedoList );
    }
    }
    else
    else    // Should not occur
        delete commandToUndo;
        delete commandToUndo;
}
}


+3 −3
Original line number Original line Diff line number Diff line
@@ -196,12 +196,12 @@ public:
     */
     */
    bool            SetPickedItemStatus( UndoRedoOpType aStatus, unsigned aIdx );
    bool            SetPickedItemStatus( UndoRedoOpType aStatus, unsigned aIdx );


    /** function RemovePickedItem
    /** function RemovePicker
     * remùove one entry (one picker) from the list of picked items
     * remove one entry (one picker) from the list of picked items
     * @param aIdx = index of the picker in the picked list
     * @param aIdx = index of the picker in the picked list
     * @return true if ok, or false if did not exist
     * @return true if ok, or false if did not exist
     */
     */
    bool            RemovePickedItem( unsigned aIdx );
    bool            RemovePicker( unsigned aIdx );


    /** Function CopyList
    /** Function CopyList
     * copy all data from aSource
     * copy all data from aSource
+0 −3
Original line number Original line Diff line number Diff line
@@ -121,9 +121,6 @@ public:
    int                      ReadSetup( FILE* File, int* LineNum );
    int                      ReadSetup( FILE* File, int* LineNum );
    int                      ReadGeneralDescrPcb( FILE* File, int* LineNum );
    int                      ReadGeneralDescrPcb( FILE* File, int* LineNum );


    // PCB handling
    bool                     Clear_Pcb( bool query );



    /**
    /**
     * Function PcbGeneralLocateAndDisplay
     * Function PcbGeneralLocateAndDisplay
+14 −6
Original line number Original line Diff line number Diff line
@@ -254,6 +254,13 @@ public:
    int              SavePcbFormatAscii( FILE* File );
    int              SavePcbFormatAscii( FILE* File );
    bool             WriteGeneralDescrPcb( FILE* File );
    bool             WriteGeneralDescrPcb( FILE* File );


    // BOARD handling
    /** function Clear_Pcb()
     * delete all and reinitialize the current board
     * @param aQuery = true to prompt user for confirmation, false to initialize silently
     */
    bool                     Clear_Pcb( bool aQuery );

    /**
    /**
     * Function RecreateBOMFileFromBoard
     * Function RecreateBOMFileFromBoard
     * Recreates a .cmp file from the current loaded board
     * Recreates a .cmp file from the current loaded board
@@ -348,12 +355,6 @@ public:
    // loading modules: see WinEDA_BasePcbFrame
    // loading modules: see WinEDA_BasePcbFrame


    // Board handling
    // Board handling
    void             Erase_Zones( bool query );
    void             Erase_Segments_Pcb( bool is_edges, bool query );
    void             Erase_Pistes( wxDC* DC, int masque_type, bool query );
    void             Erase_Modules( bool query );
    void             Erase_Textes_Pcb( bool query );
    void             Erase_Marqueurs();
    void             RemoveStruct( BOARD_ITEM* Item, wxDC* DC );
    void             RemoveStruct( BOARD_ITEM* Item, wxDC* DC );
    void             Via_Edit_Control( wxDC* DC, int command_type, SEGVIA* via );
    void             Via_Edit_Control( wxDC* DC, int command_type, SEGVIA* via );


@@ -655,6 +656,13 @@ public:
    virtual void OnSelectGrid( wxCommandEvent& event );
    virtual void OnSelectGrid( wxCommandEvent& event );
    void         LoadModuleFromBoard( wxCommandEvent& event );
    void         LoadModuleFromBoard( wxCommandEvent& event );


    // BOARD handling
    /** function Clear_Pcb()
     * delete all and reinitialize the current board
     * @param aQuery = true to prompt user for confirmation, false to initialize silently
     */
    bool                     Clear_Pcb( bool aQuery );

    /* handlers for block commands */
    /* handlers for block commands */
    int          ReturnBlockCommand( int key );
    int          ReturnBlockCommand( int key );
    virtual void HandleBlockPlace( wxDC* DC );
    virtual void HandleBlockPlace( wxDC* DC );
Loading