KiCad PCB EDA Suite
class_pcb_target.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
5  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
6  * Copyright (C) 2012 Wayne Stambaugh <stambaughw@verizon.net>
7  * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, you may find one here:
21  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22  * or you may search the http://www.gnu.org website for the version 2 license,
23  * or you may write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26 
32 #include <fctsys.h>
33 #include <gr_basic.h>
34 #include <bitmaps.h>
35 #include <pcb_edit_frame.h>
36 #include <class_board.h>
37 #include <class_pcb_target.h>
38 #include <base_units.h>
41 
42 
44  BOARD_ITEM( aParent, PCB_TARGET_T )
45 {
46  m_Shape = 0;
47  m_Size = Millimeter2iu( 5 ); // Gives a decent size
49  m_Layer = Edge_Cuts; // a target is on all layers
50 }
51 
52 PCB_TARGET::PCB_TARGET( BOARD_ITEM* aParent, int aShape, PCB_LAYER_ID aLayer,
53  const wxPoint& aPos, int aSize, int aWidth ) :
54  BOARD_ITEM( aParent, PCB_TARGET_T )
55 {
56  m_Shape = aShape;
57  m_Layer = aLayer;
58  m_Pos = aPos;
59  m_Size = aSize;
60  m_Width = aWidth;
61 }
62 
63 
65 {
66 }
67 
68 
69 bool PCB_TARGET::HitTest( const wxPoint& aPosition, int aAccuracy ) const
70 {
71  int dX = aPosition.x - m_Pos.x;
72  int dY = aPosition.y - m_Pos.y;
73  int radius = aAccuracy + ( m_Size / 2 );
74  return abs( dX ) <= radius && abs( dY ) <= radius;
75 }
76 
77 
78 bool PCB_TARGET::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
79 {
80  EDA_RECT arect = aRect;
81  arect.Inflate( aAccuracy );
82 
83  if( aContained )
84  return arect.Contains( GetBoundingBox() );
85  else
86  return GetBoundingBox().Intersects( arect );
87 }
88 
89 
90 void PCB_TARGET::Rotate(const wxPoint& aRotCentre, double aAngle)
91 {
92  RotatePoint( &m_Pos, aRotCentre, aAngle );
93 }
94 
95 
96 void PCB_TARGET::Flip(const wxPoint& aCentre, bool aFlipLeftRight )
97 {
98  if( aFlipLeftRight )
99  m_Pos.x = aCentre.x - ( m_Pos.x - aCentre.x );
100  else
101  m_Pos.y = aCentre.y - ( m_Pos.y - aCentre.y );
102 
103  SetLayer( FlipLayer( GetLayer() ) );
104 }
105 
106 
108 {
109  EDA_RECT bBox;
110  bBox.SetX( m_Pos.x - m_Size/2 );
111  bBox.SetY( m_Pos.y - m_Size/2 );
112  bBox.SetWidth( m_Size );
113  bBox.SetHeight( m_Size );
114 
115  return bBox;
116 }
117 
118 
119 wxString PCB_TARGET::GetSelectMenuText( EDA_UNITS aUnits ) const
120 {
121  // Targets are on *every* layer by definition
122  return _( "Target" );
123 }
124 
125 
127 {
128  return add_pcb_target_xpm;
129 }
130 
131 
133 {
134  return new PCB_TARGET( *this );
135 }
136 
137 
139 {
140  assert( aImage->Type() == PCB_TARGET_T );
141 
142  std::swap( *((PCB_TARGET*) this), *((PCB_TARGET*) aImage) );
143 }
144 
145 
146 static struct PCB_TARGET_DESC
147 {
149  {
153  propMgr.AddProperty( new PROPERTY<PCB_TARGET, int>( _( "Size" ),
155  propMgr.AddProperty( new PROPERTY<PCB_TARGET, int>( _( "Width" ),
157 
158  auto shape = new PROPERTY<PCB_TARGET, int>( _( "Shape" ),
160  // TODO change the integer to an enum?
161  //shape->SetValues( { { 0, _( "Cross" ) }, { 1, ( "Plus" ) } } );
162  propMgr.AddProperty( shape );
163  }
EDA_UNITS
Definition: common.h:198
static PROPERTY_MANAGER & Instance()
Definition: property_mgr.h:61
#define TYPE_HASH(x)
Macro to generate unique identifier for a type
Definition: property.h:53
PNG memory record (file in memory).
Definition: bitmap_def.h:29
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
Implementation of conversion functions that require both schematic and board internal units.
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
void SetSize(int aSize)
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
int GetSize() const
PCB_LAYER_ID FlipLayer(PCB_LAYER_ID aLayerId, int aCopperLayersCount)
Definition: lset.cpp:520
#define DEFAULT_COPPER_LINE_WIDTH
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:208
#define REGISTER_TYPE(x)
Helper macro to map type hashes to names
Definition: property_mgr.h:244
bool Contains(const wxPoint &aPoint) const
Function Contains.
static struct PCB_TARGET_DESC _PCB_TARGET_DESC
PCB_LAYER_ID m_Layer
bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const override
Function HitTest tests if aPosition is contained within or on the bounding box of an item.
int GetWidth() const
PCB_LAYER_ID
A quick note on layer IDs:
Display value expressed in distance units (mm/inch)
Definition: property.h:47
void SetHeight(int val)
Definition: eda_rect.h:186
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
virtual void SwapData(BOARD_ITEM *aImage) override
Swap data between aItem and aImage.
void Flip(const wxPoint &aCentre, bool aFlipLeftRight) override
Function Flip Flip this object, i.e.
void InheritsAfter(TYPE_ID aDerived, TYPE_ID aBase)
Declares an inheritance relationship between types.
void SetShape(int aShape)
void SetX(int val)
Definition: eda_rect.h:168
void SetWidth(int val)
Definition: eda_rect.h:180
const BITMAP_OPAQUE add_pcb_target_xpm[1]
void SetY(int val)
Definition: eda_rect.h:174
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:105
void Rotate(const wxPoint &aRotCentre, double aAngle) override
Function Rotate Rotate this object.
#define _(s)
Definition: 3d_actions.cpp:33
void AddProperty(PROPERTY_BASE *aProperty)
Registers a property.
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
int GetShape() const
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:159
bool Intersects(const EDA_RECT &aRect) const
Function Intersects tests for a common area between rectangles.
void SetWidth(int aWidth)
Provides class metadata.
Definition: property_mgr.h:58
PCB_TARGET class definition.
PCB_TARGET(BOARD_ITEM *aParent)
static constexpr int Millimeter2iu(double mm)
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193