Commit 44bb2e6d authored by jean-pierre charras's avatar jean-pierre charras
Browse files

Pcbnew: Code cleaning and some minor fixes.

parent d0c50d56
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -130,6 +130,17 @@ public:
    virtual void Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
                       GR_DRAWMODE aDrawMode, const wxPoint& offset = ZeroOffset ) = 0;

    /**
     * Swap data between aItem and aImage.
     * aItem and aImage should have the same type
     * Used in undo redo command to swap values between an item and its copy
     * Only values like layer, size .. which are modified by edition are swapped,
     * not the pointers like
     * Pnext and Pback because aItem is not changed in the linked list
     * @param aImage = the item image which contains data to swap
     */
    void SwapData( BOARD_ITEM* aImage );

    /**
     * Function IsOnLayer
     * tests to see if this object is on the given layer.  Is virtual so
+28 −25
Original line number Diff line number Diff line
@@ -174,32 +174,23 @@ static bool TestForExistingItem( BOARD* aPcb, BOARD_ITEM* aItem )
}


void SwapData( BOARD_ITEM* aItem, BOARD_ITEM* aImage )
void BOARD_ITEM::SwapData( BOARD_ITEM* aImage )
{
    if( aItem == NULL || aImage == NULL )
    if( aImage == NULL )
    {
        wxMessageBox( wxT( "SwapData error: NULL pointer" ) );
        return;
    }

    // Swap layers:
    if( aItem->Type() != PCB_MODULE_T && aItem->Type() != PCB_ZONE_AREA_T )
    {
        // These items have a global swap function.
        LAYER_NUM layer, layerimg;
        layer    = aItem->GetLayer();
        layerimg = aImage->GetLayer();
        aItem->SetLayer( layerimg );
        aImage->SetLayer( layer );
    }
    EDA_ITEM * pnext = Next();
    EDA_ITEM * pback = Back();

    switch( aItem->Type() )
    switch( Type() )
    {
    case PCB_MODULE_T:
    {
        MODULE* tmp = (MODULE*) aImage->Clone();
        ( (MODULE*) aImage )->Copy( (MODULE*) aItem );
        ( (MODULE*) aItem )->Copy( tmp );
        ( (MODULE*) aImage )->Copy( (MODULE*) this );
        ( (MODULE*) this )->Copy( tmp );
        delete tmp;
    }
        break;
@@ -207,22 +198,24 @@ void SwapData( BOARD_ITEM* aItem, BOARD_ITEM* aImage )
    case PCB_ZONE_AREA_T:
    {
        ZONE_CONTAINER* tmp = (ZONE_CONTAINER*) aImage->Clone();
        ( (ZONE_CONTAINER*) aImage )->Copy( (ZONE_CONTAINER*) aItem );
        ( (ZONE_CONTAINER*) aItem )->Copy( tmp );
        ( (ZONE_CONTAINER*) aImage )->Copy( (ZONE_CONTAINER*) this );
        ( (ZONE_CONTAINER*) this )->Copy( tmp );
        delete tmp;
    }
        break;

    case PCB_LINE_T:
        std::swap( *((DRAWSEGMENT*)aItem), *((DRAWSEGMENT*)aImage) );
        std::swap( *((DRAWSEGMENT*)this), *((DRAWSEGMENT*)aImage) );
        break;

    case PCB_TRACE_T:
    case PCB_VIA_T:
    {
        TRACK* track = (TRACK*) aItem;
        TRACK* track = (TRACK*) this;
        TRACK* image = (TRACK*) aImage;

        EXCHG(track->m_Layer, image->m_Layer );

        // swap start, end, width and shape for track and image.
        wxPoint exchp = track->GetStart();
        track->SetStart( image->GetStart() );
@@ -263,22 +256,32 @@ void SwapData( BOARD_ITEM* aItem, BOARD_ITEM* aImage )
        break;

    case PCB_TEXT_T:
        std::swap( *((TEXTE_PCB*)aItem), *((TEXTE_PCB*)aImage) );
        std::swap( *((TEXTE_PCB*)this), *((TEXTE_PCB*)aImage) );
        break;

    case PCB_TARGET_T:
        std::swap( *((PCB_TARGET*)aItem), *((PCB_TARGET*)aImage) );
        std::swap( *((PCB_TARGET*)this), *((PCB_TARGET*)aImage) );
        break;

    case PCB_DIMENSION_T:
        std::swap( *((DIMENSION*)aItem), *((DIMENSION*)aImage) );
        std::swap( *((DIMENSION*)this), *((DIMENSION*)aImage) );
        break;

    case PCB_ZONE_T:
    default:
        wxMessageBox( wxT( "SwapData() error: unexpected type" ) );
        wxLogMessage( wxT( "SwapData() error: unexpected type %d" ), Type() );
        break;
    }

    if( pnext != Next() || pback != Back() )
    {
        Pnext = pnext;
        Pback = pback;
#ifdef DEBUG
        wxLogMessage( wxT( "SwapData Error: %s Pnext or Pback pointers modified" ),
                      GetClass().GetData() );
#endif
    }
}


@@ -481,7 +484,7 @@ void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed
        case UR_CHANGED:    /* Exchange old and new data for each item */
        {
            BOARD_ITEM* image = (BOARD_ITEM*) aList->GetPickedItemLink( ii );
            SwapData( item, image );
            item->SwapData( image );
        }
        break;

+0 −1
Original line number Diff line number Diff line
@@ -44,7 +44,6 @@
#include <msgpanel.h>

#include <pcbnew.h>
#include <protos.h>
#include <math_for_graphics.h>

#include <class_board.h>
+0 −1
Original line number Diff line number Diff line
@@ -38,7 +38,6 @@
#include <colors_selection.h>
#include <trigo.h>
#include <macros.h>
#include <protos.h>
#include <richio.h>

#include <class_board.h>
+0 −1
Original line number Diff line number Diff line
@@ -34,7 +34,6 @@
#include <confirm.h>
#include <kicad_string.h>
#include <trigo.h>
#include <protos.h>
#include <richio.h>
#include <wxstruct.h>
#include <macros.h>
Loading