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
 
KIGFX::ORIGIN_VIEWITEM m_viewSnapPoint
 
KIGFX::ORIGIN_VIEWITEM m_viewAxis
 

Detailed Description

Definition at line 40 of file grid_helper.h.

Member Enumeration Documentation

Enumerator
CORNER 
OUTLINE 
SNAPPABLE 
ORIGIN 

Definition at line 62 of file grid_helper.h.

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

Constructor & Destructor Documentation

GRID_HELPER::GRID_HELPER ( PCB_BASE_FRAME aFrame)

Definition at line 45 of file grid_helper.cpp.

References KIGFX::VIEW::Add(), KIGFX::ORIGIN_VIEWITEM::CIRCLE_CROSS, KIGFX::ORIGIN_VIEWITEM::CROSS, EDA_DRAW_FRAME::GetGalCanvas(), EDA_DRAW_PANEL_GAL::GetView(), m_diagonalAuxAxesEnable, m_frame, m_viewAxis, m_viewSnapPoint, KIGFX::ORIGIN_VIEWITEM::SetColor(), KIGFX::ORIGIN_VIEWITEM::SetDrawAtZero(), KIGFX::ORIGIN_VIEWITEM::SetSize(), KIGFX::ORIGIN_VIEWITEM::SetStyle(), and KIGFX::VIEW::SetVisible().

45  :
46  m_frame( aFrame )
47 {
50 
51  m_viewAxis.SetSize( 20000 );
53  m_viewAxis.SetColor( COLOR4D( 1.0, 1.0, 1.0, 0.4 ) );
54  m_viewAxis.SetDrawAtZero( true );
55  view->Add( &m_viewAxis );
56  view->SetVisible( &m_viewAxis, false );
57 
59  m_viewSnapPoint.SetColor( COLOR4D( 1.0, 1.0, 1.0, 1.0 ) );
61  view->Add( &m_viewSnapPoint );
62  view->SetVisible( &m_viewSnapPoint, false );
63 }
KIGFX::ORIGIN_VIEWITEM m_viewAxis
Definition: grid_helper.h:107
bool m_diagonalAuxAxesEnable
Definition: grid_helper.h:106
KIGFX::VIEW * GetView() const
Function GetView() Returns a pointer to the VIEW instance used in the panel.
KIGFX::ORIGIN_VIEWITEM m_viewSnapPoint
Definition: grid_helper.h:107
void SetSize(int aSize)
void SetDrawAtZero(bool aDrawFlag)
Function SetDrawAtZero() Set the draw at zero flag.
PCB_BASE_FRAME * m_frame
Definition: grid_helper.h:104
void SetColor(const KIGFX::COLOR4D &aColor)
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Sets the item visibility.
Definition: view.cpp:1323
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Function GetGalCanvas returns a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:831
void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:311
Class VIEW.
Definition: view.h:58
void SetStyle(MARKER_STYLE aStyle)
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
GRID_HELPER::~GRID_HELPER ( )

Definition at line 66 of file grid_helper.cpp.

67 {
68 }

Member Function Documentation

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

Definition at line 90 of file grid_helper.h.

Referenced by computeAnchors().

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

Definition at line 119 of file grid_helper.cpp.

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

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

120 {
121  const VECTOR2D gridOffset( GetOrigin() );
122  const VECTOR2D gridSize( GetGrid() );
123 
124  VECTOR2I nearest( KiROUND( ( aPoint.x - gridOffset.x ) / gridSize.x ) * gridSize.x + gridOffset.x,
125  KiROUND( ( aPoint.y - gridOffset.y ) / gridSize.y ) * gridSize.y + gridOffset.y );
126 
127  if( !m_auxAxis )
128  return nearest;
129 
130  if( std::abs( m_auxAxis->x - aPoint.x ) < std::abs( nearest.x - aPoint.x ) )
131  nearest.x = m_auxAxis->x;
132 
133  if( std::abs( m_auxAxis->y - aPoint.y ) < std::abs( nearest.y - aPoint.y ) )
134  nearest.y = m_auxAxis->y;
135 
136  return nearest;
137 }
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:83
#define abs(a)
Definition: auxiliary.h:84
boost::optional< VECTOR2I > m_auxAxis
Definition: grid_helper.h:105
VECTOR2I GetOrigin() const
Definition: grid_helper.cpp:93
VECTOR2I GRID_HELPER::AlignToSegment ( const VECTOR2I aPoint,
const SEG aSeg 
)

Definition at line 140 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().

141 {
142  OPT_VECTOR2I pts[6];
143 
144  const VECTOR2D gridOffset( GetOrigin() );
145  const VECTOR2D gridSize( GetGrid() );
146 
147  VECTOR2I nearest( KiROUND( ( aPoint.x - gridOffset.x ) / gridSize.x ) * gridSize.x + gridOffset.x,
148  KiROUND( ( aPoint.y - gridOffset.y ) / gridSize.y ) * gridSize.y + gridOffset.y );
149 
150  pts[0] = aSeg.A;
151  pts[1] = aSeg.B;
152  pts[2] = aSeg.IntersectLines( SEG( nearest, nearest + VECTOR2I( 1, 0 ) ) );
153  pts[3] = aSeg.IntersectLines( SEG( nearest, nearest + VECTOR2I( 0, 1 ) ) );
154 
155  int min_d = std::numeric_limits<int>::max();
156 
157  for( int i = 0; i < 4; i++ )
158  {
159  if( pts[i] && aSeg.Contains( *pts[i] ) )
160  {
161  int d = (*pts[i] - aPoint).EuclideanNorm();
162 
163  if( d < min_d )
164  {
165  min_d = d;
166  nearest = *pts[i];
167  }
168  }
169  }
170 
171  return nearest;
172 }
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:83
VECTOR2< int > VECTOR2I
Definition: vector2d.h:590
VECTOR2I GetOrigin() const
Definition: grid_helper.cpp:93
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 175 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().

176 {
177  clearAnchors();
178  computeAnchors( aItem, aMousePos );
179 
180  double worldScale = m_frame->GetGalCanvas()->GetGAL()->GetWorldScale();
181  double lineSnapMinCornerDistance = 50.0 / worldScale;
182 
183  ANCHOR* nearestOutline = nearestAnchor( aMousePos, OUTLINE, LSET::AllLayersMask() );
184  ANCHOR* nearestCorner = nearestAnchor( aMousePos, CORNER, LSET::AllLayersMask() );
185  ANCHOR* nearestOrigin = nearestAnchor( aMousePos, ORIGIN, LSET::AllLayersMask() );
186  ANCHOR* best = NULL;
187  double minDist = std::numeric_limits<double>::max();
188 
189  if( nearestOrigin )
190  {
191  minDist = nearestOrigin->Distance( aMousePos );
192  best = nearestOrigin;
193  }
194 
195  if( nearestCorner )
196  {
197  double dist = nearestCorner->Distance( aMousePos );
198 
199  if( dist < minDist )
200  {
201  minDist = dist;
202  best = nearestCorner;
203  }
204  }
205 
206  if( nearestOutline )
207  {
208  double dist = nearestOutline->Distance( aMousePos );
209 
210  if( minDist > lineSnapMinCornerDistance && dist < minDist )
211  best = nearestOutline;
212  }
213 
214  return best ? best->pos : aMousePos;
215 }
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:104
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:831
void clearAnchors()
Definition: grid_helper.h:99
VECTOR2I GRID_HELPER::BestSnapAnchor ( const VECTOR2I aOrigin,
BOARD_ITEM aDraggedItem 
)

Definition at line 240 of file grid_helper.cpp.

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

Referenced by EDIT_TOOL::Main().

241 {
242  double worldScale = m_frame->GetGalCanvas()->GetGAL()->GetWorldScale();
243  int snapRange = (int) ( 100.0 / worldScale );
244 
245  BOX2I bb( VECTOR2I( aOrigin.x - snapRange / 2, aOrigin.y - snapRange / 2 ), VECTOR2I( snapRange, snapRange ) );
246 
247  clearAnchors();
248 
249  for( BOARD_ITEM* item : queryVisible( bb ) )
250  {
251  computeAnchors( item, aOrigin );
252  }
253 
254  LSET layers( aDraggedItem->GetLayer() );
255  ANCHOR* nearest = nearestAnchor( aOrigin, CORNER | SNAPPABLE, layers );
256 
257  VECTOR2I nearestGrid = Align( aOrigin );
258  double gridDist = ( nearestGrid - aOrigin ).EuclideanNorm();
259 
260  if( nearest )
261  {
262  double snapDist = nearest->Distance( aOrigin );
263 
264  if( nearest && snapDist < gridDist )
265  {
266  m_viewSnapPoint.SetPosition( nearest->pos );
268  return nearest->pos;
269  }
270  }
271 
273  return nearestGrid;
274 }
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
std::set< BOARD_ITEM * > queryVisible(const BOX2I &aArea) const
KIGFX::VIEW * GetView() const
Function GetView() Returns a pointer to the VIEW instance used in the panel.
VECTOR2< int > VECTOR2I
Definition: vector2d.h:590
KIGFX::ORIGIN_VIEWITEM m_viewSnapPoint
Definition: grid_helper.h:107
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)
void SetPosition(const VECTOR2D &aPosition)
PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
PCB_BASE_FRAME * m_frame
Definition: grid_helper.h:104
void computeAnchors(BOARD_ITEM *aItem, const VECTOR2I &aRefPos)
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Sets the item visibility.
Definition: view.cpp:1323
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Function GetGalCanvas returns a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:831
void clearAnchors()
Definition: grid_helper.h:99
void GRID_HELPER::clearAnchors ( )
inlineprivate

Definition at line 99 of file grid_helper.h.

Referenced by BestDragOrigin(), and BestSnapAnchor().

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

Definition at line 277 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().

278 {
279  VECTOR2I origin;
280 
281  switch( aItem->Type() )
282  {
283  case PCB_MODULE_T:
284  {
285  MODULE* mod = static_cast<MODULE*>( aItem );
286 
287  for( auto pad : mod->Pads() )
288  {
289  if( pad->GetBoundingBox().Contains( wxPoint( aRefPos.x, aRefPos.y ) ) )
290  {
291  addAnchor( pad->GetPosition(), CORNER | SNAPPABLE, pad );
292  break;
293  }
294  }
295 
296  // if the cursor is not over a pad, then drag the module by its origin
297  addAnchor( mod->GetPosition(), ORIGIN | SNAPPABLE, mod );
298  break;
299  }
300 
301  case PCB_PAD_T:
302  {
303  D_PAD* pad = static_cast<D_PAD*>( aItem );
304  addAnchor( pad->GetPosition(), CORNER | SNAPPABLE, pad );
305 
306  break;
307  }
308 
309  case PCB_MODULE_EDGE_T:
310  case PCB_LINE_T:
311  {
312  DRAWSEGMENT* dseg = static_cast<DRAWSEGMENT*>( aItem );
313  VECTOR2I start = dseg->GetStart();
314  VECTOR2I end = dseg->GetEnd();
315  //PCB_LAYER_ID layer = dseg->GetLayer();
316 
317  switch( dseg->GetShape() )
318  {
319  case S_CIRCLE:
320  {
321  int r = ( start - end ).EuclideanNorm();
322 
323  addAnchor( start, ORIGIN | SNAPPABLE, dseg );
324  addAnchor( start + VECTOR2I( -r, 0 ), OUTLINE | SNAPPABLE, dseg );
325  addAnchor( start + VECTOR2I( r, 0 ), OUTLINE | SNAPPABLE, dseg );
326  addAnchor( start + VECTOR2I( 0, -r ), OUTLINE | SNAPPABLE, dseg );
327  addAnchor( start + VECTOR2I( 0, r ), OUTLINE | SNAPPABLE, dseg );
328  break;
329  }
330 
331  case S_ARC:
332  {
333  origin = dseg->GetCenter();
334  addAnchor( dseg->GetArcStart(), CORNER | SNAPPABLE, dseg );
335  addAnchor( dseg->GetArcEnd(), CORNER | SNAPPABLE, dseg );
336  addAnchor( origin, ORIGIN | SNAPPABLE, dseg );
337  break;
338  }
339 
340  case S_SEGMENT:
341  {
342  origin.x = start.x + ( start.x - end.x ) / 2;
343  origin.y = start.y + ( start.y - end.y ) / 2;
344  addAnchor( start, CORNER | SNAPPABLE, dseg );
345  addAnchor( end, CORNER | SNAPPABLE, dseg );
346  addAnchor( origin, ORIGIN, dseg );
347  break;
348  }
349 
350  default:
351  {
352  origin = dseg->GetStart();
353  addAnchor( origin, ORIGIN | SNAPPABLE, dseg );
354  break;
355  }
356  }
357  break;
358  }
359 
360  case PCB_TRACE_T:
361  {
362  TRACK* track = static_cast<TRACK*>( aItem );
363  VECTOR2I start = track->GetStart();
364  VECTOR2I end = track->GetEnd();
365  origin.x = start.x + ( start.x - end.x ) / 2;
366  origin.y = start.y + ( start.y - end.y ) / 2;
367  addAnchor( start, CORNER | SNAPPABLE, track );
368  addAnchor( end, CORNER | SNAPPABLE, track );
369  addAnchor( origin, ORIGIN, track);
370  break;
371  }
372 
373  case PCB_VIA_T:
374  addAnchor( aItem->GetPosition(), CORNER | SNAPPABLE, aItem );
375  break;
376 
377  case PCB_ZONE_AREA_T:
378  {
379  const SHAPE_POLY_SET* outline = static_cast<const ZONE_CONTAINER*>( aItem )->Outline();
380 
381  SHAPE_LINE_CHAIN lc;
382  lc.SetClosed( true );
383 
384  for( auto iter = outline->CIterateWithHoles(); iter; iter++ )
385  {
386  addAnchor( *iter, CORNER, aItem );
387  lc.Append( *iter );
388  }
389 
390  addAnchor( lc.NearestPoint( aRefPos ), OUTLINE, aItem );
391 
392  break;
393  }
394 
395  case PCB_MODULE_TEXT_T:
396  case PCB_TEXT_T:
397  addAnchor( aItem->GetPosition(), ORIGIN, aItem );
398  default:
399 
400  break;
401  }
402 }
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:205
Arcs (with rounded ends)
void addAnchor(const VECTOR2I &aPos, int aFlags=CORNER|SNAPPABLE, BOARD_ITEM *aItem=NULL)
Definition: grid_helper.h:90
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 83 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().

84 {
85  PCB_SCREEN* screen = m_frame->GetScreen();
86 
87  const wxRealPoint& size = screen->GetGridSize();
88 
89  return VECTOR2I( KiROUND( size.x ), KiROUND( size.y ) );
90 }
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:104
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 93 of file grid_helper.cpp.

References PCB_BASE_FRAME::GetGridOrigin(), and m_frame.

Referenced by Align(), and AlignToSegment().

94 {
95  return VECTOR2I( m_frame->GetGridOrigin() );
96 }
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:104
GRID_HELPER::ANCHOR * GRID_HELPER::nearestAnchor ( const VECTOR2I aPos,
int  aFlags,
LSET  aMatchLayers 
)
private

Definition at line 405 of file grid_helper.cpp.

References dist, m_anchors, and max.

Referenced by BestDragOrigin(), and BestSnapAnchor().

406 {
407  double minDist = std::numeric_limits<double>::max();
408  ANCHOR* best = NULL;
409 
410  for( ANCHOR& a : m_anchors )
411  {
412  if( !aMatchLayers[a.item->GetLayer()] )
413  continue;
414 
415  if( ( aFlags & a.flags ) != aFlags )
416  continue;
417 
418  double dist = a.Distance( aPos );
419 
420  if( dist < minDist )
421  {
422  minDist = dist;
423  best = &a;
424  }
425  }
426 
427  return best;
428 }
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:86
std::set< BOARD_ITEM * > GRID_HELPER::queryVisible ( const BOX2I aArea) const
private

Definition at line 218 of file grid_helper.cpp.

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

Referenced by BestSnapAnchor().

219 {
220  std::set<BOARD_ITEM*> items;
221 
222  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> selectedItems;
223  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR>::iterator it, it_end;
224 
225  auto view = m_frame->GetGalCanvas()->GetView();
226  view->Query( aArea, selectedItems ); // Get the list of selected items
227 
228  for( it = selectedItems.begin(), it_end = selectedItems.end(); it != it_end; ++it )
229  {
230  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( it->first );
231 
232  if( view->IsVisible( item ) )
233  items.insert ( item );
234  }
235 
236  return items;
237 }
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:104
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Function GetGalCanvas returns a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:831
void GRID_HELPER::SetAuxAxes ( bool  aEnable,
const VECTOR2I aOrigin = VECTOR2I( 0, 0 ),
bool  aEnableDiagonal = false 
)

Definition at line 99 of file grid_helper.cpp.

References EDA_DRAW_FRAME::GetGalCanvas(), EDA_DRAW_PANEL_GAL::GetView(), m_auxAxis, m_diagonalAuxAxesEnable, m_frame, m_viewAxis, KIGFX::ORIGIN_VIEWITEM::SetPosition(), and KIGFX::VIEW::SetVisible().

Referenced by EDIT_TOOL::Main().

100 {
101  KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView();
102 
103  if( aEnable )
104  {
105  m_auxAxis = aOrigin;
106  m_viewAxis.SetPosition( aOrigin );
107  view->SetVisible( &m_viewAxis, true );
108  }
109  else
110  {
112  view->SetVisible( &m_viewAxis, false );
113  }
114 
115  m_diagonalAuxAxesEnable = aEnable;
116 }
KIGFX::ORIGIN_VIEWITEM m_viewAxis
Definition: grid_helper.h:107
bool m_diagonalAuxAxesEnable
Definition: grid_helper.h:106
KIGFX::VIEW * GetView() const
Function GetView() Returns a pointer to the VIEW instance used in the panel.
void SetPosition(const VECTOR2D &aPosition)
boost::optional< VECTOR2I > m_auxAxis
Definition: grid_helper.h:105
PCB_BASE_FRAME * m_frame
Definition: grid_helper.h:104
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Sets the item visibility.
Definition: view.cpp:1323
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Function GetGalCanvas returns a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:831
Class VIEW.
Definition: view.h:58
void GRID_HELPER::SetGrid ( int  aSize)

Definition at line 71 of file grid_helper.cpp.

72 {
73  assert( false );
74 }
void GRID_HELPER::SetOrigin ( const VECTOR2I aOrigin)

Definition at line 77 of file grid_helper.cpp.

78 {
79  assert( false );
80 }

Member Data Documentation

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

Definition at line 86 of file grid_helper.h.

Referenced by nearestAnchor().

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

Definition at line 105 of file grid_helper.h.

Referenced by Align(), and SetAuxAxes().

bool GRID_HELPER::m_diagonalAuxAxesEnable
private

Definition at line 106 of file grid_helper.h.

Referenced by GRID_HELPER(), and SetAuxAxes().

PCB_BASE_FRAME* GRID_HELPER::m_frame
private
KIGFX::ORIGIN_VIEWITEM GRID_HELPER::m_viewAxis
private

Definition at line 107 of file grid_helper.h.

Referenced by GRID_HELPER(), and SetAuxAxes().

KIGFX::ORIGIN_VIEWITEM GRID_HELPER::m_viewSnapPoint
private

Definition at line 107 of file grid_helper.h.

Referenced by BestSnapAnchor(), and GRID_HELPER().


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