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, bool aIncludeText=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:1516
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:320
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(), and pinEditedCorner().

◆ 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  // Text anchors are often off the connectivity grid. For now, this means
69  // we can only consider anchors from text objects if they are the only thing
70  // selected.
71  bool includeText = ( aItems.Size() == 1
72  || aItems.OnlyContains( { SCH_TEXT_T, SCH_FIELD_T } ) );
73 
74  for( EDA_ITEM* item : aItems )
75  computeAnchors( static_cast<SCH_ITEM*>( item ), aMousePos, true, includeText );
76 
77  double worldScale = m_toolMgr->GetView()->GetGAL()->GetWorldScale();
78  double lineSnapMinCornerDistance = 50.0 / worldScale;
79 
80  ANCHOR* nearestOutline = nearestAnchor( aMousePos, OUTLINE, aLayer );
81  ANCHOR* nearestCorner = nearestAnchor( aMousePos, CORNER, aLayer );
82  ANCHOR* nearestOrigin = nearestAnchor( aMousePos, ORIGIN, aLayer );
83  ANCHOR* best = nullptr;
84  double minDist = std::numeric_limits<double>::max();
85 
86  if( nearestOrigin )
87  {
88  minDist = nearestOrigin->Distance( aMousePos );
89  best = nearestOrigin;
90  }
91 
92  if( nearestCorner )
93  {
94  double dist = nearestCorner->Distance( aMousePos );
95 
96  if( dist < minDist )
97  {
98  minDist = dist;
99  best = nearestCorner;
100  }
101  }
102 
103  if( nearestOutline )
104  {
105  double dist = nearestOutline->Distance( aMousePos );
106 
107  if( minDist > lineSnapMinCornerDistance && dist < minDist )
108  best = nearestOutline;
109  }
110 
111  return best ? best->pos : aMousePos;
112 }
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
ANCHOR * nearestAnchor(const VECTOR2I &aPos, int aFlags, int aMatchLayer)
bool OnlyContains(std::vector< KICAD_T > aList) const
Checks if all items in the selection have a type in aList.
Definition: selection.cpp:170
int Size() const
Returns the number of selected parts.
Definition: selection.h:104
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:99
void computeAnchors(SCH_ITEM *aItem, const VECTOR2I &aRefPos, bool aFrom=false, bool aIncludeText=false)
Insert the local anchor points in to the grid helper for the specified schematic item,...
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(), SELECTION::OnlyContains(), GRID_HELPER::ORIGIN, GRID_HELPER::OUTLINE, GRID_HELPER::ANCHOR::pos, SCH_FIELD_T, SCH_TEXT_T, and SELECTION::Size().

◆ BestSnapAnchor() [1/2]

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

Definition at line 115 of file ee_grid_helper.cpp.

116 {
117  EE_SELECTION skipItems;
118  skipItems.Add( aSkip );
119 
120  return BestSnapAnchor( aOrigin, aLayer, skipItems );
121 }
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 124 of file ee_grid_helper.cpp.

126 {
127  constexpr int snapRange = SNAP_RANGE * IU_PER_MILS;
128 
129  VECTOR2I pt = aOrigin;
130  VECTOR2I snapDist( snapRange, snapRange );
131  bool snapLineX = false;
132  bool snapLineY = false;
133  bool snapPoint = false;
134  bool gridChecked = false;
135 
136  BOX2I bb( VECTOR2I( aOrigin.x - snapRange / 2, aOrigin.y - snapRange / 2 ),
137  VECTOR2I( snapRange, snapRange ) );
138 
139  clearAnchors();
140 
141  for( SCH_ITEM* item : queryVisible( bb, aSkip ) )
142  computeAnchors( item, aOrigin );
143 
144  ANCHOR* nearest = nearestAnchor( aOrigin, SNAPPABLE, aLayer );
145  VECTOR2I nearestGrid = Align( aOrigin );
146 
148  {
149  if( std::abs( m_viewSnapLine.GetPosition().x - aOrigin.x ) < snapDist.x )
150  {
151  pt.x = m_viewSnapLine.GetPosition().x;
152  snapDist.x = std::abs( m_viewSnapLine.GetPosition().x - aOrigin.x );
153  snapLineX = true;
154  }
155 
156  if( std::abs( m_viewSnapLine.GetPosition().y - aOrigin.y ) < snapDist.y )
157  {
158  pt.y = m_viewSnapLine.GetPosition().y;
159  snapDist.y = std::abs( m_viewSnapLine.GetPosition().y - aOrigin.y );
160  snapLineY = true;
161  }
162 
163  if( canUseGrid() && std::abs( nearestGrid.x - aOrigin.x ) < snapDist.x )
164  {
165  pt.x = nearestGrid.x;
166  snapDist.x = std::abs( nearestGrid.x - aOrigin.x );
167  snapLineX = false;
168  }
169 
170  if( canUseGrid() && std::abs( nearestGrid.y - aOrigin.y ) < snapDist.y )
171  {
172  pt.y = nearestGrid.y;
173  snapDist.y = std::abs( nearestGrid.y - aOrigin.y );
174  snapLineY = false;
175  }
176 
177  gridChecked = true;
178  }
179 
180  if( m_enableSnap && nearest && nearest->Distance( aOrigin ) < snapDist.EuclideanNorm() )
181  {
182 
183  if( canUseGrid() && ( nearestGrid - aOrigin ).EuclideanNorm() < snapDist.EuclideanNorm() )
184  {
185  pt = nearestGrid;
186  snapDist.x = std::abs( nearestGrid.x - aOrigin.x );
187  snapDist.y = std::abs( nearestGrid.y - aOrigin.y );
188  snapPoint = false;
189  }
190  else
191  {
192  pt = nearest->pos;
193  snapDist.x = std::abs( nearest->pos.x - aOrigin.x );
194  snapDist.y = std::abs( nearest->pos.y - aOrigin.y );
195  snapPoint = true;
196  }
197 
198  snapLineX = snapLineY = false;
199  gridChecked = true;
200  }
201 
202  if( canUseGrid() && !gridChecked )
203  pt = nearestGrid;
204 
205  if( snapLineX || snapLineY )
206  {
208 
211  else
213  }
214  else if( snapPoint )
215  {
216  m_snapItem = nearest;
217  m_viewSnapPoint.SetPosition( (wxPoint) pt );
218  m_viewSnapLine.SetPosition( (wxPoint) pt );
219 
221 
224  else
226  }
227  else
228  {
231  }
232 
233  return pt;
234 }
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
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:622
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:1556
#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:130
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Set the item visibility.
Definition: view.cpp:1516
void computeAnchors(SCH_ITEM *aItem, const VECTOR2I &aRefPos, bool aFrom=false, bool aIncludeText=false)
Insert the local anchor points in to the grid helper for the specified schematic item,...
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:1570
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::AlignToNearestPad(), 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:622
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,
bool  aIncludeText = 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
aIncludeTextif true will compute anchors for text items

Definition at line 271 of file ee_grid_helper.cpp.

273 {
274  switch( aItem->Type() )
275  {
276  case SCH_TEXT_T:
277  case SCH_FIELD_T:
278  {
279  if( aIncludeText )
280  addAnchor( aItem->GetPosition(), ORIGIN, aItem );
281 
282  break;
283  }
284 
285  case SCH_SYMBOL_T:
286  case SCH_SHEET_T:
287  addAnchor( aItem->GetPosition(), ORIGIN, aItem );
289 
290  case SCH_JUNCTION_T:
291  case SCH_NO_CONNECT_T:
292  case SCH_LINE_T:
293  case SCH_GLOBAL_LABEL_T:
294  case SCH_HIER_LABEL_T:
295  case SCH_LABEL_T:
297  {
298  std::vector<wxPoint> pts = aItem->GetConnectionPoints();
299 
300  for( const wxPoint& pt : pts )
301  addAnchor( VECTOR2I( pt ), SNAPPABLE | CORNER, aItem );
302 
303  break;
304  }
305 
306  default:
307  break;
308  }
309 
310  if( SCH_LINE* line = dyn_cast<SCH_LINE*>( aItem ) )
311  {
312  VECTOR2I pt = Align( aRefPos );
313 
314  if( line->GetStartPoint().x == line->GetEndPoint().x )
315  {
316  VECTOR2I possible( line->GetStartPoint().x, pt.y );
317 
318  if( TestSegmentHit( wxPoint( possible ), line->GetStartPoint(), line->GetEndPoint(),
319  0 ) )
320  addAnchor( possible, SNAPPABLE | VERTICAL, aItem );
321  }
322  else if( line->GetStartPoint().y == line->GetEndPoint().y )
323  {
324  VECTOR2I possible( pt.x, line->GetStartPoint().y );
325 
326  if( TestSegmentHit( wxPoint( possible ), line->GetStartPoint(), line->GetEndPoint(),
327  0 ) )
328  addAnchor( possible, SNAPPABLE | HORIZONTAL, aItem );
329  }
330 
331  }
332 }
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:364
#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:251
VECTOR2< int > VECTOR2I
Definition: vector2d.h:622
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:112

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_FIELD_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, SCH_TEXT_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:622
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:622
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 DRAWING_TOOL::DrawVia(), and 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 236 of file ee_grid_helper.cpp.

237 {
238  if( !m_snapItem )
239  return nullptr;
240 
241  return static_cast<SCH_ITEM*>( m_snapItem->item );
242 }
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 335 of file ee_grid_helper.cpp.

337 {
338  double minDist = std::numeric_limits<double>::max();
339  ANCHOR* best = nullptr;
340 
341  for( ANCHOR& a : m_anchors )
342  {
343  SCH_ITEM* item = static_cast<SCH_ITEM*>( a.item );
344 
345  if( ( aFlags & a.flags ) != aFlags )
346  continue;
347 
348  if( aMatchLayer == LAYER_CONNECTABLE && !item->IsConnectable() )
349  continue;
350  else if( aMatchLayer == LAYER_GRAPHICS && item->IsConnectable() )
351  continue;
352 
353  double dist = a.Distance( aPos );
354 
355  if( dist < minDist )
356  {
357  minDist = dist;
358  best = &a;
359  }
360  }
361 
362  return best;
363 }
virtual bool IsConnectable() const
Definition: sch_item.h:349
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 245 of file ee_grid_helper.cpp.

247 {
248  std::set<SCH_ITEM*> items;
249  std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> selectedItems;
250 
251  KIGFX::VIEW* view = m_toolMgr->GetView();
252 
253  view->Query( aArea, selectedItems );
254 
255  for( const KIGFX::VIEW::LAYER_ITEM_PAIR& it : selectedItems )
256  {
257  SCH_ITEM* item = static_cast<SCH_ITEM*>( it.first );
258 
259  // The item must be visible and on an active layer
260  if( view->IsVisible( item ) && item->ViewGetLOD( it.second, view ) < view->GetScale() )
261  items.insert ( item );
262  }
263 
264  for( EDA_ITEM* skipItem : aSkipList )
265  items.erase( static_cast<SCH_ITEM*>( skipItem ) );
266 
267  return items;
268 }
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:1556
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:99
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:426
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:1516

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: