7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-20 00:21:31 +00:00

Pcbnew: snap to object faster if no objects activated

Otherwise it's annoying to snap to the first item you get to
if you have to wait every time.
This commit is contained in:
John Beard 2025-01-25 22:14:30 +08:00
parent 66df840353
commit c120254aa4
2 changed files with 41 additions and 17 deletions

View File

@ -67,7 +67,7 @@ public:
}
}
void ProposeActivation( T&& aProposal, std::size_t aProposalTag )
void ProposeActivation( T&& aProposal, std::size_t aProposalTag, bool aAcceptImmediately )
{
std::lock_guard<std::mutex> lock( m_mutex );
@ -86,7 +86,11 @@ public:
m_pendingProposalTag = aProposalTag;
m_lastProposal = std::move( aProposal );
m_proposalDeadline = std::chrono::steady_clock::now() + m_timeout;
m_proposalDeadline = std::chrono::steady_clock::now();
if( !aAcceptImmediately )
m_proposalDeadline += m_timeout;
m_cv.notify_all();
}
@ -224,19 +228,28 @@ void CONSTRUCTION_MANAGER::ProposeConstructionItems(
return;
}
auto pendingBatch = std::make_unique<PENDING_BATCH>( PENDING_BATCH{ std::move( *aBatch ),
aIsPersistent } );
bool acceptImmediately = false;
if( aIsPersistent )
{
// If the batch is persistent, we can accept it immediately
acceptConstructionItems( std::move( pendingBatch ) );
}
else
{
const std::size_t hash = HashConstructionBatchSources( pendingBatch->Batch, aIsPersistent );
m_activationHelper->ProposeActivation( std::move( pendingBatch ), hash );
std::lock_guard<std::mutex> lock( m_batchesMutex );
if( aIsPersistent )
{
acceptImmediately = true;
}
else
{
// If the batch is temporary, we can accept it immediately if there's room
acceptImmediately = m_temporaryConstructionBatches.size() < getMaxTemporaryBatches();
}
}
auto pendingBatch =
std::make_unique<PENDING_BATCH>( PENDING_BATCH{ std::move( *aBatch ), aIsPersistent } );
const std::size_t hash = HashConstructionBatchSources( pendingBatch->Batch, aIsPersistent );
// Immediate or not, propose the batch via the activation helper as this handles duplicates
m_activationHelper->ProposeActivation( std::move( pendingBatch ), hash, acceptImmediately );
}
@ -246,6 +259,14 @@ void CONSTRUCTION_MANAGER::CancelProposal()
}
unsigned CONSTRUCTION_MANAGER::getMaxTemporaryBatches() const
{
// We only keep up to one previous temporary batch and the current one
// we could make this a setting if we want to keep more, but it gets cluttered
return 2;
}
void CONSTRUCTION_MANAGER::acceptConstructionItems( std::unique_ptr<PENDING_BATCH> aAcceptedBatch )
{
const auto getInvolved = [&]( const CONSTRUCTION_ITEM_BATCH& aBatchToAdd )
@ -289,11 +310,7 @@ void CONSTRUCTION_MANAGER::acceptConstructionItems( std::unique_ptr<PENDING_BATC
return;
}
// We only keep up to one previous temporary batch and the current one
// we could make this a setting if we want to keep more, but it gets cluttered
const int maxTempItems = 2;
while( m_temporaryConstructionBatches.size() >= maxTempItems )
while( m_temporaryConstructionBatches.size() >= getMaxTemporaryBatches() )
{
m_temporaryConstructionBatches.pop_front();
}

View File

@ -201,6 +201,13 @@ private:
void acceptConstructionItems( std::unique_ptr<PENDING_BATCH> aAcceptedBatchHash );
/**
* How many batches of temporary construction items can be active at once.
*
* This is to prevent too much clutter.
*/
unsigned getMaxTemporaryBatches() const;
CONSTRUCTION_VIEW_HANDLER& m_viewHandler;
/// Within one "operation", there is one set of construction items that are