51 m_magneticSettings( aMagneticSettings )
81 const int c_gridSnapEpsilon_sq = 4;
88 std::vector<VECTOR2I> points;
90 const SEG testSegments[] = {
SEG( aligned, aligned +
VECTOR2( 1, 0 ) ),
95 for(
const SEG& seg : testSegments )
100 points.push_back( *vec );
107 for(
const VECTOR2I& pt : { aSeg.
A, aSeg.
B } )
109 SEG::ecoord d_sq = ( pt - aPoint ).SquaredEuclideanNorm();
111 if( d_sq < min_d_sq )
121 SEG::ecoord d_sq = ( pt - aligned ).SquaredEuclideanNorm();
123 if( d_sq < min_d_sq )
141 std::vector<VECTOR2I> points;
154 SEG::ecoord d_sq = ( pt - aPoint ).SquaredEuclideanNorm();
156 if( d_sq < min_d_sq )
166 SEG::ecoord d_sq = ( pt - aligned ).SquaredEuclideanNorm();
168 if( d_sq < min_d_sq )
186 double minDist = std::numeric_limits<double>::max();
187 ANCHOR* nearestOrigin =
nullptr;
196 if( !item->
HitTest( aMousePos ) )
199 double dist = a.Distance( aMousePos );
208 return nearestOrigin ? nearestOrigin->
pos : aMousePos;
213 std::vector<BOARD_ITEM*>& aItems,
222 double lineSnapMinCornerDistance = 50.0 / worldScale;
228 double minDist = std::numeric_limits<double>::max();
232 minDist = nearestOrigin->
Distance( aMousePos );
233 best = nearestOrigin;
238 double dist = nearestCorner->
Distance( aMousePos );
243 best = nearestCorner;
249 double dist = nearestOutline->
Distance( aMousePos );
251 if( minDist > lineSnapMinCornerDistance && dist < minDist )
252 best = nearestOutline;
255 return best ? best->
pos : aMousePos;
262 std::vector<BOARD_ITEM*> item;
267 item.push_back( aReferenceItem );
279 const std::vector<BOARD_ITEM*>& aSkip )
282 const int snapSize = 25;
291 int snapDist = snapRange;
295 bb.
SetOrigin( GetClampedCoords<double, int>(
VECTOR2D( aOrigin ) - snapRange / 2.0 ) );
296 bb.
SetEnd( GetClampedCoords<double, int>(
VECTOR2D( aOrigin ) + snapRange / 2.0 ) );
307 snapDist = nearest->
Distance( aOrigin );
312 bool snapLine =
false;
317 if( x_dist < snapRange && ( !nearest || snapDist > snapRange ) )
323 if( y_dist < snapRange && ( !nearest || snapDist > snapRange ) )
344 if( nearest->
Distance( aOrigin ) <= snapRange )
377 const std::vector<BOARD_ITEM*>& aSkip )
const
379 std::set<BOARD_ITEM*> items;
380 std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> selectedItems;
387 view->
Query( aArea, selectedItems );
402 && ( !isHighContrast || activeLayers.count( it.second ) )
405 items.insert ( item );
410 items.erase( skipItem );
424 auto handlePadShape =
433 switch( aPad->GetShape() )
435 case PAD_SHAPE::CIRCLE:
437 int r = aPad->GetSizeX() / 2;
447 case PAD_SHAPE::OVAL:
450 VECTOR2I half_size = aPad->GetSize() / 2;
451 int half_width = std::min( half_size.
x, half_size.
y );
452 VECTOR2I half_len( half_size.
x - half_width, half_size.
y - half_width );
459 normal.Resize( half_width );
476 case PAD_SHAPE::RECTANGLE:
477 case PAD_SHAPE::TRAPEZOID:
478 case PAD_SHAPE::ROUNDRECT:
479 case PAD_SHAPE::CHAMFERED_RECT:
481 VECTOR2I half_size( aPad->GetSize() / 2 );
484 if( aPad->GetShape() == PAD_SHAPE::TRAPEZOID )
485 trap_delta = aPad->GetDelta() / 2;
489 corners.
Append( -half_size.
x - trap_delta.
y, half_size.
y + trap_delta.
x );
490 corners.
Append( half_size.
x + trap_delta.
y, half_size.
y - trap_delta.
x );
491 corners.
Append( half_size.
x - trap_delta.
y, -half_size.
y + trap_delta.
x );
492 corners.
Append( -half_size.
x + trap_delta.
y, -half_size.
y - trap_delta.
x );
495 corners.
Rotate( aPad->GetOrientation() );
496 corners.
Move( aPad->ShapePos() );
513 const std::shared_ptr<SHAPE_POLY_SET>& outline = aPad->GetEffectivePolygon();
515 if( !outline->IsEmpty() )
517 for(
const VECTOR2I& pt : outline->Outline( 0 ).CPoints() )
532 switch( shape->GetShape() )
534 case SHAPE_T::CIRCLE:
557 SEG first( start, point2 );
558 SEG second( point2, end );
559 SEG third( end, point3 );
560 SEG fourth( point3, start );
573 case SHAPE_T::SEGMENT:
583 std::vector<VECTOR2I> poly;
584 shape->DupPolyPointsList( poly );
596 case SHAPE_T::BEZIER:
607 switch( aItem->
Type() )
617 if( aSelectionFilter && !aSelectionFilter->
pads )
626 if( !view->
IsVisible(
pad ) || !
pad->GetBoundingBox().Contains( aRefPos ) )
630 bool onActiveLayer = !isHighContrast;
631 bool isLODVisible =
false;
635 if( !onActiveLayer && activeLayers.count( layer ) )
636 onActiveLayer =
true;
638 if( !isLODVisible &&
pad->ViewGetLOD( layer, view ) < view->
GetScale() )
641 if( onActiveLayer && isLODVisible )
643 handlePadShape(
pad );
649 if( aFrom && aSelectionFilter && !aSelectionFilter->
footprints )
660 if( ( center - position ).SquaredEuclideanNorm() >
grid.SquaredEuclideanNorm() )
669 if( aSelectionFilter && !aSelectionFilter->
pads )
678 handlePadShape(
static_cast<PAD*
>( aItem ) );
685 if( aSelectionFilter && !aSelectionFilter->
text )
694 handleShape(
static_cast<PCB_SHAPE*
>( aItem ) );
700 if( aSelectionFilter && !aSelectionFilter->
graphics )
709 handleShape(
static_cast<PCB_SHAPE*
>( aItem ) );
717 if( aSelectionFilter && !aSelectionFilter->
tracks )
743 if( aSelectionFilter && !aSelectionFilter->
vias )
758 if( aFrom && aSelectionFilter && !aSelectionFilter->
zones )
780 if( aFrom && aSelectionFilter && !aSelectionFilter->
dimensions )
793 if( aFrom && aSelectionFilter && !aSelectionFilter->
dimensions )
803 for(
int i = 0; i < 2; i++ )
814 if( aFrom && aSelectionFilter && !aSelectionFilter->
dimensions )
827 if( aFrom && aSelectionFilter && !aSelectionFilter->
dimensions )
838 if( aFrom && aSelectionFilter && !aSelectionFilter->
text )
863 double minDist = std::numeric_limits<double>::max();
873 if( ( aFlags & a.flags ) != aFlags )
876 double dist = a.Distance( aPos );
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
virtual VECTOR2I GetCenter() const
This defaults to the center of the bounding box if not overridden.
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
void SetOrigin(const Vec &pos)
void SetEnd(coord_type x, coord_type y)
virtual VECTOR2I GetPosition() const
KICAD_T Type() const
Returns the type of object.
virtual bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const
Test if aPosition is inside or on the boundary of this item.
const VECTOR2I & GetTextPos() const
VECTOR2I GetVisibleGrid() const
virtual VECTOR2I Align(const VECTOR2I &aPoint) const
void addAnchor(const VECTOR2I &aPos, int aFlags, EDA_ITEM *aItem)
KIGFX::ORIGIN_VIEWITEM m_viewSnapPoint
KIGFX::ORIGIN_VIEWITEM m_viewSnapLine
KIGFX::ORIGIN_VIEWITEM m_viewAxis
std::vector< ANCHOR > m_anchors
A color representation with 4 components: red, green, blue, alpha.
COLOR4D WithAlpha(double aAlpha) const
Return a color with the same color, but the given alpha.
double GetWorldScale() const
Get the world scale.
void SetPosition(const VECTOR2I &aPosition) override
void SetColor(const KIGFX::COLOR4D &aColor)
VECTOR2I GetPosition() const override
void SetStyle(MARKER_STYLE aStyle)
void SetDrawAtZero(bool aDrawFlag)
Set the draw at zero flag.
void SetEndPosition(const VECTOR2D &aPosition)
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
const std::set< int > GetHighContrastLayers() const
Returns the set of currently high-contrast layers.
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
bool GetHighContrast() const
virtual double ViewGetLOD(int aLayer, VIEW *aView) const
Return the level of detail (LOD) of the item.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
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.
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...
GAL * GetGAL() const
Return the #GAL this view is using to draw graphical primitives.
std::pair< VIEW_ITEM *, int > LAYER_ITEM_PAIR
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
bool IsVisible(const VIEW_ITEM *aItem) const
Return information if the item is visible (or not).
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Set the item visibility.
LSET is a set of PCB_LAYER_IDs.
static LSET AllLayersMask()
virtual const VECTOR2I & GetStart() const
The dimension's origin is the first feature point for the dimension.
virtual const VECTOR2I & GetEnd() const
For better understanding of the points that make a dimension:
const VECTOR2I & GetCrossbarStart() const
const VECTOR2I & GetCrossbarEnd() const
Mark the center of a circle or arc with a cross shape.
A leader is a dimension-like object pointing to a specific point.
A radial dimension indicates either the radius or diameter of an arc or circle.
VECTOR2I AlignToArc(const VECTOR2I &aPoint, const SHAPE_ARC &aSeg)
VECTOR2I BestSnapAnchor(const VECTOR2I &aOrigin, BOARD_ITEM *aReferenceItem)
Chooses the "best" snap anchor around the given point, optionally taking layers from the reference it...
void computeAnchors(BOARD_ITEM *aItem, const VECTOR2I &aRefPos, bool aFrom=false, const SELECTION_FILTER_OPTIONS *aSelectionFilter=nullptr)
computeAnchors inserts the local anchor points in to the grid helper for the specified board item,...
BOARD_ITEM * GetSnapped() const
Function GetSnapped If the PCB_GRID_HELPER has highlighted a snap point (target shown),...
VECTOR2I BestDragOrigin(const VECTOR2I &aMousePos, std::vector< BOARD_ITEM * > &aItem, const SELECTION_FILTER_OPTIONS *aSelectionFilter=nullptr)
std::set< BOARD_ITEM * > queryVisible(const BOX2I &aArea, const std::vector< BOARD_ITEM * > &aSkip) const
ANCHOR * nearestAnchor(const VECTOR2I &aPos, int aFlags, LSET aMatchLayers)
MAGNETIC_SETTINGS * m_magneticSettings
VECTOR2I AlignToSegment(const VECTOR2I &aPoint, const SEG &aSeg)
PCB_GRID_HELPER(TOOL_MANAGER *aToolMgr, MAGNETIC_SETTINGS *aMagneticSettings)
VECTOR2I AlignToNearestPad(const VECTOR2I &aMousePos, PADS &aPads)
A set of BOARD_ITEMs (i.e., without duplicates).
const VECTOR2I & GetStart() const
const VECTOR2I & GetEnd() const
ecoord SquaredDistance(const SEG &aSeg) const
VECTOR2I::extended_type ecoord
OPT_VECTOR2I IntersectLines(const SEG &aSeg) const
Compute the intersection point of lines passing through ends of (this) and aSeg.
const VECTOR2I & GetP1() const
int IntersectLine(const SEG &aSeg, std::vector< VECTOR2I > *aIpsBuffer) const
Find intersection points between this arc and aSeg, treating aSeg as an infinite line.
const VECTOR2I & GetP0() const
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
void Move(const VECTOR2I &aVector) override
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
void Rotate(const EDA_ANGLE &aAngle, const VECTOR2I &aCenter={ 0, 0 }) override
Rotate all vertices by a given angle.
virtual const SEG GetSegment(int aIndex) const override
const VECTOR2I NearestPoint(const VECTOR2I &aP, bool aAllowInternalShapePoints=true) const
Find a point on the line chain that is closest to point aP.
virtual size_t GetSegmentCount() const override
Represent a set of closed polygons.
CONST_ITERATOR CIterateWithHoles(int aOutline) const
static constexpr extended_type ECOORD_MAX
Handle a list of polygons defining a copper zone.
static constexpr EDA_ANGLE & ANGLE_90
@ LAYER_AUX_ITEMS
Auxiliary items (guides, rule, etc)
@ LAYER_ANCHOR
anchor of items having an anchor point (texts, footprints)
PCB_LAYER_ID
A quick note on layer IDs:
This file contains miscellaneous commonly used macros and functions.
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
@ GEOMETRY
Position or shape has changed.
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Class to handle a set of BOARD_ITEMs.
std::optional< VECTOR2I > OPT_VECTOR2I
double Distance(const VECTOR2I &aP) const
This file contains data structures that are saved in the project file or project local settings file ...
bool graphics
Graphic lines, shapes, polygons.
bool text
Text (free or attached to a footprint)
bool vias
Vias (all types>
bool tracks
Copper tracks.
bool footprints
Allow selecting entire footprints.
bool dimensions
Dimension items.
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
double EuclideanNorm(const VECTOR2I &vector)
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
@ PCB_DIM_ORTHOGONAL_T
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
@ PCB_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
@ PCB_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
@ PCB_ZONE_T
class ZONE, a copper pour area
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
@ PCB_MARKER_T
class PCB_MARKER, a marker used to show something
@ PCB_TARGET_T
class PCB_TARGET, a target (graphic item)
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
@ PCB_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
@ PCB_PAD_T
class PAD, a pad in a footprint
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
@ PCB_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
VECTOR2< double > VECTOR2D