71 double lineSnapMinCornerDistance = 50.0 / worldScale;
77 double minDist = std::numeric_limits<double>::max();
81 minDist = nearestOrigin->
Distance( aMousePos );
87 double dist = nearestCorner->
Distance( aMousePos );
98 double dist = nearestOutline->
Distance( aMousePos );
100 if( minDist > lineSnapMinCornerDistance && dist < minDist )
101 best = nearestOutline;
104 return best ? best->
pos : aMousePos;
111 skipItems.
Add( aSkip );
123 VECTOR2I snapDist( snapRange, snapRange );
124 bool snapLineX =
false;
125 bool snapLineY =
false;
126 bool snapPoint =
false;
127 bool gridChecked =
false;
129 BOX2I bb(
VECTOR2I( aOrigin.
x - snapRange / 2, aOrigin.
y - snapRange / 2 ),
156 if(
canUseGrid() && std::abs( nearestGrid.
x - aOrigin.
x ) < snapDist.
x )
158 pt.
x = nearestGrid.
x;
159 snapDist.
x = std::abs( nearestGrid.
x - aOrigin.
x );
163 if(
canUseGrid() && std::abs( nearestGrid.
y - aOrigin.
y ) < snapDist.
y )
165 pt.
y = nearestGrid.
y;
166 snapDist.
y = std::abs( nearestGrid.
y - aOrigin.
y );
179 snapDist.
x = std::abs( nearestGrid.
x - aOrigin.
x );
180 snapDist.
y = std::abs( nearestGrid.
y - aOrigin.
y );
186 snapDist.
x = std::abs( nearest->
pos.
x - aOrigin.
x );
187 snapDist.
y = std::abs( nearest->
pos.
y - aOrigin.
y );
191 snapLineX = snapLineY =
false;
198 if( snapLineX || snapLineY )
241 std::set<SCH_ITEM*> items;
242 std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> selectedItems;
246 view->
Query( aArea, selectedItems );
250 SCH_ITEM* item = static_cast<SCH_ITEM*>( it.first );
254 items.insert ( item );
257 for(
EDA_ITEM* skipItem : aSkipList )
258 items.erase( static_cast<SCH_ITEM*>( skipItem ) );
266 switch ( aItem->
Type() )
282 for(
const wxPoint &pt : pts )
292 if(
SCH_LINE* line = dyn_cast<SCH_LINE*>( aItem ) )
296 if( line->GetStartPoint().x == line->GetEndPoint().x )
298 VECTOR2I possible( line->GetStartPoint().x, pt.
y );
300 if(
TestSegmentHit( wxPoint( possible ), line->GetStartPoint(), line->GetEndPoint(), 0 ) )
303 else if( line->GetStartPoint().y == line->GetEndPoint().y )
305 VECTOR2I possible( pt.
x, line->GetStartPoint().y );
307 if(
TestSegmentHit( wxPoint( possible ), line->GetStartPoint(), line->GetEndPoint(), 0 ) )
318 double minDist = std::numeric_limits<double>::max();
323 SCH_ITEM* item = static_cast<SCH_ITEM*>( a.item );
325 if( ( aFlags & a.flags ) != aFlags )
333 double dist = a.Distance( aPos );
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
void SetPosition(const wxPoint &aPosition) override
virtual bool IsConnectable() const
wxPoint GetPosition() const override
EE_GRID_HELPER(TOOL_MANAGER *aToolMgr)
void addAnchor(const VECTOR2I &aPos, int aFlags, EDA_ITEM *aItem)
virtual std::vector< wxPoint > GetConnectionPoints() const
Add all the connection points for this item to aPoints.
SCH_ITEM * GetSnapped() const
Function GetSnapped If the EE_GRID_HELPER has highlighted a snap point (target shown),...
KIGFX::ORIGIN_VIEWITEM m_viewAxis
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...
VECTOR2I BestSnapAnchor(const VECTOR2I &aOrigin, int aLayer, SCH_ITEM *aDraggedItem)
GAL * GetGAL() const
Return the #GAL this view is using to draw graphical primitives.
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
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)
virtual wxPoint GetPosition() const
virtual void Add(EDA_ITEM *aItem)
VECTOR2I BestDragOrigin(const VECTOR2I &aMousePos, int aLayer, const EE_SELECTION &aItems)
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.
KIGFX::ORIGIN_VIEWITEM m_viewSnapPoint
double Distance(const VECTOR2I &aP) const
bool IsVisible(const VIEW_ITEM *aItem) const
Return information if the item is visible (or not).
void SetDrawAtZero(bool aDrawFlag)
Set the draw at zero flag.
bool canUseGrid() const
Check whether it is possible to use the grid – this depends both on local grid helper settings and gl...
virtual VECTOR2I Align(const VECTOR2I &aPoint) const
Segment description base class to describe items which have 2 end points (track, wire,...
std::pair< VIEW_ITEM *, int > LAYER_ITEM_PAIR
void SetColor(const KIGFX::COLOR4D &aColor)
A base class for most all the KiCad significant classes used in schematics and boards.
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Set the item visibility.
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
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.
KIGFX::ORIGIN_VIEWITEM m_viewSnapLine
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
void SetStyle(MARKER_STYLE aStyle)
double GetWorldScale() const
Get the world scale.
std::vector< ANCHOR > m_anchors
Base class for any item which can be embedded within the SCHEMATIC container class,...
virtual double ViewGetLOD(int aLayer, VIEW *aView) const
Return the level of detail (LOD) of the item.
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...
KICAD_T Type() const
Returns the type of object.
Position or shape has changed.
A color representation with 4 components: red, green, blue, alpha.