27#include <condition_variable>
59 std::lock_guard<std::mutex> lock(
m_mutex );
72 std::lock_guard<std::mutex> lock(
m_mutex );
95 std::lock_guard<std::mutex> lock(
m_mutex );
104 std::unique_lock<std::mutex> lock(
m_mutex );
114 auto now = std::chrono::steady_clock::now();
119 now = std::chrono::steady_clock::now();
177 m_viewHandler( aHelper )
179 const std::chrono::milliseconds acceptanceTimeout(
182 m_activationHelper = std::make_unique<ACTIVATION_HELPER<std::unique_ptr<PENDING_BATCH>>>(
184 [
this]( std::unique_ptr<PENDING_BATCH>&& aAccepted )
203 std::size_t hash =
hash_val( aIsPersistent );
214 std::unique_ptr<CONSTRUCTION_ITEM_BATCH> aBatch,
bool aIsPersistent )
216 if( aBatch->empty() )
226 std::make_unique<PENDING_BATCH>(
PENDING_BATCH{ std::move( *aBatch ), aIsPersistent } ),
253 std::vector<CONSTRUCTION_ITEM_BATCH> persistentBatches, temporaryBatches;
257 if( aAcceptedBatch->IsPersistent )
264 bool anyNewItems =
false;
282 const int maxTempItems = 2;
303 getInvolved( batch );
304 temporaryBatches.push_back( batch );
311 const auto addDrawables =
312 [&](
const std::vector<CONSTRUCTION_ITEM_BATCH>& aBatches,
bool aIsPersistent )
326 addDrawables( persistentBatches,
true );
327 addDrawables( temporaryBatches,
false );
347 std::vector<CONSTRUCTION_ITEM_BATCH>& aToExtend )
const
357 aToExtend.push_back( batch );
368 m_viewHandler( aViewHandler )
433 int aEscapeRange,
EDA_ANGLE aLongRangeEscapeAngle )
435 if(
std::abs( aCursor.
x - aSnapLineOrigin.
x ) < aEscapeRange )
447 int aEscapeRange,
EDA_ANGLE aLongRangeEscapeAngle )
449 if(
std::abs( aCursor.
y - aSnapLineOrigin.
y ) < aEscapeRange )
460 std::optional<int> aDistToNearest,
461 int aSnapRange )
const
466 bool snapLine =
false;
467 VECTOR2I bestSnapPoint = aNearestGrid;
470 const bool gridBetterThanNearest = !aDistToNearest || *aDistToNearest > aSnapRange;
476 const int escapeRange = 2 * aSnapRange;
480 longRangeEscapeAngle );
482 longRangeEscapeAngle );
486 if( !escapedX && gridBetterThanNearest )
492 if( !escapedY && gridBetterThanNearest )
500 return bestSnapPoint;
510 m_constructionManager( *this )
527std::vector<CONSTRUCTION_MANAGER::CONSTRUCTION_ITEM_BATCH>
530 std::vector<CONSTRUCTION_MANAGER::CONSTRUCTION_ITEM_BATCH> batches;
535 snapLineOrigin.has_value() )
548 LINE{ *snapLineOrigin, *snapLineOrigin +
VECTOR2I( 100000, 0 ) } );
550 LINE{ *snapLineOrigin, *snapLineOrigin +
VECTOR2I( 0, 100000 ) } );
552 batches.push_back( std::move( batch ) );
A helper class to manage the activation of a "proposal" after a timeout.
std::atomic< bool > m_stop
ACTIVATION_HELPER(std::chrono::milliseconds aTimeout, ACTIVATION_CALLBACK aCallback)
std::optional< std::size_t > m_lastAcceptedProposalTag
ACTIVATION_CALLBACK m_callback
std::chrono::milliseconds m_timeout
void ProposalCheckFunction()
void ProposeActivation(T &&aProposal, std::size_t aProposalTag)
std::chrono::time_point< std::chrono::steady_clock > m_proposalDeadline
The last proposal tag that was made.
std::condition_variable m_cv
std::optional< std::size_t > m_pendingProposalTag
The last proposal that was accepted.
T m_lastProposal
Callback to call when the proposal is accepted.
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
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
std::vector< CONSTRUCTION_ITEM > CONSTRUCTION_ITEM_BATCH
std::optional< CONSTRUCTION_ITEM_BATCH > m_persistentConstructionBatch
std::unique_ptr< ACTIVATION_HELPER< std::unique_ptr< PENDING_BATCH > > > m_activationHelper
std::mutex m_batchesMutex
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
Interface wrapper for the construction geometry preview, with a callback to signal the view owner tha...
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