62 std::unique_lock<std::mutex> lock(
m_mutex );
72 std::unique_lock<std::mutex> lock(
m_mutex );
90 if( aAcceptImmediately )
104 std::lock_guard<std::mutex> lock(
m_mutex );
120 std::unique_lock<std::mutex> lock(
m_mutex );
166 m_viewHandler( aHelper )
168 const std::chrono::milliseconds acceptanceTimeout(
171 m_activationHelper = std::make_unique<ACTIVATION_HELPER<std::unique_ptr<PENDING_BATCH>>>(
173 [
this]( std::unique_ptr<PENDING_BATCH>&& aAccepted )
177 wxCHECK_MSG( aAccepted !=
nullptr,
void(),
"Null proposal accepted" );
196 std::size_t hash =
hash_val( aIsPersistent );
207 std::unique_ptr<CONSTRUCTION_ITEM_BATCH> aBatch,
bool aIsPersistent )
209 if( aBatch->empty() )
216 bool acceptImmediately =
false;
223 acceptImmediately =
true;
233 std::make_unique<PENDING_BATCH>(
PENDING_BATCH{ std::move( *aBatch ), aIsPersistent } );
237 m_activationHelper->ProposeActivation( std::move( pendingBatch ), hash, acceptImmediately );
271 std::vector<CONSTRUCTION_ITEM_BATCH> persistentBatches, temporaryBatches;
275 if( aAcceptedBatch->IsPersistent )
282 bool anyNewItems =
false;
317 getInvolved( batch );
318 temporaryBatches.push_back( batch );
325 const auto addDrawables =
326 [&](
const std::vector<CONSTRUCTION_ITEM_BATCH>& aBatches,
bool aIsPersistent )
340 addDrawables( persistentBatches,
true );
341 addDrawables( temporaryBatches,
false );
363 std::vector<CONSTRUCTION_ITEM_BATCH>& aToExtend )
const
373 aToExtend.push_back( batch );
386 m_viewHandler( aViewHandler )
455 int aEscapeRange,
EDA_ANGLE aLongRangeEscapeAngle )
457 if(
std::abs( aCursor.
x - aSnapLineOrigin.
x ) < aEscapeRange )
470 int aEscapeRange,
EDA_ANGLE aLongRangeEscapeAngle )
472 if(
std::abs( aCursor.
y - aSnapLineOrigin.
y ) < aEscapeRange )
483 std::optional<int> aDistToNearest,
484 int aSnapRange )
const
489 bool snapLine =
false;
490 VECTOR2I bestSnapPoint = aNearestGrid;
493 const bool gridBetterThanNearest = !aDistToNearest || *aDistToNearest > aSnapRange;
499 const int escapeRange = 2 * aSnapRange;
503 longRangeEscapeAngle );
505 longRangeEscapeAngle );
509 if( !escapedX && gridBetterThanNearest )
515 if( !escapedY && gridBetterThanNearest )
523 return bestSnapPoint;
533 m_constructionManager( *this )
550std::vector<CONSTRUCTION_MANAGER::CONSTRUCTION_ITEM_BATCH>
553 std::vector<CONSTRUCTION_MANAGER::CONSTRUCTION_ITEM_BATCH> batches;
558 snapLineOrigin.has_value() )
571 LINE{ *snapLineOrigin, *snapLineOrigin +
VECTOR2I( 100000, 0 ) } );
573 LINE{ *snapLineOrigin, *snapLineOrigin +
VECTOR2I( 0, 100000 ) } );
575 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