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 GetVisibleGrid () 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
 
std::optional< 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 77 of file grid_helper.h.

77 {
78 CORNER = 1,
79 OUTLINE = 2,
80 SNAPPABLE = 4,
81 ORIGIN = 8,
82 VERTICAL = 16,
83 HORIZONTAL = 32,
85 };

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 ) );
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}
GRID_HELPER(TOOL_MANAGER *aToolMgr)
Definition: grid_helper.cpp:35
TOOL_MANAGER * m_toolMgr
Definition: grid_helper.h:131
KIGFX::ORIGIN_VIEWITEM m_viewSnapPoint
Definition: grid_helper.h:143
KIGFX::ORIGIN_VIEWITEM m_viewSnapLine
Definition: grid_helper.h:144
KIGFX::ORIGIN_VIEWITEM m_viewAxis
Definition: grid_helper.h:145
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
void SetColor(const KIGFX::COLOR4D &aColor)
void SetStyle(MARKER_STYLE aStyle)
void SetSize(int aSize)
void SetDrawAtZero(bool aDrawFlag)
Set the draw at zero flag.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:69
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:316
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Set the item visibility.
Definition: view.cpp:1529
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:285

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 107 of file grid_helper.h.

108 {
109 if( ( aFlags & m_maskTypes ) == aFlags )
110 m_anchors.emplace_back( ANCHOR( aPos, aFlags, aItem ) );
111 }
std::vector< ANCHOR > m_anchors
Definition: grid_helper.h:129

References GRID_HELPER::m_anchors, and GRID_HELPER::m_maskTypes.

Referenced by PCB_GRID_HELPER::computeAnchors(), and computeAnchors().

◆ Align()

VECTOR2I GRID_HELPER::Align ( const VECTOR2I aPoint) const
virtualinherited

Definition at line 103 of file grid_helper.cpp.

104{
105 if( !canUseGrid() )
106 return aPoint;
107
108 VECTOR2I nearest = AlignGrid( aPoint );
109
110 if( !m_auxAxis )
111 return nearest;
112
113 if( std::abs( m_auxAxis->x - aPoint.x ) < std::abs( nearest.x - aPoint.x ) )
114 nearest.x = m_auxAxis->x;
115
116 if( std::abs( m_auxAxis->y - aPoint.y ) < std::abs( nearest.y - aPoint.y ) )
117 nearest.y = m_auxAxis->y;
118
119 return nearest;
120}
std::optional< VECTOR2I > m_auxAxis
Definition: grid_helper.h:132
VECTOR2I AlignGrid(const VECTOR2I &aPoint) const
Definition: grid_helper.cpp:91
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:123
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition: eda_angle.h:412

References std::abs(), GRID_HELPER::AlignGrid(), GRID_HELPER::canUseGrid(), GRID_HELPER::m_auxAxis, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by PCB_GRID_HELPER::AlignToArc(), PCB_GRID_HELPER::AlignToSegment(), PCB_GRID_HELPER::BestSnapAnchor(), BestSnapAnchor(), computeAnchors(), PNS::TOOL_BASE::snapToItem(), and PNS::TOOL_BASE::updateEndItem().

◆ AlignGrid()

VECTOR2I GRID_HELPER::AlignGrid ( const VECTOR2I aPoint) const
inherited

Definition at line 91 of file grid_helper.cpp.

92{
93 const VECTOR2D gridOffset( GetOrigin() );
94 const VECTOR2D grid( GetGrid() );
95
96 VECTOR2I nearest( KiROUND( ( aPoint.x - gridOffset.x ) / grid.x ) * grid.x + gridOffset.x,
97 KiROUND( ( aPoint.y - gridOffset.y ) / grid.y ) * grid.y + gridOffset.y );
98
99 return nearest;
100}
VECTOR2I GetGrid() const
Definition: grid_helper.cpp:51
VECTOR2I GetOrigin() const
Definition: grid_helper.cpp:67
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:85

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

Referenced by GRID_HELPER::Align(), EC_VERTICAL::Apply(), EC_HORIZONTAL::Apply(), EC_45DEGREE::Apply(), EC_LINE::Apply(), and EE_POINT_EDITOR::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{
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
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}
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
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,...
ANCHOR * nearestAnchor(const VECTOR2I &aPos, int aFlags, int aMatchLayer)
void clearAnchors()
Definition: grid_helper.h:113
double GetWorldScale() const
Get the world scale.
GAL * GetGAL() const
Return the #GAL this view is using to draw graphical primitives.
Definition: view.h:195
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:147
int Size() const
Returns the number of selected parts.
Definition: selection.h:115
bool OnlyContains(std::vector< KICAD_T > aList) const
Checks if all items in the selection have a type in aList.
Definition: selection.cpp:191
@ SCH_FIELD_T
Definition: typeinfo.h:155
@ SCH_TEXT_T
Definition: typeinfo.h:150
@ SCH_TEXTBOX_T
Definition: typeinfo.h:149

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, SCH_TEXTBOX_T, and SELECTION::Size().

◆ BestSnapAnchor() [1/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 * schIUScale.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 {
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 {
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;
219
221
224 else
226 }
227 else
228 {
231 }
232
233 return pt;
234}
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:111
std::set< SCH_ITEM * > queryVisible(const BOX2I &aArea, const EE_SELECTION &aSkipList) const
VECTOR2I m_skipPoint
Definition: grid_helper.h:141
virtual VECTOR2I Align(const VECTOR2I &aPoint) const
ANCHOR * m_snapItem
Definition: grid_helper.h:139
bool m_enableSnapLine
Definition: grid_helper.h:138
bool m_enableSnap
Definition: grid_helper.h:136
void SetPosition(const VECTOR2I &aPosition) override
VECTOR2I GetPosition() const override
void SetEndPosition(const VECTOR2D &aPosition)
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:1591
bool IsVisible(const VIEW_ITEM *aItem) const
Return information if the item is visible (or not).
Definition: view.cpp:1569
#define SNAP_RANGE
@ GEOMETRY
Position or shape has changed.
Definition: view_item.h:49
const double IU_PER_MILS
Definition: base_units.h:78
double EuclideanNorm(const VECTOR2I &vector)
Definition: trigo.h:129
VECTOR2< int > VECTOR2I
Definition: vector2d.h:618

References std::abs(), 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(), EDA_IU_SCALE::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(), schIUScale, 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.

◆ BestSnapAnchor() [2/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}
VECTOR2I BestSnapAnchor(const VECTOR2I &aOrigin, int aLayer, SCH_ITEM *aDraggedItem)
virtual void Add(EDA_ITEM *aItem)
Definition: selection.cpp:42

References SELECTION::Add(), and BestSnapAnchor().

Referenced by EE_SELECTION_TOOL::autostartEvent(), and BestSnapAnchor().

◆ 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 123 of file grid_helper.h.

124 {
126 }
bool m_enableGrid
Definition: grid_helper.h:137
bool GetGridSnapping() const

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

◆ ClearMaskFlag()

void GRID_HELPER::ClearMaskFlag ( int  aFlag)
inlineinherited

Definition at line 75 of file grid_helper.h.

75{ 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 60 of file grid_helper.h.

61 {
62 m_skipPoint = VECTOR2I( std::numeric_limits<int>::min(), std::numeric_limits<int>::min() );
63 }

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_TEXTBOX_T:
278 case SCH_FIELD_T:
279 {
280 if( aIncludeText )
281 addAnchor( aItem->GetPosition(), ORIGIN, aItem );
282
283 break;
284 }
285
286 case SCH_SYMBOL_T:
287 case SCH_SHEET_T:
288 addAnchor( aItem->GetPosition(), ORIGIN, aItem );
290
291 case SCH_JUNCTION_T:
292 case SCH_NO_CONNECT_T:
293 case SCH_LINE_T:
295 case SCH_HIER_LABEL_T:
296 case SCH_LABEL_T:
299 case SCH_SHEET_PIN_T:
300 {
301 std::vector<VECTOR2I> pts = aItem->GetConnectionPoints();
302
303 for( const VECTOR2I& pt : pts )
304 addAnchor( VECTOR2I( pt ), SNAPPABLE | CORNER, aItem );
305
306 break;
307 }
308
309 default:
310 break;
311 }
312
313 if( SCH_LINE* line = dyn_cast<SCH_LINE*>( aItem ) )
314 {
315 VECTOR2I pt = Align( aRefPos );
316
317 if( line->GetStartPoint().x == line->GetEndPoint().x )
318 {
319 VECTOR2I possible( line->GetStartPoint().x, pt.y );
320
321 if( TestSegmentHit( possible, line->GetStartPoint(), line->GetEndPoint(), 0 ) )
322 addAnchor( possible, SNAPPABLE | VERTICAL, aItem );
323 }
324 else if( line->GetStartPoint().y == line->GetEndPoint().y )
325 {
326 VECTOR2I possible( pt.x, line->GetStartPoint().y );
327
328 if( TestSegmentHit( possible, line->GetStartPoint(), line->GetEndPoint(), 0 ) )
329 addAnchor( possible, SNAPPABLE | HORIZONTAL, aItem );
330 }
331
332 }
333}
virtual VECTOR2I GetPosition() const
Definition: eda_item.h:249
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
void addAnchor(const VECTOR2I &aPos, int aFlags, EDA_ITEM *aItem)
Definition: grid_helper.h:107
virtual std::vector< VECTOR2I > GetConnectionPoints() const
Add all the connection points for this item to aPoints.
Definition: sch_item.h:364
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:40
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
Definition: macros.h:83
bool TestSegmentHit(const VECTOR2I &aRefPoint, const VECTOR2I &aStart, const VECTOR2I &aEnd, int aDist)
Test if aRefPoint is with aDistance on the line defined by aStart and aEnd.
Definition: trigo.cpp:129
@ SCH_LINE_T
Definition: typeinfo.h:146
@ SCH_NO_CONNECT_T
Definition: typeinfo.h:143
@ SCH_SYMBOL_T
Definition: typeinfo.h:156
@ SCH_DIRECTIVE_LABEL_T
Definition: typeinfo.h:154
@ SCH_LABEL_T
Definition: typeinfo.h:151
@ SCH_SHEET_T
Definition: typeinfo.h:158
@ SCH_HIER_LABEL_T
Definition: typeinfo.h:153
@ SCH_SHEET_PIN_T
Definition: typeinfo.h:157
@ SCH_BUS_WIRE_ENTRY_T
Definition: typeinfo.h:144
@ SCH_GLOBAL_LABEL_T
Definition: typeinfo.h:152
@ SCH_JUNCTION_T
Definition: typeinfo.h:142

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_DIRECTIVE_LABEL_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_PIN_T, SCH_SHEET_T, SCH_SYMBOL_T, SCH_TEXT_T, SCH_TEXTBOX_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}
const VECTOR2D & GetGridSize() const
Return the grid size.

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(), and PCB_GRID_HELPER::computeAnchors().

◆ GetOrigin()

VECTOR2I GRID_HELPER::GetOrigin ( ) const
inherited

Definition at line 67 of file grid_helper.cpp.

68{
70
71 return VECTOR2I( origin );
72}
const VECTOR2D & GetGridOrigin() const

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

Referenced by GRID_HELPER::AlignGrid().

◆ GetSnap()

bool GRID_HELPER::GetSnap ( ) const
inlineinherited

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

References GRID_HELPER::ANCHOR::item, and GRID_HELPER::m_snapItem.

◆ GetUseGrid()

bool GRID_HELPER::GetUseGrid ( ) const
inlineinherited

Definition at line 69 of file grid_helper.h.

69{ return m_enableGrid; }

References GRID_HELPER::m_enableGrid.

Referenced by PNS::TOOL_BASE::updateStartItem().

◆ GetVisibleGrid()

VECTOR2I GRID_HELPER::GetVisibleGrid ( ) const
inherited

Definition at line 59 of file grid_helper.cpp.

60{
62
63 return VECTOR2I( KiROUND( size.x ), KiROUND( size.y ) );
64}
VECTOR2D GetVisibleGridSize() const
Return the visible grid size in x and y directions.

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

Referenced by PCB_GRID_HELPER::BestSnapAnchor().

◆ nearestAnchor()

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

Definition at line 336 of file ee_grid_helper.cpp.

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

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}
virtual double ViewGetLOD(int aLayer, VIEW *aView) const
Return the level of detail (LOD) of the item.
Definition: view_item.h:132
double GetScale() const
Definition: view.h:269
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:425
std::pair< VIEW_ITEM *, int > LAYER_ITEM_PAIR
Definition: view.h:73

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 75 of file grid_helper.cpp.

76{
77 if( aEnable )
78 {
79 m_auxAxis = aOrigin;
80 m_viewAxis.SetPosition( wxPoint( aOrigin ) );
82 }
83 else
84 {
85 m_auxAxis = std::optional<VECTOR2I>();
87 }
88}

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 73 of file grid_helper.h.

73{ m_maskTypes = aMask; }

References GRID_HELPER::m_maskTypes.

◆ SetMaskFlag()

void GRID_HELPER::SetMaskFlag ( int  aFlag)
inlineinherited

Definition at line 74 of file grid_helper.h.

74{ m_maskTypes |= aFlag; }

References GRID_HELPER::m_maskTypes.

◆ SetSkipPoint()

void GRID_HELPER::SetSkipPoint ( const VECTOR2I aPoint)
inlineinherited

Definition at line 52 of file grid_helper.h.

53 {
54 m_skipPoint = aPoint;
55 }

References GRID_HELPER::m_skipPoint.

◆ SetSnap()

◆ SetSnapLine()

void GRID_HELPER::SetSnapLine ( bool  aSnap)
inlineinherited

Definition at line 71 of file grid_helper.h.

71{ m_enableSnapLine = aSnap; }

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

std::optional<VECTOR2I> GRID_HELPER::m_auxAxis
protectedinherited

Definition at line 132 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

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