KiCad PCB EDA Suite
PCB_GRID_HELPER Class Reference

#include <pcb_grid_helper.h>

Inheritance diagram for PCB_GRID_HELPER:
GRID_HELPER

Public Types

enum  ANCHOR_FLAGS {
  CORNER = 1, OUTLINE = 2, SNAPPABLE = 4, ORIGIN = 8,
  VERTICAL = 16, HORIZONTAL = 32, ALL = CORNER | OUTLINE | SNAPPABLE | ORIGIN | VERTICAL | HORIZONTAL
}
 

Public Member Functions

 PCB_GRID_HELPER (TOOL_MANAGER *aToolMgr, MAGNETIC_SETTINGS *aMagneticSettings)
 
BOARD_ITEMGetSnapped () const
 Function GetSnapped If the PCB_GRID_HELPER has highlighted a snap point (target shown), this function will return a pointer to the item to which it snapped. More...
 
VECTOR2I AlignToSegment (const VECTOR2I &aPoint, const SEG &aSeg)
 
VECTOR2I BestDragOrigin (const VECTOR2I &aMousePos, std::vector< BOARD_ITEM * > &aItem)
 
VECTOR2I AlignToArc (const VECTOR2I &aPoint, const SHAPE_ARC &aSeg)
 
VECTOR2I BestSnapAnchor (const VECTOR2I &aOrigin, BOARD_ITEM *aReferenceItem)
 Chooses the "best" snap anchor around the given point, optionally taking layers from the reference item. More...
 
VECTOR2I BestSnapAnchor (const VECTOR2I &aOrigin, const LSET &aLayers, const std::vector< BOARD_ITEM * > &aSkip={})
 
VECTOR2I GetGrid () const
 
VECTOR2I GetOrigin () const
 
void SetAuxAxes (bool aEnable, const VECTOR2I &aOrigin=VECTOR2I(0, 0))
 
virtual VECTOR2I Align (const VECTOR2I &aPoint) const
 
VECTOR2I AlignGrid (const VECTOR2I &aPoint) const
 
void SetSkipPoint (const VECTOR2I &aPoint)
 
void ClearSkipPoint ()
 We clear the skip point by setting it to an unreachable position, thereby preventing matching. More...
 
void SetSnap (bool aSnap)
 
bool GetSnap () const
 
void SetUseGrid (bool aSnapToGrid)
 
bool GetUseGrid () const
 
void SetSnapLine (bool aSnap)
 
void SetMask (int aMask)
 
void SetMaskFlag (int aFlag)
 
void ClearMaskFlag (int aFlag)
 

Protected Member Functions

void addAnchor (const VECTOR2I &aPos, int aFlags, EDA_ITEM *aItem)
 
void clearAnchors ()
 
bool canUseGrid () const
 Check whether it is possible to use the grid – this depends both on local grid helper settings and global (tool manager) KiCad settings. More...
 

Protected Attributes

std::vector< ANCHORm_anchors
 
TOOL_MANAGERm_toolMgr
 
OPT< VECTOR2Im_auxAxis
 
int m_maskTypes
 
bool m_enableSnap
 
bool m_enableGrid
 
bool m_enableSnapLine
 
ANCHORm_snapItem
 
VECTOR2I m_skipPoint
 
KIGFX::ORIGIN_VIEWITEM m_viewSnapPoint
 
KIGFX::ORIGIN_VIEWITEM m_viewSnapLine
 
KIGFX::ORIGIN_VIEWITEM m_viewAxis
 

Private Member Functions

std::set< BOARD_ITEM * > queryVisible (const BOX2I &aArea, const std::vector< BOARD_ITEM * > &aSkip) const
 
ANCHORnearestAnchor (const VECTOR2I &aPos, int aFlags, LSET aMatchLayers)
 
void computeAnchors (BOARD_ITEM *aItem, const VECTOR2I &aRefPos, bool aFrom=false)
 computeAnchors inserts the local anchor points in to the grid helper for the specified board item, given the reference point and the direction of use for the point. More...
 

Private Attributes

MAGNETIC_SETTINGSm_magneticSettings
 

Detailed Description

Definition at line 34 of file pcb_grid_helper.h.

Member Enumeration Documentation

◆ ANCHOR_FLAGS

enum GRID_HELPER::ANCHOR_FLAGS
inherited
Enumerator
CORNER 
OUTLINE 
SNAPPABLE 
ORIGIN 
VERTICAL 
HORIZONTAL 
ALL 

Definition at line 76 of file grid_helper.h.

Constructor & Destructor Documentation

◆ PCB_GRID_HELPER()

PCB_GRID_HELPER::PCB_GRID_HELPER ( TOOL_MANAGER aToolMgr,
MAGNETIC_SETTINGS aMagneticSettings 
)

Definition at line 48 of file pcb_grid_helper.cpp.

48  :
49  GRID_HELPER( aToolMgr ),
50  m_magneticSettings( aMagneticSettings )
51 {
52  KIGFX::VIEW* view = m_toolMgr->GetView();
53  KIGFX::RENDER_SETTINGS* settings = view->GetPainter()->GetSettings();
54  KIGFX::COLOR4D auxItemsColor = settings->GetLayerColor( LAYER_AUX_ITEMS );
55  KIGFX::COLOR4D umbilicalColor = settings->GetLayerColor( LAYER_ANCHOR );
56 
57  m_viewAxis.SetSize( 20000 );
59  m_viewAxis.SetColor( auxItemsColor.WithAlpha( 0.4 ) );
60  m_viewAxis.SetDrawAtZero( true );
61  view->Add( &m_viewAxis );
62  view->SetVisible( &m_viewAxis, false );
63 
65  m_viewSnapPoint.SetColor( auxItemsColor );
67  view->Add( &m_viewSnapPoint );
68  view->SetVisible( &m_viewSnapPoint, false );
69 
71  m_viewSnapLine.SetColor( umbilicalColor );
73  view->Add( &m_viewSnapLine );
74  view->SetVisible( &m_viewSnapLine, false );
75 }
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:289
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
anchor of items having an anchor point (texts, footprints)
TOOL_MANAGER * m_toolMgr
Definition: grid_helper.h:129
KIGFX::ORIGIN_VIEWITEM m_viewAxis
Definition: grid_helper.h:143
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
COLOR4D WithAlpha(double aAlpha) const
Return a color with the same color, but the given alpha.
Definition: color4d.h:300
MAGNETIC_SETTINGS * m_magneticSettings
GRID_HELPER(TOOL_MANAGER *aToolMgr)
Definition: grid_helper.cpp:35
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:207
KIGFX::ORIGIN_VIEWITEM m_viewSnapPoint
Definition: grid_helper.h:141
Auxiliary items (guides, rule, etc)
void SetSize(int aSize)
void SetDrawAtZero(bool aDrawFlag)
Set the draw at zero flag.
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
void SetColor(const KIGFX::COLOR4D &aColor)
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Set the item visibility.
Definition: view.cpp:1449
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:322
KIGFX::ORIGIN_VIEWITEM m_viewSnapLine
Definition: grid_helper.h:142
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:67
void SetStyle(MARKER_STYLE aStyle)
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98

References KIGFX::VIEW::Add(), KIGFX::ORIGIN_VIEWITEM::CIRCLE_CROSS, KIGFX::ORIGIN_VIEWITEM::CROSS, KIGFX::ORIGIN_VIEWITEM::DASH_LINE, KIGFX::RENDER_SETTINGS::GetLayerColor(), KIGFX::VIEW::GetPainter(), KIGFX::PAINTER::GetSettings(), TOOL_MANAGER::GetView(), LAYER_ANCHOR, LAYER_AUX_ITEMS, GRID_HELPER::m_toolMgr, GRID_HELPER::m_viewAxis, GRID_HELPER::m_viewSnapLine, GRID_HELPER::m_viewSnapPoint, KIGFX::ORIGIN_VIEWITEM::SetColor(), KIGFX::ORIGIN_VIEWITEM::SetDrawAtZero(), KIGFX::ORIGIN_VIEWITEM::SetSize(), KIGFX::ORIGIN_VIEWITEM::SetStyle(), KIGFX::VIEW::SetVisible(), and KIGFX::COLOR4D::WithAlpha().

Member Function Documentation

◆ addAnchor()

void GRID_HELPER::addAnchor ( const VECTOR2I aPos,
int  aFlags,
EDA_ITEM aItem 
)
inlineprotectedinherited

Definition at line 106 of file grid_helper.h.

107  {
108  if( ( aFlags & m_maskTypes ) == aFlags )
109  m_anchors.emplace_back( ANCHOR( aPos, aFlags, aItem ) );
110  }
std::vector< ANCHOR > m_anchors
Definition: grid_helper.h:127

References GRID_HELPER::m_anchors, and GRID_HELPER::m_maskTypes.

Referenced by EE_GRID_HELPER::computeAnchors(), and computeAnchors().

◆ Align()

VECTOR2I GRID_HELPER::Align ( const VECTOR2I aPoint) const
virtualinherited

Definition at line 95 of file grid_helper.cpp.

96 {
97  if( !canUseGrid() )
98  return aPoint;
99 
100  VECTOR2I nearest = AlignGrid( aPoint );
101 
102  if( !m_auxAxis )
103  return nearest;
104 
105  if( std::abs( m_auxAxis->x - aPoint.x ) < std::abs( nearest.x - aPoint.x ) )
106  nearest.x = m_auxAxis->x;
107 
108  if( std::abs( m_auxAxis->y - aPoint.y ) < std::abs( nearest.y - aPoint.y ) )
109  nearest.y = m_auxAxis->y;
110 
111  return nearest;
112 }
OPT< VECTOR2I > m_auxAxis
Definition: grid_helper.h:130
bool canUseGrid() const
Check whether it is possible to use the grid – this depends both on local grid helper settings and gl...
Definition: grid_helper.h:121
VECTOR2I AlignGrid(const VECTOR2I &aPoint) const
Definition: grid_helper.cpp:83

References GRID_HELPER::AlignGrid(), GRID_HELPER::canUseGrid(), GRID_HELPER::m_auxAxis, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by EE_GRID_HELPER::BestSnapAnchor(), BestSnapAnchor(), EE_GRID_HELPER::computeAnchors(), PNS::TOOL_BASE::snapToItem(), and PNS::TOOL_BASE::updateEndItem().

◆ AlignGrid()

VECTOR2I GRID_HELPER::AlignGrid ( const VECTOR2I aPoint) const
inherited

Definition at line 83 of file grid_helper.cpp.

84 {
85  const VECTOR2D gridOffset( GetOrigin() );
86  const VECTOR2D grid( GetGrid() );
87 
88  VECTOR2I nearest( KiROUND( ( aPoint.x - gridOffset.x ) / grid.x ) * grid.x + gridOffset.x,
89  KiROUND( ( aPoint.y - gridOffset.y ) / grid.y ) * grid.y + gridOffset.y );
90 
91  return nearest;
92 }
VECTOR2I GetOrigin() const
Definition: grid_helper.cpp:59
VECTOR2I GetGrid() const
Definition: grid_helper.cpp:51
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:68

References GRID_HELPER::GetGrid(), GRID_HELPER::GetOrigin(), grid, KiROUND(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by GRID_HELPER::Align().

◆ AlignToArc()

VECTOR2I PCB_GRID_HELPER::AlignToArc ( const VECTOR2I aPoint,
const SHAPE_ARC aSeg 
)

Definition at line 118 of file pcb_grid_helper.cpp.

119 {
120  if( !m_enableSnap )
121  return aPoint;
122 
123  const VECTOR2D gridOffset( GetOrigin() );
124  const VECTOR2D gridSize( GetGrid() );
125 
126  VECTOR2I nearest( KiROUND( ( aPoint.x - gridOffset.x ) / gridSize.x ) * gridSize.x + gridOffset.x,
127  KiROUND( ( aPoint.y - gridOffset.y ) / gridSize.y ) * gridSize.y + gridOffset.y );
128 
129  int min_d = std::numeric_limits<int>::max();
130 
131  for( auto pt : { aArc.GetP0(), aArc.GetP1() } )
132  {
133  int d = ( pt - aPoint ).EuclideanNorm();
134 
135  if( d < min_d )
136  {
137  min_d = d;
138  nearest = pt;
139  }
140  else
141  break;
142  }
143 
144  return nearest;
145 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:148
VECTOR2I GetOrigin() const
Definition: grid_helper.cpp:59
VECTOR2I GetGrid() const
Definition: grid_helper.cpp:51
bool m_enableSnap
Definition: grid_helper.h:134
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:68

References EuclideanNorm(), GRID_HELPER::GetGrid(), GRID_HELPER::GetOrigin(), SHAPE_ARC::GetP0(), SHAPE_ARC::GetP1(), KiROUND(), GRID_HELPER::m_enableSnap, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by PNS::TOOL_BASE::snapToItem().

◆ AlignToSegment()

VECTOR2I PCB_GRID_HELPER::AlignToSegment ( const VECTOR2I aPoint,
const SEG aSeg 
)

Definition at line 78 of file pcb_grid_helper.cpp.

79 {
80  OPT_VECTOR2I pts[6];
81 
82  const int c_gridSnapEpsilon = 2;
83 
84  if( !m_enableSnap )
85  return aPoint;
86 
87  const VECTOR2D gridOffset( GetOrigin() );
88  const VECTOR2D gridSize( GetGrid() );
89 
90  VECTOR2I nearest( KiROUND( ( aPoint.x - gridOffset.x ) / gridSize.x ) * gridSize.x + gridOffset.x,
91  KiROUND( ( aPoint.y - gridOffset.y ) / gridSize.y ) * gridSize.y + gridOffset.y );
92 
93  pts[0] = aSeg.A;
94  pts[1] = aSeg.B;
95  pts[2] = aSeg.IntersectLines( SEG( nearest + VECTOR2I( -1, 1 ), nearest + VECTOR2I( 1, -1 ) ) );
96  pts[3] = aSeg.IntersectLines( SEG( nearest + VECTOR2I( -1, -1 ), nearest + VECTOR2I( 1, 1 ) ) );
97 
98  int min_d = std::numeric_limits<int>::max();
99 
100  for( int i = 0; i < 4; i++ )
101  {
102  if( pts[i] && aSeg.Distance( *pts[i] ) <= c_gridSnapEpsilon )
103  {
104  int d = (*pts[i] - aPoint).EuclideanNorm();
105 
106  if( d < min_d )
107  {
108  min_d = d;
109  nearest = *pts[i];
110  }
111  }
112  }
113 
114  return nearest;
115 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:148
int Distance(const SEG &aSeg) const
Compute minimum Euclidean distance to segment aSeg.
Definition: seg.h:239
VECTOR2I GetOrigin() const
Definition: grid_helper.cpp:59
OPT_VECTOR2I IntersectLines(const SEG &aSeg) const
Compute the intersection point of lines passing through ends of (this) and aSeg.
Definition: seg.h:208
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
VECTOR2I GetGrid() const
Definition: grid_helper.cpp:51
OPT< VECTOR2I > OPT_VECTOR2I
Definition: seg.h:39
bool m_enableSnap
Definition: grid_helper.h:134
Definition: seg.h:41
VECTOR2I A
Definition: seg.h:49
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:68
VECTOR2I B
Definition: seg.h:50

References SEG::A, SEG::B, SEG::Distance(), EuclideanNorm(), GRID_HELPER::GetGrid(), GRID_HELPER::GetOrigin(), SEG::IntersectLines(), KiROUND(), GRID_HELPER::m_enableSnap, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by DRAWING_TOOL::DrawVia(), and PNS::TOOL_BASE::snapToItem().

◆ BestDragOrigin()

VECTOR2I PCB_GRID_HELPER::BestDragOrigin ( const VECTOR2I aMousePos,
std::vector< BOARD_ITEM * > &  aItem 
)

Definition at line 148 of file pcb_grid_helper.cpp.

150 {
151  clearAnchors();
152 
153  for( BOARD_ITEM* item : aItems )
154  computeAnchors( item, aMousePos, true );
155 
156  double worldScale = m_toolMgr->GetView()->GetGAL()->GetWorldScale();
157  double lineSnapMinCornerDistance = 50.0 / worldScale;
158 
159  ANCHOR* nearestOutline = nearestAnchor( aMousePos, OUTLINE, LSET::AllLayersMask() );
160  ANCHOR* nearestCorner = nearestAnchor( aMousePos, CORNER, LSET::AllLayersMask() );
161  ANCHOR* nearestOrigin = nearestAnchor( aMousePos, ORIGIN, LSET::AllLayersMask() );
162  ANCHOR* best = NULL;
163  double minDist = std::numeric_limits<double>::max();
164 
165  if( nearestOrigin )
166  {
167  minDist = nearestOrigin->Distance( aMousePos );
168  best = nearestOrigin;
169  }
170 
171  if( nearestCorner )
172  {
173  double dist = nearestCorner->Distance( aMousePos );
174 
175  if( dist < minDist )
176  {
177  minDist = dist;
178  best = nearestCorner;
179  }
180  }
181 
182  if( nearestOutline )
183  {
184  double dist = nearestOutline->Distance( aMousePos );
185 
186  if( minDist > lineSnapMinCornerDistance && dist < minDist )
187  best = nearestOutline;
188  }
189 
190  return best ? best->pos : aMousePos;
191 }
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:289
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:82
TOOL_MANAGER * m_toolMgr
Definition: grid_helper.h:129
GAL * GetGAL() const
Return the #GAL this view is using to draw graphical primitives.
Definition: view.h:189
ANCHOR * nearestAnchor(const VECTOR2I &aPos, int aFlags, LSET aMatchLayers)
void computeAnchors(BOARD_ITEM *aItem, const VECTOR2I &aRefPos, bool aFrom=false)
computeAnchors inserts the local anchor points in to the grid helper for the specified board item,...
#define NULL
static LSET AllLayersMask()
Definition: lset.cpp:787
double GetWorldScale() const
Get the world scale.
void clearAnchors()
Definition: grid_helper.h:112

References LSET::AllLayersMask(), GRID_HELPER::clearAnchors(), computeAnchors(), GRID_HELPER::CORNER, GRID_HELPER::ANCHOR::Distance(), KIGFX::VIEW::GetGAL(), TOOL_MANAGER::GetView(), KIGFX::GAL::GetWorldScale(), GRID_HELPER::m_toolMgr, nearestAnchor(), NULL, GRID_HELPER::ORIGIN, GRID_HELPER::OUTLINE, and GRID_HELPER::ANCHOR::pos.

◆ BestSnapAnchor() [1/2]

VECTOR2I PCB_GRID_HELPER::BestSnapAnchor ( const VECTOR2I aOrigin,
BOARD_ITEM aReferenceItem 
)

Chooses the "best" snap anchor around the given point, optionally taking layers from the reference item.

The reference item will not be snapped to (it is being dragged or created) and we choose the layers that can be snapped based on the reference item layer

Parameters
aOriginPoint we want to snap from
aReferenceItemReference item for layer/type special casing
Returns
snapped screen point

Definition at line 194 of file pcb_grid_helper.cpp.

195 {
196  LSET layers;
197  std::vector<BOARD_ITEM*> item;
198 
199  if( aReferenceItem )
200  {
201  layers = aReferenceItem->GetLayerSet();
202  item.push_back( aReferenceItem );
203  }
204  else
205  layers = LSET::AllLayersMask();
206 
207  return BestSnapAnchor( aOrigin, layers, item );
208 }
LSET is a set of PCB_LAYER_IDs.
VECTOR2I BestSnapAnchor(const VECTOR2I &aOrigin, BOARD_ITEM *aReferenceItem)
Chooses the "best" snap anchor around the given point, optionally taking layers from the reference it...
static LSET AllLayersMask()
Definition: lset.cpp:787
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition: board_item.h:178

References LSET::AllLayersMask(), and BOARD_ITEM::GetLayerSet().

◆ BestSnapAnchor() [2/2]

VECTOR2I PCB_GRID_HELPER::BestSnapAnchor ( const VECTOR2I aOrigin,
const LSET aLayers,
const std::vector< BOARD_ITEM * > &  aSkip = {} 
)

Allows de-snapping from the line if you are closer to another snap point

Definition at line 211 of file pcb_grid_helper.cpp.

213 {
214  // Tuning constant: snap radius in screen space
215  const int snapSize = 25;
216 
217  // Snapping distance is in screen space, clamped to the current grid to ensure that the grid
218  // points that are visible can always be snapped to.
219  // see https://gitlab.com/kicad/code/kicad/-/issues/5638
220  // see https://gitlab.com/kicad/code/kicad/-/issues/7125
221  double snapScale = snapSize / m_toolMgr->GetView()->GetGAL()->GetWorldScale();
222  int snapRange = std::min( KiROUND( snapScale ), GetGrid().x );
223  int snapDist = snapRange;
224 
225  BOX2I bb( VECTOR2I( aOrigin.x - snapRange / 2, aOrigin.y - snapRange / 2 ),
226  VECTOR2I( snapRange, snapRange ) );
227 
228  clearAnchors();
229 
230  for( BOARD_ITEM* item : queryVisible( bb, aSkip ) )
231  computeAnchors( item, aOrigin );
232 
233  ANCHOR* nearest = nearestAnchor( aOrigin, SNAPPABLE, aLayers );
234  VECTOR2I nearestGrid = Align( aOrigin );
235 
236  if( nearest )
237  snapDist = nearest->Distance( aOrigin );
238 
239  // Existing snap lines need priority over new snaps
241  {
242  bool snapLine = false;
243  int x_dist = std::abs( m_viewSnapLine.GetPosition().x - aOrigin.x );
244  int y_dist = std::abs( m_viewSnapLine.GetPosition().y - aOrigin.y );
245 
247  if( x_dist < snapRange && ( !nearest || snapDist > snapRange ) )
248  {
249  nearestGrid.x = m_viewSnapLine.GetPosition().x;
250  snapLine = true;
251  }
252 
253  if( y_dist < snapRange && ( !nearest || snapDist > snapRange ) )
254  {
255  nearestGrid.y = m_viewSnapLine.GetPosition().y;
256  snapLine = true;
257  }
258 
259  if( snapLine && m_skipPoint != VECTOR2I( m_viewSnapLine.GetPosition() ) )
260  {
261  m_viewSnapLine.SetEndPosition( nearestGrid );
262 
265  else
267 
268  return nearestGrid;
269  }
270  }
271 
272  if( nearest && m_enableSnap )
273  {
274  if( nearest->Distance( aOrigin ) <= snapRange )
275  {
276  m_viewSnapPoint.SetPosition( wxPoint( nearest->pos ) );
277  m_viewSnapLine.SetPosition( wxPoint( nearest->pos ) );
279 
282  else
284 
285  m_snapItem = nearest;
286  return nearest->pos;
287  }
288  }
289 
290  m_snapItem = nullptr;
293  return nearestGrid;
294 }
void SetPosition(const wxPoint &aPosition) override
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:289
wxPoint GetPosition() const override
ANCHOR * m_snapItem
Definition: grid_helper.h:137
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:82
TOOL_MANAGER * m_toolMgr
Definition: grid_helper.h:129
Define a general 2D-vector/point.
Definition: vector2d.h:61
GAL * GetGAL() const
Return the #GAL this view is using to draw graphical primitives.
Definition: view.h:189
void SetEndPosition(const VECTOR2D &aPosition)
std::set< BOARD_ITEM * > queryVisible(const BOX2I &aArea, const std::vector< BOARD_ITEM * > &aSkip) const
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
VECTOR2I GetGrid() const
Definition: grid_helper.cpp:51
KIGFX::ORIGIN_VIEWITEM m_viewSnapPoint
Definition: grid_helper.h:141
ANCHOR * nearestAnchor(const VECTOR2I &aPos, int aFlags, LSET aMatchLayers)
void computeAnchors(BOARD_ITEM *aItem, const VECTOR2I &aRefPos, bool aFrom=false)
computeAnchors inserts the local anchor points in to the grid helper for the specified board item,...
bool IsVisible(const VIEW_ITEM *aItem) const
Return information if the item is visible (or not).
Definition: view.cpp:1489
bool m_enableSnap
Definition: grid_helper.h:134
bool m_enableSnapLine
Definition: grid_helper.h:136
virtual VECTOR2I Align(const VECTOR2I &aPoint) const
Definition: grid_helper.cpp:95
VECTOR2I m_skipPoint
Definition: grid_helper.h:139
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:68
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Set the item visibility.
Definition: view.cpp:1449
KIGFX::ORIGIN_VIEWITEM m_viewSnapLine
Definition: grid_helper.h:142
double GetWorldScale() const
Get the world scale.
void clearAnchors()
Definition: grid_helper.h:112
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition: view.cpp:1503
Position or shape has changed.
Definition: view_item.h:54

References GRID_HELPER::Align(), GRID_HELPER::clearAnchors(), computeAnchors(), GRID_HELPER::ANCHOR::Distance(), KIGFX::GEOMETRY, KIGFX::VIEW::GetGAL(), GRID_HELPER::GetGrid(), KIGFX::ORIGIN_VIEWITEM::GetPosition(), TOOL_MANAGER::GetView(), KIGFX::GAL::GetWorldScale(), KIGFX::VIEW::IsVisible(), KiROUND(), GRID_HELPER::m_enableSnap, GRID_HELPER::m_enableSnapLine, GRID_HELPER::m_skipPoint, GRID_HELPER::m_snapItem, GRID_HELPER::m_toolMgr, GRID_HELPER::m_viewSnapLine, GRID_HELPER::m_viewSnapPoint, nearestAnchor(), GRID_HELPER::ANCHOR::pos, queryVisible(), KIGFX::ORIGIN_VIEWITEM::SetEndPosition(), KIGFX::ORIGIN_VIEWITEM::SetPosition(), KIGFX::VIEW::SetVisible(), GRID_HELPER::SNAPPABLE, KIGFX::VIEW::Update(), VECTOR2< T >::x, and VECTOR2< T >::y.

◆ canUseGrid()

bool GRID_HELPER::canUseGrid ( ) const
inlineprotectedinherited

Check whether it is possible to use the grid – this depends both on local grid helper settings and global (tool manager) KiCad settings.

Definition at line 121 of file grid_helper.h.

122  {
124  }
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:289
TOOL_MANAGER * m_toolMgr
Definition: grid_helper.h:129
GAL * GetGAL() const
Return the #GAL this view is using to draw graphical primitives.
Definition: view.h:189
bool GetGridSnapping() const
bool m_enableGrid
Definition: grid_helper.h:135

References KIGFX::VIEW::GetGAL(), KIGFX::GAL::GetGridSnapping(), TOOL_MANAGER::GetView(), GRID_HELPER::m_enableGrid, and GRID_HELPER::m_toolMgr.

Referenced by GRID_HELPER::Align(), and EE_GRID_HELPER::BestSnapAnchor().

◆ clearAnchors()

void GRID_HELPER::clearAnchors ( )
inlineprotectedinherited

Definition at line 112 of file grid_helper.h.

113  {
114  m_anchors.clear();
115  }
std::vector< ANCHOR > m_anchors
Definition: grid_helper.h:127

References GRID_HELPER::m_anchors.

Referenced by BestDragOrigin(), EE_GRID_HELPER::BestDragOrigin(), EE_GRID_HELPER::BestSnapAnchor(), and BestSnapAnchor().

◆ ClearMaskFlag()

void GRID_HELPER::ClearMaskFlag ( int  aFlag)
inlineinherited

Definition at line 74 of file grid_helper.h.

74 { m_maskTypes = m_maskTypes & ~aFlag; }

References GRID_HELPER::m_maskTypes.

◆ ClearSkipPoint()

void GRID_HELPER::ClearSkipPoint ( )
inlineinherited

We clear the skip point by setting it to an unreachable position, thereby preventing matching.

Definition at line 59 of file grid_helper.h.

60  {
61  m_skipPoint = VECTOR2I( std::numeric_limits<int>::min(), std::numeric_limits<int>::min() );
62  }
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
VECTOR2I m_skipPoint
Definition: grid_helper.h:139

References GRID_HELPER::m_skipPoint.

◆ computeAnchors()

void PCB_GRID_HELPER::computeAnchors ( BOARD_ITEM aItem,
const VECTOR2I aRefPos,
bool  aFrom = false 
)
private

computeAnchors inserts the local anchor points in to the grid helper for the specified board item, given the reference point and the direction of use for the point.

Parameters
aItemThe board item for which to compute the anchors
aRefPosThe point for which to compute the anchors (if used by the component)
aFromIs this for an anchor that is designating a source point (aFrom=true) or not

If we are getting a drag point, we don't want to center the edge of pads

Definition at line 346 of file pcb_grid_helper.cpp.

347 {
348  KIGFX::VIEW* view = m_toolMgr->GetView();
349  RENDER_SETTINGS* settings = view->GetPainter()->GetSettings();
350  const std::set<unsigned int>& activeLayers = settings->GetHighContrastLayers();
351  bool isHighContrast = settings->GetHighContrast();
352 
353  auto handlePadShape =
354  [&]( PAD* aPad )
355  {
356  addAnchor( aPad->GetPosition(), ORIGIN | SNAPPABLE, aPad );
357 
359  if( aFrom )
360  return;
361 
362  const std::shared_ptr<SHAPE> eshape = aPad->GetEffectiveShape( aPad->GetLayer() );
363 
364  wxASSERT( eshape->Type() == SH_COMPOUND );
365  const std::vector<SHAPE*> shapes =
366  static_cast<const SHAPE_COMPOUND*>( eshape.get() )->Shapes();
367 
368  for( const SHAPE* shape : shapes )
369  {
370  switch( shape->Type() )
371  {
372  case SH_RECT:
373  {
374  const SHAPE_RECT* rect = static_cast<const SHAPE_RECT*>( shape );
375  SHAPE_LINE_CHAIN outline = rect->Outline();
376 
377  for( int i = 0; i < outline.SegmentCount(); i++ )
378  {
379  const SEG& seg = outline.CSegment( i );
380  addAnchor( seg.A, OUTLINE | SNAPPABLE, aPad );
381  addAnchor( seg.Center(), OUTLINE | SNAPPABLE, aPad );
382  }
383 
384  break;
385  }
386 
387  case SH_SEGMENT:
388  {
389  const SHAPE_SEGMENT* segment = static_cast<const SHAPE_SEGMENT*>( shape );
390 
391  int offset = segment->GetWidth() / 2;
392  SEG seg = segment->GetSeg();
393  VECTOR2I normal = ( seg.B - seg.A ).Resize( offset ).Rotate( -M_PI_2 );
394 
395  /*
396  * TODO: This creates more snap points than necessary for rounded rect pads
397  * because they are built up of overlapping segments. We could fix this if
398  * desired by testing these to see if they are "inside" the pad.
399  */
400 
401  addAnchor( seg.A + normal, OUTLINE | SNAPPABLE, aPad );
402  addAnchor( seg.A - normal, OUTLINE | SNAPPABLE, aPad );
403  addAnchor( seg.B + normal, OUTLINE | SNAPPABLE, aPad );
404  addAnchor( seg.B - normal, OUTLINE | SNAPPABLE, aPad );
405  addAnchor( seg.Center() + normal, OUTLINE | SNAPPABLE, aPad );
406  addAnchor( seg.Center() - normal, OUTLINE | SNAPPABLE, aPad );
407 
408  normal = normal.Rotate( M_PI_2 );
409 
410  addAnchor( seg.A - normal, OUTLINE | SNAPPABLE, aPad );
411  addAnchor( seg.B + normal, OUTLINE | SNAPPABLE, aPad );
412  break;
413  }
414 
415  case SH_CIRCLE:
416  {
417  const SHAPE_CIRCLE* circle = static_cast<const SHAPE_CIRCLE*>( shape );
418 
419  int r = circle->GetRadius();
420  VECTOR2I start = circle->GetCenter();
421 
422  addAnchor( start + VECTOR2I( -r, 0 ), OUTLINE | SNAPPABLE, aPad );
423  addAnchor( start + VECTOR2I( r, 0 ), OUTLINE | SNAPPABLE, aPad );
424  addAnchor( start + VECTOR2I( 0, -r ), OUTLINE | SNAPPABLE, aPad );
425  addAnchor( start + VECTOR2I( 0, r ), OUTLINE | SNAPPABLE, aPad );
426  break;
427  }
428 
429  case SH_ARC:
430  {
431  const SHAPE_ARC* arc = static_cast<const SHAPE_ARC*>( shape );
432 
433  addAnchor( arc->GetP0(), OUTLINE | SNAPPABLE, aPad );
434  addAnchor( arc->GetP1(), OUTLINE | SNAPPABLE, aPad );
435  addAnchor( arc->GetArcMid(), OUTLINE | SNAPPABLE, aPad );
436  break;
437  }
438 
439  case SH_SIMPLE:
440  {
441  const SHAPE_SIMPLE* poly = static_cast<const SHAPE_SIMPLE*>( shape );
442 
443  for( size_t i = 0; i < poly->GetSegmentCount(); i++ )
444  {
445  const SEG& seg = poly->GetSegment( i );
446 
447  addAnchor( seg.A, OUTLINE | SNAPPABLE, aPad );
448  addAnchor( seg.Center(), OUTLINE | SNAPPABLE, aPad );
449 
450  if( i == poly->GetSegmentCount() - 1 )
451  addAnchor( seg.B, OUTLINE | SNAPPABLE, aPad );
452  }
453 
454  break;
455  }
456 
457  case SH_POLY_SET:
458  case SH_LINE_CHAIN:
459  case SH_COMPOUND:
461  case SH_NULL:
462  default:
463  break;
464  }
465  }
466  };
467 
468  switch( aItem->Type() )
469  {
470  case PCB_FOOTPRINT_T:
471  {
472  FOOTPRINT* footprint = static_cast<FOOTPRINT*>( aItem );
473 
474  for( PAD* pad : footprint->Pads() )
475  {
476  // Getting pads from the footprint requires re-checking that the pad is shown
478  && pad->GetBoundingBox().Contains( wxPoint( aRefPos.x, aRefPos.y ) )
479  && view->IsVisible( pad )
480  && ( !isHighContrast || activeLayers.count( pad->GetLayer() ) )
481  && pad->ViewGetLOD( pad->GetLayer(), view ) < view->GetScale() )
482  {
483  handlePadShape( pad );
484  break;
485  }
486  }
487 
488  // if the cursor is not over a pad, then drag the footprint by its origin
489  VECTOR2I position = footprint->GetPosition();
490  addAnchor( position, ORIGIN | SNAPPABLE, footprint );
491 
492  // Add the footprint center point if it is markedly different from the origin
493  VECTOR2I center = footprint->GetBoundingBox( false, false ).Centre();
494  VECTOR2I grid( GetGrid() );
495 
496  if( ( center - position ).SquaredEuclideanNorm() > grid.SquaredEuclideanNorm() )
497  addAnchor( center, ORIGIN | SNAPPABLE, footprint );
498 
499  break;
500  }
501 
502  case PCB_PAD_T:
503  {
505  {
506  PAD* pad = static_cast<PAD*>( aItem );
507  handlePadShape( pad );
508  }
509 
510  break;
511  }
512 
513  case PCB_FP_SHAPE_T:
514  case PCB_SHAPE_T:
515  {
517  break;
518 
519  PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( aItem );
520  VECTOR2I start = shape->GetStart();
521  VECTOR2I end = shape->GetEnd();
522 
523  switch( shape->GetShape() )
524  {
525  case S_CIRCLE:
526  {
527  int r = ( start - end ).EuclideanNorm();
528 
529  addAnchor( start, ORIGIN | SNAPPABLE, shape );
530  addAnchor( start + VECTOR2I( -r, 0 ), OUTLINE | SNAPPABLE, shape );
531  addAnchor( start + VECTOR2I( r, 0 ), OUTLINE | SNAPPABLE, shape );
532  addAnchor( start + VECTOR2I( 0, -r ), OUTLINE | SNAPPABLE, shape );
533  addAnchor( start + VECTOR2I( 0, r ), OUTLINE | SNAPPABLE, shape );
534  break;
535  }
536 
537  case S_ARC:
538  addAnchor( shape->GetArcStart(), CORNER | SNAPPABLE, shape );
539  addAnchor( shape->GetArcEnd(), CORNER | SNAPPABLE, shape );
540  addAnchor( shape->GetArcMid(), CORNER | SNAPPABLE, shape );
541  addAnchor( shape->GetCenter(), ORIGIN | SNAPPABLE, shape );
542  break;
543 
544  case S_RECT:
545  {
546  VECTOR2I point2( end.x, start.y );
547  VECTOR2I point3( start.x, end.y );
548  SEG first( start, point2 );
549  SEG second( point2, end );
550  SEG third( end, point3 );
551  SEG fourth( point3, start );
552 
553  addAnchor( first.A, CORNER | SNAPPABLE, shape );
554  addAnchor( first.Center(), CORNER | SNAPPABLE, shape );
555  addAnchor( second.A, CORNER | SNAPPABLE, shape );
556  addAnchor( second.Center(), CORNER | SNAPPABLE, shape );
557  addAnchor( third.A, CORNER | SNAPPABLE, shape );
558  addAnchor( third.Center(), CORNER | SNAPPABLE, shape );
559  addAnchor( fourth.A, CORNER | SNAPPABLE, shape );
560  addAnchor( fourth.Center(), CORNER | SNAPPABLE, shape );
561  break;
562  }
563 
564  case S_SEGMENT:
565  addAnchor( start, CORNER | SNAPPABLE, shape );
566  addAnchor( end, CORNER | SNAPPABLE, shape );
567  addAnchor( shape->GetCenter(), CORNER | SNAPPABLE, shape );
568  break;
569 
570  case S_POLYGON:
571  {
572  SHAPE_LINE_CHAIN lc;
573  lc.SetClosed( true );
574 
575  for( const wxPoint& p : shape->BuildPolyPointsList() )
576  {
577  addAnchor( p, CORNER | SNAPPABLE, shape );
578  lc.Append( p );
579  }
580 
581  addAnchor( lc.NearestPoint( aRefPos ), OUTLINE, aItem );
582  break;
583  }
584 
585  case S_CURVE:
586  addAnchor( start, CORNER | SNAPPABLE, shape );
587  addAnchor( end, CORNER | SNAPPABLE, shape );
589 
590  default:
591  addAnchor( shape->GetStart(), ORIGIN | SNAPPABLE, shape );
592  break;
593  }
594  break;
595  }
596 
597  case PCB_TRACE_T:
598  case PCB_ARC_T:
599  {
601  {
602  TRACK* track = static_cast<TRACK*>( aItem );
603 
604  addAnchor( track->GetStart(), CORNER | SNAPPABLE, track );
605  addAnchor( track->GetEnd(), CORNER | SNAPPABLE, track );
606  addAnchor( track->GetCenter(), ORIGIN, track);
607  }
608 
609  break;
610  }
611 
612  case PCB_MARKER_T:
613  case PCB_TARGET_T:
614  addAnchor( aItem->GetPosition(), ORIGIN | CORNER | SNAPPABLE, aItem );
615  break;
616 
617  case PCB_VIA_T:
618  {
620  addAnchor( aItem->GetPosition(), ORIGIN | CORNER | SNAPPABLE, aItem );
621 
622  break;
623  }
624 
625  case PCB_ZONE_T:
626  {
627  const SHAPE_POLY_SET* outline = static_cast<const ZONE*>( aItem )->Outline();
628 
629  SHAPE_LINE_CHAIN lc;
630  lc.SetClosed( true );
631 
632  for( auto iter = outline->CIterateWithHoles(); iter; iter++ )
633  {
634  addAnchor( *iter, CORNER, aItem );
635  lc.Append( *iter );
636  }
637 
638  addAnchor( lc.NearestPoint( aRefPos ), OUTLINE, aItem );
639 
640  break;
641  }
642 
643  case PCB_DIM_ALIGNED_T:
645  {
646  const ALIGNED_DIMENSION* dim = static_cast<const ALIGNED_DIMENSION*>( aItem );
647  addAnchor( dim->GetCrossbarStart(), CORNER | SNAPPABLE, aItem );
648  addAnchor( dim->GetCrossbarEnd(), CORNER | SNAPPABLE, aItem );
649  addAnchor( dim->GetStart(), CORNER | SNAPPABLE, aItem );
650  addAnchor( dim->GetEnd(), CORNER | SNAPPABLE, aItem );
651  break;
652  }
653 
654  case PCB_DIM_CENTER_T:
655  {
656  const CENTER_DIMENSION* dim = static_cast<const CENTER_DIMENSION*>( aItem );
657  addAnchor( dim->GetStart(), CORNER | SNAPPABLE, aItem );
658  addAnchor( dim->GetEnd(), CORNER | SNAPPABLE, aItem );
659 
660  VECTOR2I start( dim->GetStart() );
661  VECTOR2I radial( dim->GetEnd() - dim->GetStart() );
662 
663  for( int i = 0; i < 2; i++ )
664  {
665  radial = radial.Rotate( DEG2RAD( 90 ) );
666  addAnchor( start + radial, CORNER | SNAPPABLE, aItem );
667  }
668 
669  break;
670  }
671 
672  case PCB_DIM_LEADER_T:
673  {
674  const LEADER* leader = static_cast<const LEADER*>( aItem );
675  addAnchor( leader->GetStart(), CORNER | SNAPPABLE, aItem );
676  addAnchor( leader->GetEnd(), CORNER | SNAPPABLE, aItem );
677  addAnchor( leader->Text().GetPosition(), CORNER | SNAPPABLE, aItem );
678  break;
679  }
680 
681  case PCB_FP_TEXT_T:
682  case PCB_TEXT_T:
683  addAnchor( aItem->GetPosition(), ORIGIN, aItem );
684  break;
685 
686  case PCB_GROUP_T:
687  {
688  const PCB_GROUP* group = static_cast<const PCB_GROUP*>( aItem );
689 
690  for( BOARD_ITEM* item : group->GetItems() )
691  computeAnchors( item, aRefPos, aFrom );
692 
693  break;
694  }
695 
696  default:
697  break;
698  }
699 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:148
compound shape, consisting of multiple simple shapes
Definition: shape.h:49
wxPoint GetArcEnd() const
Definition: pcb_shape.cpp:374
virtual const SEG GetSegment(int aIndex) const override
Definition: shape_simple.h:185
const std::set< unsigned int > GetHighContrastLayers() const
Returns the set of currently high-contrast layers.
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:289
SHAPE_SIMPLE.
Definition: shape_simple.h:43
class ALIGNED_DIMENSION, a linear dimension (graphic item)
Definition: typeinfo.h:100
class LEADER, a leader dimension (graphic item)
Definition: typeinfo.h:101
class FP_TEXT, text in a footprint
Definition: typeinfo.h:92
void addAnchor(const VECTOR2I &aPos, int aFlags, EDA_ITEM *aItem)
Definition: grid_helper.h:106
const SHAPE_LINE_CHAIN Outline() const
Definition: shape_rect.h:170
int GetRadius() const
Definition: shape_circle.h:107
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
const wxPoint & GetEnd() const
Function GetEnd returns the ending point of the graphic.
Definition: pcb_shape.h:156
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:82
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:108
const wxPoint & GetStart() const
Definition: track.h:116
A set of BOARD_ITEMs (i.e., without duplicates).
Definition: pcb_group.h:50
class CENTER_DIMENSION, a center point marking (graphic item)
Definition: typeinfo.h:102
TOOL_MANAGER * m_toolMgr
Definition: grid_helper.h:129
#define M_PI_2
Definition: transline.cpp:37
virtual const wxPoint & GetStart() const
The dimension's origin is the first feature point for the dimension.
Definition: dimension.h:121
Define a general 2D-vector/point.
Definition: vector2d.h:61
polygon (not yet used for tracks, but could be in microwave apps)
Definition: board_item.h:54
CONST_ITERATOR CIterateWithHoles(int aOutline) const
class PCB_TEXT, text on a layer
Definition: typeinfo.h:91
class ARC, an arc track segment on a copper layer
Definition: typeinfo.h:97
usual segment : line with rounded ends
Definition: board_item.h:50
MAGNETIC_SETTINGS * m_magneticSettings
Arcs (with rounded ends)
Definition: board_item.h:52
class FP_SHAPE, a footprint edge
Definition: typeinfo.h:93
class PAD, a pad in a footprint
Definition: typeinfo.h:89
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
Definition: macros.h:83
const VECTOR2I GetCenter() const
Definition: shape_circle.h:112
VECTOR2I Center() const
Definition: seg.h:391
virtual wxPoint GetPosition() const
Definition: eda_item.h:302
segment with non rounded ends
Definition: board_item.h:51
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
const wxPoint & GetCrossbarStart() const
Definition: dimension.h:363
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:207
const SEG & GetSeg() const
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
PADS & Pads()
Definition: footprint.h:164
const wxPoint & GetCrossbarEnd() const
Definition: dimension.h:365
const VECTOR2I NearestPoint(const VECTOR2I &aP, bool aAllowInternalShapePoints=true) const
Finds a point on the line chain that is closest to point aP.
wxPoint GetArcStart() const
Definition: pcb_shape.h:179
VECTOR2I GetGrid() const
Definition: grid_helper.cpp:51
const std::vector< wxPoint > BuildPolyPointsList() const
Build and return the list of corners in a std::vector<wxPoint> It must be used only to convert the SH...
Definition: pcb_shape.cpp:1198
void SetClosed(bool aClosed)
Function SetClosed()
void computeAnchors(BOARD_ITEM *aItem, const VECTOR2I &aRefPos, bool aFrom=false)
computeAnchors inserts the local anchor points in to the grid helper for the specified board item,...
virtual wxPoint GetPosition() const override
Definition: pcb_text.h:72
A leader is a dimension-like object pointing to a specific point.
Definition: dimension.h:478
bool IsVisible(const VIEW_ITEM *aItem) const
Return information if the item is visible (or not).
Definition: view.cpp:1489
Represent a set of closed polygons.
const VECTOR2I & GetP0() const
Definition: shape_arc.h:95
PCB_TEXT & Text()
Definition: dimension.h:209
wxPoint GetCenter() const override
This defaults to the center of the bounding box if not overridden.
Definition: pcb_shape.cpp:342
const wxPoint & GetStart() const
Function GetStart returns the starting point of the graphic.
Definition: pcb_shape.h:145
const VECTOR2I & GetArcMid() const
Definition: shape_arc.h:97
circular arc
Definition: shape.h:50
virtual wxPoint GetCenter() const
This defaults to the center of the bounding box if not overridden.
Definition: board_item.h:114
class ZONE, a copper pour area
Definition: typeinfo.h:105
An abstract shape on 2D plane.
Definition: shape.h:116
int SegmentCount() const
Function SegmentCount()
circle
Definition: shape.h:46
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:104
class FOOTPRINT, a footprint
Definition: typeinfo.h:88
Definition: seg.h:41
virtual size_t GetSegmentCount() const override
Definition: shape_simple.h:187
bool GetHighContrast() const
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
VECTOR2< T > Rotate(double aAngle) const
Rotate the vector by a given angle.
Definition: vector2d.h:371
set of polygons (with holes, etc.)
Definition: shape.h:48
class MARKER_PCB, a marker used to show something
Definition: typeinfo.h:98
a single triangle belonging to a POLY_SET triangulation
Definition: shape.h:52
const SEG CSegment(int aIndex) const
Function CSegment()
double DEG2RAD(double deg)
Definition: trigo.h:231
SHAPE_LINE_CHAIN.
const EDA_RECT GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: footprint.cpp:631
VECTOR2I A
Definition: seg.h:49
MAGNETIC_OPTIONS pads
empty shape (no shape...),
Definition: shape.h:51
line chain (polyline)
Definition: shape.h:45
wxPoint GetPosition() const override
Definition: footprint.h:182
wxPoint Centre() const
Definition: eda_rect.h:60
const wxPoint & GetEnd() const
Definition: track.h:113
ring
Definition: board_item.h:53
class ORTHOGONAL_DIMENSION, a linear dimension constrained to x/y
Definition: typeinfo.h:103
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
wxPoint GetArcMid() const
Definition: pcb_shape.cpp:392
axis-aligned rectangle
Definition: shape.h:43
PCB_SHAPE_TYPE_T GetShape() const
Definition: pcb_shape.h:130
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:67
Definition: pad.h:60
double GetScale() const
Definition: view.h:263
For better understanding of the points that make a dimension:
Definition: dimension.h:334
int GetWidth() const
class PCB_SHAPE, a segment not on copper layers
Definition: typeinfo.h:90
Bezier Curve.
Definition: board_item.h:55
virtual const wxPoint & GetEnd() const
Definition: dimension.h:124
simple polygon
Definition: shape.h:47
const VECTOR2I & GetP1() const
Definition: shape_arc.h:96
Definition: track.h:83
MAGNETIC_OPTIONS tracks
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:163
line segment
Definition: shape.h:44
VECTOR2I B
Definition: seg.h:50
Marks the center of a circle or arc with a cross shape The size and orientation of the cross is adjus...
Definition: dimension.h:517

References SEG::A, GRID_HELPER::addAnchor(), SHAPE_LINE_CHAIN::Append(), SEG::B, PCB_SHAPE::BuildPolyPointsList(), CAPTURE_ALWAYS, SEG::Center(), EDA_RECT::Centre(), SHAPE_POLY_SET::CIterateWithHoles(), GRID_HELPER::CORNER, SHAPE_LINE_CHAIN::CSegment(), DEG2RAD(), EuclideanNorm(), PCB_SHAPE::GetArcEnd(), SHAPE_ARC::GetArcMid(), PCB_SHAPE::GetArcMid(), PCB_SHAPE::GetArcStart(), FOOTPRINT::GetBoundingBox(), SHAPE_CIRCLE::GetCenter(), BOARD_ITEM::GetCenter(), PCB_SHAPE::GetCenter(), ALIGNED_DIMENSION::GetCrossbarEnd(), ALIGNED_DIMENSION::GetCrossbarStart(), TRACK::GetEnd(), DIMENSION_BASE::GetEnd(), PCB_SHAPE::GetEnd(), GRID_HELPER::GetGrid(), KIGFX::RENDER_SETTINGS::GetHighContrast(), KIGFX::RENDER_SETTINGS::GetHighContrastLayers(), SHAPE_ARC::GetP0(), SHAPE_ARC::GetP1(), KIGFX::VIEW::GetPainter(), PCB_TEXT::GetPosition(), FOOTPRINT::GetPosition(), EDA_ITEM::GetPosition(), SHAPE_CIRCLE::GetRadius(), KIGFX::VIEW::GetScale(), SHAPE_SEGMENT::GetSeg(), SHAPE_SIMPLE::GetSegment(), SHAPE_SIMPLE::GetSegmentCount(), KIGFX::PAINTER::GetSettings(), PCB_SHAPE::GetShape(), TRACK::GetStart(), DIMENSION_BASE::GetStart(), PCB_SHAPE::GetStart(), TOOL_MANAGER::GetView(), SHAPE_SEGMENT::GetWidth(), MAGNETIC_SETTINGS::graphics, grid, group, KIGFX::VIEW::IsVisible(), KI_FALLTHROUGH, m_magneticSettings, M_PI_2, GRID_HELPER::m_toolMgr, SHAPE_LINE_CHAIN::NearestPoint(), normal, GRID_HELPER::ORIGIN, GRID_HELPER::OUTLINE, SHAPE_RECT::Outline(), SHAPE_POLY_SET::Outline(), pad, MAGNETIC_SETTINGS::pads, FOOTPRINT::Pads(), PCB_ARC_T, PCB_DIM_ALIGNED_T, PCB_DIM_CENTER_T, PCB_DIM_LEADER_T, PCB_DIM_ORTHOGONAL_T, PCB_FOOTPRINT_T, PCB_FP_SHAPE_T, PCB_FP_TEXT_T, PCB_GROUP_T, PCB_MARKER_T, PCB_PAD_T, PCB_SHAPE_T, PCB_TARGET_T, PCB_TEXT_T, PCB_TRACE_T, PCB_VIA_T, PCB_ZONE_T, VECTOR2< T >::Rotate(), S_ARC, S_CIRCLE, S_CURVE, S_POLYGON, S_RECT, S_SEGMENT, SHAPE_LINE_CHAIN::SegmentCount(), SHAPE_LINE_CHAIN::SetClosed(), SH_ARC, SH_CIRCLE, SH_COMPOUND, SH_LINE_CHAIN, SH_NULL, SH_POLY_SET, SH_POLY_SET_TRIANGLE, SH_RECT, SH_SEGMENT, SH_SIMPLE, GRID_HELPER::SNAPPABLE, DIMENSION_BASE::Text(), MAGNETIC_SETTINGS::tracks, EDA_ITEM::Type(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by BestDragOrigin(), and BestSnapAnchor().

◆ GetGrid()

VECTOR2I GRID_HELPER::GetGrid ( ) const
inherited

Definition at line 51 of file grid_helper.cpp.

52 {
54 
55  return VECTOR2I( KiROUND( size.x ), KiROUND( size.y ) );
56 }
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:289
TOOL_MANAGER * m_toolMgr
Definition: grid_helper.h:129
GAL * GetGAL() const
Return the #GAL this view is using to draw graphical primitives.
Definition: view.h:189
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
const VECTOR2D & GetGridSize() const
Return the grid size.
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:68

References KIGFX::VIEW::GetGAL(), KIGFX::GAL::GetGridSize(), TOOL_MANAGER::GetView(), KiROUND(), GRID_HELPER::m_toolMgr, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by GRID_HELPER::AlignGrid(), AlignToArc(), AlignToSegment(), BestSnapAnchor(), and computeAnchors().

◆ GetOrigin()

VECTOR2I GRID_HELPER::GetOrigin ( ) const
inherited

Definition at line 59 of file grid_helper.cpp.

60 {
61  VECTOR2D origin = m_toolMgr->GetView()->GetGAL()->GetGridOrigin();
62 
63  return VECTOR2I( origin );
64 }
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:289
TOOL_MANAGER * m_toolMgr
Definition: grid_helper.h:129
GAL * GetGAL() const
Return the #GAL this view is using to draw graphical primitives.
Definition: view.h:189
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
const VECTOR2D & GetGridOrigin() const

References KIGFX::VIEW::GetGAL(), KIGFX::GAL::GetGridOrigin(), TOOL_MANAGER::GetView(), and GRID_HELPER::m_toolMgr.

Referenced by GRID_HELPER::AlignGrid(), AlignToArc(), and AlignToSegment().

◆ GetSnap()

bool GRID_HELPER::GetSnap ( ) const
inlineinherited

Definition at line 65 of file grid_helper.h.

65 { return m_enableSnap; }
bool m_enableSnap
Definition: grid_helper.h:134

References GRID_HELPER::m_enableSnap.

Referenced by PNS::TOOL_BASE::updateEndItem().

◆ GetSnapped()

BOARD_ITEM * PCB_GRID_HELPER::GetSnapped ( ) const

Function GetSnapped If the PCB_GRID_HELPER has highlighted a snap point (target shown), this function will return a pointer to the item to which it snapped.

Returns
NULL if not snapped. Pointer to snapped item otherwise

Definition at line 297 of file pcb_grid_helper.cpp.

298 {
299  if( !m_snapItem )
300  return nullptr;
301 
302  return static_cast<BOARD_ITEM*>( m_snapItem->item );
303 }
ANCHOR * m_snapItem
Definition: grid_helper.h:137

References GRID_HELPER::ANCHOR::item, and GRID_HELPER::m_snapItem.

◆ GetUseGrid()

bool GRID_HELPER::GetUseGrid ( ) const
inlineinherited

Definition at line 68 of file grid_helper.h.

68 { return m_enableGrid; }
bool m_enableGrid
Definition: grid_helper.h:135

References GRID_HELPER::m_enableGrid.

Referenced by PNS::TOOL_BASE::updateStartItem().

◆ nearestAnchor()

PCB_GRID_HELPER::ANCHOR * PCB_GRID_HELPER::nearestAnchor ( const VECTOR2I aPos,
int  aFlags,
LSET  aMatchLayers 
)
private

Definition at line 702 of file pcb_grid_helper.cpp.

704 {
705  double minDist = std::numeric_limits<double>::max();
706  ANCHOR* best = NULL;
707 
708  for( ANCHOR& a : m_anchors )
709  {
710  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( a.item );
711 
712  if( ( aMatchLayers & item->GetLayerSet() ) == 0 )
713  continue;
714 
715  if( ( aFlags & a.flags ) != aFlags )
716  continue;
717 
718  double dist = a.Distance( aPos );
719 
720  if( dist < minDist )
721  {
722  minDist = dist;
723  best = &a;
724  }
725  }
726 
727  return best;
728 }
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:82
#define NULL
std::vector< ANCHOR > m_anchors
Definition: grid_helper.h:127
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition: board_item.h:178

References BOARD_ITEM::GetLayerSet(), GRID_HELPER::m_anchors, and NULL.

Referenced by BestDragOrigin(), and BestSnapAnchor().

◆ queryVisible()

std::set< BOARD_ITEM * > PCB_GRID_HELPER::queryVisible ( const BOX2I aArea,
const std::vector< BOARD_ITEM * > &  aSkip 
) const
private

Definition at line 306 of file pcb_grid_helper.cpp.

308 {
309  std::set<BOARD_ITEM*> items;
310  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> selectedItems;
311 
312  KIGFX::VIEW* view = m_toolMgr->GetView();
313  RENDER_SETTINGS* settings = view->GetPainter()->GetSettings();
314  const std::set<unsigned int>& activeLayers = settings->GetHighContrastLayers();
315  bool isHighContrast = settings->GetHighContrast();
316 
317  view->Query( aArea, selectedItems );
318 
319  for( const KIGFX::VIEW::LAYER_ITEM_PAIR& it : selectedItems )
320  {
321  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( it.first );
322 
323  // If we are in the footprint editor, don't use the footprint itself
324  if( static_cast<PCB_TOOL_BASE*>( m_toolMgr->GetCurrentTool() )->IsFootprintEditor()
325  && item->Type() == PCB_FOOTPRINT_T )
326  {
327  continue;
328  }
329 
330  // The item must be visible and on an active layer
331  if( view->IsVisible( item )
332  && ( !isHighContrast || activeLayers.count( it.second ) )
333  && item->ViewGetLOD( it.second, view ) < view->GetScale() )
334  {
335  items.insert ( item );
336  }
337  }
338 
339  for( BOARD_ITEM* skipItem : aSkip )
340  items.erase( skipItem );
341 
342  return items;
343 }
const std::set< unsigned int > GetHighContrastLayers() const
Returns the set of currently high-contrast layers.
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:289
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:82
TOOL_MANAGER * m_toolMgr
Definition: grid_helper.h:129
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:207
bool IsVisible(const VIEW_ITEM *aItem) const
Return information if the item is visible (or not).
Definition: view.cpp:1489
TOOL_BASE * GetCurrentTool() const
Return the tool that is on the top of the active tools stack (was invoked the most recently).
Definition: tool_manager.h:319
class FOOTPRINT, a footprint
Definition: typeinfo.h:88
bool GetHighContrast() const
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
std::pair< VIEW_ITEM *, int > LAYER_ITEM_PAIR
Definition: view.h:72
virtual int Query(const BOX2I &aRect, std::vector< LAYER_ITEM_PAIR > &aResult) const
Find all visible items that touch or are within the rectangle aRect.
Definition: view.cpp:428
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:67
double GetScale() const
Definition: view.h:263
virtual double ViewGetLOD(int aLayer, VIEW *aView) const
Return the level of detail (LOD) of the item.
Definition: view_item.h:137
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:163

References TOOL_MANAGER::GetCurrentTool(), KIGFX::RENDER_SETTINGS::GetHighContrast(), KIGFX::RENDER_SETTINGS::GetHighContrastLayers(), KIGFX::VIEW::GetPainter(), KIGFX::VIEW::GetScale(), KIGFX::PAINTER::GetSettings(), TOOL_MANAGER::GetView(), KIGFX::VIEW::IsVisible(), GRID_HELPER::m_toolMgr, PCB_FOOTPRINT_T, KIGFX::VIEW::Query(), EDA_ITEM::Type(), and KIGFX::VIEW_ITEM::ViewGetLOD().

Referenced by BestSnapAnchor().

◆ SetAuxAxes()

void GRID_HELPER::SetAuxAxes ( bool  aEnable,
const VECTOR2I aOrigin = VECTOR2I( 0, 0 ) 
)
inherited

Definition at line 67 of file grid_helper.cpp.

68 {
69  if( aEnable )
70  {
71  m_auxAxis = aOrigin;
72  m_viewAxis.SetPosition( wxPoint( aOrigin ) );
73  m_toolMgr->GetView()->SetVisible( &m_viewAxis, true );
74  }
75  else
76  {
78  m_toolMgr->GetView()->SetVisible( &m_viewAxis, false );
79  }
80 }
void SetPosition(const wxPoint &aPosition) override
OPT< VECTOR2I > m_auxAxis
Definition: grid_helper.h:130
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:289
TOOL_MANAGER * m_toolMgr
Definition: grid_helper.h:129
KIGFX::ORIGIN_VIEWITEM m_viewAxis
Definition: grid_helper.h:143
boost::optional< T > OPT
Definition: optional.h:7
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Set the item visibility.
Definition: view.cpp:1449

References TOOL_MANAGER::GetView(), GRID_HELPER::m_auxAxis, GRID_HELPER::m_toolMgr, GRID_HELPER::m_viewAxis, KIGFX::ORIGIN_VIEWITEM::SetPosition(), and KIGFX::VIEW::SetVisible().

Referenced by ROUTER_TOOL::InlineDrag(), and ROUTER_TOOL::performDragging().

◆ SetMask()

void GRID_HELPER::SetMask ( int  aMask)
inlineinherited

Definition at line 72 of file grid_helper.h.

72 { m_maskTypes = aMask; }

References GRID_HELPER::m_maskTypes.

◆ SetMaskFlag()

void GRID_HELPER::SetMaskFlag ( int  aFlag)
inlineinherited

Definition at line 73 of file grid_helper.h.

73 { m_maskTypes |= aFlag; }

References GRID_HELPER::m_maskTypes.

◆ SetSkipPoint()

void GRID_HELPER::SetSkipPoint ( const VECTOR2I aPoint)
inlineinherited

Definition at line 51 of file grid_helper.h.

52  {
53  m_skipPoint = aPoint;
54  }
VECTOR2I m_skipPoint
Definition: grid_helper.h:139

References GRID_HELPER::m_skipPoint.

◆ SetSnap()

void GRID_HELPER::SetSnap ( bool  aSnap)
inlineinherited

◆ SetSnapLine()

void GRID_HELPER::SetSnapLine ( bool  aSnap)
inlineinherited

Definition at line 70 of file grid_helper.h.

70 { m_enableSnapLine = aSnap; }
bool m_enableSnapLine
Definition: grid_helper.h:136

References GRID_HELPER::m_enableSnapLine.

◆ SetUseGrid()

void GRID_HELPER::SetUseGrid ( bool  aSnapToGrid)
inlineinherited

Member Data Documentation

◆ m_anchors

std::vector<ANCHOR> GRID_HELPER::m_anchors
protectedinherited

◆ m_auxAxis

OPT<VECTOR2I> GRID_HELPER::m_auxAxis
protectedinherited

Definition at line 130 of file grid_helper.h.

Referenced by GRID_HELPER::Align(), and GRID_HELPER::SetAuxAxes().

◆ m_enableGrid

bool GRID_HELPER::m_enableGrid
protectedinherited

◆ m_enableSnap

bool GRID_HELPER::m_enableSnap
protectedinherited

◆ m_enableSnapLine

bool GRID_HELPER::m_enableSnapLine
protectedinherited

◆ m_magneticSettings

MAGNETIC_SETTINGS* PCB_GRID_HELPER::m_magneticSettings
private

Definition at line 84 of file pcb_grid_helper.h.

Referenced by computeAnchors().

◆ m_maskTypes

int GRID_HELPER::m_maskTypes
protectedinherited

◆ m_skipPoint

VECTOR2I GRID_HELPER::m_skipPoint
protectedinherited

◆ m_snapItem

ANCHOR* GRID_HELPER::m_snapItem
protectedinherited

◆ m_toolMgr

◆ m_viewAxis

KIGFX::ORIGIN_VIEWITEM GRID_HELPER::m_viewAxis
protectedinherited

◆ m_viewSnapLine

KIGFX::ORIGIN_VIEWITEM GRID_HELPER::m_viewSnapLine
protectedinherited

◆ m_viewSnapPoint

KIGFX::ORIGIN_VIEWITEM GRID_HELPER::m_viewSnapPoint
protectedinherited

The documentation for this class was generated from the following files: