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
 
OPT< 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:1331
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Function GetGalCanvas returns a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:870
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:312
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 }
OPT< VECTOR2I > m_auxAxis
Definition: grid_helper.h:105
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:106
VECTOR2I GetGrid() const
Definition: grid_helper.cpp:83
#define abs(a)
Definition: auxiliary.h:84
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:112
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:106
OPT_VECTOR2I IntersectLines(const SEG &aSeg) const
Function IntersectLines()
Definition: seg.h:169
VECTOR2I GetGrid() const
Definition: grid_helper.cpp:83
VECTOR2< int > VECTOR2I
Definition: vector2d.h:589
OPT< VECTOR2I > OPT_VECTOR2I
Definition: seg.h:34
VECTOR2I GetOrigin() const
Definition: grid_helper.cpp:93
Definition: seg.h:36
#define max(a, b)
Definition: auxiliary.h:86
VECTOR2I A
Definition: seg.h:46
bool Contains(const VECTOR2I &aP) const
Definition: seg.cpp:155
VECTOR2I B
Definition: seg.h:47
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:683
#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:870
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(), LSET::AllLayersMask(), clearAnchors(), computeAnchors(), CORNER, GRID_HELPER::ANCHOR::Distance(), 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(), GRID_HELPER::ANCHOR::pos, queryVisible(), KIGFX::ORIGIN_VIEWITEM::SetPosition(), KIGFX::VIEW::SetVisible(), SNAPPABLE, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by PICKER_TOOL::Main(), and 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;
255 
256  if( aDraggedItem )
257  layers = aDraggedItem->GetLayer();
258  else
259  layers = LSET::AllLayersMask();
260 
261  ANCHOR* nearest = nearestAnchor( aOrigin, CORNER | SNAPPABLE, layers );
262 
263  VECTOR2I nearestGrid = Align( aOrigin );
264  double gridDist = ( nearestGrid - aOrigin ).EuclideanNorm();
265 
266  if( nearest )
267  {
268  double snapDist = nearest->Distance( aOrigin );
269 
270  if( nearest && snapDist < gridDist )
271  {
272  m_viewSnapPoint.SetPosition( nearest->pos );
274  return nearest->pos;
275  }
276  }
277 
279  return nearestGrid;
280 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:112
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.
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
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:589
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)
static LSET AllLayersMask()
Definition: lset.cpp:683
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:1331
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Function GetGalCanvas returns a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:870
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 283 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_POLYGON, S_SEGMENT, SHAPE_LINE_CHAIN::SetClosed(), SNAPPABLE, EDA_ITEM::Type(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by BestDragOrigin(), and BestSnapAnchor().

284 {
285  VECTOR2I origin;
286 
287  switch( aItem->Type() )
288  {
289  case PCB_MODULE_T:
290  {
291  MODULE* mod = static_cast<MODULE*>( aItem );
292 
293  for( auto pad : mod->Pads() )
294  {
295  if( pad->GetBoundingBox().Contains( wxPoint( aRefPos.x, aRefPos.y ) ) )
296  {
297  addAnchor( pad->GetPosition(), CORNER | SNAPPABLE, pad );
298  break;
299  }
300  }
301 
302  // if the cursor is not over a pad, then drag the module by its origin
303  addAnchor( mod->GetPosition(), ORIGIN | SNAPPABLE, mod );
304  break;
305  }
306 
307  case PCB_PAD_T:
308  {
309  D_PAD* pad = static_cast<D_PAD*>( aItem );
310  addAnchor( pad->GetPosition(), CORNER | SNAPPABLE, pad );
311 
312  break;
313  }
314 
315  case PCB_MODULE_EDGE_T:
316  case PCB_LINE_T:
317  {
318  DRAWSEGMENT* dseg = static_cast<DRAWSEGMENT*>( aItem );
319  VECTOR2I start = dseg->GetStart();
320  VECTOR2I end = dseg->GetEnd();
321  //PCB_LAYER_ID layer = dseg->GetLayer();
322 
323  switch( dseg->GetShape() )
324  {
325  case S_CIRCLE:
326  {
327  int r = ( start - end ).EuclideanNorm();
328 
329  addAnchor( start, ORIGIN | SNAPPABLE, dseg );
330  addAnchor( start + VECTOR2I( -r, 0 ), OUTLINE | SNAPPABLE, dseg );
331  addAnchor( start + VECTOR2I( r, 0 ), OUTLINE | SNAPPABLE, dseg );
332  addAnchor( start + VECTOR2I( 0, -r ), OUTLINE | SNAPPABLE, dseg );
333  addAnchor( start + VECTOR2I( 0, r ), OUTLINE | SNAPPABLE, dseg );
334  break;
335  }
336 
337  case S_ARC:
338  {
339  origin = dseg->GetCenter();
340  addAnchor( dseg->GetArcStart(), CORNER | SNAPPABLE, dseg );
341  addAnchor( dseg->GetArcEnd(), CORNER | SNAPPABLE, dseg );
342  addAnchor( origin, ORIGIN | SNAPPABLE, dseg );
343  break;
344  }
345 
346  case S_SEGMENT:
347  {
348  origin.x = start.x + ( start.x - end.x ) / 2;
349  origin.y = start.y + ( start.y - end.y ) / 2;
350  addAnchor( start, CORNER | SNAPPABLE, dseg );
351  addAnchor( end, CORNER | SNAPPABLE, dseg );
352  addAnchor( origin, ORIGIN, dseg );
353  break;
354  }
355 
356  case S_POLYGON:
357  {
358  // no anchors for the moment
359  break;
360  }
361 
362  default:
363  {
364  origin = dseg->GetStart();
365  addAnchor( origin, ORIGIN | SNAPPABLE, dseg );
366  break;
367  }
368  }
369  break;
370  }
371 
372  case PCB_TRACE_T:
373  {
374  TRACK* track = static_cast<TRACK*>( aItem );
375  VECTOR2I start = track->GetStart();
376  VECTOR2I end = track->GetEnd();
377  origin.x = start.x + ( start.x - end.x ) / 2;
378  origin.y = start.y + ( start.y - end.y ) / 2;
379  addAnchor( start, CORNER | SNAPPABLE, track );
380  addAnchor( end, CORNER | SNAPPABLE, track );
381  addAnchor( origin, ORIGIN, track);
382  break;
383  }
384 
385  case PCB_VIA_T:
386  addAnchor( aItem->GetPosition(), CORNER | SNAPPABLE, aItem );
387  break;
388 
389  case PCB_ZONE_AREA_T:
390  {
391  const SHAPE_POLY_SET* outline = static_cast<const ZONE_CONTAINER*>( aItem )->Outline();
392 
393  SHAPE_LINE_CHAIN lc;
394  lc.SetClosed( true );
395 
396  for( auto iter = outline->CIterateWithHoles(); iter; iter++ )
397  {
398  addAnchor( *iter, CORNER, aItem );
399  lc.Append( *iter );
400  }
401 
402  addAnchor( lc.NearestPoint( aRefPos ), OUTLINE, aItem );
403 
404  break;
405  }
406 
407  case PCB_MODULE_TEXT_T:
408  case PCB_TEXT_T:
409  addAnchor( aItem->GetPosition(), ORIGIN, aItem );
410  default:
411 
412  break;
413  }
414 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:112
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
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:167
polygon (not yet used for tracks, but could be in microwave apps)
CONST_ITERATOR CIterateWithHoles(int aOutline) const
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:102
DLIST_ITERATOR_WRAPPER< D_PAD > Pads()
Definition: class_module.h:152
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:92
usual segment : line with rounded ends
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
VECTOR2< int > VECTOR2I
Definition: vector2d.h:589
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:94
const wxPoint & GetEnd() const
Definition: class_track.h:120
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()
const wxPoint & GetArcStart() const
class MODULE, a footprint
Definition: typeinfo.h:89
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:123
const wxPoint & GetPosition() const override
Definition: class_pad.h:220
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:93
Class SHAPE_LINE_CHAIN.
const wxPoint GetArcEnd() const
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
class DRAWSEGMENT, a segment not on copper layers
Definition: typeinfo.h:91
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:106
VECTOR2< int > VECTOR2I
Definition: vector2d.h:589
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:589
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 417 of file grid_helper.cpp.

References dist, m_anchors, and max.

Referenced by BestDragOrigin(), and BestSnapAnchor().

418 {
419  double minDist = std::numeric_limits<double>::max();
420  ANCHOR* best = NULL;
421 
422  for( ANCHOR& a : m_anchors )
423  {
424  if( !aMatchLayers[a.item->GetLayer()] )
425  continue;
426 
427  if( ( aFlags & a.flags ) != aFlags )
428  continue;
429 
430  double dist = a.Distance( aPos );
431 
432  if( dist < minDist )
433  {
434  minDist = dist;
435  best = &a;
436  }
437  }
438 
439  return best;
440 }
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 }
virtual 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:418
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:870
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 }
OPT< VECTOR2I > m_auxAxis
Definition: grid_helper.h:105
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)
PCB_BASE_FRAME * m_frame
Definition: grid_helper.h:104
boost::optional< T > OPT
Definition: optional.h:7
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Sets the item visibility.
Definition: view.cpp:1331
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Function GetGalCanvas returns a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:870
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().

OPT<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: