60 std::unique_lock<std::mutex> lock(
m_mutex );
78 if( aAcceptImmediately )
92 std::lock_guard<std::mutex> lock(
m_mutex );
108 std::unique_lock<std::mutex> lock(
m_mutex );
154 m_viewHandler( aHelper )
156 const std::chrono::milliseconds acceptanceTimeout(
159 m_activationHelper = std::make_unique<ACTIVATION_HELPER<std::unique_ptr<PENDING_BATCH>>>(
161 [
this]( std::unique_ptr<PENDING_BATCH>&& aAccepted )
180 std::size_t hash =
hash_val( aIsPersistent );
191 std::unique_ptr<CONSTRUCTION_ITEM_BATCH> aBatch,
bool aIsPersistent )
193 if( aBatch->empty() )
200 bool acceptImmediately =
false;
207 acceptImmediately =
true;
217 std::make_unique<PENDING_BATCH>(
PENDING_BATCH{ std::move( *aBatch ), aIsPersistent } );
221 m_activationHelper->ProposeActivation( std::move( pendingBatch ), hash, acceptImmediately );
255 std::vector<CONSTRUCTION_ITEM_BATCH> persistentBatches, temporaryBatches;
259 if( aAcceptedBatch->IsPersistent )
266 bool anyNewItems =
false;
301 getInvolved( batch );
302 temporaryBatches.push_back( batch );
309 const auto addDrawables =
310 [&](
const std::vector<CONSTRUCTION_ITEM_BATCH>& aBatches,
bool aIsPersistent )
324 addDrawables( persistentBatches,
true );
325 addDrawables( temporaryBatches,
false );
347 std::vector<CONSTRUCTION_ITEM_BATCH>& aToExtend )
const
357 aToExtend.push_back( batch );
370 m_viewHandler( aViewHandler )
439 int aEscapeRange,
EDA_ANGLE aLongRangeEscapeAngle )
441 if(
std::abs( aCursor.
x - aSnapLineOrigin.
x ) < aEscapeRange )
454 int aEscapeRange,
EDA_ANGLE aLongRangeEscapeAngle )
456 if(
std::abs( aCursor.
y - aSnapLineOrigin.
y ) < aEscapeRange )
467 std::optional<int> aDistToNearest,
468 int aSnapRange )
const
473 bool snapLine =
false;
474 VECTOR2I bestSnapPoint = aNearestGrid;
477 const bool gridBetterThanNearest = !aDistToNearest || *aDistToNearest > aSnapRange;
483 const int escapeRange = 2 * aSnapRange;
487 longRangeEscapeAngle );
489 longRangeEscapeAngle );
493 if( !escapedX && gridBetterThanNearest )
499 if( !escapedY && gridBetterThanNearest )
507 return bestSnapPoint;
517 m_constructionManager( *this )
534std::vector<CONSTRUCTION_MANAGER::CONSTRUCTION_ITEM_BATCH>
537 std::vector<CONSTRUCTION_MANAGER::CONSTRUCTION_ITEM_BATCH> batches;
542 snapLineOrigin.has_value() )
555 LINE{ *snapLineOrigin, *snapLineOrigin +
VECTOR2I( 100000, 0 ) } );
557 LINE{ *snapLineOrigin, *snapLineOrigin +
VECTOR2I( 0, 100000 ) } );
559 batches.push_back( std::move( batch ) );
A helper class to manage the activation of a "proposal" after a timeout.
void onTimerExpiry(wxTimerEvent &aEvent)
Timer expiry callback in the UI thread.
void acceptPendingProposal()
ACTIVATION_HELPER(std::chrono::milliseconds aTimeout, ACTIVATION_CALLBACK aCallback)
std::optional< std::size_t > m_lastAcceptedProposalTag
The last proposal that was accepted.
ACTIVATION_CALLBACK m_callback
Callback to call when the proposal is accepted.
std::chrono::milliseconds m_timeout
Activation timeout in milliseconds.
void ProposeActivation(T &&aProposal, std::size_t aProposalTag, bool aAcceptImmediately)
std::optional< std::size_t > m_pendingProposalTag
The last proposal tag that was made.
T m_lastProposal
The most recently-proposed item.
std::function< void(T &&)> ACTIVATION_CALLBACK
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
void GetConstructionItems(std::vector< CONSTRUCTION_ITEM_BATCH > &aToExtend) const
Get the list of additional geometry items that should be considered.
void ProposeConstructionItems(std::unique_ptr< CONSTRUCTION_ITEM_BATCH > aBatch, bool aIsPersistent)
Add a batch of construction items to the helper.
CONSTRUCTION_VIEW_HANDLER & m_viewHandler
bool HasActiveConstruction() const
CONSTRUCTION_MANAGER(CONSTRUCTION_VIEW_HANDLER &aViewHandler)
void CancelProposal()
Cancel outstanding proposals for new geometry.
std::deque< CONSTRUCTION_ITEM_BATCH > m_temporaryConstructionBatches
Temporary construction items are added and removed as needed.
std::vector< CONSTRUCTION_ITEM > CONSTRUCTION_ITEM_BATCH
std::optional< CONSTRUCTION_ITEM_BATCH > m_persistentConstructionBatch
Within one "operation", there is one set of construction items that are "persistent",...
std::unique_ptr< ACTIVATION_HELPER< std::unique_ptr< PENDING_BATCH > > > m_activationHelper
unsigned getMaxTemporaryBatches() const
How many batches of temporary construction items can be active at once.
std::mutex m_batchesMutex
Protects the persistent and temporary construction batches.
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...
void acceptConstructionItems(std::unique_ptr< PENDING_BATCH > aAcceptedBatchHash)
std::set< EDA_ITEM * > m_involvedItems
Set of all items for which construction geometry has been added.
Interface wrapper for the construction geometry preview with a callback to signal the view owner that...
virtual void updateView()=0
KIGFX::CONSTRUCTION_GEOM & GetViewItem()
A base class for most all the KiCad significant classes used in schematics and boards.
Shows construction geometry for things like line extensions, arc centers, etc.
void AddDrawable(const DRAWABLE &aItem, bool aIsPersistent)
std::variant< SEG, LINE, HALF_LINE, CIRCLE, SHAPE_ARC, VECTOR2I > DRAWABLE
void SetSnapLine(const SEG &aLine)
OPT_VECTOR2I m_snapLineEnd
void SetSnappedAnchor(const VECTOR2I &aAnchorPos)
Inform this manager that an anchor snap has been made.
OPT_VECTOR2I GetNearestSnapLinePoint(const VECTOR2I &aCursor, const VECTOR2I &aNearestGrid, std::optional< int > aDistToNearest, int snapRange) const
If the snap line is active, return the best snap point that is closest to the cursor.
CONSTRUCTION_VIEW_HANDLER & m_viewHandler
void ClearSnapLine()
Clear the snap line origin and end points.
bool HasCompleteSnapLine() const
SNAP_LINE_MANAGER(CONSTRUCTION_VIEW_HANDLER &aViewHandler)
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.
const OPT_VECTOR2I & GetSnapLineOrigin() const
OPT_VECTOR2I m_snapLineOrigin
GFX_UPDATE_CALLBACK m_updateCallback
CONSTRUCTION_MANAGER m_constructionManager
std::vector< CONSTRUCTION_MANAGER::CONSTRUCTION_ITEM_BATCH > GetConstructionItems() const
Get a list of all the active construction geometry, computed from the combined state of the snap line...
void updateView() override
SNAP_LINE_MANAGER m_snapLineManager
SNAP_MANAGER(KIGFX::CONSTRUCTION_GEOM &aHelper)
static std::size_t HashConstructionBatchSources(const CONSTRUCTION_MANAGER::CONSTRUCTION_ITEM_BATCH &aBatch, bool aIsPersistent)
Construct a hash based on the sources of the items in the batch.
static bool pointHasEscapedSnapLineX(const VECTOR2I &aCursor, const VECTOR2I &aSnapLineOrigin, int aEscapeRange, EDA_ANGLE aLongRangeEscapeAngle)
Check if the cursor has moved far enough away from the snap line origin to escape snapping in the X d...
static bool pointHasEscapedSnapLineY(const VECTOR2I &aCursor, const VECTOR2I &aSnapLineOrigin, int aEscapeRange, EDA_ANGLE aLongRangeEscapeAngle)
As above, but for the Y direction.
static constexpr void hash_combine(std::size_t &seed)
This is a dummy function to take the final case of hash_combine below.
static constexpr std::size_t hash_val(const Types &... args)
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
std::optional< VECTOR2I > OPT_VECTOR2I
Items to be used for the construction of "virtual" anchors, for example, when snapping to a point inv...
std::vector< KIGFX::CONSTRUCTION_GEOM::DRAWABLE > Constructions
CONSTRUCTION_ITEM_BATCH Batch
VECTOR2< int32_t > VECTOR2I