2012-01-14 19:50:32 +00:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2011-09-20 13:57:40 +00:00
|
|
|
/**
|
|
|
|
* @file class_board_item.h
|
|
|
|
* @brief Classes BOARD_ITEM and BOARD_CONNECTED_ITEM.
|
|
|
|
*/
|
2008-04-14 19:22:48 +00:00
|
|
|
|
|
|
|
#ifndef BOARD_ITEM_STRUCT_H
|
|
|
|
#define BOARD_ITEM_STRUCT_H
|
|
|
|
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <base_struct.h>
|
2012-09-01 13:38:27 +00:00
|
|
|
#include <gr_basic.h>
|
2013-03-30 17:24:04 +00:00
|
|
|
#include <layers_id_colors_and_visibility.h>
|
2008-11-18 18:13:55 +00:00
|
|
|
|
2012-04-12 21:31:31 +00:00
|
|
|
/// Abbrevation for fomatting internal units to a string.
|
|
|
|
#define FMT_IU BOARD_ITEM::FormatInternalUnits
|
|
|
|
#define FMT_ANGLE BOARD_ITEM::FormatAngle
|
|
|
|
|
2011-09-20 13:57:40 +00:00
|
|
|
class BOARD;
|
|
|
|
class EDA_DRAW_PANEL;
|
|
|
|
|
|
|
|
|
2011-12-01 22:50:41 +00:00
|
|
|
/**
|
|
|
|
* Enum STROKE_T
|
|
|
|
* is the set of shapes for segments (graphic segments and tracks) which are often
|
|
|
|
* in the .m_Shape member
|
|
|
|
*/
|
|
|
|
enum STROKE_T
|
|
|
|
{
|
|
|
|
S_SEGMENT = 0, ///< usual segment : line with rounded ends
|
|
|
|
S_RECT, ///< segment with non rounded ends
|
|
|
|
S_ARC, ///< Arcs (with rounded ends)
|
|
|
|
S_CIRCLE, ///< ring
|
|
|
|
S_POLYGON, ///< polygon (not yet used for tracks, but could be in microwave apps)
|
|
|
|
S_CURVE, ///< Bezier Curve
|
|
|
|
S_LAST ///< last value for this list
|
2008-05-05 19:56:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
/**
|
|
|
|
* Class BOARD_ITEM
|
|
|
|
* is a base class for any item which can be embedded within the BOARD
|
|
|
|
* container class, and therefore instances of derived classes should only be
|
2011-09-30 18:15:37 +00:00
|
|
|
* found in Pcbnew or other programs that use class BOARD and its contents.
|
|
|
|
* The corresponding class in Eeschema is SCH_ITEM.
|
2008-04-14 19:22:48 +00:00
|
|
|
*/
|
2010-12-08 20:12:46 +00:00
|
|
|
class BOARD_ITEM : public EDA_ITEM
|
2008-04-14 19:22:48 +00:00
|
|
|
{
|
2008-12-06 21:20:50 +00:00
|
|
|
// These are made private here so they may not be used.
|
|
|
|
// Instead everything derived from BOARD_ITEM is handled via DLIST<>'s
|
|
|
|
// use of DHEAD's member functions.
|
2010-12-08 20:12:46 +00:00
|
|
|
void SetNext( EDA_ITEM* aNext ) { Pnext = aNext; }
|
|
|
|
void SetBack( EDA_ITEM* aBack ) { Pback = aBack; }
|
2008-12-06 21:20:50 +00:00
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
protected:
|
2014-06-24 16:17:18 +00:00
|
|
|
LAYER_ID m_Layer;
|
2008-04-14 19:22:48 +00:00
|
|
|
|
2015-02-12 03:22:24 +00:00
|
|
|
static int getTrailingInt( wxString aStr );
|
2015-02-18 19:30:14 +00:00
|
|
|
static int getNextNumberInSequence( std::set<int> aSeq, bool aFillSequenceGaps );
|
2015-02-12 03:22:24 +00:00
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
public:
|
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
BOARD_ITEM( BOARD_ITEM* aParent, KICAD_T idtype ) :
|
2014-06-24 16:17:18 +00:00
|
|
|
EDA_ITEM( aParent, idtype ), m_Layer( F_Cu )
|
2008-04-14 19:22:48 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-01-14 19:50:32 +00:00
|
|
|
// Do not create a copy constructor. The one generated by the compiler is adequate.
|
2008-04-14 19:22:48 +00:00
|
|
|
|
2013-08-29 10:06:06 +00:00
|
|
|
virtual const wxPoint& GetPosition() const = 0;
|
|
|
|
|
2015-02-12 03:22:24 +00:00
|
|
|
/**
|
|
|
|
* Function GetCenter()
|
|
|
|
*
|
|
|
|
* This defaults to the same point as returned by GetPosition(), unless
|
|
|
|
* overridden
|
|
|
|
*
|
|
|
|
* @return centre point of the item
|
|
|
|
*/
|
|
|
|
virtual const wxPoint GetCenter() const { return GetPosition(); }
|
|
|
|
|
2013-08-29 10:06:06 +00:00
|
|
|
virtual void SetPosition( const wxPoint& aPos ) = 0;
|
|
|
|
|
2014-01-28 15:23:08 +00:00
|
|
|
/**
|
|
|
|
* Function IsConnected()
|
|
|
|
* Returns information if the object is derived from BOARD_CONNECTED_ITEM.
|
|
|
|
* @return True if the object is of BOARD_CONNECTED_ITEM type, false otherwise.
|
|
|
|
*/
|
|
|
|
virtual bool IsConnected() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
/**
|
|
|
|
* A value of wxPoint(0,0) which can be passed to the Draw() functions.
|
|
|
|
*/
|
2011-08-01 15:29:27 +00:00
|
|
|
static wxPoint ZeroOffset;
|
2008-04-14 19:22:48 +00:00
|
|
|
|
2014-04-30 19:16:22 +00:00
|
|
|
BOARD_ITEM* Next() const { return static_cast<BOARD_ITEM*>( Pnext ); }
|
|
|
|
BOARD_ITEM* Back() const { return static_cast<BOARD_ITEM*>( Pback ); }
|
2008-04-14 19:22:48 +00:00
|
|
|
BOARD_ITEM* GetParent() const { return (BOARD_ITEM*) m_Parent; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetLayer
|
2015-06-04 12:54:07 +00:00
|
|
|
* returns the primary layer this item is on.
|
2008-04-14 19:22:48 +00:00
|
|
|
*/
|
2014-06-24 16:17:18 +00:00
|
|
|
LAYER_ID GetLayer() const { return m_Layer; }
|
2008-04-14 19:22:48 +00:00
|
|
|
|
2015-06-04 12:54:07 +00:00
|
|
|
/**
|
|
|
|
* Function GetLayerSet
|
|
|
|
* returns a "layer mask", which is a bitmap of all layers on which the
|
|
|
|
* TRACK segment or VIA physically resides.
|
|
|
|
* @return int - a layer mask, see layers_id_colors_visibility.h.
|
|
|
|
*/
|
|
|
|
virtual LSET GetLayerSet() const { return LSET( m_Layer ); }
|
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
/**
|
|
|
|
* Function SetLayer
|
|
|
|
* sets the layer this item is on.
|
|
|
|
* @param aLayer The layer number.
|
2010-04-23 09:54:40 +00:00
|
|
|
* is virtual because some items (in fact: class DIMENSION)
|
2011-08-01 15:29:27 +00:00
|
|
|
* have a slightly different initialization
|
2008-04-14 19:22:48 +00:00
|
|
|
*/
|
2014-06-24 16:17:18 +00:00
|
|
|
virtual void SetLayer( LAYER_ID aLayer )
|
2013-11-04 02:09:28 +00:00
|
|
|
{
|
|
|
|
// trap any invalid layers, then go find the caller and fix it.
|
|
|
|
// wxASSERT( unsigned( aLayer ) < unsigned( NB_PCB_LAYERS ) );
|
|
|
|
m_Layer = aLayer;
|
|
|
|
}
|
2008-04-14 19:22:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Draw
|
|
|
|
* BOARD_ITEMs have their own color information.
|
|
|
|
*/
|
2011-01-21 19:30:59 +00:00
|
|
|
virtual void Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
|
2012-09-01 13:38:27 +00:00
|
|
|
GR_DRAWMODE aDrawMode, const wxPoint& offset = ZeroOffset ) = 0;
|
2008-04-14 19:22:48 +00:00
|
|
|
|
2013-11-20 17:26:47 +00:00
|
|
|
/**
|
|
|
|
* 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 );
|
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
/**
|
|
|
|
* Function IsOnLayer
|
|
|
|
* tests to see if this object is on the given layer. Is virtual so
|
|
|
|
* objects like D_PAD, which reside on multiple layers can do their own
|
|
|
|
* form of testing.
|
|
|
|
* @param aLayer The layer to test for.
|
|
|
|
* @return bool - true if on given layer, else false.
|
|
|
|
*/
|
2014-06-29 13:05:51 +00:00
|
|
|
virtual bool IsOnLayer( LAYER_ID aLayer ) const
|
2008-04-14 19:22:48 +00:00
|
|
|
{
|
|
|
|
return m_Layer == aLayer;
|
|
|
|
}
|
|
|
|
|
2010-11-24 15:10:33 +00:00
|
|
|
/**
|
|
|
|
* Function IsTrack
|
|
|
|
* tests to see if this object is a track or via (or microvia).
|
|
|
|
* form of testing.
|
|
|
|
* @return bool - true if a track or via, else false.
|
|
|
|
*/
|
2011-08-01 15:29:27 +00:00
|
|
|
bool IsTrack() const
|
2010-11-24 15:10:33 +00:00
|
|
|
{
|
2011-10-01 19:24:27 +00:00
|
|
|
return ( Type() == PCB_TRACE_T ) || ( Type() == PCB_VIA_T );
|
2010-11-24 15:10:33 +00:00
|
|
|
}
|
2008-04-14 19:22:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function IsLocked
|
|
|
|
* @return bool - true if the object is locked, else false
|
|
|
|
*/
|
|
|
|
virtual bool IsLocked() const
|
|
|
|
{
|
2016-05-09 08:29:06 +00:00
|
|
|
// only MODULEs & TRACKs can be locked at this time.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function SetLocked
|
|
|
|
* modifies 'lock' status for of the item.
|
|
|
|
*/
|
|
|
|
virtual void SetLocked( bool aLocked )
|
|
|
|
{
|
|
|
|
// only MODULEs & TRACKs can be locked at this time.
|
2008-04-14 19:22:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function UnLink
|
2008-12-04 04:28:11 +00:00
|
|
|
* detaches this object from its owner. This base class implementation
|
|
|
|
* should work for all derived classes which are held in a DLIST<>.
|
2008-04-14 19:22:48 +00:00
|
|
|
*/
|
2008-12-04 04:28:11 +00:00
|
|
|
virtual void UnLink();
|
2008-04-14 19:22:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function DeleteStructure
|
2013-11-19 21:51:33 +00:00
|
|
|
* deletes this object after UnLink()ing it from its owner if it has one.
|
2008-04-14 19:22:48 +00:00
|
|
|
*/
|
|
|
|
void DeleteStructure()
|
|
|
|
{
|
2013-11-19 21:51:33 +00:00
|
|
|
if( GetList() != NULL )
|
|
|
|
UnLink();
|
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
2008-05-05 19:56:06 +00:00
|
|
|
/**
|
|
|
|
* Function ShowShape
|
2011-12-01 22:50:41 +00:00
|
|
|
* converts the enum STROKE_T integer value to a wxString.
|
2008-05-05 19:56:06 +00:00
|
|
|
*/
|
2011-12-01 22:50:41 +00:00
|
|
|
static wxString ShowShape( STROKE_T aShape );
|
2008-05-05 19:56:06 +00:00
|
|
|
|
2011-08-01 15:29:27 +00:00
|
|
|
// Some geometric transforms, that must be rewritten for derived classes
|
2009-08-01 19:26:05 +00:00
|
|
|
/**
|
|
|
|
* Function Move
|
|
|
|
* move this object.
|
2010-12-14 15:56:30 +00:00
|
|
|
* @param aMoveVector - the move vector for this object.
|
2009-08-01 19:26:05 +00:00
|
|
|
*/
|
2011-08-01 15:29:27 +00:00
|
|
|
virtual void Move( const wxPoint& aMoveVector )
|
2009-08-01 19:26:05 +00:00
|
|
|
{
|
2011-08-01 15:29:27 +00:00
|
|
|
wxMessageBox( wxT( "virtual BOARD_ITEM::Move used, should not occur" ), GetClass() );
|
2009-08-01 19:26:05 +00:00
|
|
|
}
|
2009-08-17 02:59:38 +00:00
|
|
|
|
2009-08-01 19:26:05 +00:00
|
|
|
/**
|
|
|
|
* Function Rotate
|
|
|
|
* Rotate this object.
|
2010-12-28 11:24:42 +00:00
|
|
|
* @param aRotCentre - the rotation point.
|
2009-08-01 19:26:05 +00:00
|
|
|
* @param aAngle - the rotation angle in 0.1 degree.
|
|
|
|
*/
|
2011-12-14 04:29:25 +00:00
|
|
|
virtual void Rotate( const wxPoint& aRotCentre, double aAngle )
|
2009-08-01 19:26:05 +00:00
|
|
|
{
|
2011-08-01 15:29:27 +00:00
|
|
|
wxMessageBox( wxT( "virtual BOARD_ITEM::Rotate used, should not occur" ), GetClass() );
|
2009-08-01 19:26:05 +00:00
|
|
|
}
|
2009-08-17 02:59:38 +00:00
|
|
|
|
2009-08-01 19:26:05 +00:00
|
|
|
/**
|
|
|
|
* Function Flip
|
|
|
|
* Flip this object, i.e. change the board side for this object
|
2010-12-28 11:24:42 +00:00
|
|
|
* @param aCentre - the rotation point.
|
2009-08-01 19:26:05 +00:00
|
|
|
*/
|
2011-08-01 15:29:27 +00:00
|
|
|
virtual void Flip( const wxPoint& aCentre )
|
2009-08-01 19:26:05 +00:00
|
|
|
{
|
2011-08-01 15:29:27 +00:00
|
|
|
wxMessageBox( wxT( "virtual BOARD_ITEM::Flip used, should not occur" ), GetClass() );
|
2009-08-01 19:26:05 +00:00
|
|
|
}
|
2009-08-17 02:59:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetBoard
|
|
|
|
* returns the BOARD in which this BOARD_ITEM resides, or NULL if none.
|
|
|
|
*/
|
|
|
|
virtual BOARD* GetBoard() const;
|
2011-07-14 15:42:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetLayerName
|
|
|
|
* returns the name of the PCB layer on which the item resides.
|
|
|
|
*
|
|
|
|
* @return wxString containing the layer name associated with this item.
|
|
|
|
*/
|
|
|
|
wxString GetLayerName() const;
|
2012-04-12 21:31:31 +00:00
|
|
|
|
2014-05-04 17:08:36 +00:00
|
|
|
virtual bool HitTest( const wxPoint& aPosition ) const
|
2013-09-21 18:09:41 +00:00
|
|
|
{
|
|
|
|
return EDA_ITEM::HitTest( aPosition );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function HitTest
|
|
|
|
* tests if the \a aRect intersects or contains this object (depending on \a aContained).
|
|
|
|
*
|
|
|
|
* @param aRect A reference to an EDA_RECT object containg the area to test.
|
|
|
|
* @param aContained Test if \a aRect contains this object completly.
|
|
|
|
* @param aAccuracy Increase the item bounding box by this amount.
|
|
|
|
* @return bool - True if \a aRect contains this object completly or if \a aRect intersects
|
|
|
|
* the object and \a aContained is False, otherwise false.
|
|
|
|
*/
|
|
|
|
virtual bool HitTest( const EDA_RECT& aRect, bool aContained = true, int aAccuracy = 0) const
|
|
|
|
{
|
|
|
|
return false; // derived classes should override this function
|
|
|
|
}
|
|
|
|
|
2012-04-12 21:31:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function FormatInternalUnits
|
|
|
|
* converts \a aValue from board internal units to a string appropriate for writing to file.
|
|
|
|
*
|
|
|
|
* @note Internal units for board items can be either deci-mils or nanometers depending
|
|
|
|
* on how KiCad is build.
|
|
|
|
* @param aValue A coordinate value to convert.
|
|
|
|
* @return A std::string object containing the converted value.
|
|
|
|
*/
|
|
|
|
static std::string FormatInternalUnits( int aValue );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function FormatAngle
|
|
|
|
* converts \a aAngle from board units to a string appropriate for writing to file.
|
|
|
|
*
|
|
|
|
* @note Internal angles for board items can be either degrees or tenths of degree
|
|
|
|
* on how KiCad is built.
|
|
|
|
* @param aAngle A angle value to convert.
|
|
|
|
* @return A std::string object containing the converted angle.
|
|
|
|
*/
|
|
|
|
static std::string FormatAngle( double aAngle );
|
|
|
|
|
|
|
|
static std::string FormatInternalUnits( const wxPoint& aPoint );
|
|
|
|
|
|
|
|
static std::string FormatInternalUnits( const wxSize& aSize );
|
Introduction of Graphics Abstraction Layer based rendering for pcbnew.
New classes:
- VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.)
- VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes).
- EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL).
- GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries.
- WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc.
- PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods.
- STROKE_FONT - Implements stroke font drawing using GAL methods.
Most important changes to Kicad original code:
* EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects.
* EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime.
* There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew)
* Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom.
* Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime.
* Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods.
* Removed tools/class_painter.h, as now it is extended and included in source code.
Build changes:
* GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL.
* When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required.
* GAL-related code is compiled into a static library (common/libgal).
* Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad
Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS).
More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
2013-04-02 06:54:03 +00:00
|
|
|
|
|
|
|
/// @copydoc VIEW_ITEM::ViewGetLayers()
|
|
|
|
virtual void ViewGetLayers( int aLayers[], int& aCount ) const;
|
2015-03-22 09:42:41 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* Function IncrementItemReference
|
|
|
|
* Implement if the concept of "incrementing" makes sense for an
|
|
|
|
* item (e.g. modules and pads)
|
|
|
|
* @return if item reference was incremented
|
|
|
|
*/
|
|
|
|
virtual bool IncrementItemReference() { return false; }
|
2008-04-14 19:22:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* BOARD_ITEM_STRUCT_H */
|