52std::optional<INTERSECTABLE_GEOM> getSchematicIntersectable(
const SCH_ITEM& aItem )
71 default:
return std::nullopt;
126 auto batch = std::make_unique<CONSTRUCTION_MANAGER::CONSTRUCTION_ITEM_BATCH>();
130 std::vector<KIGFX::CONSTRUCTION_GEOM::DRAWABLE> drawables;
131 std::optional<SEG> segment;
149 drawables.emplace_back( shape.
GetCenter() );
153 drawables.emplace_back( shape.
GetCenter() );
161 VECTOR2I direction = segment->B - segment->A;
162 drawables.emplace_back(
HALF_LINE( segment->A, segment->A - direction ) );
163 drawables.emplace_back(
HALF_LINE( segment->B, segment->B + direction ) );
167 drawables.emplace_back(
LINE( *segment ) );
172 drawables.emplace_back( segment->A );
173 drawables.emplace_back( segment->B );
177 std::vector<CONSTRUCTION_MANAGER::CONSTRUCTION_ITEM::DRAWABLE_ENTRY> entries;
180 entries.push_back( { std::move( drawable ), 1 } );
203 settings = cfg->m_SnapInference;
207 settings = cfg->m_SnapInference;
218 return static_cast<const SCH_SYMBOL&
>( aItem ).GetBodyAndPinsBoundingBox();
226 std::vector<std::pair<const SCH_PIN*, VECTOR2I>> pins;
231 pins.emplace_back( &
pin,
pin.GetPosition() );
236 pins.emplace_back(
pin,
pin->GetPosition() );
250 bool hasConnectables =
false;
257 hasConnectables =
true;
265 double worldScale =
m_toolMgr->GetView()->GetGAL()->GetWorldScale();
266 double lineSnapMinCornerDistance = 50.0 / worldScale;
272 double minDist = std::numeric_limits<double>::max();
276 minDist = nearestOrigin->
Distance( aMousePos );
277 best = nearestOrigin;
282 double dist = nearestCorner->
Distance( aMousePos );
287 best = nearestCorner;
293 double dist = nearestOutline->
Distance( aMousePos );
295 if( minDist > lineSnapMinCornerDistance && dist < minDist )
296 best = nearestOutline;
303 std::optional<BOX2I> movingBounds;
314 movingBounds->Merge( bounds );
316 movingBounds = bounds;
320 std::vector<std::pair<const SCH_PIN*, VECTOR2I>> pins =
layoutPins( schematicItem );
322 pinEnd = std::any_of( pins.begin(), pins.end(),
323 [&](
const std::pair<const SCH_PIN*, VECTOR2I>& aPin )
325 return aPin.second == ret;
347 skipItems.
Add( aSkip );
354 std::optional<VECTOR2I> aMovingReferencePoint )
357 const double snapScale = ranges.
scale;
358 const int snapRange = ranges.
range;
359 const int snapIn = ranges.
in;
360 const int snapOut = ranges.
out;
364 const bool constructionEnabled =
367 if( !constructionEnabled )
370 BOX2I bb(
VECTOR2I( aOrigin.
x - snapRange / 2, aOrigin.
y - snapRange / 2 ),
VECTOR2I( snapRange, snapRange ) );
375 const std::set<SCH_ITEM*> visibleItems =
queryVisible( bb, aSkip );
377 for(
SCH_ITEM* item : visibleItems )
387 ad->AddAnchor( a.pos );
389 ad->SetNearest( nearest ?
OPT_VECTOR2I( nearest->
pos ) : std::nullopt );
398 std::optional<VECTOR2I> guideSnap;
403 const auto anchorId = [&](
const ANCHOR& aAnchor )
405 std::vector<SNAP_TARGET_ID> targets;
407 for(
const EDA_ITEM* item : aAnchor.items )
416 if( targets.empty() )
419 if( targets.size() == 1 )
420 return SNAP_STABLE_ID{ kind, targets.front(), aAnchor.pointTypes, 0 };
459 enum class PRESENTATION_KIND
467 PRESENTATION_KIND kind;
468 std::optional<ANCHOR>
anchor;
469 bool proposeConstruction;
503 if( inferenceEnabled )
505 for(
SCH_ITEM* item : visibleItems )
509 std::optional<INTERSECTABLE_GEOM> geometry = getSchematicIntersectable( *item );
514 static_cast<int>( item->Type() ), 0 };
515 const bool curved = std::holds_alternative<CIRCLE>( *geometry )
516 || std::holds_alternative<SHAPE_ARC>( *geometry );
519 inferenceProvider.
AddPath( { id, *geometry,
false } );
521 if( tangentEnabled && curved )
522 tangentProvider.
AddPath( { std::move(
id ), std::move( *geometry ),
false } );
529 static_cast<int>( item->Type() ), 0 },
544 int constructionIndex = 0;
546 if( constructionEnabled )
559 [&](
const auto& drawable )
561 using DRAWABLE_TYPE = std::decay_t<
decltype( drawable )>;
563 if constexpr( std::is_same_v<DRAWABLE_TYPE, VECTOR2I> )
567 drawable, drawable.Distance( aOrigin ) / snapScale ) );
571 inferenceProvider.
AddPath( { id, drawable,
false,
true } );
583 frame.
candidates.push_back( std::move( candidate ) );
590 frame.
candidates.push_back( std::move( candidate ) );
597 frame.
candidates.push_back( std::move( candidate ) );
600 frame.
candidates.push_back( std::move( candidate ) );
603 if(
m_enableSnap && retained && retained->Distance( aOrigin ) <= snapOut )
611 retained->pos, retained->Distance( aOrigin ) / snapScale ) );
612 frame.
presentation.emplace( retainedId, PRESENTATION{ PRESENTATION_KIND::ANCHOR_MARKER, *retained,
false } );
622 nearest->
pos, nearest->
Distance( aOrigin ) / snapScale ) );
624 PRESENTATION{ PRESENTATION_KIND::ANCHOR_MARKER, *nearest,
true } );
632 *guideSnap, guideSnap->Distance( aOrigin ) / snapScale );
633 frame.
candidates.push_back( std::move( candidate ) );
634 frame.
presentation.emplace( guideId, PRESENTATION{ PRESENTATION_KIND::GUIDE, std::nullopt,
false } );
647 bool keepConstructionProposal =
false;
657 const PRESENTATION& presentation = output.
presentation->payload;
658 std::vector<SCH_ITEM*> items;
660 for(
EDA_ITEM* item : presentation.anchor->items )
663 items.push_back(
static_cast<SCH_ITEM*
>( item ) );
666 if( presentation.proposeConstruction && constructionEnabled && !items.empty() )
669 keepConstructionProposal =
true;
692 if( constructionEnabled && !keepConstructionProposal &&
ADVANCED_CFG::GetCfg().m_ExtensionSnapActivateOnHover )
694 for(
SCH_ITEM* item : visibleItems )
696 if( item->HitTest( aOrigin, 0 ) )
699 keepConstructionProposal =
true;
705 if( !keepConstructionProposal )
719 if( !
grid.overrides_enabled )
725 if(
grid.override_connected )
726 idx =
grid.override_connected_idx;
731 if(
grid.override_wires )
732 idx =
grid.override_wires_idx;
737 if(
grid.override_text )
738 idx =
grid.override_text_idx;
743 if(
grid.override_graphics )
744 idx =
grid.override_graphics_idx;
752 if( idx >= 0 && idx < (
int)
grid.grids.size() )
774 std::set<SCH_ITEM*> items;
775 std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> selectedItems;
780 view->
Query( aArea, selectedItems );
784 if( !it.first->IsSCH_ITEM() )
804 items.insert( item );
807 for(
EDA_ITEM* skipItem : aSkipList )
808 items.erase(
static_cast<SCH_ITEM*
>( skipItem ) );
819 switch( aItem->
Type() )
848 if(
static_cast<const SCH_LINE*
>( aItem )->IsConnectable() )
863 if(
group->GetItems().empty() )
888 switch( aItem->
Type() )
932 if( isGraphicLine && !aIncludeText )
971 if( aItem->
Type() ==
SCH_LINE_T && ( aIncludeText || !isGraphicLine ) )
997 double minDist = std::numeric_limits<double>::max();
1002 if( ( aFlags & a.flags ) != aFlags )
1006 if( !a.items.empty() )
1017 double dist = a.Distance( aPos );
1019 if( dist < minDist )
constexpr EDA_IU_SCALE schIUScale
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
static constexpr BOX2< VECTOR2I > ByCorners(const VECTOR2I &aCorner1, const VECTOR2I &aCorner2)
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.
void Clear()
Clear all construction items.
std::vector< CONSTRUCTION_ITEM > CONSTRUCTION_ITEM_BATCH
bool IsType(FRAME_T aType) const
The base class for create windows for drawing purpose.
A base class for most all the KiCad significant classes used in schematics and boards.
virtual VECTOR2I GetPosition() const
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
KICAD_T Type() const
Returns the type of object.
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
static std::vector< std::pair< const SCH_PIN *, VECTOR2I > > layoutPins(SCH_ITEM &aItem)
Pin connection points the item offers as alignment anchors.
~EE_GRID_HELPER() override
GRID_HELPER_GRIDS GetItemGrid(const EDA_ITEM *aItem) const override
Get the coarsest grid that applies to an item.
VECTOR2I BestDragOrigin(const VECTOR2I &aMousePos, GRID_HELPER_GRIDS aGrid, const SCH_SELECTION &aItems)
std::set< SCH_ITEM * > queryVisible(const BOX2I &aArea, const SCH_SELECTION &aSkipList) const
void AddConstructionItems(std::vector< SCH_ITEM * > aItems, bool aExtensionOnly, bool aIsPersistent)
ANCHOR * nearestAnchor(const VECTOR2I &aPos, int aFlags, GRID_HELPER_GRIDS aGrid)
VECTOR2D GetGridSize(GRID_HELPER_GRIDS aGrid) const override
Return the size of the specified grid.
SCH_ITEM * GetSnapped() const
Function GetSnapped If the EE_GRID_HELPER has highlighted a snap point (target shown),...
SNAP_RESULT ResolveSnap(const VECTOR2I &aOrigin, GRID_HELPER_GRIDS aGrid, SCH_ITEM *aSkip)
SNAP_INFERENCE_SETTINGS snapInferenceSettings() const
Snap inference settings for whichever editor owns this helper.
void computeAnchors(SCH_ITEM *aItem, const VECTOR2I &aRefPos, bool aFrom=false, bool aIncludeText=false)
Insert the local anchor points in to the grid helper for the specified schematic item,...
static BOX2I layoutBounds(const SCH_ITEM &aItem)
Bounds a layout relation should align to.
void retainAcceptedSnaps(const SNAP_RESULT &aResult)
Record which snaps the resolver accepted so they can be re-biased on the next resolve,...
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()
SNAP_RANGES computeSnapRanges(bool aClampToVisibleGrid) const
Compute the snap thresholds.
void emitAngleBranchCandidates(std::vector< SNAP_CANDIDATE > &aCandidates, const VECTOR2I &aOrigin, double aSnapScale) const
Emit the angle-restriction snap candidates (the two branches bracketing the cursor angle) into the cu...
void showConstructionGeometry(bool aShow)
SNAP_RESOLVER::FEASIBILITY_CALLBACK m_feasibilityCallback
std::vector< SEG > m_stationarySelfSegments
SNAP_RESOLVER::TRACE_CALLBACK snapTraceCallback(const SNAP_SOURCE_CONTEXT &aContext) const
bool canUseGrid() const
Check whether it is possible to use the grid – this depends both on local grid helper settings and gl...
std::optional< SNAP_STABLE_ID > m_retainedAngleBranch
std::optional< ANCHOR > m_snapItem
SNAP_REFERENCE_PREFERENCE m_layoutReferencePreference
KIGFX::ANCHOR_DEBUG * enableAndGetAnchorDebug()
Enable the anchor debug if permitted and return it.
KIGFX::SNAP_INDICATOR m_viewSnapPoint
virtual VECTOR2I Align(const VECTOR2I &aPoint, GRID_HELPER_GRIDS aGrid) const
KIGFX::ORIGIN_VIEWITEM m_viewAxis
std::vector< SNAP_STABLE_ID > m_stickySnapIds
void setLayoutReference(const VECTOR2I &aPoint, const std::optional< BOX2I > &aBounds, bool aAnchorPoint)
Record the classified drag reference and trace it.
void emitSelfAndGridCandidates(std::vector< SNAP_CANDIDATE > &aCandidates, const SNAP_SOURCE_CONTEXT &aContext, const VECTOR2I &aOrigin, const VECTOR2I &aNearestGrid, double aSnapScale, int aSnapRange, bool aUseGrid) const
Emit the point editor's unchanged self-geometry and the independent grid axes.
void applySnapResultGuides(const SNAP_RESULT &aResult)
std::vector< ANCHOR > m_anchors
View item to draw debug items for anchors.
A color representation with 4 components: red, green, blue, alpha.
std::variant< SEG, LINE, HALF_LINE, CIRCLE, SHAPE_ARC, VECTOR2I > DRAWABLE
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.
std::pair< VIEW_ITEM *, int > LAYER_ITEM_PAIR
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.
A shim class between EDA_DRAW_FRAME and several derived classes: SYMBOL_EDIT_FRAME,...
A set of SCH_ITEMs (i.e., without duplicates).
Base class for any item which can be embedded within the SCHEMATIC container class,...
virtual bool IsConnectable() const
virtual std::vector< VECTOR2I > GetConnectionPoints() const
Add all the connection points for this item to aPoints.
Segment description base class to describe items which have 2 end points (track, wire,...
VECTOR2I GetEndPoint() const
VECTOR2I GetStartPoint() const
VECTOR2I GetCenter() const
virtual void Add(EDA_ITEM *aItem)
A null aItem is ignored; the selection never holds null members.
virtual unsigned int GetSize() const override
Return the number of stored items.
bool Empty() const
Checks if there is anything selected.
std::vector< SNAP_CANDIDATE > CollectObjectGeometry(const SNAP_SOURCE_CONTEXT &aContext, int aRadius) const
std::vector< SNAP_CANDIDATE > CollectEqualSpacing(const SNAP_SOURCE_CONTEXT &aContext, int aRadius) const
void AddBounds(SNAP_OBJECT_BOUNDS aBounds)
std::vector< SNAP_CANDIDATE > CollectTangentNormal(const SNAP_SOURCE_CONTEXT &aContext, int aRadius, bool aTangentEnabled, bool aNormalEnabled) const
void AddPath(SNAP_OBJECT_PATH aPath)
void AddAlignmentPoint(SNAP_ALIGNMENT_POINT aPoint)
std::vector< SNAP_CANDIDATE > CollectAlignment(const SNAP_SOURCE_CONTEXT &aContext, int aRadius) const
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.
SNAP_LINE_MANAGER & GetSnapLineManager()
CONSTRUCTION_MANAGER & GetConstructionManager()
constexpr extended_type SquaredDistance(const VECTOR2< T > &aVector) const
Compute the squared distance between two vectors.
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
@ FRAME_SCH_SYMBOL_EDITOR
SNAP_TARGET_ID SnapTargetId(const KIID &aId)
The snap identity of a document item.
bool m_EnableExtensionSnaps
Enable snap anchors based on item line extensions.
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.
Class to handle a set of SCH_ITEMs.
std::optional< VECTOR2I > OPT_VECTOR2I
SNAP_FRAME_OUTPUT< Payload > ResolveSnapFrame(SNAP_FRAME_INPUT< Payload > aInput)
SNAP_STABLE_ID MakePointSnapId(SNAP_ID_KIND aKind, const VECTOR2I &aPoint, int aFeatureIndex=0)
SNAP_STABLE_ID MakeCompositeSnapId(SNAP_ID_KIND aKind, const std::vector< SNAP_TARGET_ID > &aTargets, int aFeatureIndex=0)
SNAP_STABLE_ID MakeDerivedSnapId(SNAP_ID_KIND aKind, const SNAP_STABLE_ID &aSource, int aFeatureIndex=0, int aSolutionBranch=0)
std::array< uint8_t, 16 > SNAP_TARGET_ID
KIGFX::CONSTRUCTION_GEOM::DRAWABLE Drawable
Items to be used for the construction of "virtual" anchors, for example, when snapping to a point inv...
double Distance(const VECTOR2I &aP) const
World-space snap thresholds derived from the screen-space snap radius.
int range
Snap radius, optionally clamped to the visible grid.
int in
Distance at which a candidate is picked up.
double scale
SNAP_SCREEN_RADIUS in world units.
int out
Distance at which a held candidate is released.
double rankingHysteresis
Resolver ranking stickiness, as a fraction of the radius.
static SNAP_CANDIDATE Point(SNAP_STABLE_ID aId, SNAP_PRIORITY_TIER aPriority, SNAP_CANDIDATE_SUBTYPE aSubtype, const VECTOR2I &aPoint, double aResidual)
std::optional< SNAP_FRAME_PRESENTATION< Payload > > presentation
bool constructionExtensions
bool alignmentDistribution
std::optional< VECTOR2I > stationarySourceLeg
std::optional< BOX2I > movingBounds
std::optional< VECTOR2I > movingReferencePoint
std::optional< SNAP_STABLE_ID > movingItem
std::vector< SNAP_STABLE_ID > stationarySelfFeatures
SNAP_EDITOR_PROFILE profile
SNAP_REFERENCE_PREFERENCE referencePreference
wxString result
Test unit parsing edge cases and error handling.
bool TestSegmentHit(const VECTOR2I &aRefPoint, const VECTOR2I &aStart, const VECTOR2I &aEnd, int aDist)
Test if aRefPoint is with aDistance on the line defined by aStart and aEnd.
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D