KiCad PCB EDA Suite
class_mire.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-2012 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 <common.h>
35 #include <class_drawpanel.h>
36 #include <kicad_string.h>
37 #include <colors_selection.h>
38 #include <trigo.h>
39 #include <macros.h>
40 #include <richio.h>
41 #include <bitmaps.h>
42 
43 #include <class_board.h>
44 #include <class_mire.h>
45 #include <base_units.h>
46 
47 
49  BOARD_ITEM( aParent, PCB_TARGET_T )
50 {
51  m_Shape = 0;
52  m_Size = Millimeter2iu( 5 ); // Gives a decent size
53  m_Width = Millimeter2iu( 0.15 ); // Gives a decent width
54  m_Layer = Edge_Cuts; // a target is on all layers
55 }
56 
57 PCB_TARGET::PCB_TARGET( BOARD_ITEM* aParent, int aShape, PCB_LAYER_ID aLayer,
58  const wxPoint& aPos, int aSize, int aWidth ) :
59  BOARD_ITEM( aParent, PCB_TARGET_T )
60 {
61  m_Shape = aShape;
62  m_Layer = aLayer;
63  m_Pos = aPos;
64  m_Size = aSize;
65  m_Width = aWidth;
66 }
67 
68 
70 {
71 }
72 
73 
74 /* Draw PCB_TARGET object: 2 segments + 1 circle
75  * The circle radius is half the radius of the target
76  * 2 lines have length the diameter of the target
77  */
78 void PCB_TARGET::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE mode_color,
79  const wxPoint& offset )
80 {
81  int radius, ox, oy, width;
82  int dx1, dx2, dy1, dy2;
83 
84  ox = m_Pos.x + offset.x;
85  oy = m_Pos.y + offset.y;
86 
87  BOARD * brd = GetBoard( );
88 
89  if( brd->IsLayerVisible( m_Layer ) == false )
90  return;
91 
92  COLOR4D gcolor = brd->GetLayerColor( m_Layer );
93 
94  GRSetDrawMode( DC, mode_color );
95  DISPLAY_OPTIONS* displ_opts = (DISPLAY_OPTIONS*)panel->GetDisplayOptions();
96  bool filled = displ_opts ? displ_opts->m_DisplayDrawItemsFill : FILLED;
97  width = m_Width;
98 
99  radius = m_Size / 3;
100 
101  if( GetShape() ) // shape X
102  radius = m_Size / 2;
103 
104  if( filled )
105  GRCircle( panel->GetClipBox(), DC, ox, oy, radius, width, gcolor );
106  else
107  {
108  GRCircle( panel->GetClipBox(), DC, ox, oy, radius + (width / 2), gcolor );
109  GRCircle( panel->GetClipBox(), DC, ox, oy, radius - (width / 2), gcolor );
110  }
111 
112 
113  radius = m_Size / 2;
114  dx1 = radius;
115  dy1 = 0;
116  dx2 = 0;
117  dy2 = radius;
118 
119  if( GetShape() ) // shape X
120  {
121  dx1 = dy1 = radius;
122  dx2 = dx1;
123  dy2 = -dy1;
124  }
125 
126  if( filled )
127  {
128  GRLine( panel->GetClipBox(), DC, ox - dx1, oy - dy1, ox + dx1, oy + dy1, width, gcolor );
129  GRLine( panel->GetClipBox(), DC, ox - dx2, oy - dy2, ox + dx2, oy + dy2, width, gcolor );
130  }
131  else
132  {
133  GRCSegm( panel->GetClipBox(), DC, ox - dx1, oy - dy1, ox + dx1, oy + dy1, width, gcolor );
134  GRCSegm( panel->GetClipBox(), DC, ox - dx2, oy - dy2, ox + dx2, oy + dy2, width, gcolor );
135  }
136 }
137 
138 
139 bool PCB_TARGET::HitTest( const wxPoint& aPosition ) const
140 {
141  int dX = aPosition.x - m_Pos.x;
142  int dY = aPosition.y - m_Pos.y;
143  int radius = m_Size / 2;
144  return abs( dX ) <= radius && abs( dY ) <= radius;
145 }
146 
147 
148 bool PCB_TARGET::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
149 {
150  EDA_RECT arect = aRect;
151  arect.Inflate( aAccuracy );
152 
153  if( aContained )
154  return arect.Contains( GetBoundingBox() );
155  else
156  return GetBoundingBox().Intersects( arect );
157 }
158 
159 
160 void PCB_TARGET::Rotate(const wxPoint& aRotCentre, double aAngle)
161 {
162  RotatePoint( &m_Pos, aRotCentre, aAngle );
163 }
164 
165 
166 void PCB_TARGET::Flip(const wxPoint& aCentre )
167 {
168  m_Pos.y = aCentre.y - ( m_Pos.y - aCentre.y );
169  SetLayer( FlipLayer( GetLayer() ) );
170 }
171 
172 
174 {
175  EDA_RECT bBox;
176  bBox.SetX( m_Pos.x - m_Size/2 );
177  bBox.SetY( m_Pos.y - m_Size/2 );
178  bBox.SetWidth( m_Size );
179  bBox.SetHeight( m_Size );
180 
181  return bBox;
182 }
183 
184 
186 {
187  wxString text;
188  wxString msg;
189 
190  msg = ::CoordinateToString( m_Size );
191 
192  // Targets are on *every* layer by definition
193  text.Printf( _( "Target size %s" ), GetChars( msg ) );
194 
195  return text;
196 }
197 
198 
200 {
201  return add_mires_xpm;
202 }
203 
205 {
206  return new PCB_TARGET( *this );
207 }
wxString CoordinateToString(int aValue, bool aConvertToMils)
Function CoordinateToString is a helper to convert the integer coordinate aValue to a string in inche...
Definition: base_units.cpp:117
COLOR4D GetLayerColor(PCB_LAYER_ID aLayer) const
Function GetLayerColor gets a layer color for any valid layer, including non-copper ones...
PCB_TARGET class definition.
PNG memory record (file in memory).
Definition: bitmap_types.h:38
void GRSetDrawMode(wxDC *DC, GR_DRAWMODE draw_mode)
Definition: gr_basic.cpp:290
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: class_mire.cpp:199
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...
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
bool Contains(const wxPoint &aPoint) const
Function Contains.
void GRLine(EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, int width, COLOR4D Color)
Definition: gr_basic.cpp:352
Class BOARD to handle a board.
PCB_LAYER_ID FlipLayer(PCB_LAYER_ID aLayerId, int aCopperLayersCount)
Function FlippedLayerNumber.
Definition: lset.cpp:445
void Flip(const wxPoint &aCentre) override
Function Flip Flip this object, i.e.
Definition: class_mire.cpp:166
void GRCSegm(EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, int width, int aPenSize, COLOR4D Color)
Definition: gr_basic.cpp:481
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:317
#define abs(a)
Definition: auxiliary.h:84
This file contains miscellaneous commonly used macros and functions.
int m_Shape
Definition: class_mire.h:44
PCB_LAYER_ID m_Layer
PCB_LAYER_ID
A quick note on layer IDs:
int GetShape() const
Definition: class_mire.h:66
void SetHeight(int val)
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: class_mire.cpp:204
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:41
bool m_DisplayDrawItemsFill
Definition: pcbstruct.h:84
EDA_RECT * GetClipBox()
void SetX(int val)
void Draw(EDA_DRAW_PANEL *panel, wxDC *DC, GR_DRAWMODE aDrawMode, const wxPoint &offset=ZeroOffset) override
Function Draw BOARD_ITEMs have their own color information.
Definition: class_mire.cpp:78
void SetWidth(int val)
int m_Width
Definition: class_mire.h:46
void SetY(int val)
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:113
Class DISPLAY_OPTIONS handles display options like enable/disable some optional drawings.
Definition: pcbstruct.h:62
void Rotate(const wxPoint &aRotCentre, double aAngle) override
Function Rotate Rotate this object.
Definition: class_mire.cpp:160
bool Intersects(const EDA_RECT &aRect) const
Function Intersects tests for a common area between rectangles.
PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
void GRCircle(EDA_RECT *ClipBox, wxDC *DC, int xc, int yc, int r, int width, COLOR4D Color)
Definition: gr_basic.cpp:791
wxString GetSelectMenuText() const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: class_mire.cpp:185
Class EDA_RECT handles the component boundary box.
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:151
The common library.
virtual BOARD * GetBoard() const
Function GetBoard returns the BOARD in which this BOARD_ITEM resides, or NULL if none.
void * GetDisplayOptions()
Function GetDisplayOptions A way to pass info to draw functions.
Definition: draw_panel.cpp:182
PCB_TARGET(BOARD_ITEM *aParent)
Definition: class_mire.cpp:48
wxPoint m_Pos
Definition: class_mire.h:47
int m_Size
Definition: class_mire.h:45
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes...
Definition: class_mire.cpp:173
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
bool HitTest(const wxPoint &aPosition) const override
Function HitTest tests if aPosition is contained within or on the bounding area of an item...
Definition: class_mire.cpp:139
bool IsLayerVisible(PCB_LAYER_ID aLayer) const
Function IsLayerVisible is a proxy function that calls the correspondent function in m_BoardSettings ...
Definition: class_board.h:443
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39