Commit 5289c220 authored by Wayne Stambaugh's avatar Wayne Stambaugh
Browse files

Pcbnew object improvements.

* Remove unnecessary copy constructors from board and module library
  objects.
* Add doClone() method to board and library objects.
* Add comment to class definitions where the default copy constructor
  generated by the compiler was adequate.
* Replace copy method with clone method where applicable.
* Remove DuplicateStruct() function.
* Remove track object copy function.
parent 742486dc
Loading
Loading
Loading
Loading
+10 −10
Original line number Diff line number Diff line
@@ -68,7 +68,9 @@ EDA_ITEM::EDA_ITEM( const EDA_ITEM& base )
    m_Parent     = base.m_Parent;
    m_Son        = base.m_Son;
    m_Flags      = base.m_Flags;
    SetTimeStamp( base.m_TimeStamp );

    // A copy of an item cannot have the same time stamp as the original item.
    SetTimeStamp( GetNewTimeStamp() );
    m_Status     = base.m_Status;
}

@@ -214,13 +216,11 @@ bool EDA_ITEM::operator<( const EDA_ITEM& aItem ) const

EDA_ITEM& EDA_ITEM::operator=( const EDA_ITEM& aItem )
{
    wxCHECK_MSG( Type() == aItem.Type(), *this,
                 wxT( "Cannot assign object type " ) + aItem.GetClass() + wxT( " to type " ) +
                 GetClass() );

    if( &aItem != this )
    {
        // Do not assign the linked list pointers.
        m_StructType = aItem.Type();
        Pnext = aItem.Pnext;
        Pback = aItem.Pback;
        m_StructType = aItem.m_StructType;
        m_Parent = aItem.m_Parent;
        m_Son = aItem.m_Son;
+25 −6
Original line number Diff line number Diff line
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
 * Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you may find one here:
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * or you may search the http://www.gnu.org website for the version 2 license,
 * or you may write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

/**
 * @file  class_board_item.h
 * @brief Classes BOARD_ITEM and BOARD_CONNECTED_ITEM.
@@ -59,12 +83,7 @@ public:
    {
    }

    BOARD_ITEM( const BOARD_ITEM& src ) :
        EDA_ITEM( src.m_Parent, src.Type() )
        , m_Layer( src.m_Layer )
    {
        m_Flags = src.m_Flags;
    }
    // Do not create a copy constructor.  The one generated by the compiler is adequate.

    /**
     * A value of wxPoint(0,0) which can be passed to the Draw() functions.
+1 −2
Original line number Diff line number Diff line
@@ -44,7 +44,6 @@
#include "class_board.h"
#include "class_module.h"

extern BOARD_ITEM* DuplicateStruct( BOARD_ITEM* aItem );

typedef enum {
    FIXE_MODULE,
@@ -265,7 +264,7 @@ void PCB_EDIT_FRAME::AutoMoveModulesOnPcb( bool PlaceModulesHorsPcb )
        }

        // Undo: add copy of old Module to undo
        picker.m_Link           = DuplicateStruct( Module );
        picker.m_Link           = Module->Clone();
        picker.m_PickedItemType = Module->Type();

        if( current.x > (Xsize_allowed + start.x) )
+8 −81
Original line number Diff line number Diff line
@@ -843,86 +843,13 @@ void PCB_EDIT_FRAME::Block_Duplicate()
    for( unsigned ii = 0; ii < itemsList->GetCount(); ii++ )
    {
        BOARD_ITEM* item = (BOARD_ITEM*) itemsList->GetPickedItem( ii );
        newitem = NULL;
        switch( item->Type() )
        {
        case PCB_MODULE_T:
            {
                MODULE* module = (MODULE*) item;
                MODULE* new_module;
                m_Pcb->m_Status_Pcb = 0;
                module->ClearFlags();
                newitem = new_module = new MODULE( m_Pcb );
                new_module->Copy( module );
                new_module->SetTimeStamp( GetNewTimeStamp() );
                m_Pcb->m_Modules.PushFront( new_module );
            }
            break;

        case PCB_TRACE_T:
        case PCB_VIA_T:
            {
                TRACK* track = (TRACK*) item;
                m_Pcb->m_Status_Pcb = 0;
                TRACK* new_track = track->Copy();
                newitem = new_track;
                m_Pcb->m_Track.PushFront( new_track );
            }
            break;

        case PCB_ZONE_T:                  // SEG_ZONE items are now deprecated
            break;

        case PCB_ZONE_AREA_T:
            {
                ZONE_CONTAINER* new_zone = new ZONE_CONTAINER( (BOARD*) item->GetParent() );
                new_zone->Copy( (ZONE_CONTAINER*) item );
                new_zone->SetTimeStamp( GetNewTimeStamp() );
                newitem = new_zone;
                m_Pcb->Add( new_zone );
            }
            break;

        case PCB_LINE_T:
            {
                DRAWSEGMENT* new_drawsegment = new DRAWSEGMENT( m_Pcb );
                new_drawsegment->Copy( (DRAWSEGMENT*) item );
                m_Pcb->Add( new_drawsegment );
                newitem = new_drawsegment;
            }
            break;

        case PCB_TEXT_T:
        {
            TEXTE_PCB* new_pcbtext = new TEXTE_PCB( m_Pcb );
            new_pcbtext->Copy( (TEXTE_PCB*) item );
            m_Pcb->Add( new_pcbtext );
            newitem = new_pcbtext;
        }
        break;
        newitem = (BOARD_ITEM*)item->Clone();

        case PCB_TARGET_T:
            {
                PCB_TARGET* target = new PCB_TARGET( m_Pcb );
                target->Copy( (PCB_TARGET*) item );
                m_Pcb->Add( target );
                newitem = target;
            }
            break;

        case PCB_DIMENSION_T:
            {
                DIMENSION* new_cotation = new DIMENSION( m_Pcb );
                new_cotation->Copy( (DIMENSION*) item );
                m_Pcb->Add( new_cotation );
                newitem = new_cotation;
            }
            break;
        if( item->Type() == PCB_MODULE_T )
            m_Pcb->m_Status_Pcb = 0;

        default:
            wxMessageBox( wxT( "PCB_EDIT_FRAME::Block_Duplicate( ) error: unexpected type" ) );
            break;
        }
        m_Pcb->Add( newitem );

        if( newitem )
        {
+8 −24
Original line number Diff line number Diff line
@@ -401,12 +401,14 @@ void CopyMarkedItems( MODULE* module, wxPoint offset )
            continue;

        pad->ClearFlags( SELECTED );
        D_PAD* NewPad = new D_PAD( module );
        NewPad->Copy( pad );
        D_PAD* NewPad = new D_PAD( *pad );
        NewPad->SetParent( module );
        NewPad->SetFlags( SELECTED );
        module->m_Pads.PushFront( NewPad );
    }

    BOARD_ITEM* newItem;

    for( BOARD_ITEM* item = module->m_Drawings;  item;  item = item->Next() )
    {
        if( !item->IsSelected() )
@@ -414,28 +416,10 @@ void CopyMarkedItems( MODULE* module, wxPoint offset )

        item->ClearFlags( SELECTED );

        switch( item->Type() )
        {
        case PCB_MODULE_TEXT_T:
            TEXTE_MODULE * textm;
            textm = new TEXTE_MODULE( module );
            textm->Copy( (TEXTE_MODULE*) item );
            textm->SetFlags( SELECTED );
            module->m_Drawings.PushFront( textm );
            break;

        case PCB_MODULE_EDGE_T:
            EDGE_MODULE * edge;
            edge = new EDGE_MODULE( module );
            edge->Copy( (EDGE_MODULE*) item );
            edge->SetFlags( SELECTED );
            module->m_Drawings.PushFront( edge );
            break;

        default:
            DisplayError( NULL, wxT( "CopyMarkedItems: type undefined" ) );
            break;
        }
        newItem = (BOARD_ITEM*)item->Clone();
        newItem->SetParent( module );
        newItem->SetFlags( SELECTED );
        module->m_Drawings.PushFront( newItem );
    }

    MoveMarkedItems( module, offset );
Loading