KiCad PCB EDA Suite
GRID_HELPER Class Reference

#include <grid_helper.h>

Classes

struct  ANCHOR
 

Public Member Functions

 GRID_HELPER (PCB_BASE_FRAME *aFrame)
 
 ~GRID_HELPER ()
 
void SetGrid (int aSize)
 
void SetOrigin (const VECTOR2I &aOrigin)
 
VECTOR2I GetGrid () const
 
VECTOR2I GetOrigin () const
 
void SetAuxAxes (bool aEnable, const VECTOR2I &aOrigin=VECTOR2I(0, 0), bool aEnableDiagonal=false)
 
VECTOR2I Align (const VECTOR2I &aPoint) const
 
VECTOR2I AlignToSegment (const VECTOR2I &aPoint, const SEG &aSeg)
 
VECTOR2I BestDragOrigin (const VECTOR2I &aMousePos, BOARD_ITEM *aItem)
 
VECTOR2I BestSnapAnchor (const VECTOR2I &aOrigin, BOARD_ITEM *aDraggedItem)
 

Private Types

enum  ANCHOR_FLAGS { CORNER = 0x1, OUTLINE = 0x2, SNAPPABLE = 0x4, ORIGIN = 0x8 }
 

Private Member Functions

std::set< BOARD_ITEM * > queryVisible (const BOX2I &aArea) const
 
void addAnchor (const VECTOR2I &aPos, int aFlags=CORNER|SNAPPABLE, BOARD_ITEM *aItem=NULL)
 
ANCHORnearestAnchor (const VECTOR2I &aPos, int aFlags, LSET aMatchLayers)
 
void computeAnchors (BOARD_ITEM *aItem, const VECTOR2I &aRefPos)
 
void clearAnchors ()
 

Private Attributes

std::vector< ANCHORm_anchors
 
PCB_BASE_FRAMEm_frame
 
boost::optional< VECTOR2Im_auxAxis
 
bool m_diagonalAuxAxesEnable
 

Detailed Description

Definition at line 39 of file grid_helper.h.

Member Enumeration Documentation

Enumerator
CORNER 
OUTLINE 
SNAPPABLE 
ORIGIN 

Definition at line 61 of file grid_helper.h.

61  {
62  CORNER = 0x1,
63  OUTLINE = 0x2,
64  SNAPPABLE = 0x4,
65  ORIGIN = 0x8
66  };

Constructor & Destructor Documentation

GRID_HELPER::GRID_HELPER ( PCB_BASE_FRAME aFrame)

Definition at line 44 of file grid_helper.cpp.

References m_diagonalAuxAxesEnable.

44  :
45  m_frame( aFrame )
46 {
48 }
bool m_diagonalAuxAxesEnable
Definition: grid_helper.h:105
PCB_BASE_FRAME * m_frame
Definition: grid_helper.h:103
GRID_HELPER::~GRID_HELPER ( )

Definition at line 51 of file grid_helper.cpp.

52 {
53 }

Member Function Documentation

void GRID_HELPER::addAnchor ( const VECTOR2I aPos,
int  aFlags = CORNER | SNAPPABLE,
BOARD_ITEM aItem = NULL 
)
inlineprivate

Definition at line 89 of file grid_helper.h.

Referenced by computeAnchors().

90  {
91  m_anchors.push_back( ANCHOR( aPos, aFlags, aItem ) );
92  }
std::vector< ANCHOR > m_anchors
Definition: grid_helper.h:85
VECTOR2I GRID_HELPER::Align ( const VECTOR2I aPoint) const

Definition at line 95 of file grid_helper.cpp.

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

Referenced by BestSnapAnchor(), PCBNEW_CONTROL::CursorControl(), EDIT_TOOL::Main(), and PNS::TOOL_BASE::snapToItem().

96 {
97  const VECTOR2D gridOffset( GetOrigin() );
98  const VECTOR2D gridSize( GetGrid() );
99 
100  VECTOR2I nearest( KiROUND( ( aPoint.x - gridOffset.x ) / gridSize.x ) * gridSize.x + gridOffset.x,
101  KiROUND( ( aPoint.y - gridOffset.y ) / gridSize.y ) * gridSize.y + gridOffset.y );
102 
103  if( !m_auxAxis )
104  return nearest;
105 
106  if( std::abs( m_auxAxis->x - aPoint.x ) < std::abs( nearest.x - aPoint.x ) )
107  nearest.x = m_auxAxis->x;
108 
109  if( std::abs( m_auxAxis->y - aPoint.y ) < std::abs( nearest.y - aPoint.y ) )
110  nearest.y = m_auxAxis->y;
111 
112  return nearest;
113 }
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:107
VECTOR2I GetGrid() const
Definition: grid_helper.cpp:68
#define abs(a)
Definition: auxiliary.h:84
boost::optional< VECTOR2I > m_auxAxis
Definition: grid_helper.h:104
VECTOR2I GetOrigin() const
Definition: grid_helper.cpp:78
VECTOR2I GRID_HELPER::AlignToSegment ( const VECTOR2I aPoint,
const SEG aSeg 
)

Definition at line 116 of file grid_helper.cpp.

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

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

117 {
118  OPT_VECTOR2I pts[6];
119 
120  const VECTOR2D gridOffset( GetOrigin() );
121  const VECTOR2D gridSize( GetGrid() );
122 
123  VECTOR2I nearest( KiROUND( ( aPoint.x - gridOffset.x ) / gridSize.x ) * gridSize.x + gridOffset.x,
124  KiROUND( ( aPoint.y - gridOffset.y ) / gridSize.y ) * gridSize.y + gridOffset.y );
125 
126  pts[0] = aSeg.A;
127  pts[1] = aSeg.B;
128  pts[2] = aSeg.IntersectLines( SEG( nearest, nearest + VECTOR2I( 1, 0 ) ) );
129  pts[3] = aSeg.IntersectLines( SEG( nearest, nearest + VECTOR2I( 0, 1 ) ) );
130 
131  int min_d = std::numeric_limits<int>::max();
132 
133  for( int i = 0; i < 4; i++ )
134  {
135  if( pts[i] && aSeg.Contains( *pts[i] ) )
136  {
137  int d = (*pts[i] - aPoint).EuclideanNorm();
138 
139  if( d < min_d )
140  {
141  min_d = d;
142  nearest = *pts[i];
143  }
144  }
145  }
146 
147  return nearest;
148 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:104
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:107
OPT_VECTOR2I IntersectLines(const SEG &aSeg) const
Function IntersectLines()
Definition: seg.h:170
VECTOR2I GetGrid() const
Definition: grid_helper.cpp:68
VECTOR2< int > VECTOR2I
Definition: vector2d.h:590
VECTOR2I GetOrigin() const
Definition: grid_helper.cpp:78
Definition: seg.h:37
#define max(a, b)
Definition: auxiliary.h:86
VECTOR2I A
Definition: seg.h:47
bool Contains(const VECTOR2I &aP) const
Definition: seg.cpp:155
VECTOR2I B
Definition: seg.h:48
VECTOR2I GRID_HELPER::BestDragOrigin ( const VECTOR2I aMousePos,
BOARD_ITEM aItem 
)

Definition at line 151 of file grid_helper.cpp.

References LSET::AllLayersMask(), clearAnchors(), computeAnchors(), CORNER, dist, GRID_HELPER::ANCHOR::Distance(), EDA_DRAW_PANEL_GAL::GetGAL(), EDA_DRAW_FRAME::GetGalCanvas(), KIGFX::GAL::GetWorldScale(), m_frame, max, nearestAnchor(), ORIGIN, OUTLINE, and GRID_HELPER::ANCHOR::pos.

Referenced by EDIT_TOOL::Main().

152 {
153  clearAnchors();
154  computeAnchors( aItem, aMousePos );
155 
156  double worldScale = m_frame->GetGalCanvas()->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 }
double GetWorldScale() const
Get the world scale.
static const int dist[10][10]
Definition: dist.cpp:57
KIGFX::GAL * GetGAL() const
Function GetGAL() Returns a pointer to the GAL instance used in the panel.
ANCHOR * nearestAnchor(const VECTOR2I &aPos, int aFlags, LSET aMatchLayers)
static LSET AllLayersMask()
Definition: lset.cpp:676
#define max(a, b)
Definition: auxiliary.h:86
PCB_BASE_FRAME * m_frame
Definition: grid_helper.h:103
void computeAnchors(BOARD_ITEM *aItem, const VECTOR2I &aRefPos)
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Function GetGalCanvas returns a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:817
void clearAnchors()
Definition: grid_helper.h:98
VECTOR2I GRID_HELPER::BestSnapAnchor ( const VECTOR2I aOrigin,
BOARD_ITEM aDraggedItem 
)

Definition at line 216 of file grid_helper.cpp.

References Align(), clearAnchors(), computeAnchors(), CORNER, EuclideanNorm(), EDA_DRAW_PANEL_GAL::GetGAL(), EDA_DRAW_FRAME::GetGalCanvas(), BOARD_ITEM::GetLayer(), KIGFX::GAL::GetWorldScale(), m_frame, nearestAnchor(), queryVisible(), SNAPPABLE, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by EDIT_TOOL::Main().

217 {
218  double worldScale = m_frame->GetGalCanvas()->GetGAL()->GetWorldScale();
219  int snapRange = (int) ( 100.0 / worldScale );
220 
221  BOX2I bb( VECTOR2I( aOrigin.x - snapRange / 2, aOrigin.y - snapRange / 2 ), VECTOR2I( snapRange, snapRange ) );
222 
223  clearAnchors();
224 
225  for( BOARD_ITEM* item : queryVisible( bb ) )
226  {
227  computeAnchors( item, aOrigin );
228  }
229 
230  LSET layers( aDraggedItem->GetLayer() );
231  ANCHOR* nearest = nearestAnchor( aOrigin, CORNER | SNAPPABLE, layers );
232 
233  VECTOR2I nearestGrid = Align( aOrigin );
234  double gridDist = ( nearestGrid - aOrigin ).EuclideanNorm();
235 
236  if( nearest )
237  {
238  double snapDist = nearest->Distance( aOrigin );
239 
240  if( nearest && snapDist < gridDist )
241  return nearest->pos;
242  }
243 
244  return nearestGrid;
245 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:104
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
double GetWorldScale() const
Get the world scale.
VECTOR2I Align(const VECTOR2I &aPoint) const
Definition: grid_helper.cpp:95
std::set< BOARD_ITEM * > queryVisible(const BOX2I &aArea) const
VECTOR2< int > VECTOR2I
Definition: vector2d.h:590
KIGFX::GAL * GetGAL() const
Function GetGAL() Returns a pointer to the GAL instance used in the panel.
Class LSET is a set of PCB_LAYER_IDs.
ANCHOR * nearestAnchor(const VECTOR2I &aPos, int aFlags, LSET aMatchLayers)
PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
PCB_BASE_FRAME * m_frame
Definition: grid_helper.h:103
void computeAnchors(BOARD_ITEM *aItem, const VECTOR2I &aRefPos)
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Function GetGalCanvas returns a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:817
void clearAnchors()
Definition: grid_helper.h:98
void GRID_HELPER::clearAnchors ( )
inlineprivate

Definition at line 98 of file grid_helper.h.

Referenced by BestDragOrigin(), and BestSnapAnchor().

99  {
100  m_anchors.clear();
101  }
std::vector< ANCHOR > m_anchors
Definition: grid_helper.h:85
void GRID_HELPER::computeAnchors ( BOARD_ITEM aItem,
const VECTOR2I aRefPos 
)
private

Definition at line 248 of file grid_helper.cpp.

References addAnchor(), SHAPE_LINE_CHAIN::Append(), SHAPE_POLY_SET::CIterateWithHoles(), CORNER, EuclideanNorm(), DRAWSEGMENT::GetArcEnd(), DRAWSEGMENT::GetArcStart(), DRAWSEGMENT::GetCenter(), DRAWSEGMENT::GetEnd(), TRACK::GetEnd(), BOARD_ITEM::GetPosition(), MODULE::GetPosition(), D_PAD::GetPosition(), DRAWSEGMENT::GetShape(), DRAWSEGMENT::GetStart(), TRACK::GetStart(), mod, SHAPE_LINE_CHAIN::NearestPoint(), ORIGIN, OUTLINE, MODULE::Pads(), PCB_LINE_T, PCB_MODULE_EDGE_T, PCB_MODULE_T, PCB_MODULE_TEXT_T, PCB_PAD_T, PCB_TEXT_T, PCB_TRACE_T, PCB_VIA_T, PCB_ZONE_AREA_T, S_ARC, S_CIRCLE, S_SEGMENT, SHAPE_LINE_CHAIN::SetClosed(), SNAPPABLE, EDA_ITEM::Type(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by BestDragOrigin(), and BestSnapAnchor().

249 {
250  VECTOR2I origin;
251 
252  switch( aItem->Type() )
253  {
254  case PCB_MODULE_T:
255  {
256  MODULE* mod = static_cast<MODULE*>( aItem );
257  addAnchor( mod->GetPosition(), ORIGIN | SNAPPABLE, mod );
258 
259  for( auto pad : mod->Pads() )
260  addAnchor( pad->GetPosition(), CORNER | SNAPPABLE, pad );
261 
262  break;
263  }
264 
265  case PCB_PAD_T:
266  {
267  D_PAD* pad = static_cast<D_PAD*>( aItem );
268  addAnchor( pad->GetPosition(), CORNER | SNAPPABLE, pad );
269 
270  break;
271  }
272 
273  case PCB_MODULE_EDGE_T:
274  case PCB_LINE_T:
275  {
276  DRAWSEGMENT* dseg = static_cast<DRAWSEGMENT*>( aItem );
277  VECTOR2I start = dseg->GetStart();
278  VECTOR2I end = dseg->GetEnd();
279  //PCB_LAYER_ID layer = dseg->GetLayer();
280 
281  switch( dseg->GetShape() )
282  {
283  case S_CIRCLE:
284  {
285  int r = ( start - end ).EuclideanNorm();
286 
287  addAnchor( start, ORIGIN | SNAPPABLE, dseg );
288  addAnchor( start + VECTOR2I( -r, 0 ), OUTLINE | SNAPPABLE, dseg );
289  addAnchor( start + VECTOR2I( r, 0 ), OUTLINE | SNAPPABLE, dseg );
290  addAnchor( start + VECTOR2I( 0, -r ), OUTLINE | SNAPPABLE, dseg );
291  addAnchor( start + VECTOR2I( 0, r ), OUTLINE | SNAPPABLE, dseg );
292  break;
293  }
294 
295  case S_ARC:
296  {
297  origin = dseg->GetCenter();
298  addAnchor( dseg->GetArcStart(), CORNER | SNAPPABLE, dseg );
299  addAnchor( dseg->GetArcEnd(), CORNER | SNAPPABLE, dseg );
300  addAnchor( origin, ORIGIN | SNAPPABLE, dseg );
301  break;
302  }
303 
304  case S_SEGMENT:
305  {
306  origin.x = start.x + ( start.x - end.x ) / 2;
307  origin.y = start.y + ( start.y - end.y ) / 2;
308  addAnchor( start, CORNER | SNAPPABLE, dseg );
309  addAnchor( end, CORNER | SNAPPABLE, dseg );
310  addAnchor( origin, ORIGIN, dseg );
311  break;
312  }
313 
314  default:
315  {
316  origin = dseg->GetStart();
317  addAnchor( origin, ORIGIN | SNAPPABLE, dseg );
318  break;
319  }
320  }
321  break;
322  }
323 
324  case PCB_TRACE_T:
325  {
326  TRACK* track = static_cast<TRACK*>( aItem );
327  VECTOR2I start = track->GetStart();
328  VECTOR2I end = track->GetEnd();
329  origin.x = start.x + ( start.x - end.x ) / 2;
330  origin.y = start.y + ( start.y - end.y ) / 2;
331  addAnchor( start, CORNER | SNAPPABLE, track );
332  addAnchor( end, CORNER | SNAPPABLE, track );
333  addAnchor( origin, ORIGIN, track);
334  break;
335  }
336 
337  case PCB_VIA_T:
338  addAnchor( aItem->GetPosition(), CORNER | SNAPPABLE, aItem );
339  break;
340 
341  case PCB_ZONE_AREA_T:
342  {
343  const SHAPE_POLY_SET* outline = static_cast<const ZONE_CONTAINER*>( aItem )->Outline();
344 
345  SHAPE_LINE_CHAIN lc;
346  lc.SetClosed( true );
347 
348  for( auto iter = outline->CIterateWithHoles(); iter; iter++ )
349  {
350  addAnchor( *iter, CORNER, aItem );
351  lc.Append( *iter );
352  }
353 
354  addAnchor( lc.NearestPoint( aRefPos ), OUTLINE, aItem );
355 
356  break;
357  }
358 
359  case PCB_MODULE_TEXT_T:
360  case PCB_TEXT_T:
361  addAnchor( aItem->GetPosition(), ORIGIN, aItem );
362  default:
363 
364  break;
365  }
366 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:104
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:78
const wxPoint GetCenter() const override
Function GetCenter()
const wxPoint & GetPosition() const override
Definition: class_module.h:155
CONST_ITERATOR CIterateWithHoles(int aOutline) const
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:114
DLIST_ITERATOR_WRAPPER< D_PAD > Pads()
Definition: class_module.h:140
virtual const wxPoint & GetPosition() const =0
const VECTOR2I NearestPoint(const VECTOR2I &aP) const
Function NearestPoint()
class TEXTE_PCB, text on a layer
Definition: typeinfo.h:104
usual segment : line with rounded ends
class D_PAD, a pad in a footprint
Definition: typeinfo.h:102
VECTOR2< int > VECTOR2I
Definition: vector2d.h:590
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:106
const wxPoint & GetEnd() const
Definition: class_track.h:118
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:107
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
const wxPoint & GetArcStart() const
class MODULE, a footprint
Definition: typeinfo.h:101
void SetClosed(bool aClosed)
Function SetClosed()
STROKE_T GetShape() const
const wxPoint & GetEnd() const
Function GetEnd returns the ending point of the graphic.
Class SHAPE_POLY_SET.
const wxPoint & GetStart() const
Definition: class_track.h:121
const wxPoint & GetPosition() const override
Definition: class_pad.h:170
Arcs (with rounded ends)
void addAnchor(const VECTOR2I &aPos, int aFlags=CORNER|SNAPPABLE, BOARD_ITEM *aItem=NULL)
Definition: grid_helper.h:89
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:105
Class SHAPE_LINE_CHAIN.
const wxPoint GetArcEnd() const
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:108
class DRAWSEGMENT, a segment not on copper layers
Definition: typeinfo.h:103
const wxPoint & GetStart() const
Function GetStart returns the starting point of the graphic.
#define mod(a, n)
Definition: greymap.cpp:24
VECTOR2I GRID_HELPER::GetGrid ( ) const

Definition at line 68 of file grid_helper.cpp.

References BASE_SCREEN::GetGridSize(), PCB_BASE_FRAME::GetScreen(), KiROUND(), and m_frame.

Referenced by Align(), AlignToSegment(), PCBNEW_CONTROL::CursorControl(), and PCBNEW_CONTROL::PanControl().

69 {
70  PCB_SCREEN* screen = m_frame->GetScreen();
71 
72  const wxRealPoint& size = screen->GetGridSize();
73 
74  return VECTOR2I( KiROUND( size.x ), KiROUND( size.y ) );
75 }
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:107
VECTOR2< int > VECTOR2I
Definition: vector2d.h:590
PCB_BASE_FRAME * m_frame
Definition: grid_helper.h:103
const wxRealPoint & GetGridSize() const
Return the grid size of the currently selected grid.
PCB_SCREEN * GetScreen() const override
Function GetScreen returns a pointer to a BASE_SCREEN or one of its derivatives.
VECTOR2I GRID_HELPER::GetOrigin ( ) const

Definition at line 78 of file grid_helper.cpp.

References PCB_BASE_FRAME::GetGridOrigin(), and m_frame.

Referenced by Align(), and AlignToSegment().

79 {
80  return VECTOR2I( m_frame->GetGridOrigin() );
81 }
const wxPoint & GetGridOrigin() const override
Function GetGridOrigin returns the absolute coordinates of the origin of the snap grid...
VECTOR2< int > VECTOR2I
Definition: vector2d.h:590
PCB_BASE_FRAME * m_frame
Definition: grid_helper.h:103
GRID_HELPER::ANCHOR * GRID_HELPER::nearestAnchor ( const VECTOR2I aPos,
int  aFlags,
LSET  aMatchLayers 
)
private

Definition at line 369 of file grid_helper.cpp.

References dist, m_anchors, and max.

Referenced by BestDragOrigin(), and BestSnapAnchor().

370 {
371  double minDist = std::numeric_limits<double>::max();
372  ANCHOR* best = NULL;
373 
374  for( ANCHOR& a : m_anchors )
375  {
376  if( !aMatchLayers[a.item->GetLayer()] )
377  continue;
378 
379  if( ( aFlags & a.flags ) != aFlags )
380  continue;
381 
382  double dist = a.Distance( aPos );
383 
384  if( dist < minDist )
385  {
386  minDist = dist;
387  best = &a;
388  }
389  }
390 
391  return best;
392 }
static const int dist[10][10]
Definition: dist.cpp:57
#define max(a, b)
Definition: auxiliary.h:86
std::vector< ANCHOR > m_anchors
Definition: grid_helper.h:85
std::set< BOARD_ITEM * > GRID_HELPER::queryVisible ( const BOX2I aArea) const
private

Definition at line 194 of file grid_helper.cpp.

References EDA_DRAW_FRAME::GetGalCanvas(), EDA_DRAW_PANEL_GAL::GetView(), m_frame, and KIGFX::VIEW::Query().

Referenced by BestSnapAnchor().

195 {
196  std::set<BOARD_ITEM*> items;
197 
198  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> selectedItems;
199  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR>::iterator it, it_end;
200 
201  auto view = m_frame->GetGalCanvas()->GetView();
202  view->Query( aArea, selectedItems ); // Get the list of selected items
203 
204  for( it = selectedItems.begin(), it_end = selectedItems.end(); it != it_end; ++it )
205  {
206  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( it->first );
207 
208  if( view->IsVisible( item ) )
209  items.insert ( item );
210  }
211 
212  return items;
213 }
int Query(const BOX2I &aRect, std::vector< LAYER_ITEM_PAIR > &aResult) const
Function Query() Finds all visible items that touch or are within the rectangle aRect.
Definition: view.cpp:417
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
KIGFX::VIEW * GetView() const
Function GetView() Returns a pointer to the VIEW instance used in the panel.
PCB_BASE_FRAME * m_frame
Definition: grid_helper.h:103
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Function GetGalCanvas returns a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:817
void GRID_HELPER::SetAuxAxes ( bool  aEnable,
const VECTOR2I aOrigin = VECTOR2I( 0, 0 ),
bool  aEnableDiagonal = false 
)

Definition at line 84 of file grid_helper.cpp.

References m_auxAxis, and m_diagonalAuxAxesEnable.

Referenced by EDIT_TOOL::Main().

85 {
86  if( aEnable )
87  m_auxAxis = aOrigin;
88  else
90 
91  m_diagonalAuxAxesEnable = aEnable;
92 }
bool m_diagonalAuxAxesEnable
Definition: grid_helper.h:105
boost::optional< VECTOR2I > m_auxAxis
Definition: grid_helper.h:104
void GRID_HELPER::SetGrid ( int  aSize)

Definition at line 56 of file grid_helper.cpp.

57 {
58  assert( false );
59 }
void GRID_HELPER::SetOrigin ( const VECTOR2I aOrigin)

Definition at line 62 of file grid_helper.cpp.

63 {
64  assert( false );
65 }

Member Data Documentation

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

Definition at line 85 of file grid_helper.h.

Referenced by nearestAnchor().

boost::optional<VECTOR2I> GRID_HELPER::m_auxAxis
private

Definition at line 104 of file grid_helper.h.

Referenced by Align(), and SetAuxAxes().

bool GRID_HELPER::m_diagonalAuxAxesEnable
private

Definition at line 105 of file grid_helper.h.

Referenced by GRID_HELPER(), and SetAuxAxes().

PCB_BASE_FRAME* GRID_HELPER::m_frame
private

Definition at line 103 of file grid_helper.h.

Referenced by BestDragOrigin(), BestSnapAnchor(), GetGrid(), GetOrigin(), and queryVisible().


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