BOARD_ITEM_CONTAINER class.
This commit is contained in:
parent
09e0311d4e
commit
b897c5f290
|
@ -39,6 +39,7 @@
|
|||
/* Forward declarations of classes. */
|
||||
class PCB_SCREEN;
|
||||
class BOARD;
|
||||
class BOARD_ITEM_CONTAINER;
|
||||
class TEXTE_PCB;
|
||||
class MODULE;
|
||||
class TRACK;
|
||||
|
@ -916,6 +917,9 @@ public:
|
|||
///> @copydoc PCB_BASE_FRAME::SetBoard()
|
||||
void SetBoard( BOARD* aBoard );
|
||||
|
||||
///> @copydoc PCB_BASE_EDIT_FRAME::GetModel()
|
||||
BOARD_ITEM_CONTAINER* GetModel() const override;
|
||||
|
||||
///> @copydoc PCB_BASE_FRAME::SetPageSettings()
|
||||
void SetPageSettings( const PAGE_INFO& aPageSettings ); // overload
|
||||
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* This program source code file is part of KICAD, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2016 CERN
|
||||
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef BOARD_ITEM_CONTAINER_H
|
||||
#define BOARD_ITEM_CONTAINER_H
|
||||
|
||||
#include <class_board_item.h>
|
||||
|
||||
enum ADD_MODE { ADD_INSERT, ADD_APPEND };
|
||||
|
||||
/**
|
||||
* @brief Abstract interface for BOARD_ITEMs capable of storing other items inside.
|
||||
* @see MODULE
|
||||
* @see BOARD
|
||||
*/
|
||||
class BOARD_ITEM_CONTAINER : public BOARD_ITEM
|
||||
{
|
||||
public:
|
||||
BOARD_ITEM_CONTAINER( BOARD_ITEM* aParent, KICAD_T aType )
|
||||
: BOARD_ITEM( aParent, aType )
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~BOARD_ITEM_CONTAINER()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Adds an item to the container.
|
||||
* @param aItem is an item to be added.
|
||||
* @param aMode decides whether the item is added in the beginning or at the end of the list.
|
||||
*/
|
||||
virtual void Add( BOARD_ITEM* aItem, ADD_MODE aMode = ADD_INSERT ) = 0;
|
||||
|
||||
/**
|
||||
* @brief Removes an item from the container.
|
||||
* @param aItem is an item to be removed.
|
||||
*/
|
||||
virtual void Remove( BOARD_ITEM* aItem ) = 0;
|
||||
|
||||
/**
|
||||
* @brief Removes an item from the containter and deletes it.
|
||||
* @param aItem is an item to be deleted.
|
||||
*/
|
||||
virtual void Delete( BOARD_ITEM* aItem )
|
||||
{
|
||||
Remove( aItem );
|
||||
delete aItem;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* BOARD_ITEM_CONTAINER_H */
|
|
@ -67,7 +67,7 @@ wxPoint BOARD_ITEM::ZeroOffset( 0, 0 );
|
|||
|
||||
|
||||
BOARD::BOARD() :
|
||||
BOARD_ITEM( (BOARD_ITEM*) NULL, PCB_T ),
|
||||
BOARD_ITEM_CONTAINER( (BOARD_ITEM*) NULL, PCB_T ),
|
||||
m_NetInfo( this ),
|
||||
m_paper( PAGE_INFO::A4 )
|
||||
{
|
||||
|
@ -858,7 +858,7 @@ bool BOARD::IsModuleLayerVisible( LAYER_ID layer )
|
|||
}
|
||||
|
||||
|
||||
void BOARD::Add( BOARD_ITEM* aBoardItem, int aControl )
|
||||
void BOARD::Add( BOARD_ITEM* aBoardItem, ADD_MODE aMode )
|
||||
{
|
||||
if( aBoardItem == NULL )
|
||||
{
|
||||
|
@ -883,7 +883,7 @@ void BOARD::Add( BOARD_ITEM* aBoardItem, int aControl )
|
|||
|
||||
case PCB_TRACE_T:
|
||||
case PCB_VIA_T:
|
||||
if( aControl & ADD_APPEND )
|
||||
if( aMode == ADD_APPEND )
|
||||
{
|
||||
m_Track.PushBack( (TRACK*) aBoardItem );
|
||||
}
|
||||
|
@ -897,7 +897,7 @@ void BOARD::Add( BOARD_ITEM* aBoardItem, int aControl )
|
|||
break;
|
||||
|
||||
case PCB_ZONE_T:
|
||||
if( aControl & ADD_APPEND )
|
||||
if( aMode == ADD_APPEND )
|
||||
m_Zone.PushBack( (SEGZONE*) aBoardItem );
|
||||
else
|
||||
m_Zone.PushFront( (SEGZONE*) aBoardItem );
|
||||
|
@ -905,7 +905,7 @@ void BOARD::Add( BOARD_ITEM* aBoardItem, int aControl )
|
|||
break;
|
||||
|
||||
case PCB_MODULE_T:
|
||||
if( aControl & ADD_APPEND )
|
||||
if( aMode == ADD_APPEND )
|
||||
m_Modules.PushBack( (MODULE*) aBoardItem );
|
||||
else
|
||||
m_Modules.PushFront( (MODULE*) aBoardItem );
|
||||
|
@ -915,14 +915,11 @@ void BOARD::Add( BOARD_ITEM* aBoardItem, int aControl )
|
|||
m_Status_Pcb = 0;
|
||||
break;
|
||||
|
||||
case PCB_MODULE_EDGE_T:
|
||||
assert( false ); // TODO Orson: I am just checking if it is supposed to be here
|
||||
|
||||
case PCB_DIMENSION_T:
|
||||
case PCB_LINE_T:
|
||||
case PCB_TEXT_T:
|
||||
case PCB_TARGET_T:
|
||||
if( aControl & ADD_APPEND )
|
||||
if( aMode == ADD_APPEND )
|
||||
m_Drawings.PushBack( aBoardItem );
|
||||
else
|
||||
m_Drawings.PushFront( aBoardItem );
|
||||
|
@ -946,7 +943,7 @@ void BOARD::Add( BOARD_ITEM* aBoardItem, int aControl )
|
|||
}
|
||||
|
||||
|
||||
BOARD_ITEM* BOARD::Remove( BOARD_ITEM* aBoardItem )
|
||||
void BOARD::Remove( BOARD_ITEM* aBoardItem )
|
||||
{
|
||||
// find these calls and fix them! Don't send me no stinking' NULL.
|
||||
wxASSERT( aBoardItem );
|
||||
|
@ -959,6 +956,7 @@ BOARD_ITEM* BOARD::Remove( BOARD_ITEM* aBoardItem )
|
|||
m_NetInfo.RemoveNet( item );
|
||||
break;
|
||||
}
|
||||
|
||||
case PCB_MARKER_T:
|
||||
|
||||
// find the item in the vector, then remove it
|
||||
|
@ -1001,7 +999,6 @@ BOARD_ITEM* BOARD::Remove( BOARD_ITEM* aBoardItem )
|
|||
case PCB_DIMENSION_T:
|
||||
case PCB_LINE_T:
|
||||
case PCB_TEXT_T:
|
||||
case PCB_MODULE_EDGE_T:
|
||||
case PCB_TARGET_T:
|
||||
m_Drawings.Remove( aBoardItem );
|
||||
break;
|
||||
|
@ -1012,8 +1009,6 @@ BOARD_ITEM* BOARD::Remove( BOARD_ITEM* aBoardItem )
|
|||
}
|
||||
|
||||
m_ratsnest->Remove( aBoardItem );
|
||||
|
||||
return aBoardItem;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#include <class_title_block.h>
|
||||
#include <class_zone_settings.h>
|
||||
#include <pcb_plot_params.h>
|
||||
#include <board_item_container.h>
|
||||
|
||||
|
||||
class PCB_BASE_FRAME;
|
||||
|
@ -162,7 +163,7 @@ DECL_VEC_FOR_SWIG(TRACKS, TRACK*)
|
|||
* Class BOARD
|
||||
* holds information pertinent to a Pcbnew printed circuit board.
|
||||
*/
|
||||
class BOARD : public BOARD_ITEM
|
||||
class BOARD : public BOARD_ITEM_CONTAINER
|
||||
{
|
||||
friend class PCB_EDIT_FRAME;
|
||||
|
||||
|
@ -215,7 +216,7 @@ private:
|
|||
// The default copy constructor & operator= are inadequate,
|
||||
// either write one or do not use it at all
|
||||
BOARD( const BOARD& aOther ) :
|
||||
BOARD_ITEM( aOther ), m_NetInfo( this )
|
||||
BOARD_ITEM_CONTAINER( aOther ), m_NetInfo( this )
|
||||
{
|
||||
assert( false );
|
||||
}
|
||||
|
@ -270,38 +271,11 @@ public:
|
|||
void SetFileFormatVersionAtLoad( int aVersion ) { m_fileFormatVersionAtLoad = aVersion; }
|
||||
int GetFileFormatVersionAtLoad() const { return m_fileFormatVersionAtLoad; }
|
||||
|
||||
/**
|
||||
* Function Add
|
||||
* adds the given item to this BOARD and takes ownership of its memory.
|
||||
* @param aBoardItem The item to add to this board.
|
||||
* @param aControl An int which can vary how the item is added.
|
||||
*/
|
||||
void Add( BOARD_ITEM* aBoardItem, int aControl = 0 );
|
||||
///> @copydoc BOARD_ITEM_CONTAINER::Add()
|
||||
void Add( BOARD_ITEM* aItem, ADD_MODE aMode = ADD_INSERT ) override;
|
||||
|
||||
#define ADD_APPEND 1 ///< aControl flag for Add( aControl ), appends not inserts
|
||||
|
||||
/**
|
||||
* Function Delete
|
||||
* removes the given single item from this BOARD and deletes its memory.
|
||||
* @param aBoardItem The item to remove from this board and delete
|
||||
*/
|
||||
void Delete( BOARD_ITEM* aBoardItem )
|
||||
{
|
||||
// developers should run DEBUG versions and fix such calls with NULL
|
||||
wxASSERT( aBoardItem );
|
||||
|
||||
if( aBoardItem )
|
||||
delete Remove( aBoardItem );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Function Remove
|
||||
* removes \a aBoardItem from this BOARD and returns it to caller without deleting it.
|
||||
* @param aBoardItem The item to remove from this board.
|
||||
* @return BOARD_ITEM* \a aBoardItem which was passed in.
|
||||
*/
|
||||
BOARD_ITEM* Remove( BOARD_ITEM* aBoardItem );
|
||||
///> @copydoc BOARD_ITEM_CONTAINER::Remove()
|
||||
void Remove( BOARD_ITEM* aBoardItem ) override;
|
||||
|
||||
/**
|
||||
* Function DuplicateAndAddItem
|
||||
|
|
|
@ -50,7 +50,7 @@
|
|||
|
||||
|
||||
MODULE::MODULE( BOARD* parent ) :
|
||||
BOARD_ITEM( (BOARD_ITEM*) parent, PCB_MODULE_T ),
|
||||
BOARD_ITEM_CONTAINER( (BOARD_ITEM*) parent, PCB_MODULE_T ),
|
||||
m_initial_comments( 0 )
|
||||
{
|
||||
m_Attributs = MOD_DEFAULT;
|
||||
|
@ -79,7 +79,7 @@ MODULE::MODULE( BOARD* parent ) :
|
|||
|
||||
|
||||
MODULE::MODULE( const MODULE& aModule ) :
|
||||
BOARD_ITEM( aModule )
|
||||
BOARD_ITEM_CONTAINER( aModule )
|
||||
{
|
||||
m_Pos = aModule.m_Pos;
|
||||
m_fpid = aModule.m_fpid;
|
||||
|
@ -256,7 +256,7 @@ void MODULE::DrawAncre( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& offset,
|
|||
}
|
||||
|
||||
|
||||
void MODULE::Add( BOARD_ITEM* aBoardItem, bool doAppend )
|
||||
void MODULE::Add( BOARD_ITEM* aBoardItem, ADD_MODE aMode )
|
||||
{
|
||||
switch( aBoardItem->Type() )
|
||||
{
|
||||
|
@ -267,14 +267,14 @@ void MODULE::Add( BOARD_ITEM* aBoardItem, bool doAppend )
|
|||
// no break
|
||||
|
||||
case PCB_MODULE_EDGE_T:
|
||||
if( doAppend )
|
||||
if( aMode == ADD_APPEND )
|
||||
m_Drawings.PushBack( aBoardItem );
|
||||
else
|
||||
m_Drawings.PushFront( aBoardItem );
|
||||
break;
|
||||
|
||||
case PCB_PAD_T:
|
||||
if( doAppend )
|
||||
if( aMode == ADD_APPEND )
|
||||
m_Pads.PushBack( static_cast<D_PAD*>( aBoardItem ) );
|
||||
else
|
||||
m_Pads.PushFront( static_cast<D_PAD*>( aBoardItem ) );
|
||||
|
@ -292,10 +292,11 @@ void MODULE::Add( BOARD_ITEM* aBoardItem, bool doAppend )
|
|||
}
|
||||
|
||||
aBoardItem->SetParent( this );
|
||||
SetLastEditTime();
|
||||
}
|
||||
|
||||
|
||||
BOARD_ITEM* MODULE::Remove( BOARD_ITEM* aBoardItem )
|
||||
void MODULE::Remove( BOARD_ITEM* aBoardItem )
|
||||
{
|
||||
switch( aBoardItem->Type() )
|
||||
{
|
||||
|
@ -306,10 +307,12 @@ BOARD_ITEM* MODULE::Remove( BOARD_ITEM* aBoardItem )
|
|||
// no break
|
||||
|
||||
case PCB_MODULE_EDGE_T:
|
||||
return m_Drawings.Remove( aBoardItem );
|
||||
m_Drawings.Remove( aBoardItem );
|
||||
break;
|
||||
|
||||
case PCB_PAD_T:
|
||||
return m_Pads.Remove( static_cast<D_PAD*>( aBoardItem ) );
|
||||
m_Pads.Remove( static_cast<D_PAD*>( aBoardItem ) );
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
|
@ -319,8 +322,6 @@ BOARD_ITEM* MODULE::Remove( BOARD_ITEM* aBoardItem )
|
|||
wxFAIL_MSG( msg );
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include <dlist.h>
|
||||
#include <layers_id_colors_and_visibility.h> // ALL_LAYERS definition.
|
||||
#include <class_board_item.h>
|
||||
#include <board_item_container.h>
|
||||
#include <fpid.h>
|
||||
|
||||
#include <class_text_mod.h>
|
||||
|
@ -75,7 +76,7 @@ enum MODULE_ATTR_T
|
|||
};
|
||||
|
||||
|
||||
class MODULE : public BOARD_ITEM
|
||||
class MODULE : public BOARD_ITEM_CONTAINER
|
||||
{
|
||||
public:
|
||||
MODULE( BOARD* parent );
|
||||
|
@ -94,35 +95,11 @@ public:
|
|||
MODULE* Next() const { return static_cast<MODULE*>( Pnext ); }
|
||||
MODULE* Back() const { return static_cast<MODULE*>( Pback ); }
|
||||
|
||||
/**
|
||||
* Function Add
|
||||
* adds the given item to this MODULE and takes ownership of its memory.
|
||||
* @param aBoardItem The item to add to this board.
|
||||
* @param doAppend If true, then append, else insert.
|
||||
*/
|
||||
void Add( BOARD_ITEM* aBoardItem, bool doAppend = true );
|
||||
///> @copydoc BOARD_ITEM_CONTAINER::Add()
|
||||
void Add( BOARD_ITEM* aBoardItem, ADD_MODE aMode = ADD_INSERT ) override;
|
||||
|
||||
/**
|
||||
* Function Delete
|
||||
* removes the given single item from this MODULE and deletes its memory.
|
||||
* @param aBoardItem The item to remove from this module and delete
|
||||
*/
|
||||
void Delete( BOARD_ITEM* aBoardItem )
|
||||
{
|
||||
// developers should run DEBUG versions and fix such calls with NULL
|
||||
wxASSERT( aBoardItem );
|
||||
|
||||
if( aBoardItem )
|
||||
delete Remove( aBoardItem );
|
||||
}
|
||||
|
||||
/**
|
||||
* Function Remove
|
||||
* removes \a aBoardItem from this MODULE and returns it to caller without deleting it.
|
||||
* @param aBoardItem The item to remove from this module.
|
||||
* @return BOARD_ITEM* \a aBoardItem which was passed in.
|
||||
*/
|
||||
BOARD_ITEM* Remove( BOARD_ITEM* aBoardItem );
|
||||
///> @copydoc BOARD_ITEM_CONTAINER::Remove()
|
||||
void Remove( BOARD_ITEM* aBoardItem ) override;
|
||||
|
||||
/**
|
||||
* Function ClearAllNets
|
||||
|
|
|
@ -54,6 +54,9 @@ public:
|
|||
*/
|
||||
static const wxChar* GetFootprintEditorFrameName();
|
||||
|
||||
///> @copydoc PCB_BASE_FRAME::GetModel()
|
||||
BOARD_ITEM_CONTAINER* GetModel() const override;
|
||||
|
||||
BOARD_DESIGN_SETTINGS& GetDesignSettings() const; // overload PCB_BASE_FRAME, get parent's
|
||||
void SetDesignSettings( const BOARD_DESIGN_SETTINGS& aSettings ); // overload
|
||||
|
||||
|
|
|
@ -350,6 +350,12 @@ FOOTPRINT_EDIT_FRAME::~FOOTPRINT_EDIT_FRAME()
|
|||
}
|
||||
|
||||
|
||||
BOARD_ITEM_CONTAINER* FOOTPRINT_EDIT_FRAME::GetModel() const
|
||||
{
|
||||
return GetBoard()->m_Modules;
|
||||
}
|
||||
|
||||
|
||||
const wxString FOOTPRINT_EDIT_FRAME::getLibPath()
|
||||
{
|
||||
try
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
|
||||
#include <wxBasePcbFrame.h>
|
||||
|
||||
class BOARD_ITEM_CONTAINER;
|
||||
|
||||
/**
|
||||
* Common, abstract interface for edit frames.
|
||||
*/
|
||||
|
@ -42,6 +44,12 @@ public:
|
|||
|
||||
virtual ~PCB_BASE_EDIT_FRAME() {};
|
||||
|
||||
/**
|
||||
* Function GetModel()
|
||||
* returns the primary data model.
|
||||
*/
|
||||
virtual BOARD_ITEM_CONTAINER* GetModel() const = 0;
|
||||
|
||||
/**
|
||||
* Function CreateNewLibrary
|
||||
* prompts user for a library path, then creates a new footprint library at that
|
||||
|
|
|
@ -489,6 +489,12 @@ void PCB_EDIT_FRAME::SetBoard( BOARD* aBoard )
|
|||
}
|
||||
|
||||
|
||||
BOARD_ITEM_CONTAINER* PCB_EDIT_FRAME::GetModel() const
|
||||
{
|
||||
return m_Pcb;
|
||||
}
|
||||
|
||||
|
||||
void PCB_EDIT_FRAME::SetPageSettings( const PAGE_INFO& aPageSettings )
|
||||
{
|
||||
PCB_BASE_FRAME::SetPageSettings( aPageSettings );
|
||||
|
|
Loading…
Reference in New Issue