KiCad PCB EDA Suite
EE_GRID_HELPER Class Reference

#include <ee_grid_helper.h>

Inheritance diagram for EE_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

 EE_GRID_HELPER (TOOL_MANAGER *aToolMgr)
 
SCH_ITEMGetSnapped () const
 Function GetSnapped If the EE_GRID_HELPER has highlighted a snap point (target shown), this function will return a pointer to the item to which it snapped. More...
 
VECTOR2I BestDragOrigin (const VECTOR2I &aMousePos, int aLayer, const EE_SELECTION &aItems)
 
VECTOR2I BestSnapAnchor (const VECTOR2I &aOrigin, int aLayer, SCH_ITEM *aDraggedItem)
 
VECTOR2I BestSnapAnchor (const VECTOR2I &aOrigin, int aLayer, const EE_SELECTION &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< SCH_ITEM * > queryVisible (const BOX2I &aArea, const EE_SELECTION &aSkipList) const
 
ANCHORnearestAnchor (const VECTOR2I &aPos, int aFlags, int aMatchLayer)
 
void computeAnchors (SCH_ITEM *aItem, const VECTOR2I &aRefPos, bool aFrom=false)
 Insert the local anchor points in to the grid helper for the specified schematic item, given the reference point and the direction of use for the point. More...
 

Detailed Description

Definition at line 45 of file ee_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

◆ EE_GRID_HELPER()

EE_GRID_HELPER::EE_GRID_HELPER ( TOOL_MANAGER aToolMgr)

Definition at line 37 of file ee_grid_helper.cpp.

37  :
38  GRID_HELPER( aToolMgr )
39 {
40  KIGFX::VIEW* view = m_toolMgr->GetView();
41 
42  m_viewAxis.SetSize( 20000 );
44  m_viewAxis.SetColor( COLOR4D( 0.0, 0.1, 0.4, 0.8 ) );
45  m_viewAxis.SetDrawAtZero( true );
46  view->Add( &m_viewAxis );
47  view->SetVisible( &m_viewAxis, false );
48 
50  m_viewSnapPoint.SetColor( COLOR4D( 0.0, 0.1, 0.4, 1.0 ) );
52  view->Add( &m_viewSnapPoint );
53  view->SetVisible( &m_viewSnapPoint, false );
54 
56  m_viewSnapLine.SetColor( COLOR4D( 0.33, 0.55, 0.95, 1.0 ) );
58  view->Add( &m_viewSnapLine );
59  view->SetVisible( &m_viewSnapLine, false );
60 }
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:283
TOOL_MANAGER * m_toolMgr
Definition: grid_helper.h:129
KIGFX::ORIGIN_VIEWITEM m_viewAxis
Definition: grid_helper.h:143
GRID_HELPER(TOOL_MANAGER *aToolMgr)
Definition: grid_helper.cpp:35
KIGFX::ORIGIN_VIEWITEM m_viewSnapPoint
Definition: grid_helper.h:141
void SetSize(int aSize)
void SetDrawAtZero(bool aDrawFlag)
Set the draw at zero flag.
void SetColor(const KIGFX::COLOR4D &aColor)
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Set the item visibility.
Definition: view.cpp:1458
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:318
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:68
void SetStyle(MARKER_STYLE aStyle)
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103

References KIGFX::VIEW::Add(), KIGFX::ORIGIN_VIEWITEM::CIRCLE_CROSS, KIGFX::ORIGIN_VIEWITEM::CROSS, KIGFX::ORIGIN_VIEWITEM::DASH_LINE, TOOL_MANAGER::GetView(), 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(), and KIGFX::VIEW::SetVisible().

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 computeAnchors(), and PCB_GRID_HELPER::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 PCB_GRID_HELPER::AlignToSegment(), BestSnapAnchor(), PCB_GRID_HELPER::BestSnapAnchor(), 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:73

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

Referenced by GRID_HELPER::Align().

◆ BestDragOrigin()

VECTOR2I EE_GRID_HELPER::BestDragOrigin ( const VECTOR2I aMousePos,
int  aLayer,
const EE_SELECTION aItems 
)

Definition at line 63 of file ee_grid_helper.cpp.

65 {
66  clearAnchors();
67 
68  for( EDA_ITEM* item : aItems )
69  computeAnchors( static_cast<SCH_ITEM*>( item ), aMousePos, true );
70 
71  double worldScale = m_toolMgr->GetView()->GetGAL()->GetWorldScale();
72  double lineSnapMinCornerDistance = 50.0 / worldScale;
73 
74  ANCHOR* nearestOutline = nearestAnchor( aMousePos, OUTLINE, aLayer );
75  ANCHOR* nearestCorner = nearestAnchor( aMousePos, CORNER, aLayer );
76  ANCHOR* nearestOrigin = nearestAnchor( aMousePos, ORIGIN, aLayer );
77  ANCHOR* best = nullptr;
78  double minDist = std::numeric_limits<double>::max();
79 
80  if( nearestOrigin )
81  {
82  minDist = nearestOrigin->Distance( aMousePos );
83  best = nearestOrigin;
84  }
85 
86  if( nearestCorner )
87  {
88  double dist = nearestCorner->Distance( aMousePos );
89 
90  if( dist < minDist )
91  {
92  minDist = dist;
93  best = nearestCorner;
94  }
95  }
96 
97  if( nearestOutline )
98  {
99  double dist = nearestOutline->Distance( aMousePos );
100 
101  if( minDist > lineSnapMinCornerDistance && dist < minDist )
102  best = nearestOutline;
103  }
104 
105  return best ? best->pos : aMousePos;
106 }
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:283
TOOL_MANAGER * m_toolMgr
Definition: grid_helper.h:129
void computeAnchors(SCH_ITEM *aItem, const VECTOR2I &aRefPos, bool aFrom=false)
Insert the local anchor points in to the grid helper for the specified schematic item,...
GAL * GetGAL() const
Return the #GAL this view is using to draw graphical primitives.
Definition: view.h:190
ANCHOR * nearestAnchor(const VECTOR2I &aPos, int aFlags, int aMatchLayer)
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100
double GetWorldScale() const
Get the world scale.
void clearAnchors()
Definition: grid_helper.h:112

References 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(), GRID_HELPER::ORIGIN, GRID_HELPER::OUTLINE, and GRID_HELPER::ANCHOR::pos.

◆ BestSnapAnchor() [1/2]

VECTOR2I EE_GRID_HELPER::BestSnapAnchor ( const VECTOR2I aOrigin,
int  aLayer,
SCH_ITEM aDraggedItem 
)

Definition at line 109 of file ee_grid_helper.cpp.

110 {
111  EE_SELECTION skipItems;
112  skipItems.Add( aSkip );
113 
114  return BestSnapAnchor( aOrigin, aLayer, skipItems );
115 }
virtual void Add(EDA_ITEM *aItem)
Definition: selection.cpp:32
VECTOR2I BestSnapAnchor(const VECTOR2I &aOrigin, int aLayer, SCH_ITEM *aDraggedItem)

References SELECTION::Add().

◆ BestSnapAnchor() [2/2]

VECTOR2I EE_GRID_HELPER::BestSnapAnchor ( const VECTOR2I aOrigin,
int  aLayer,
const EE_SELECTION aSkip = {} 
)

Definition at line 118 of file ee_grid_helper.cpp.

120 {
121  constexpr int snapRange = SNAP_RANGE * IU_PER_MILS;
122 
123  VECTOR2I pt = aOrigin;
124  VECTOR2I snapDist( snapRange, snapRange );
125  bool snapLineX = false;
126  bool snapLineY = false;
127  bool snapPoint = false;
128  bool gridChecked = false;
129 
130  BOX2I bb( VECTOR2I( aOrigin.x - snapRange / 2, aOrigin.y - snapRange / 2 ),
131  VECTOR2I( snapRange, snapRange ) );
132 
133  clearAnchors();
134 
135  for( SCH_ITEM* item : queryVisible( bb, aSkip ) )
136  computeAnchors( item, aOrigin );
137 
138  ANCHOR* nearest = nearestAnchor( aOrigin, SNAPPABLE, aLayer );
139  VECTOR2I nearestGrid = Align( aOrigin );
140 
142  {
143  if( std::abs( m_viewSnapLine.GetPosition().x - aOrigin.x ) < snapDist.x )
144  {
145  pt.x = m_viewSnapLine.GetPosition().x;
146  snapDist.x = std::abs( m_viewSnapLine.GetPosition().x - aOrigin.x );
147  snapLineX = true;
148  }
149 
150  if( std::abs( m_viewSnapLine.GetPosition().y - aOrigin.y ) < snapDist.y )
151  {
152  pt.y = m_viewSnapLine.GetPosition().y;
153  snapDist.y = std::abs( m_viewSnapLine.GetPosition().y - aOrigin.y );
154  snapLineY = true;
155  }
156 
157  if( canUseGrid() && std::abs( nearestGrid.x - aOrigin.x ) < snapDist.x )
158  {
159  pt.x = nearestGrid.x;
160  snapDist.x = std::abs( nearestGrid.x - aOrigin.x );
161  snapLineX = false;
162  }
163 
164  if( canUseGrid() && std::abs( nearestGrid.y - aOrigin.y ) < snapDist.y )
165  {
166  pt.y = nearestGrid.y;
167  snapDist.y = std::abs( nearestGrid.y - aOrigin.y );
168  snapLineY = false;
169  }
170 
171  gridChecked = true;
172  }
173 
174  if( m_enableSnap && nearest && nearest->Distance( aOrigin ) < snapDist.EuclideanNorm() )
175  {
176 
177  if( canUseGrid() && ( nearestGrid - aOrigin ).EuclideanNorm() < snapDist.EuclideanNorm() )
178  {
179  pt = nearestGrid;
180  snapDist.x = std::abs( nearestGrid.x - aOrigin.x );
181  snapDist.y = std::abs( nearestGrid.y - aOrigin.y );
182  snapPoint = false;
183  }
184  else
185  {
186  pt = nearest->pos;
187  snapDist.x = std::abs( nearest->pos.x - aOrigin.x );
188  snapDist.y = std::abs( nearest->pos.y - aOrigin.y );
189  snapPoint = true;
190  }
191 
192  snapLineX = snapLineY = false;
193  gridChecked = true;
194  }
195 
196  if( canUseGrid() && !gridChecked )
197  pt = nearestGrid;
198 
199  if( snapLineX || snapLineY )
200  {
202 
205  else
207  }
208  else if( snapPoint )
209  {
210  m_snapItem = nearest;
211  m_viewSnapPoint.SetPosition( (wxPoint) pt );
212  m_viewSnapLine.SetPosition( (wxPoint) pt );
213 
215 
218  else
220  }
221  else
222  {
225  }
226 
227  return pt;
228 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:146
void SetPosition(const wxPoint &aPosition) override
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:283
wxPoint GetPosition() const override
ANCHOR * m_snapItem
Definition: grid_helper.h:137
TOOL_MANAGER * m_toolMgr
Definition: grid_helper.h:129
void computeAnchors(SCH_ITEM *aItem, const VECTOR2I &aRefPos, bool aFrom=false)
Insert the local anchor points in to the grid helper for the specified schematic item,...
std::set< SCH_ITEM * > queryVisible(const BOX2I &aArea, const EE_SELECTION &aSkipList) const
ANCHOR * nearestAnchor(const VECTOR2I &aPos, int aFlags, int aMatchLayer)
void SetEndPosition(const VECTOR2D &aPosition)
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
KIGFX::ORIGIN_VIEWITEM m_viewSnapPoint
Definition: grid_helper.h:141
bool IsVisible(const VIEW_ITEM *aItem) const
Return information if the item is visible (or not).
Definition: view.cpp:1498
#define SNAP_RANGE
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
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
#define IU_PER_MILS
Definition: plotter.cpp:136
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Set the item visibility.
Definition: view.cpp:1458
KIGFX::ORIGIN_VIEWITEM m_viewSnapLine
Definition: grid_helper.h:142
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:182
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:1512
Position or shape has changed.
Definition: view_item.h:49

References GRID_HELPER::Align(), GRID_HELPER::canUseGrid(), GRID_HELPER::clearAnchors(), computeAnchors(), GRID_HELPER::ANCHOR::Distance(), VECTOR2< T >::EuclideanNorm(), EuclideanNorm(), KIGFX::GEOMETRY, KIGFX::ORIGIN_VIEWITEM::GetPosition(), TOOL_MANAGER::GetView(), KIGFX::VIEW::IsVisible(), IU_PER_MILS, 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(), SNAP_RANGE, 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:283
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:190
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 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 PCB_GRID_HELPER::BestDragOrigin(), BestDragOrigin(), BestSnapAnchor(), and PCB_GRID_HELPER::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 EE_GRID_HELPER::computeAnchors ( SCH_ITEM aItem,
const VECTOR2I aRefPos,
bool  aFrom = false 
)
private

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

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

Definition at line 265 of file ee_grid_helper.cpp.

266 {
267  switch ( aItem->Type() )
268  {
269  case SCH_SYMBOL_T:
270  case SCH_SHEET_T:
271  addAnchor( aItem->GetPosition(), ORIGIN, aItem );
273  case SCH_JUNCTION_T:
274  case SCH_NO_CONNECT_T:
275  case SCH_LINE_T:
276  case SCH_GLOBAL_LABEL_T:
277  case SCH_HIER_LABEL_T:
278  case SCH_LABEL_T:
280  {
281  std::vector<wxPoint> pts = aItem->GetConnectionPoints();
282 
283  for( const wxPoint &pt : pts )
284  addAnchor( VECTOR2I( pt ), SNAPPABLE | CORNER, aItem );
285 
286  break;
287  }
288 
289  default:
290  break;
291  }
292 
293  if( SCH_LINE* line = dyn_cast<SCH_LINE*>( aItem ) )
294  {
295  VECTOR2I pt = Align( aRefPos );
296 
297  if( line->GetStartPoint().x == line->GetEndPoint().x )
298  {
299  VECTOR2I possible( line->GetStartPoint().x, pt.y );
300 
301  if( TestSegmentHit( wxPoint( possible ), line->GetStartPoint(), line->GetEndPoint(),
302  0 ) )
303  addAnchor( possible, SNAPPABLE | VERTICAL, aItem );
304  }
305  else if( line->GetStartPoint().y == line->GetEndPoint().y )
306  {
307  VECTOR2I possible( pt.x, line->GetStartPoint().y );
308 
309  if( TestSegmentHit( wxPoint( possible ), line->GetStartPoint(), line->GetEndPoint(),
310  0 ) )
311  addAnchor( possible, SNAPPABLE | HORIZONTAL, aItem );
312  }
313 
314  }
315 }
void addAnchor(const VECTOR2I &aPos, int aFlags, EDA_ITEM *aItem)
Definition: grid_helper.h:106
virtual std::vector< wxPoint > GetConnectionPoints() const
Add all the connection points for this item to aPoints.
Definition: sch_item.h:362
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
Definition: macros.h:83
virtual wxPoint GetPosition() const
Definition: eda_item.h:252
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
bool TestSegmentHit(const wxPoint &aRefPoint, const wxPoint &aStart, const wxPoint &aEnd, int aDist)
Test if aRefPoint is with aDistance on the line defined by aStart and aEnd.
Definition: trigo.cpp:129
virtual VECTOR2I Align(const VECTOR2I &aPoint) const
Definition: grid_helper.cpp:95
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:37
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113

References GRID_HELPER::addAnchor(), GRID_HELPER::Align(), GRID_HELPER::CORNER, SCH_ITEM::GetConnectionPoints(), EDA_ITEM::GetPosition(), GRID_HELPER::HORIZONTAL, KI_FALLTHROUGH, GRID_HELPER::ORIGIN, SCH_BUS_WIRE_ENTRY_T, SCH_GLOBAL_LABEL_T, SCH_HIER_LABEL_T, SCH_JUNCTION_T, SCH_LABEL_T, SCH_LINE_T, SCH_NO_CONNECT_T, SCH_SHEET_T, SCH_SYMBOL_T, GRID_HELPER::SNAPPABLE, TestSegmentHit(), EDA_ITEM::Type(), GRID_HELPER::VERTICAL, 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:283
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:190
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:73

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(), PCB_GRID_HELPER::AlignToArc(), PCB_GRID_HELPER::BestSnapAnchor(), and PCB_GRID_HELPER::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:283
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:190
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(), and PCB_GRID_HELPER::AlignToArc().

◆ 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()

SCH_ITEM * EE_GRID_HELPER::GetSnapped ( ) const

Function GetSnapped If the EE_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 230 of file ee_grid_helper.cpp.

231 {
232  if( !m_snapItem )
233  return nullptr;
234 
235  return static_cast<SCH_ITEM*>( m_snapItem->item );
236 }
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()

EE_GRID_HELPER::ANCHOR * EE_GRID_HELPER::nearestAnchor ( const VECTOR2I aPos,
int  aFlags,
int  aMatchLayer 
)
private

Definition at line 318 of file ee_grid_helper.cpp.

320 {
321  double minDist = std::numeric_limits<double>::max();
322  ANCHOR* best = nullptr;
323 
324  for( ANCHOR& a : m_anchors )
325  {
326  SCH_ITEM* item = static_cast<SCH_ITEM*>( a.item );
327 
328  if( ( aFlags & a.flags ) != aFlags )
329  continue;
330 
331  if( aMatchLayer == LAYER_CONNECTABLE && !item->IsConnectable() )
332  continue;
333  else if( aMatchLayer == LAYER_GRAPHICS && item->IsConnectable() )
334  continue;
335 
336  double dist = a.Distance( aPos );
337 
338  if( dist < minDist )
339  {
340  minDist = dist;
341  best = &a;
342  }
343  }
344 
345  return best;
346 }
virtual bool IsConnectable() const
Definition: sch_item.h:347
std::vector< ANCHOR > m_anchors
Definition: grid_helper.h:127
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:182

References SCH_ITEM::IsConnectable(), LAYER_CONNECTABLE, LAYER_GRAPHICS, and GRID_HELPER::m_anchors.

Referenced by BestDragOrigin(), and BestSnapAnchor().

◆ queryVisible()

std::set< SCH_ITEM * > EE_GRID_HELPER::queryVisible ( const BOX2I aArea,
const EE_SELECTION aSkipList 
) const
private

Definition at line 239 of file ee_grid_helper.cpp.

241 {
242  std::set<SCH_ITEM*> items;
243  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> selectedItems;
244 
245  KIGFX::VIEW* view = m_toolMgr->GetView();
246 
247  view->Query( aArea, selectedItems );
248 
249  for( const KIGFX::VIEW::LAYER_ITEM_PAIR& it : selectedItems )
250  {
251  SCH_ITEM* item = static_cast<SCH_ITEM*>( it.first );
252 
253  // The item must be visible and on an active layer
254  if( view->IsVisible( item ) && item->ViewGetLOD( it.second, view ) < view->GetScale() )
255  items.insert ( item );
256  }
257 
258  for( EDA_ITEM* skipItem : aSkipList )
259  items.erase( static_cast<SCH_ITEM*>( skipItem ) );
260 
261  return items;
262 }
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:283
TOOL_MANAGER * m_toolMgr
Definition: grid_helper.h:129
bool IsVisible(const VIEW_ITEM *aItem) const
Return information if the item is visible (or not).
Definition: view.cpp:1498
std::pair< VIEW_ITEM *, int > LAYER_ITEM_PAIR
Definition: view.h:73
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100
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:424
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:68
double GetScale() const
Definition: view.h:264
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:182
virtual double ViewGetLOD(int aLayer, VIEW *aView) const
Return the level of detail (LOD) of the item.
Definition: view_item.h:132

References KIGFX::VIEW::GetScale(), TOOL_MANAGER::GetView(), KIGFX::VIEW::IsVisible(), GRID_HELPER::m_toolMgr, KIGFX::VIEW::Query(), 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:283
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:1458

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

◆ m_enableSnapLine

bool GRID_HELPER::m_enableSnapLine
protectedinherited

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