Commit bec24b6c authored by Maciej Suminski's avatar Maciej Suminski
Browse files

Ratsnest is updated after rotation, flip, undo/redo operations.

Fixed crashes of ratsnest when a pointer for an item has changed after undo/redo operations.
Vias are properly removed from ratsnest (pcbnew/class_board.cpp).
parent 83f7c7e3
Loading
Loading
Loading
Loading
+18 −6
Original line number Original line Diff line number Diff line
@@ -41,6 +41,8 @@
#include <class_zone.h>
#include <class_zone.h>
#include <class_edge_mod.h>
#include <class_edge_mod.h>


#include <ratsnest_data.h>

#include <tools/selection_tool.h>
#include <tools/selection_tool.h>
#include <tool/tool_manager.h>
#include <tool/tool_manager.h>


@@ -453,6 +455,7 @@ void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed
    bool        not_found = false;
    bool        not_found = false;
    bool        reBuild_ratsnest = false;
    bool        reBuild_ratsnest = false;
    KIGFX::VIEW* view = GetGalCanvas()->GetView();
    KIGFX::VIEW* view = GetGalCanvas()->GetView();
    RN_DATA* ratsnest = GetBoard()->GetRatsnest();


    // Undo in the reverse order of list creation: (this can allow stacked changes
    // Undo in the reverse order of list creation: (this can allow stacked changes
    // like the same item can be changes and deleted in the same complex command
    // like the same item can be changes and deleted in the same complex command
@@ -519,8 +522,8 @@ void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed
            if( item->Type() == PCB_MODULE_T )
            if( item->Type() == PCB_MODULE_T )
            {
            {
                MODULE* oldModule = static_cast<MODULE*>( item );
                MODULE* oldModule = static_cast<MODULE*>( item );
                oldModule->RunOnChildren( std::bind1st( std::mem_fun( &KIGFX::VIEW::Remove ),
                oldModule->RunOnChildren( std::bind1st( std::mem_fun( &KIGFX::VIEW::Remove ), view ) );
                                                        view ) );
                oldModule->RunOnChildren( std::bind1st( std::mem_fun( &RN_DATA::Remove ), ratsnest ) );
            }
            }


            item->SwapData( image );
            item->SwapData( image );
@@ -530,8 +533,8 @@ void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed
            if( item->Type() == PCB_MODULE_T )
            if( item->Type() == PCB_MODULE_T )
            {
            {
                MODULE* newModule = static_cast<MODULE*>( item );
                MODULE* newModule = static_cast<MODULE*>( item );
                newModule->RunOnChildren( std::bind1st( std::mem_fun( &KIGFX::VIEW::Add ),
                newModule->RunOnChildren( std::bind1st( std::mem_fun( &KIGFX::VIEW::Add ), view ) );
                                                        view ) );
                newModule->RunOnChildren( std::bind1st( std::mem_fun( &RN_DATA::Add ), ratsnest ) );
            }
            }


            item->ViewUpdate( KIGFX::VIEW_ITEM::LAYERS );
            item->ViewUpdate( KIGFX::VIEW_ITEM::LAYERS );
@@ -577,11 +580,13 @@ void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed
        case UR_ROTATED:
        case UR_ROTATED:
            item->Rotate( aList->m_TransformPoint,
            item->Rotate( aList->m_TransformPoint,
                          aRedoCommand ? m_rotationAngle : -m_rotationAngle );
                          aRedoCommand ? m_rotationAngle : -m_rotationAngle );
            item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
            break;
            break;


        case UR_ROTATED_CLOCKWISE:
        case UR_ROTATED_CLOCKWISE:
            item->Rotate( aList->m_TransformPoint,
            item->Rotate( aList->m_TransformPoint,
                          aRedoCommand ? -m_rotationAngle : m_rotationAngle );
                          aRedoCommand ? -m_rotationAngle : m_rotationAngle );
            item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
            break;
            break;


        case UR_FLIPPED:
        case UR_FLIPPED:
@@ -598,6 +603,8 @@ void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed
        }
        }
        break;
        break;
        }
        }

        ratsnest->Update( item );
    }
    }


    if( not_found )
    if( not_found )
@@ -605,8 +612,13 @@ void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed


    // Rebuild pointers and ratsnest that can be changed.
    // Rebuild pointers and ratsnest that can be changed.
    if( reBuild_ratsnest && aRebuildRatsnet )
    if( reBuild_ratsnest && aRebuildRatsnet )
    {
        if( IsGalCanvasActive() )
            ratsnest->Recalculate();
        else
            Compile_Ratsnest( NULL, true );
            Compile_Ratsnest( NULL, true );
    }
    }
}




void PCB_EDIT_FRAME::GetBoardFromUndoList( wxCommandEvent& event )
void PCB_EDIT_FRAME::GetBoardFromUndoList( wxCommandEvent& event )
+8 −1
Original line number Original line Diff line number Diff line
@@ -895,7 +895,6 @@ BOARD_ITEM* BOARD::Remove( BOARD_ITEM* aBoardItem )
    break;
    break;


    case PCB_TRACE_T:
    case PCB_TRACE_T:
    case PCB_VIA_T:
    {
    {
        TRACK* track = static_cast<TRACK*>( aBoardItem );
        TRACK* track = static_cast<TRACK*>( aBoardItem );
        m_Track.Remove( track );
        m_Track.Remove( track );
@@ -903,6 +902,14 @@ BOARD_ITEM* BOARD::Remove( BOARD_ITEM* aBoardItem )
    }
    }
    break;
    break;


    case PCB_VIA_T:
    {
        SEGVIA* via = static_cast<SEGVIA*>( aBoardItem );
        m_Track.Remove( via );
        m_ratsnest->GetNets()[via->GetNet()].RemoveItem( via );
    }
    break;

    case PCB_ZONE_T:
    case PCB_ZONE_T:
        m_Zone.Remove( (SEGZONE*) aBoardItem );
        m_Zone.Remove( (SEGZONE*) aBoardItem );
        break;
        break;
+12 −7
Original line number Original line Diff line number Diff line
@@ -119,7 +119,7 @@ int EDIT_TOOL::Main( TOOL_EVENT& aEvent )
            {
            {
                Remove( aEvent );
                Remove( aEvent );


                break;
                break;       // exit the loop, as there is no further processing for removed items
            }
            }
        }
        }


@@ -207,6 +207,7 @@ int EDIT_TOOL::Properties( TOOL_EVENT& aEvent )


    setTransitions();
    setTransitions();
    updateRatsnest( true );
    updateRatsnest( true );
    getModel<BOARD>( PCB_T )->GetRatsnest()->Recalculate();


    return 0;
    return 0;
}
}
@@ -233,12 +234,14 @@ int EDIT_TOOL::Rotate( TOOL_EVENT& aEvent )
            item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
            item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
    }
    }


    if( m_dragging )
        selection.group->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );

    setTransitions();
    setTransitions();
    updateRatsnest( true );
    updateRatsnest( true );


    if( m_dragging )
        selection.group->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
    else
        getModel<BOARD>( PCB_T )->GetRatsnest()->Recalculate();

    return 0;
    return 0;
}
}


@@ -264,12 +267,14 @@ int EDIT_TOOL::Flip( TOOL_EVENT& aEvent )
            item->ViewUpdate( KIGFX::VIEW_ITEM::LAYERS );
            item->ViewUpdate( KIGFX::VIEW_ITEM::LAYERS );
    }
    }


    if( m_dragging )
        selection.group->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );

    setTransitions();
    setTransitions();
    updateRatsnest( true );
    updateRatsnest( true );


    if( m_dragging )
        selection.group->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
    else
        getModel<BOARD>( PCB_T )->GetRatsnest()->Recalculate();

    return 0;
    return 0;
}
}