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 );
551 auto checkVisibility =
557 bool onActiveLayer = !isHighContrast;
558 bool isLODVisible =
false;
562 if( !onActiveLayer && activeLayers.count( layer ) )
563 onActiveLayer =
true;
565 if( !isLODVisible && item->ViewGetLOD( layer, view ) < view->
GetScale() )
568 if( onActiveLayer && isLODVisible )
582 auto getCircleKeyPoints =
585 return std::vector<VECTOR2I>{ { 0, 0 },
592 auto handlePadShape =
601 switch( aPad->GetShape() )
603 case PAD_SHAPE::CIRCLE:
604 for(
const VECTOR2I& pt: getCircleKeyPoints( aPad->GetSizeX() / 2 ) )
612 case PAD_SHAPE::OVAL:
614 aPad->GetOrientation(),
615 ovalKeyPointFlags ) )
623 case PAD_SHAPE::RECTANGLE:
624 case PAD_SHAPE::TRAPEZOID:
625 case PAD_SHAPE::ROUNDRECT:
626 case PAD_SHAPE::CHAMFERED_RECT:
628 VECTOR2I half_size( aPad->GetSize() / 2 );
631 if( aPad->GetShape() == PAD_SHAPE::TRAPEZOID )
632 trap_delta = aPad->GetDelta() / 2;
636 corners.
Append( -half_size.
x - trap_delta.
y, half_size.
y + trap_delta.
x );
637 corners.
Append( half_size.
x + trap_delta.
y, half_size.
y - trap_delta.
x );
638 corners.
Append( half_size.
x - trap_delta.
y, -half_size.
y + trap_delta.
x );
639 corners.
Append( -half_size.
x + trap_delta.
y, -half_size.
y - trap_delta.
x );
642 corners.
Rotate( aPad->GetOrientation() );
643 corners.
Move( aPad->ShapePos() );
660 const auto& outline = aPad->GetEffectivePolygon(
ERROR_INSIDE );
662 if( !outline->IsEmpty() )
664 for(
const VECTOR2I& pt : outline->Outline( 0 ).CPoints() )
672 if( aPad->HasHole() )
675 const VECTOR2I hole_pos = aPad->GetPosition();
676 const VECTOR2I hole_size = aPad->GetDrillSize();
678 std::vector<VECTOR2I> snap_pts;
680 if ( hole_size.
x == hole_size.
y )
683 snap_pts = getCircleKeyPoints( hole_size.
x / 2 );
696 for(
const VECTOR2I& snap_pt : snap_pts )
707 switch( shape->GetShape() )
709 case SHAPE_T::CIRCLE:
711 int r = ( start - end ).EuclideanNorm();
728 case SHAPE_T::RECTANGLE:
732 SEG first( start, point2 );
733 SEG second( point2, end );
734 SEG third( end, point3 );
735 SEG fourth( point3, start );
748 case SHAPE_T::SEGMENT:
758 std::vector<VECTOR2I> poly;
759 shape->DupPolyPointsList( poly );
771 case SHAPE_T::BEZIER:
782 switch( aItem->
Type() )
792 if( aSelectionFilter && !aSelectionFilter->
pads )
801 if( !checkVisibility(
pad ) )
804 if( !
pad->GetBoundingBox().Contains( aRefPos ) )
807 handlePadShape(
pad );
810 if( aFrom && aSelectionFilter && !aSelectionFilter->
footprints )
822 if( ( center - position ).SquaredEuclideanNorm() >
grid.SquaredEuclideanNorm() )
831 if( aSelectionFilter && !aSelectionFilter->
pads )
840 if( checkVisibility( aItem ) )
841 handlePadShape(
static_cast<PAD*
>( aItem ) );
848 if( aSelectionFilter && !aSelectionFilter->
text )
857 if( checkVisibility( aItem ) )
858 handleShape(
static_cast<PCB_SHAPE*
>( aItem ) );
865 if( aSelectionFilter && !aSelectionFilter->
graphics )
874 if( checkVisibility( aItem ) )
875 handleShape(
static_cast<PCB_SHAPE*
>( aItem ) );
883 if( aSelectionFilter && !aSelectionFilter->
tracks )
892 if( checkVisibility( aItem ) )
911 if( aSelectionFilter && !aSelectionFilter->
vias )
920 if( checkVisibility( aItem ) )
926 if( aFrom && aSelectionFilter && !aSelectionFilter->
zones )
929 if( checkVisibility( aItem ) )
949 if( aFrom && aSelectionFilter && !aSelectionFilter->
dimensions )
952 if( checkVisibility( aItem ) )
964 if( aFrom && aSelectionFilter && !aSelectionFilter->
dimensions )
967 if( checkVisibility( aItem ) )
976 for(
int i = 0; i < 2; i++ )
986 if( aFrom && aSelectionFilter && !aSelectionFilter->
dimensions )
989 if( checkVisibility( aItem ) )
1001 if( aFrom && aSelectionFilter && !aSelectionFilter->
dimensions )
1004 if( checkVisibility( aItem ) )
1016 if( aFrom && aSelectionFilter && !aSelectionFilter->
text )
1019 if( checkVisibility( aItem ) )
1027 if( checkVisibility( item ) )
1042 double minDist = std::numeric_limits<double>::max();
1052 if( ( aFlags & a.flags ) != aFlags )
1055 double dist = a.Distance( aPos );
1057 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.
FOOTPRINT * GetParentFootprint() const
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
virtual void RunOnDescendants(const std::function< void(BOARD_ITEM *)> &aFunction, int aDepth=0) const
Invoke a function on all descendants.
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.
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.
bool IsLayerVisible(int aLayer) const
Return information about visibility of a particular layer.
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.
void computeAnchors(BOARD_ITEM *aItem, const VECTOR2I &aRefPos, bool aFrom=false, const PCB_SELECTION_FILTER_OPTIONS *aSelectionFilter=nullptr)
computeAnchors inserts the local anchor points in to the grid helper for the specified board item,...
~PCB_GRID_HELPER() override
VECTOR2I AlignToArc(const VECTOR2I &aPoint, const SHAPE_ARC &aSeg)
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 PCB_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)
VECTOR2I AlignToNearestPad(const VECTOR2I &aMousePos, std::deque< PAD * > &aPads)
virtual VECTOR2I Align(const VECTOR2I &aPoint, GRID_HELPER_GRIDS aGrid) const
PCB_GRID_HELPER(TOOL_MANAGER *aToolMgr, MAGNETIC_SETTINGS *aMagneticSettings)
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 vias
Vias (all types>
bool graphics
Graphic lines, shapes, polygons.
bool footprints
Allow selecting entire footprints.
bool text
Text (free or attached to a footprint)
bool tracks
Copper tracks.
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.
@ 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, bool aQuiet=false)
Round a floating point number to an integer using "round halfway cases away from zero".
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D