69 std::unique_lock<std::mutex> lock(
m_mutex );
79 std::unique_lock<std::mutex> lock(
m_mutex );
97 if( aAcceptImmediately )
111 std::lock_guard<std::mutex> lock(
m_mutex );
127 std::unique_lock<std::mutex> lock(
m_mutex );
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 )
188 wxCHECK_MSG( aAccepted !=
nullptr,
void(),
"Null proposal accepted" );
207 std::size_t hash =
hash_val( aIsPersistent );
218 std::unique_ptr<CONSTRUCTION_ITEM_BATCH> aBatch,
bool aIsPersistent )
220 if( aBatch->empty() )
227 bool acceptImmediately =
false;
234 acceptImmediately =
true;
244 std::make_unique<PENDING_BATCH>(
PENDING_BATCH{ std::move( *aBatch ), aIsPersistent } );
248 m_activationHelper->ProposeActivation( std::move( pendingBatch ), hash, acceptImmediately );
282 std::vector<CONSTRUCTION_ITEM_BATCH> persistentBatches, temporaryBatches;
286 if( aAcceptedBatch->IsPersistent )
293 bool anyNewItems =
false;
328 getInvolved( batch );
329 temporaryBatches.push_back( batch );
336 const auto addDrawables =
337 [&](
const std::vector<CONSTRUCTION_ITEM_BATCH>& aBatches,
bool aIsPersistent )
351 addDrawables( persistentBatches,
true );
352 addDrawables( temporaryBatches,
false );
374 std::vector<CONSTRUCTION_ITEM_BATCH>& aToExtend )
const
384 aToExtend.push_back( batch );
406 if( aDir.
x == 0 && aDir.
y == 0 )
420 if( dx < 0 || ( dx == 0 && dy < 0 ) )
435 if( normalized.
x == 0 && normalized.
y == 0 )
438 for(
size_t i = 0; i < aDirections.size(); ++i )
440 if( aDirections[i] == normalized )
441 return static_cast<int>( i );
450 std::vector<VECTOR2I> uniqueDirections;
451 uniqueDirections.reserve( aDirections.size() );
453 for(
const VECTOR2I& direction : aDirections )
457 if( normalized.
x == 0 && normalized.
y == 0 )
460 if( std::find( uniqueDirections.begin(), uniqueDirections.end(), normalized )
461 == uniqueDirections.end() )
463 uniqueDirections.push_back( normalized );
561 std::optional<int> aDistToNearest,
562 int aSnapRange )
const
564 wxUnusedVar( aNearestGrid );
569 const bool gridBetterThanNearest = !aDistToNearest || *aDistToNearest > aSnapRange;
571 if( !gridBetterThanNearest )
574 const int escapeRange = 2 * aSnapRange;
581 double bestPerpDistance = std::numeric_limits<double>::max();
582 std::optional<VECTOR2I> bestSnapPoint;
589 if( dirLength == 0.0 )
592 VECTOR2D dirUnit = dirVector / dirLength;
594 double distanceAlong =
delta.Dot( dirUnit );
595 VECTOR2D projection = origin + dirUnit * distanceAlong;
599 if( perpDistance > aSnapRange )
602 bool escaped =
false;
604 if( perpDistance >= escapeRange )
608 double angleDiff = ( deltaAngle - directionAngle ).Normalize180().AsDegrees();
614 if( !escaped && perpDistance < bestPerpDistance )
616 bestPerpDistance = perpDistance;
622 return *bestSnapPoint;
660 std::vector<KIGFX::CONSTRUCTION_GEOM::SNAP_GUIDE> guides;
665 if( origin && !directions.empty() )
667 const std::optional<int> activeDirection =
m_snapLineManager.GetActiveDirection();
668 const int guideLength = 500000;
670 for(
size_t ii = 0; ii < directions.size(); ++ii )
672 const VECTOR2I& direction = directions[ii];
674 if( direction.
x == 0 && direction.
y == 0 )
677 VECTOR2I scaled = direction * guideLength;
680 guide.
Segment =
SEG( *origin - scaled, *origin + scaled );
682 if( activeDirection && *activeDirection ==
static_cast<int>( ii ) )
693 guides.push_back( guide );
709std::vector<CONSTRUCTION_MANAGER::CONSTRUCTION_ITEM_BATCH>
712 std::vector<CONSTRUCTION_MANAGER::CONSTRUCTION_ITEM_BATCH> batches;
717 snapLineOrigin.has_value() )
729 const std::optional<int> activeDirection =
m_snapLineManager.GetActiveDirection();
731 for(
size_t ii = 0; ii < directions.size(); ++ii )
733 const VECTOR2I& direction = directions[ii];
735 VECTOR2I scaledDirection = direction * 100000;
738 entry.
Drawable =
LINE{ *snapLineOrigin, *snapLineOrigin + scaledDirection };
739 entry.
LineWidth = ( activeDirection && *activeDirection ==
static_cast<int>( ii ) ) ? 2 : 1;
745 batches.push_back( std::move( batch ) );
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
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.
A color representation with 4 components: red, green, blue, alpha.
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...
CONSTRUCTION_VIEW_HANDLER(KIGFX::CONSTRUCTION_GEOM &aHelper)
KIGFX::CONSTRUCTION_GEOM & GetViewItem()
A base class for most all the KiCad significant classes used in schematics and boards.
A color representation with 4 components: red, green, blue, alpha.
Shows construction geometry for things like line extensions, arc centers, etc.
void AddDrawable(const DRAWABLE &aItem, bool aIsPersistent, int aLineWidth=1)
void SetSnapGuides(std::vector< SNAP_GUIDE > aGuides)
OPT_VECTOR2I m_snapLineEnd
void SetDirections(const std::vector< VECTOR2I > &aDirections)
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.
std::vector< VECTOR2I > m_directions
SNAP_MANAGER * m_snapManager
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.
std::optional< int > m_activeDirection
void SetSnapLineEnd(const OPT_VECTOR2I &aSnapPoint)
Set the end point of the snap line.
OPT_VECTOR2I m_snapLineOrigin
A SNAP_MANAGER glues together the snap line manager and construction manager., along with some other ...
void SetSnapGuideColors(const KIGFX::COLOR4D &aBase, const KIGFX::COLOR4D &aHighlight)
KIGFX::COLOR4D m_snapGuideColor
KIGFX::COLOR4D m_snapGuideHighlightColor
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)
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
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 VECTOR2I normalizeDirection(const VECTOR2I &aDir)
static std::optional< int > findDirectionIndex(const std::vector< VECTOR2I > &aDirections, const VECTOR2I &aDelta)
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)
The Cairo implementation of the graphics abstraction layer.
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
std::optional< VECTOR2I > OPT_VECTOR2I
KIGFX::CONSTRUCTION_GEOM::DRAWABLE Drawable
Items to be used for the construction of "virtual" anchors, for example, when snapping to a point inv...
std::vector< DRAWABLE_ENTRY > Constructions
CONSTRUCTION_ITEM_BATCH Batch
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D