54 m_magneticSettings( aMagneticSettings )
94 const int c_gridSnapEpsilon_sq = 4;
101 std::vector<VECTOR2I> points;
103 const SEG testSegments[] = {
SEG( aligned, aligned +
VECTOR2( 1, 0 ) ),
108 for(
const SEG& seg : testSegments )
113 points.push_back( *vec );
120 for(
const VECTOR2I& pt : { aSeg.
A, aSeg.
B } )
122 SEG::ecoord d_sq = ( pt - aPoint ).SquaredEuclideanNorm();
124 if( d_sq < min_d_sq )
134 SEG::ecoord d_sq = ( pt - aligned ).SquaredEuclideanNorm();
136 if( d_sq < min_d_sq )
154 std::vector<VECTOR2I> points;
167 SEG::ecoord d_sq = ( pt - aPoint ).SquaredEuclideanNorm();
169 if( d_sq < min_d_sq )
179 SEG::ecoord d_sq = ( pt - aligned ).SquaredEuclideanNorm();
181 if( d_sq < min_d_sq )
199 double minDist = std::numeric_limits<double>::max();
200 ANCHOR* nearestOrigin =
nullptr;
209 if( !item->
HitTest( aMousePos ) )
212 double dist = a.Distance( aMousePos );
221 return nearestOrigin ? nearestOrigin->
pos : aMousePos;
226 std::vector<BOARD_ITEM*>& aItems,
236 double lineSnapMinCornerDistance = 50.0 / worldScale;
242 double minDist = std::numeric_limits<double>::max();
246 minDist = nearestOrigin->
Distance( aMousePos );
247 best = nearestOrigin;
252 double dist = nearestCorner->
Distance( aMousePos );
257 best = nearestCorner;
263 double dist = nearestOutline->
Distance( aMousePos );
265 if( minDist > lineSnapMinCornerDistance && dist < minDist )
266 best = nearestOutline;
269 return best ? best->
pos : aMousePos;
277 std::vector<BOARD_ITEM*> item;
282 item.push_back( aReferenceItem );
295 const std::vector<BOARD_ITEM*>& aSkip )
298 const int snapSize = 25;
309 int snapDist = snapRange;
313 bb.
SetOrigin( GetClampedCoords<double, int>(
VECTOR2D( aOrigin ) - snapRange / 2.0 ) );
314 bb.
SetEnd( GetClampedCoords<double, int>(
VECTOR2D( aOrigin ) + snapRange / 2.0 ) );
325 snapDist = nearest->
Distance( aOrigin );
330 bool snapLine =
false;
335 if( x_dist < snapRange && ( !nearest || snapDist > snapRange ) )
341 if( y_dist < snapRange && ( !nearest || snapDist > snapRange ) )
362 if( nearest->
Distance( aOrigin ) <= snapRange )
399 switch( aItem->
Type() )
435 if( !
grid.overrides_enabled )
441 if(
grid.override_connected )
442 idx =
grid.override_connected_idx;
447 if(
grid.override_wires )
448 idx =
grid.override_wires_idx;
453 if(
grid.override_vias )
454 idx =
grid.override_vias_idx;
459 if(
grid.override_text )
460 idx =
grid.override_text_idx;
465 if(
grid.override_graphics )
466 idx =
grid.override_graphics_idx;
474 if( idx >= 0 && idx < (
int)
grid.grids.size() )
482 const std::vector<BOARD_ITEM*>& aSkip )
const
484 std::set<BOARD_ITEM*> items;
485 std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> selectedItems;
493 view->
Query( aArea, selectedItems );
495 for(
const auto& [ viewItem, layer ] : selectedItems )
510 if(
IsPcbLayer( layer ) && parentFP->GetPrivateLayers().test( layer ) )
517 && ( !isHighContrast || activeLayers.count( layer ) )
520 items.insert ( boardItem );
527 items.erase( aItem );
556 const auto getCircleKeyPoints = [] (
int radius )
558 return std::vector<VECTOR2I>{
567 auto handlePadShape =
576 switch( aPad->GetShape() )
578 case PAD_SHAPE::CIRCLE:
580 int r = aPad->GetSizeX() / 2;
583 const std::vector<VECTOR2I> circle_pts = getCircleKeyPoints( r );
585 for (
const VECTOR2I& pt: circle_pts ) {
592 case PAD_SHAPE::OVAL:
594 const VECTOR2I pos = aPad->ShapePos();
597 aPad->GetSize(), aPad->GetOrientation(), ovalKeyPointFlags );
599 for (
const VECTOR2I& pt: oval_pts ) {
606 case PAD_SHAPE::RECTANGLE:
607 case PAD_SHAPE::TRAPEZOID:
608 case PAD_SHAPE::ROUNDRECT:
609 case PAD_SHAPE::CHAMFERED_RECT:
611 VECTOR2I half_size( aPad->GetSize() / 2 );
614 if( aPad->GetShape() == PAD_SHAPE::TRAPEZOID )
615 trap_delta = aPad->GetDelta() / 2;
619 corners.
Append( -half_size.
x - trap_delta.
y, half_size.
y + trap_delta.
x );
620 corners.
Append( half_size.
x + trap_delta.
y, half_size.
y - trap_delta.
x );
621 corners.
Append( half_size.
x - trap_delta.
y, -half_size.
y + trap_delta.
x );
622 corners.
Append( -half_size.
x + trap_delta.
y, -half_size.
y - trap_delta.
x );
625 corners.
Rotate( aPad->GetOrientation() );
626 corners.
Move( aPad->ShapePos() );
643 const auto& outline = aPad->GetEffectivePolygon(
ERROR_INSIDE );
645 if( !outline->IsEmpty() )
647 for(
const VECTOR2I& pt : outline->Outline( 0 ).CPoints() )
655 if (aPad->HasHole()) {
658 const VECTOR2I hole_pos = aPad->GetPosition();
659 const VECTOR2I hole_size = aPad->GetDrillSize();
661 std::vector<VECTOR2I> snap_pts;
663 if ( hole_size.
x == hole_size.
y )
666 snap_pts = getCircleKeyPoints( hole_size.
x / 2 );
675 const EDA_ANGLE hole_orientation = aPad->GetOrientation();
676 snap_pts =
GetOvalKeyPoints( hole_size, hole_orientation, ovalKeyPointFlags );
679 for (
const auto& snap_pt : snap_pts)
692 switch( shape->GetShape() )
694 case SHAPE_T::CIRCLE:
713 case SHAPE_T::RECTANGLE:
717 SEG first( start, point2 );
718 SEG second( point2, end );
719 SEG third( end, point3 );
720 SEG fourth( point3, start );
733 case SHAPE_T::SEGMENT:
743 std::vector<VECTOR2I> poly;
744 shape->DupPolyPointsList( poly );
756 case SHAPE_T::BEZIER:
767 switch( aItem->
Type() )
777 if( aSelectionFilter && !aSelectionFilter->
pads )
786 if( !view->
IsVisible(
pad ) || !
pad->GetBoundingBox().Contains( aRefPos ) )
790 bool onActiveLayer = !isHighContrast;
791 bool isLODVisible =
false;
795 if( !onActiveLayer && activeLayers.count( layer ) )
796 onActiveLayer =
true;
798 if( !isLODVisible &&
pad->ViewGetLOD( layer, view ) < view->
GetScale() )
801 if( onActiveLayer && isLODVisible )
803 handlePadShape(
pad );
809 if( aFrom && aSelectionFilter && !aSelectionFilter->
footprints )
820 if( ( center - position ).SquaredEuclideanNorm() >
grid.SquaredEuclideanNorm() )
829 if( aSelectionFilter && !aSelectionFilter->
pads )
838 handlePadShape(
static_cast<PAD*
>( aItem ) );
845 if( aSelectionFilter && !aSelectionFilter->
text )
854 handleShape(
static_cast<PCB_SHAPE*
>( aItem ) );
860 if( aSelectionFilter && !aSelectionFilter->
graphics )
869 handleShape(
static_cast<PCB_SHAPE*
>( aItem ) );
877 if( aSelectionFilter && !aSelectionFilter->
tracks )
903 if( aSelectionFilter && !aSelectionFilter->
vias )
918 if( aFrom && aSelectionFilter && !aSelectionFilter->
zones )
940 if( aFrom && aSelectionFilter && !aSelectionFilter->
dimensions )
953 if( aFrom && aSelectionFilter && !aSelectionFilter->
dimensions )
963 for(
int i = 0; i < 2; i++ )
974 if( aFrom && aSelectionFilter && !aSelectionFilter->
dimensions )
987 if( aFrom && aSelectionFilter && !aSelectionFilter->
dimensions )
999 if( aFrom && aSelectionFilter && !aSelectionFilter->
text )
1024 double minDist = std::numeric_limits<double>::max();
1034 if( ( aFlags & a.flags ) != aFlags )
1037 double dist = a.Distance( aPos );
1039 if( dist < minDist )
constexpr EDA_IU_SCALE pcbIUScale
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 void RunOnDescendants(const std::function< void(BOARD_ITEM *)> &aFunction) const
Invoke a function on all descendants.
FOOTPRINT * GetParentFootprint() const
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)
A base class for most all the KiCad significant classes used in schematics and boards.
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
VECTOR2D GetVisibleGrid() 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.
const VECTOR2D & GetGridSize() const
Return the grid size.
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 void Remove(VIEW_ITEM *aItem)
Remove a VIEW_ITEM from 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.
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.
~PCB_GRID_HELPER() override
VECTOR2I AlignToArc(const VECTOR2I &aPoint, const SHAPE_ARC &aSeg)
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),...
VECTOR2D GetGridSize(GRID_HELPER_GRIDS aGrid) const override
Return the size of the specified grid.
VECTOR2I BestSnapAnchor(const VECTOR2I &aOrigin, BOARD_ITEM *aReferenceItem, GRID_HELPER_GRIDS aGrid=GRID_HELPER_GRIDS::GRID_CURRENT)
Chooses the "best" snap anchor around the given point, optionally taking layers from the reference it...
VECTOR2I BestDragOrigin(const VECTOR2I &aMousePos, std::vector< BOARD_ITEM * > &aItem, GRID_HELPER_GRIDS aGrid=GRID_HELPER_GRIDS::GRID_CURRENT, 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
GRID_HELPER_GRIDS GetItemGrid(const EDA_ITEM *aItem) const override
Gets the coarsest grid that applies to an item.
VECTOR2I AlignToSegment(const VECTOR2I &aPoint, const SEG &aSeg)
virtual VECTOR2I Align(const VECTOR2I &aPoint, GRID_HELPER_GRIDS aGrid) const
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
bool IsPcbLayer(int aLayer)
Test whether a layer is a valid layer for Pcbnew.
@ 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)
unsigned int OVAL_KEY_POINT_FLAGS
std::vector< VECTOR2I > GetOvalKeyPoints(const VECTOR2I &aOvalSize, const EDA_ANGLE &aRotation, OVAL_KEY_POINT_FLAGS aFlags)
Get a list of interesting points on an oval (rectangle with semicircular end caps)
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)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
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_REFERENCE_IMAGE_T
class PCB_REFERENCE_IMAGE, bitmap on a layer
@ PCB_FIELD_T
class PCB_FIELD, text associated with a footprint property
@ 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_DIMENSION_T
class PCB_DIMENSION_BASE: abstract dimension meta-type
@ 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