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() );
238 pins.emplace_back(
pin,
pin->GetPosition() );
252 bool hasConnectables =
false;
259 hasConnectables =
true;
267 double worldScale =
m_toolMgr->GetView()->GetGAL()->GetWorldScale();
268 double lineSnapMinCornerDistance = 50.0 / worldScale;
274 double minDist = std::numeric_limits<double>::max();
278 minDist = nearestOrigin->
Distance( aMousePos );
279 best = nearestOrigin;
284 double dist = nearestCorner->
Distance( aMousePos );
289 best = nearestCorner;
295 double dist = nearestOutline->
Distance( aMousePos );
297 if( minDist > lineSnapMinCornerDistance && dist < minDist )
298 best = nearestOutline;
305 std::optional<BOX2I> movingBounds;
316 movingBounds->Merge( bounds );
318 movingBounds = bounds;
322 std::vector<std::pair<const SCH_PIN*, VECTOR2I>> pins =
layoutPins( schematicItem );
324 pinEnd = std::any_of( pins.begin(), pins.end(),
325 [&](
const std::pair<const SCH_PIN*, VECTOR2I>& aPin )
327 return aPin.second == ret;
349 skipItems.
Add( aSkip );
356 std::optional<VECTOR2I> aMovingReferencePoint )
359 const double snapScale = ranges.
scale;
360 const int snapRange = ranges.
range;
361 const int snapIn = ranges.
in;
362 const int snapOut = ranges.
out;
366 const bool constructionEnabled =
369 if( !constructionEnabled )
372 BOX2I bb(
VECTOR2I( aOrigin.
x - snapRange / 2, aOrigin.
y - snapRange / 2 ),
VECTOR2I( snapRange, snapRange ) );
377 const std::set<SCH_ITEM*> visibleItems =
queryVisible( bb, aSkip );
379 for(
SCH_ITEM* item : visibleItems )
389 ad->AddAnchor( a.pos );
391 ad->SetNearest( nearest ?
OPT_VECTOR2I( nearest->
pos ) : std::nullopt );
400 std::optional<VECTOR2I> guideSnap;
405 const auto anchorId = [&](
const ANCHOR& aAnchor )
407 std::vector<SNAP_TARGET_ID> targets;
409 for(
const EDA_ITEM* item : aAnchor.items )
418 if( targets.empty() )
421 if( targets.size() == 1 )
422 return SNAP_STABLE_ID{ kind, targets.front(), aAnchor.pointTypes, 0 };
461 enum class PRESENTATION_KIND
469 PRESENTATION_KIND kind;
470 std::optional<ANCHOR>
anchor;
471 bool proposeConstruction;
505 if( inferenceEnabled )
507 for(
SCH_ITEM* item : visibleItems )
511 std::optional<INTERSECTABLE_GEOM> geometry = getSchematicIntersectable( *item );
516 static_cast<int>( item->Type() ), 0 };
517 const bool curved = std::holds_alternative<CIRCLE>( *geometry )
518 || std::holds_alternative<SHAPE_ARC>( *geometry );
521 inferenceProvider.
AddPath( { id, *geometry,
false } );
523 if( tangentEnabled && curved )
524 tangentProvider.
AddPath( { std::move(
id ), std::move( *geometry ),
false } );
531 static_cast<int>( item->Type() ), 0 },
546 int constructionIndex = 0;
548 if( constructionEnabled )
563 using DRAWABLE_TYPE = std::decay_t<
decltype(
drawable )>;
565 if constexpr( std::is_same_v<DRAWABLE_TYPE, VECTOR2I> )
585 frame.
candidates.push_back( std::move( candidate ) );
592 frame.
candidates.push_back( std::move( candidate ) );
599 frame.
candidates.push_back( std::move( candidate ) );
602 frame.
candidates.push_back( std::move( candidate ) );
605 if(
m_enableSnap && retained && retained->Distance( aOrigin ) <= snapOut )
613 retained->pos, retained->Distance( aOrigin ) / snapScale ) );
614 frame.
presentation.emplace( retainedId, PRESENTATION{ PRESENTATION_KIND::ANCHOR_MARKER, *retained,
false } );
624 nearest->
pos, nearest->
Distance( aOrigin ) / snapScale ) );
626 PRESENTATION{ PRESENTATION_KIND::ANCHOR_MARKER, *nearest,
true } );
634 *guideSnap, guideSnap->Distance( aOrigin ) / snapScale );
635 frame.
candidates.push_back( std::move( candidate ) );
636 frame.
presentation.emplace( guideId, PRESENTATION{ PRESENTATION_KIND::GUIDE, std::nullopt,
false } );
649 bool keepConstructionProposal =
false;
659 const PRESENTATION& presentation = output.
presentation->payload;
660 std::vector<SCH_ITEM*> items;
662 for(
EDA_ITEM* item : presentation.anchor->items )
665 items.push_back(
static_cast<SCH_ITEM*
>( item ) );
668 if( presentation.proposeConstruction && constructionEnabled && !items.empty() )
671 keepConstructionProposal =
true;
694 if( constructionEnabled && !keepConstructionProposal &&
ADVANCED_CFG::GetCfg().m_ExtensionSnapActivateOnHover )
696 for(
SCH_ITEM* item : visibleItems )
698 if( item->HitTest( aOrigin, 0 ) )
701 keepConstructionProposal =
true;
707 if( !keepConstructionProposal )
724 if( !
grid.overrides_enabled )
730 if(
grid.override_connected )
731 idx =
grid.override_connected_idx;
736 if(
grid.override_wires )
737 idx =
grid.override_wires_idx;
742 if(
grid.override_text )
743 idx =
grid.override_text_idx;
748 if(
grid.override_graphics )
749 idx =
grid.override_graphics_idx;
757 if( idx >= 0 && idx < (
int)
grid.grids.size() )
779 std::set<SCH_ITEM*> items;
780 std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> selectedItems;
786 view->
Query( aArea, selectedItems );
790 if( !it.first->IsSCH_ITEM() )
810 items.insert( item );
813 for(
EDA_ITEM* skipItem : aSkipList )
814 items.erase(
static_cast<SCH_ITEM*
>( skipItem ) );
825 switch( aItem->
Type() )
854 if(
static_cast<const SCH_LINE*
>( aItem )->IsConnectable() )
869 if(
group->GetItems().empty() )
894 switch( aItem->
Type() )
938 if( isGraphicLine && !aIncludeText )
977 if( aItem->
Type() ==
SCH_LINE_T && ( aIncludeText || !isGraphicLine ) )
1003 double minDist = std::numeric_limits<double>::max();
1008 if( ( aFlags & a.flags ) != aFlags )
1012 if( !a.items.empty() )
1023 double dist = a.Distance( aPos );
1025 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
virtual VECTOR2D GetGridSize(GRID_HELPER_GRIDS aGrid) const
Return the size of the specified grid.
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.
void SyncLayerVisibilityCache()
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