Browse Source

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.
pcb_db
John Beard 10 months ago
parent
commit
c120254aa4
  1. 51
      common/tool/construction_manager.cpp
  2. 7
      include/tool/construction_manager.h

51
common/tool/construction_manager.cpp

@ -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();
}

7
include/tool/construction_manager.h

@ -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

Loading…
Cancel
Save