68std::optional<INTERSECTABLE_GEOM> GetBoardIntersectable(
const BOARD_ITEM& aItem )
70 switch( aItem.
Type() )
122std::optional<int64_t> FindSquareDistanceToItem(
const BOARD_ITEM& item,
const VECTOR2I& aPos )
124 std::optional<INTERSECTABLE_GEOM> intersectable = GetBoardIntersectable( item );
125 std::optional<NEARABLE_GEOM> nearable;
131 [&](
const auto& geom )
211 auto constructionItemsBatch = std::make_unique<CONSTRUCTION_MANAGER::CONSTRUCTION_ITEM_BATCH>();
213 std::vector<VECTOR2I> referenceOnlyPoints;
217 std::vector<KIGFX::CONSTRUCTION_GEOM::DRAWABLE> constructionDrawables;
219 switch( item->
Type() )
229 if( !aExtensionOnly )
245 constructionDrawables.emplace_back( shape.
GetStart() );
246 constructionDrawables.emplace_back( shape.
GetEnd() );
249 referenceOnlyPoints.emplace_back( shape.
GetStart() );
250 referenceOnlyPoints.emplace_back( shape.
GetEnd() );
256 if( !aExtensionOnly )
267 constructionDrawables.push_back( shape.
GetCenter() );
273 constructionDrawables.emplace_back( shape.
GetStart() );
274 constructionDrawables.emplace_back( shape.
GetEnd() );
277 referenceOnlyPoints.emplace_back( shape.
GetStart() );
278 referenceOnlyPoints.emplace_back( shape.
GetEnd() );
286 constructionDrawables.push_back( shape.
GetCenter() );
306 constructionDrawables.push_back( refImg.
GetPosition() );
312 constructionDrawables.push_back( seg );
326 std::vector<CONSTRUCTION_MANAGER::CONSTRUCTION_ITEM::DRAWABLE_ENTRY> drawableEntries;
327 drawableEntries.reserve( constructionDrawables.size() );
328 for(
auto& drawable : constructionDrawables )
330 drawableEntries.emplace_back(
337 std::move( drawableEntries ),
341 if( referenceOnlyPoints.size() )
352 const int c_gridSnapEpsilon_sq = 4;
359 std::vector<VECTOR2I> points;
361 const SEG testSegments[] = {
SEG( aligned, aligned +
VECTOR2( 1, 0 ) ),
366 for(
const SEG& seg : testSegments )
371 points.push_back( *vec );
378 for(
const VECTOR2I& pt : { aSeg.
A, aSeg.
B } )
380 SEG::ecoord d_sq = ( pt - aPoint ).SquaredEuclideanNorm();
382 if( d_sq < min_d_sq )
392 SEG::ecoord d_sq = ( pt - aligned ).SquaredEuclideanNorm();
394 if( d_sq < min_d_sq )
412 std::vector<VECTOR2I> points;
425 SEG::ecoord d_sq = ( pt - aPoint ).SquaredEuclideanNorm();
427 if( d_sq < min_d_sq )
437 SEG::ecoord d_sq = ( pt - aligned ).SquaredEuclideanNorm();
439 if( d_sq < min_d_sq )
452 wxLogTrace(
traceSnap,
"SnapToPad: mouse pos (%d, %d), pads count: %zu", aMousePos.
x, aMousePos.
y, aPads.size() );
457 if( item->
HitTest( aMousePos ) )
461 double minDist = std::numeric_limits<double>::max();
462 ANCHOR* nearestOrigin =
nullptr;
469 double dist = a.Distance( aMousePos );
478 return nearestOrigin ? nearestOrigin->
pos : aMousePos;
512 std::vector<BOARD_ITEM*>& aItems,
516 wxLogTrace(
traceSnap,
"BestDragOrigin: mouse pos (%d, %d), items count: %zu", aMousePos.
x, aMousePos.
y,
520 computeAnchors( aItems, aMousePos,
true, aSelectionFilter,
nullptr,
true );
522 double lineSnapMinCornerDistance =
m_toolMgr->GetView()->ToWorld( 50 );
528 double minDist = std::numeric_limits<double>::max();
532 minDist = nearestOrigin->
Distance( aMousePos );
533 best = nearestOrigin;
535 wxLogTrace(
traceSnap,
" nearest origin winning at (%d, %d), distance=%f", nearestOrigin->
pos.
x,
536 nearestOrigin->
pos.
y, minDist );
541 double dist = nearestCorner->
Distance( aMousePos );
546 best = nearestCorner;
548 wxLogTrace(
traceSnap,
" nearest corner winning at (%d, %d), distance=%f", nearestCorner->
pos.
x,
549 nearestCorner->
pos.
y, dist );
555 double dist = nearestOutline->
Distance( aMousePos );
557 if( minDist > lineSnapMinCornerDistance && dist < minDist )
559 best = nearestOutline;
561 wxLogTrace(
traceSnap,
" nearest outline winning at (%d, %d), distance=%f", nearestOutline->
pos.
x,
562 nearestOutline->
pos.
y, dist );
567 wxLogTrace(
traceSnap,
" have best: %s, returning (%d, %d)", best ?
"yes" :
"no", ret.
x, ret.
y );
576 std::vector<BOARD_ITEM*> item;
581 item.push_back( aReferenceItem );
586 layers =
LSET( { frame->GetActiveLayer() } );
599 const std::vector<BOARD_ITEM*>& aSkip )
601 wxLogTrace(
traceSnap,
"BestSnapAnchor: origin (%d, %d), enableSnap=%d, enableGrid=%d, enableSnapLine=%d",
605 const int snapSize = 25;
612 double snapScale =
m_toolMgr->GetView()->ToWorld( snapSize );
623 const std::vector<BOARD_ITEM*> visibleItems =
queryVisible( visibilityHorizon, aSkip );
624 computeAnchors( visibleItems, aOrigin,
false,
nullptr, &aLayers,
false );
631 const int snapIn = std::max( 0, snapRange - hysteresisWorld );
632 const int snapOut = snapRange + hysteresisWorld;
634 wxLogTrace(
traceSnap,
" snapRange=%d, snapIn=%d, snapOut=%d, hysteresis=%d",
635 snapRange, snapIn, snapOut, hysteresisWorld );
636 wxLogTrace(
traceSnap,
" visibleItems count=%zu, anchors count=%zu",
638 wxLogTrace(
traceSnap,
" nearest anchor: %s at (%d, %d), distance=%f",
639 nearest ?
"found" :
"none",
640 nearest ? nearest->
pos.
x : 0,
641 nearest ? nearest->
pos.
y : 0,
642 nearest ? nearest->
Distance( aOrigin ) : -1.0 );
643 wxLogTrace(
traceSnap,
" nearestGrid: (%d, %d)", nearestGrid.
x, nearestGrid.
y );
650 ad->AddAnchor(
anchor.pos );
652 ad->SetNearest( nearest ?
OPT_VECTOR2I{ nearest->
pos } : std::nullopt );
657 std::optional<int> snapDist;
660 snapDist = nearest->
Distance( aOrigin );
664 int existingDist =
m_snapItem->Distance( aOrigin );
665 if( !snapDist || existingDist < *snapDist )
666 snapDist = existingDist;
669 wxLogTrace(
traceSnap,
" snapDist: %s (value=%d)",
670 snapDist ?
"set" :
"none", snapDist ? *snapDist : -1 );
678 const auto ptIsReferenceOnly =
682 return std::find( referenceOnlyPoints.begin(), referenceOnlyPoints.end(), aPt )
683 != referenceOnlyPoints.end();
686 const auto proposeConstructionForItems =
687 [&](
const std::vector<EDA_ITEM*>& aItems )
691 std::vector<BOARD_ITEM*> items;
707 items.push_back( boardItem );
716 bool snapValid =
false;
720 wxLogTrace(
traceSnap,
" Snap enabled, checking snap options..." );
725 wxLogTrace(
traceSnap,
" Checking snap lines..." );
728 aOrigin, nearestGrid, snapDist, snapRange, gridSize,
GetOrigin() );
732 std::optional<VECTOR2I> constructionSnap =
735 if( constructionSnap )
736 snapLineSnap = *constructionSnap;
742 wxLogTrace(
traceSnap,
" Snap line found at (%d, %d)",
743 snapLineSnap->x, snapLineSnap->y );
747 bool preferAnchor =
false;
748 if( nearest && nearest->
Distance( aOrigin ) <= snapIn )
751 wxLogTrace(
traceSnap,
" Preferring anchor over snap line (anchorDist=%f, snapRange=%d)",
752 nearest->
Distance( aOrigin ), snapRange );
758 wxLogTrace(
traceSnap,
" Nearest anchor at (%d, %d), distance=%f is out of range (snapRange=%d)",
765 wxLogTrace(
traceSnap,
" No nearest anchor to consider" );
781 if( !ptIsReferenceOnly( *snapLineSnap ) )
783 wxLogTrace(
traceSnap,
" RETURNING snap line point (non-reference): (%d, %d)",
784 snapLineSnap->x, snapLineSnap->y );
785 return *snapLineSnap;
789 wxLogTrace(
traceSnap,
" Snap line point is reference-only, continuing..." );
794 wxLogTrace(
traceSnap,
" Skipping snap line, will use anchor instead" );
803 wxLogTrace(
traceSnap,
" Checking existing m_snapItem, dist=%d (snapOut=%d)",
806 if( dist <= snapOut )
808 if( nearest && ptIsReferenceOnly( nearest->
pos ) &&
809 nearest->
Distance( aOrigin ) <= snapRange )
815 wxLogTrace(
traceSnap,
" RETURNING existing m_snapItem: (%d, %d)",
820 wxLogTrace(
traceSnap,
" m_snapItem too far, clearing..." );
825 if( nearest && nearest->
Distance( aOrigin ) <= snapIn )
827 wxLogTrace(
traceSnap,
" Nearest anchor within snapIn range" );
833 if( ptIsReferenceOnly( nearest->
pos ) )
835 wxLogTrace(
traceSnap,
" Nearest anchor is reference-only, setting snap line origin" );
842 wxLogTrace(
traceSnap,
" Nearest anchor accepted, constructed=%d", anchorIsConstructed );
849 if( !anchorIsConstructed )
850 proposeConstructionForItems( nearest->
items );
859 wxLogTrace(
traceSnap,
" RETURNING nearest anchor: (%d, %d)",
868 wxLogTrace(
traceSnap,
" No nearest anchor within snapIn range" );
872 if( canActivateByHitTest )
874 wxLogTrace(
traceSnap,
" Checking hit test for construction activation..." );
879 const int hoverAccuracy = 0;
883 if( item->
HitTest( aOrigin, hoverAccuracy ) )
885 wxLogTrace(
traceSnap,
" Hit item, proposing construction geometry" );
886 proposeConstructionForItems( { item } );
900 wxLogTrace(
traceSnap,
" Grid disabled, checking point-on-element snap..." );
905 if( nearestPointOnAnElement && nearestPointOnAnElement->Distance( aOrigin ) <= snapRange )
907 wxLogTrace(
traceSnap,
" RETURNING point-on-element: (%d, %d)",
908 nearestPointOnAnElement->x, nearestPointOnAnElement->y );
915 return *nearestPointOnAnElement;
922 wxLogTrace(
traceSnap,
" RETURNING grid snap: (%d, %d)", nearestGrid.
x, nearestGrid.
y );
956 switch( aItem->
Type() )
993 if( !
grid.overrides_enabled )
999 if(
grid.override_connected )
1000 idx =
grid.override_connected_idx;
1005 if(
grid.override_wires )
1006 idx =
grid.override_wires_idx;
1011 if(
grid.override_vias )
1012 idx =
grid.override_vias_idx;
1017 if(
grid.override_text )
1018 idx =
grid.override_text_idx;
1023 if(
grid.override_graphics )
1024 idx =
grid.override_graphics_idx;
1032 if( idx >= 0 && idx < (
int)
grid.grids.size() )
1039std::vector<BOARD_ITEM*>
1042 std::set<BOARD_ITEM*> items;
1043 std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> visibleItems;
1051 view->
Query( aArea, visibleItems );
1053 for(
const auto& [ viewItem, layer ] : visibleItems )
1055 if( !viewItem->IsBOARD_ITEM() )
1071 if(
IsPcbLayer( layer ) && parentFP->GetPrivateLayers().test( layer ) )
1078 && ( !isHighContrast || activeLayers.count( layer ) )
1081 items.insert ( boardItem );
1085 std::function<void(
BOARD_ITEM* )> skipItem =
1088 items.erase( aItem );
1101 return {items.begin(), items.end()};
1120 const VECTOR2I& aRefPos,
bool aFrom,
1122 const LSET* aMatchLayers,
bool aForDrag )
1124 std::vector<PCB_INTERSECTABLE> intersectables;
1128 const bool computeIntersections = !aForDrag;
1129 const bool computePointsOnElements = !aForDrag;
1130 const bool excludeGraphics = aSelectionFilter && !aSelectionFilter->
graphics;
1131 const bool excludeTracks = aSelectionFilter && !aSelectionFilter->
tracks;
1133 const auto itemIsSnappable =
1143 const auto processItem =
1147 if( !itemIsSnappable( item ) )
1155 if( computeIntersections || computePointsOnElements )
1157 std::optional<INTERSECTABLE_GEOM> intersectableGeom;
1159 if( !excludeGraphics
1162 intersectableGeom = GetBoardIntersectable( item );
1166 intersectableGeom = GetBoardIntersectable( item );
1169 if( intersectableGeom )
1170 intersectables.emplace_back( &item, *intersectableGeom );
1176 processItem( *item );
1188 [&](
const auto& visited )
1190 using ItemType = std::decay_t<
decltype( visited )>;
1192 if constexpr( std::is_same_v<ItemType, LINE>
1193 || std::is_same_v<ItemType, CIRCLE>
1194 || std::is_same_v<ItemType, HALF_LINE>
1195 || std::is_same_v<ItemType, SHAPE_ARC> )
1197 intersectables.emplace_back( involvedItem, visited );
1199 else if constexpr( std::is_same_v<ItemType, VECTOR2I> )
1215 if( computeIntersections )
1217 for( std::size_t ii = 0; ii < intersectables.size(); ++ii )
1221 for( std::size_t jj = ii + 1; jj < intersectables.size(); ++jj )
1227 if( intersectableA.
Item == intersectableB.
Item )
1230 std::vector<VECTOR2I> intersections;
1233 std::visit( visitor, intersectableB.
Geometry );
1236 for(
const VECTOR2I& intersection : intersections )
1238 std::vector<EDA_ITEM*> items = {
1239 intersectableA.
Item,
1240 intersectableB.
Item,
1253 if( computePointsOnElements )
1260 [&](
const auto& geom )
1265 intersectable.Geometry );
1277 switch( aPadStack.
Mode() )
1287 switch( aPadstackUniqueLayer )
1292 return aPadstackUniqueLayer == aRealLayer;
1297 wxFAIL_MSG( wxString::Format(
"Unexpected padstack unique layer %d in FRONT_INNER_BACK mode",
1298 aPadstackUniqueLayer ) );
1306 return aRealLayer == aPadstackUniqueLayer;
1323 const auto checkVisibility =
1330 bool onActiveLayer = !isHighContrast;
1331 bool isLODVisible =
false;
1335 if( !onActiveLayer && activeLayers.count( layer ) )
1336 onActiveLayer =
true;
1339 isLODVisible =
true;
1341 if( onActiveLayer && isLODVisible )
1354 auto handlePadShape =
1393 trap_delta = aPad->
GetDelta( aLayer ) / 2;
1397 corners.
Append( -half_size.
x - trap_delta.
y, half_size.
y + trap_delta.
x );
1398 corners.
Append( half_size.
x + trap_delta.
y, half_size.
y - trap_delta.
x );
1399 corners.
Append( half_size.
x - trap_delta.
y, -half_size.
y + trap_delta.
x );
1400 corners.
Append( -half_size.
x + trap_delta.
y, -half_size.
y - trap_delta.
x );
1423 if( !outline->IsEmpty() )
1425 for(
const VECTOR2I& pt : outline->Outline( 0 ).CPoints() )
1439 std::vector<TYPED_POINT2I> snap_pts;
1441 if( hole_size.
x == hole_size.
y )
1464 const auto addRectPoints =
1471 const SEG second( topRight, aBox.
GetEnd() );
1472 const SEG third( aBox.
GetEnd(), bottomLeft );
1489 const auto handleShape =
1499 const int r = ( start -
end ).EuclideanNorm();
1579 switch( aItem->
Type() )
1584 bool footprintVisible = checkVisibility( footprint );
1590 if( aSelectionFilter && !aSelectionFilter->
pads )
1599 if( !checkVisibility(
pad ) )
1602 if( !
pad->GetBoundingBox().Contains( aRefPos ) )
1605 pad->Padstack().ForEachUniqueLayer(
1610 activeHighContrastPrimaryLayer ) )
1612 handlePadShape(
pad, aLayer );
1620 if( aSelectionFilter && !aSelectionFilter->
points )
1623 if( !checkVisibility( pt ) )
1634 if( !footprintVisible && !aFrom )
1637 if( aFrom && aSelectionFilter && !aSelectionFilter->
footprints )
1656 if( (
center - position ).SquaredEuclideanNorm() >
grid.SquaredEuclideanNorm() )
1665 if( aSelectionFilter && !aSelectionFilter->
pads )
1674 if( checkVisibility( aItem ) )
1678 pad->Padstack().ForEachUniqueLayer(
1683 activeHighContrastPrimaryLayer ) )
1685 handlePadShape(
pad, aLayer );
1695 if( aSelectionFilter && !aSelectionFilter->
text )
1704 if( checkVisibility( aItem ) )
1705 handleShape(
static_cast<PCB_SHAPE*
>( aItem ) );
1712 if( aSelectionFilter && !aSelectionFilter->
text )
1721 if( checkVisibility( aItem ) )
1726 VECTOR2I topLeft =
table->GetCell( 0, 0 )->GetCornersInSequence( drawAngle )[0];
1728 table->GetCell(
table->GetRowCount() - 1, 0 )->GetCornersInSequence( drawAngle )[3];
1729 VECTOR2I topRight =
table->GetCell( 0,
table->GetColCount() - 1 )->GetCornersInSequence( drawAngle )[1];
1731 ->GetCornersInSequence( drawAngle )[2];
1746 if( aSelectionFilter && !aSelectionFilter->
graphics )
1755 if( checkVisibility( aItem ) )
1756 handleShape(
static_cast<PCB_SHAPE*
>( aItem ) );
1764 if( aSelectionFilter && !aSelectionFilter->
tracks )
1773 if( checkVisibility( aItem ) )
1790 if( aSelectionFilter && !aSelectionFilter->
points )
1793 if( checkVisibility( aItem ) )
1801 if( aSelectionFilter && !aSelectionFilter->
vias )
1810 if( checkVisibility( aItem ) )
1816 if( aFrom && aSelectionFilter && !aSelectionFilter->
zones )
1819 if( checkVisibility( aItem ) )
1839 if( aFrom && aSelectionFilter && !aSelectionFilter->
dimensions )
1842 if( checkVisibility( aItem ) )
1854 if( aFrom && aSelectionFilter && !aSelectionFilter->
dimensions )
1857 if( checkVisibility( aItem ) )
1866 for(
int i = 0; i < 2; i++ )
1876 if( aFrom && aSelectionFilter && !aSelectionFilter->
dimensions )
1879 if( checkVisibility( aItem ) )
1891 if( aFrom && aSelectionFilter && !aSelectionFilter->
dimensions )
1894 if( checkVisibility( aItem ) )
1906 if( aFrom && aSelectionFilter && !aSelectionFilter->
text )
1909 if( checkVisibility( aItem ) )
1915 if( aFrom && aSelectionFilter && !aSelectionFilter->
otherItems )
1918 if( checkVisibility( aItem ) )
1924 addRectPoints( bbox, *barcode );
1932 if( checkVisibility( item ) )
1939 if( aFrom && aSelectionFilter && !aSelectionFilter->
graphics )
1942 if( checkVisibility( aItem ) )
1948 addRectPoints( bbox, *
image );
1970 ecoord minDist = std::numeric_limits<ecoord>::max();
1971 std::vector<ANCHOR*> anchorsAtMinDistance;
1977 if( ( aFlags &
anchor.flags ) != aFlags )
1980 if( !anchorsAtMinDistance.empty() &&
anchor.pos == anchorsAtMinDistance.front()->pos )
1983 anchorsAtMinDistance.push_back( &
anchor );
1987 const double dist =
anchor.pos.SquaredDistance( aPos );
1989 if( dist < minDist )
1993 anchorsAtMinDistance.clear();
1994 anchorsAtMinDistance.push_back( &
anchor );
2008 auto noRealItemsInAnchorAreInvolved =
2009 [&](
ANCHOR* aAnchor ) ->
bool
2014 if( !haveExtensions )
2022 if( !anchorIsConstructed )
2026 return !allRealAreInvolved;
2030 std::erase_if( anchorsAtMinDistance, noRealItemsInAnchorAreInvolved );
2037 ecoord minDistToItem = std::numeric_limits<ecoord>::max();
2043 ecoord distToNearestItem = std::numeric_limits<ecoord>::max();
2050 std::optional<ecoord> distToThisItem =
2051 FindSquareDistanceToItem(
static_cast<const BOARD_ITEM&
>( *item ), aPos );
2053 if( distToThisItem )
2054 distToNearestItem = std::min( distToNearestItem, *distToThisItem );
2059 distToNearestItem = std::min( distToNearestItem, minDist );
2061 if( distToNearestItem < minDistToItem )
2063 minDistToItem = distToNearestItem;
constexpr EDA_IU_SCALE pcbIUScale
constexpr BOX2I BOX2ISafe(const BOX2D &aInput)
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
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 RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction, RECURSE_MODE aMode) const
Invoke a function on all children.
Information pertinent to a Pcbnew printed circuit board.
void AddListener(BOARD_LISTENER *aListener)
Add a listener to the board to receive calls whenever something on the board has been modified.
void RemoveListener(BOARD_LISTENER *aListener)
Remove the specified listener.
static constexpr BOX2< VECTOR2I > ByCorners(const VECTOR2I &aCorner1, const VECTOR2I &aCorner2)
constexpr const Vec GetEnd() const
constexpr Vec Centre() const
constexpr const Vec GetCenter() const
constexpr coord_type GetLeft() const
constexpr const Vec & GetOrigin() const
constexpr coord_type GetRight() const
constexpr coord_type GetTop() const
constexpr coord_type GetBottom() const
Represent basic circle geometry with utility geometry functions.
void ProposeConstructionItems(std::unique_ptr< CONSTRUCTION_ITEM_BATCH > aBatch, bool aIsPersistent)
Add a batch of construction items to the helper.
void CancelProposal()
Cancel outstanding proposals for new geometry.
std::vector< CONSTRUCTION_ITEM > CONSTRUCTION_ITEM_BATCH
bool InvolvesAllGivenRealItems(const std::vector< EDA_ITEM * > &aItems) const
Check if all 'real' (non-null = constructed) the items in the batch are in the list of items currentl...
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.
int GetEllipseMinorRadius() const
const VECTOR2I & GetEllipseCenter() const
int GetEllipseMajorRadius() const
std::vector< VECTOR2I > GetPolyPoints() const
Duplicate the polygon outlines into a flat list of VECTOR2I points.
EDA_ANGLE GetEllipseRotation() const
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
VECTOR2I GetArcMid() const
std::optional< VECTOR2I > SnapToConstructionLines(const VECTOR2I &aPoint, const VECTOR2I &aNearestGrid, const VECTOR2D &aGrid, double aSnapRange) const
void addAnchor(const VECTOR2I &aPos, int aFlags, EDA_ITEM *aItem, int aPointTypes=POINT_TYPE::PT_NONE)
SNAP_MANAGER & getSnapManager()
void showConstructionGeometry(bool aShow)
VECTOR2D GetVisibleGrid() const
VECTOR2I GetOrigin() const
std::optional< ANCHOR > m_snapItem
KIGFX::ANCHOR_DEBUG * enableAndGetAnchorDebug()
Enable the anchor debug if permitted and return it.
KIGFX::SNAP_INDICATOR m_viewSnapPoint
void updateSnapPoint(const TYPED_POINT2I &aPoint)
KIGFX::ORIGIN_VIEWITEM m_viewAxis
std::vector< ANCHOR > m_anchors
View item to draw debug items for 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.
COLOR4D Brightened(double aFactor) const
Return a color that is brighter by a given factor, without modifying object.
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.
PCB_LAYER_ID GetPrimaryHighContrastLayer() const
Return the board layer which is in high-contrast mode.
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
bool GetHighContrast() const
bool IsBOARD_ITEM() const
virtual double ViewGetLOD(int aLayer, const 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.
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 const LSET & AllLayersMask()
A PADSTACK defines the characteristics of a single or multi-layer pad, in the IPC sense of the word.
@ NORMAL
Shape is the same on all layers.
@ CUSTOM
Shapes can be defined on arbitrary layers.
@ FRONT_INNER_BACK
Up to three shapes can be defined (F_Cu, inner copper layers, B_Cu)
static constexpr PCB_LAYER_ID INNER_LAYERS
! The layer identifier to use for "inner layers" on top/inner/bottom padstacks
const VECTOR2I & GetDelta(PCB_LAYER_ID aLayer) const
VECTOR2I GetPosition() const override
VECTOR2I GetDrillSize() const
PAD_SHAPE GetShape(PCB_LAYER_ID aLayer) const
VECTOR2I GetSize(PCB_LAYER_ID aLayer) const
EDA_ANGLE GetOrientation() const
Return the rotation angle of the pad.
const std::shared_ptr< SHAPE_POLY_SET > & GetEffectivePolygon(PCB_LAYER_ID aLayer, ERROR_LOC aErrorLoc=ERROR_INSIDE) const
bool HasHole() const override
VECTOR2I ShapePos(PCB_LAYER_ID aLayer) const
const VECTOR2I & GetMid() const
const SHAPE_POLY_SET & GetSymbolPoly() const
Access the cached polygon for the barcode symbol only (no text, no margins/knockout).
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
virtual VECTOR2I GetEnd() const
virtual VECTOR2I GetStart() const
The dimension's origin is the first feature point for the dimension.
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.
std::vector< NEARABLE_GEOM > m_pointOnLineCandidates
void OnBoardItemRemoved(BOARD &aBoard, BOARD_ITEM *aRemovedItem) override
~PCB_GRID_HELPER() override
VECTOR2I AlignToArc(const VECTOR2I &aPoint, const SHAPE_ARC &aSeg)
VECTOR2I SnapToPad(const VECTOR2I &aMousePos, std::deque< PAD * > &aPads)
void OnBoardItemsRemoved(BOARD &aBoard, std::vector< BOARD_ITEM * > &aBoardItems) override
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)
void AddConstructionItems(std::vector< BOARD_ITEM * > aItems, bool aExtensionOnly, bool aIsPersistent)
Add construction geometry for a set of board items.
ANCHOR * nearestAnchor(const VECTOR2I &aPos, int aFlags)
Find the nearest anchor point to the given position with matching flags.
MAGNETIC_SETTINGS * m_magneticSettings
GRID_HELPER_GRIDS GetItemGrid(const EDA_ITEM *aItem) const override
Get 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
void computeAnchors(const std::vector< BOARD_ITEM * > &aItems, const VECTOR2I &aRefPos, bool aFrom, const PCB_SELECTION_FILTER_OPTIONS *aSelectionFilter, const LSET *aLayers, bool aForDrag)
computeAnchors inserts the local anchor points in to the grid helper for the specified container of b...
std::vector< BOARD_ITEM * > queryVisible(const BOX2I &aArea, const std::vector< BOARD_ITEM * > &aSkip) const
A set of BOARD_ITEMs (i.e., without duplicates).
A PCB_POINT is a 0-dimensional point that is used to mark a position on a PCB, or more usually a foot...
Object to handle a bitmap image that can be inserted in a PCB.
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
REFERENCE_IMAGE & GetReferenceImage()
VECTOR2I GetCenter() const override
This defaults to the center of the bounding box if not overridden.
VECTOR2I GetPosition() const override
VECTOR2I GetTextPos() const override
const VECTOR2I & GetStart() const
const VECTOR2I & GetEnd() const
A REFERENCE_IMAGE is a wrapper around a BITMAP_IMAGE that is displayed in an editor as a reference fo...
VECTOR2I GetTransformOriginOffset() const
Get the center of scaling, etc, relative to the image center (GetPosition()).
VECTOR2I GetPosition() const
BOX2I GetBoundingBox() 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
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
static SHAPE_SEGMENT BySizeAndCenter(const VECTOR2I &aSize, const VECTOR2I &aCenter, const EDA_ANGLE &aRotation)
OPT_VECTOR2I GetNearestSnapLinePoint(const VECTOR2I &aCursor, const VECTOR2I &aNearestGrid, std::optional< int > aDistToNearest, int snapRange, const VECTOR2D &aGridSize=VECTOR2D(0, 0), const VECTOR2I &aGridOrigin=VECTOR2I(0, 0)) const
If the snap line is active, return the best snap point that is closest to the cursor.
void SetSnappedAnchor(const VECTOR2I &aAnchorPos)
Inform this manager that an anchor snap has been made.
void SetSnapLineOrigin(const VECTOR2I &aOrigin)
The snap point is a special point that is located at the last point the cursor snapped to.
void SetSnapLineEnd(const OPT_VECTOR2I &aSnapPoint)
Set the end point of the snap line.
A SNAP_MANAGER glues together the snap line manager and construction manager., along with some other ...
SNAP_LINE_MANAGER & GetSnapLineManager()
CONSTRUCTION_MANAGER & GetConstructionManager()
const std::vector< VECTOR2I > & GetReferenceOnlyPoints() const
void SetReferenceOnlyPoints(std::vector< VECTOR2I > aPoints)
Set the reference-only points - these are points that are not snapped to, but can still be used for c...
Define a general 2D-vector/point.
constexpr extended_type SquaredDistance(const VECTOR2< T > &aVector) const
Compute the squared distance between two vectors.
static constexpr extended_type ECOORD_MAX
VECTOR2_TRAITS< int32_t >::extended_type extended_type
Handle a list of polygons defining a copper zone.
A type-safe container of any type.
static constexpr EDA_ANGLE ANGLE_90
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
bool m_ExtensionSnapActivateOnHover
If extension snaps are enabled, 'activate' items on hover, even if not near a snap point.
bool m_EnableExtensionSnaps
Enable snap anchors based on item line extensions.
const wxChar *const traceSnap
Flag to enable snap/grid helper debug tracing.
std::variant< LINE, HALF_LINE, SEG, CIRCLE, SHAPE_ARC, BOX2I > INTERSECTABLE_GEOM
A variant type that can hold any of the supported geometry types for intersection calculations.
bool IsPcbLayer(int aLayer)
Test whether a layer is a valid layer for Pcbnew.
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
@ LAYER_FOOTPRINTS_FR
Show footprints on front.
@ LAYER_AUX_ITEMS
Auxiliary items (guides, rule, etc).
@ LAYER_FOOTPRINTS_BK
Show footprints on back.
@ LAYER_ANCHOR
Anchor of items having an anchor point (texts, footprints).
bool IsInnerCopperLayer(int aLayerId)
Test whether a layer is an inner (In1_Cu to In30_Cu) copper layer.
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 ...
std::vector< TYPED_POINT2I > GetCircleKeyPoints(const CIRCLE &aCircle, bool aIncludeCenter)
Get key points of an CIRCLE.
std::vector< TYPED_POINT2I > GetOvalKeyPoints(const SHAPE_SEGMENT &aOval, OVAL_KEY_POINT_FLAGS aFlags)
Get a list of interesting points on an oval (rectangle with semicircular end caps)
std::array< SEG, 4 > BoxToSegs(const BOX2I &aBox)
Decompose a BOX2 into four segments.
unsigned int OVAL_KEY_POINT_FLAGS
@ GEOMETRY
Position or shape has changed.
VECTOR2I GetNearestPoint(const NEARABLE_GEOM &aGeom, const VECTOR2I &aPt)
Get the nearest point on a geometry to a given point.
std::variant< LINE, HALF_LINE, SEG, CIRCLE, SHAPE_ARC, BOX2I, VECTOR2I > NEARABLE_GEOM
A variant type that can hold any of the supported geometry types for nearest point calculations.
BARCODE class definition.
static bool PadstackUniqueLayerAppliesToLayer(const PADSTACK &aPadStack, PCB_LAYER_ID aPadstackUniqueLayer, const PCB_LAYER_ID aRealLayer)
Class to handle a set of BOARD_ITEMs.
@ PT_INTERSECTION
The point is an intersection of two (or more) items.
@ PT_CENTER
The point is the center of something.
@ PT_CORNER
The point is a corner of a polygon, rectangle, etc (you may want to infer PT_END from this)
@ PT_NONE
No specific point type.
@ PT_QUADRANT
The point is on a quadrant of a circle (N, E, S, W points).
@ PT_END
The point is at the end of a segment, arc, etc.
@ PT_MID
The point is at the middle of a segment, arc, etc.
@ PT_ON_ELEMENT
The point is somewhere on another element, but not some specific point.
std::optional< VECTOR2I > OPT_VECTOR2I
VECTOR2I::extended_type ecoord
Utility functions for working with shapes.
KIGFX::CONSTRUCTION_GEOM::DRAWABLE Drawable
Items to be used for the construction of "virtual" anchors, for example, when snapping to a point inv...
std::vector< EDA_ITEM * > items
Items that are associated with this anchor (can be more than one, e.g.
double Distance(const VECTOR2I &aP) const
A visitor that visits INTERSECTABLE_GEOM variant objects with another (which is held as state: m_othe...
PCB_INTERSECTABLE(BOARD_ITEM *aItem, INTERSECTABLE_GEOM aSeg)
INTERSECTABLE_GEOM Geometry
This file contains data structures that are saved in the project file or project local settings file ...
bool otherItems
Anything not fitting one of the above categories.
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.
std::vector< std::vector< std::string > > table
SHAPE_CIRCLE circle(c.m_circle_center, c.m_circle_radius)
wxLogTrace helper definitions.
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_BARCODE_T
class PCB_BARCODE, a barcode (graphic item)
@ 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_TABLE_T
class PCB_TABLE, table of PCB_TABLECELLs
@ PCB_POINT_T
class PCB_POINT, a 0-dimensional point
@ 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
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D