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)
 computeAnchors inserts 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 36 of file ee_grid_helper.cpp.

36  :
37  GRID_HELPER( aToolMgr )
38 {
39  KIGFX::VIEW* view = m_toolMgr->GetView();
40 
41  m_viewAxis.SetSize( 20000 );
43  m_viewAxis.SetColor( COLOR4D( 0.0, 0.1, 0.4, 0.8 ) );
44  m_viewAxis.SetDrawAtZero( true );
45  view->Add( &m_viewAxis );
46  view->SetVisible( &m_viewAxis, false );
47 
49  m_viewSnapPoint.SetColor( COLOR4D( 0.0, 0.1, 0.4, 1.0 ) );
51  view->Add( &m_viewSnapPoint );
52  view->SetVisible( &m_viewSnapPoint, false );
53 
55  m_viewSnapLine.SetColor( COLOR4D( 0.33, 0.55, 0.95, 1.0 ) );
57  view->Add( &m_viewSnapLine );
58  view->SetVisible( &m_viewSnapLine, false );
59 }
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:289
TOOL_MANAGER * m_toolMgr
Definition: grid_helper.h:129
KIGFX::ORIGIN_VIEWITEM m_viewAxis
Definition: grid_helper.h:143
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:1454
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:321
KIGFX::ORIGIN_VIEWITEM m_viewSnapLine
Definition: grid_helper.h:142
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:67
void SetStyle(MARKER_STYLE aStyle)
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98

References KIGFX::VIEW::Add(), KIGFX::ORIGIN_VIEWITEM::CIRCLE_CROSS, KIGFX::ORIGIN_VIEWITEM::CROSS, KIGFX::ORIGIN_VIEWITEM::DASH_LINE, 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 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:68

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

Referenced by GRID_HELPER::Align(), and SCH_MOVE_TOOL::AlignElements().

◆ BestDragOrigin()

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

Definition at line 62 of file ee_grid_helper.cpp.

64 {
65  clearAnchors();
66 
67  for( EDA_ITEM* item : aItems )
68  computeAnchors( static_cast<SCH_ITEM*>( item ), aMousePos, true );
69 
70  double worldScale = m_toolMgr->GetView()->GetGAL()->GetWorldScale();
71  double lineSnapMinCornerDistance = 50.0 / worldScale;
72 
73  ANCHOR* nearestOutline = nearestAnchor( aMousePos, OUTLINE, aLayer );
74  ANCHOR* nearestCorner = nearestAnchor( aMousePos, CORNER, aLayer );
75  ANCHOR* nearestOrigin = nearestAnchor( aMousePos, ORIGIN, aLayer );
76  ANCHOR* best = NULL;
77  double minDist = std::numeric_limits<double>::max();
78 
79  if( nearestOrigin )
80  {
81  minDist = nearestOrigin->Distance( aMousePos );
82  best = nearestOrigin;
83  }
84 
85  if( nearestCorner )
86  {
87  double dist = nearestCorner->Distance( aMousePos );
88 
89  if( dist < minDist )
90  {
91  minDist = dist;
92  best = nearestCorner;
93  }
94  }
95 
96  if( nearestOutline )
97  {
98  double dist = nearestOutline->Distance( aMousePos );
99 
100  if( minDist > lineSnapMinCornerDistance && dist < minDist )
101  best = nearestOutline;
102  }
103 
104  return best ? best->pos : aMousePos;
105 }
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:289
TOOL_MANAGER * m_toolMgr
Definition: grid_helper.h:129
void computeAnchors(SCH_ITEM *aItem, const VECTOR2I &aRefPos, bool aFrom=false)
computeAnchors inserts 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:189
ANCHOR * nearestAnchor(const VECTOR2I &aPos, int aFlags, int aMatchLayer)
#define NULL
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:149
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(), NULL, GRID_HELPER::ORIGIN, GRID_HELPER::OUTLINE, and GRID_HELPER::ANCHOR::pos.

Referenced by SCH_MOVE_TOOL::Main().

◆ BestSnapAnchor() [1/2]

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

Definition at line 108 of file ee_grid_helper.cpp.

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

References SELECTION::Add().

Referenced by SCH_LINE_WIRE_BUS_TOOL::doDrawSegments(), SCH_LINE_WIRE_BUS_TOOL::DrawSegments(), EE_SELECTION_TOOL::GuessSelectionCandidates(), SCH_MOVE_TOOL::Main(), EE_SELECTION_TOOL::Main(), and SCH_DRAWING_TOOLS::TwoClickPlace().

◆ BestSnapAnchor() [2/2]

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

Definition at line 117 of file ee_grid_helper.cpp.

119 {
120  constexpr int snapRange = SNAP_RANGE * IU_PER_MILS;
121 
122  VECTOR2I pt = aOrigin;
123  VECTOR2I snapDist( snapRange, snapRange );
124  bool snapLineX = false;
125  bool snapLineY = false;
126  bool snapPoint = false;
127  bool gridChecked = false;
128 
129  BOX2I bb( VECTOR2I( aOrigin.x - snapRange / 2, aOrigin.y - snapRange / 2 ),
130  VECTOR2I( snapRange, snapRange ) );
131 
132  clearAnchors();
133 
134  for( SCH_ITEM* item : queryVisible( bb, aSkip ) )
135  computeAnchors( item, aOrigin );
136 
137  ANCHOR* nearest = nearestAnchor( aOrigin, SNAPPABLE, aLayer );
138  VECTOR2I nearestGrid = Align( aOrigin );
139 
141  {
142  if( std::abs( m_viewSnapLine.GetPosition().x - aOrigin.x ) < snapDist.x )
143  {
144  pt.x = m_viewSnapLine.GetPosition().x;
145  snapDist.x = std::abs( m_viewSnapLine.GetPosition().x - aOrigin.x );
146  snapLineX = true;
147  }
148 
149  if( std::abs( m_viewSnapLine.GetPosition().y - aOrigin.y ) < snapDist.y )
150  {
151  pt.y = m_viewSnapLine.GetPosition().y;
152  snapDist.y = std::abs( m_viewSnapLine.GetPosition().y - aOrigin.y );
153  snapLineY = true;
154  }
155 
156  if( canUseGrid() && std::abs( nearestGrid.x - aOrigin.x ) < snapDist.x )
157  {
158  pt.x = nearestGrid.x;
159  snapDist.x = std::abs( nearestGrid.x - aOrigin.x );
160  snapLineX = false;
161  }
162 
163  if( canUseGrid() && std::abs( nearestGrid.y - aOrigin.y ) < snapDist.y )
164  {
165  pt.y = nearestGrid.y;
166  snapDist.y = std::abs( nearestGrid.y - aOrigin.y );
167  snapLineY = false;
168  }
169 
170  gridChecked = true;
171  }
172 
173  if( m_enableSnap && nearest && nearest->Distance( aOrigin ) < snapDist.EuclideanNorm() )
174  {
175 
176  if( canUseGrid() && ( nearestGrid - aOrigin ).EuclideanNorm() < snapDist.EuclideanNorm() )
177  {
178  pt = nearestGrid;
179  snapDist.x = std::abs( nearestGrid.x - aOrigin.x );
180  snapDist.y = std::abs( nearestGrid.y - aOrigin.y );
181  snapPoint = false;
182  }
183  else
184  {
185  pt = nearest->pos;
186  snapDist.x = std::abs( nearest->pos.x - aOrigin.x );
187  snapDist.y = std::abs( nearest->pos.y - aOrigin.y );
188  snapPoint = true;
189  }
190 
191  snapLineX = snapLineY = false;
192  gridChecked = true;
193  }
194 
195  if( canUseGrid() && !gridChecked )
196  pt = nearestGrid;
197 
198  if( snapLineX || snapLineY )
199  {
201 
204  else
206  }
207  else if( snapPoint )
208  {
209  m_snapItem = nearest;
210  m_viewSnapPoint.SetPosition( (wxPoint) pt );
211  m_viewSnapLine.SetPosition( (wxPoint) pt );
212 
214 
217  else
219  }
220  else
221  {
224  }
225 
226  return pt;
227 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:148
void SetPosition(const wxPoint &aPosition) override
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:289
wxPoint GetPosition() const override
ANCHOR * m_snapItem
Definition: grid_helper.h:137
TOOL_MANAGER * m_toolMgr
Definition: grid_helper.h:129
void computeAnchors(SCH_ITEM *aItem, const VECTOR2I &aRefPos, bool aFrom=false)
computeAnchors inserts 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:1494
#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:137
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Set the item visibility.
Definition: view.cpp:1454
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:196
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:1508
Position or shape has changed.
Definition: view_item.h:54

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:289
TOOL_MANAGER * m_toolMgr
Definition: grid_helper.h:129
GAL * GetGAL() const
Return the #GAL this view is using to draw graphical primitives.
Definition: view.h:189
bool GetGridSnapping() const
bool m_enableGrid
Definition: grid_helper.h:135

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

Referenced by GRID_HELPER::Align(), and 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.

Referenced by SCH_LINE_WIRE_BUS_TOOL::doDrawSegments().

◆ 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

computeAnchors inserts 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 component)
aFromIs this for an anchor that is designating a source point (aFrom=true) or not

Definition at line 264 of file ee_grid_helper.cpp.

265 {
266  switch ( aItem->Type() )
267  {
268  case SCH_COMPONENT_T:
269  case SCH_SHEET_T:
270  addAnchor( aItem->GetPosition(), ORIGIN, aItem );
272  case SCH_JUNCTION_T:
273  case SCH_NO_CONNECT_T:
274  case SCH_LINE_T:
275  case SCH_GLOBAL_LABEL_T:
276  case SCH_HIER_LABEL_T:
277  case SCH_LABEL_T:
279  {
280  std::vector<wxPoint> pts = aItem->GetConnectionPoints();
281 
282  for( const wxPoint &pt : pts )
283  addAnchor( VECTOR2I( pt ), SNAPPABLE | CORNER, aItem );
284 
285  break;
286  }
287 
288  default:
289  break;
290  }
291 
292  if( SCH_LINE* line = dyn_cast<SCH_LINE*>( aItem ) )
293  {
294  VECTOR2I pt = Align( aRefPos );
295 
296  if( line->GetStartPoint().x == line->GetEndPoint().x )
297  {
298  VECTOR2I possible( line->GetStartPoint().x, pt.y );
299 
300  if( TestSegmentHit( wxPoint( possible ), line->GetStartPoint(), line->GetEndPoint(), 0 ) )
301  addAnchor( possible, SNAPPABLE | VERTICAL, aItem );
302  }
303  else if( line->GetStartPoint().y == line->GetEndPoint().y )
304  {
305  VECTOR2I possible( pt.x, line->GetStartPoint().y );
306 
307  if( TestSegmentHit( wxPoint( possible ), line->GetStartPoint(), line->GetEndPoint(), 0 ) )
308  addAnchor( possible, SNAPPABLE | HORIZONTAL, aItem );
309  }
310 
311  }
312 }
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:390
#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:301
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
bool TestSegmentHit(const wxPoint &aRefPoint, wxPoint aStart, 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:162

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_COMPONENT_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, 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:289
TOOL_MANAGER * m_toolMgr
Definition: grid_helper.h:129
GAL * GetGAL() const
Return the #GAL this view is using to draw graphical primitives.
Definition: view.h:189
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
const VECTOR2D & GetGridSize() const
Return the grid size.
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:68

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

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

◆ GetOrigin()

VECTOR2I GRID_HELPER::GetOrigin ( ) const
inherited

Definition at line 59 of file grid_helper.cpp.

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

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

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

◆ GetSnap()

bool GRID_HELPER::GetSnap ( ) const
inlineinherited

Definition at line 65 of file grid_helper.h.

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

References GRID_HELPER::m_enableSnap.

◆ 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 229 of file ee_grid_helper.cpp.

230 {
231  if( !m_snapItem )
232  return nullptr;
233 
234  return static_cast<SCH_ITEM*>( m_snapItem->item );
235 }
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 315 of file ee_grid_helper.cpp.

317 {
318  double minDist = std::numeric_limits<double>::max();
319  ANCHOR* best = NULL;
320 
321  for( ANCHOR& a : m_anchors )
322  {
323  SCH_ITEM* item = static_cast<SCH_ITEM*>( a.item );
324 
325  if( ( aFlags & a.flags ) != aFlags )
326  continue;
327 
328  if( aMatchLayer == LAYER_CONNECTABLE && !item->IsConnectable() )
329  continue;
330  else if( aMatchLayer == LAYER_GRAPHICS && item->IsConnectable() )
331  continue;
332 
333  double dist = a.Distance( aPos );
334 
335  if( dist < minDist )
336  {
337  minDist = dist;
338  best = &a;
339  }
340  }
341 
342  return best;
343 }
virtual bool IsConnectable() const
Definition: sch_item.h:376
#define NULL
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:196

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

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 238 of file ee_grid_helper.cpp.

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

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:289
TOOL_MANAGER * m_toolMgr
Definition: grid_helper.h:129
KIGFX::ORIGIN_VIEWITEM m_viewAxis
Definition: grid_helper.h:143
boost::optional< T > OPT
Definition: optional.h:7
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Set the item visibility.
Definition: view.cpp:1454

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.

Referenced by SCH_LINE_WIRE_BUS_TOOL::doDrawSegments().

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

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

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: