Commit 89100b19 authored by Jon Evans's avatar Jon Evans

Rework some event handling

parent a164ba6e
......@@ -33,10 +33,6 @@ DIALOG_RULE_CHECK_CONTROL::DIALOG_RULE_CHECK_CONTROL( RULE_CHECK_MANAGER_BASE* a
m_manager( aManager )
{
m_btnBrowseReportPath->SetBitmap( KiBitmap( folder_xpm ) );
m_manager->GetEngine()->SetCallbacks(
std::bind( &DIALOG_RULE_CHECK_CONTROL::onEngineFinished, this, _1 ),
std::bind( &DIALOG_RULE_CHECK_CONTROL::onEngineProgress, this, _1, _2 ) );
}
......@@ -89,7 +85,7 @@ void DIALOG_RULE_CHECK_CONTROL::OnStartChecksClick( wxCommandEvent& event )
}
void DIALOG_RULE_CHECK_CONTROL::onEngineFinished( bool aChecksPassed )
void DIALOG_RULE_CHECK_CONTROL::OnEngineFinished( bool aChecksPassed )
{
m_progressBar->SetValue( 100 );
m_progressBar->Hide();
......@@ -98,7 +94,7 @@ void DIALOG_RULE_CHECK_CONTROL::onEngineFinished( bool aChecksPassed )
}
void DIALOG_RULE_CHECK_CONTROL::onEngineProgress( double aProgress, wxString aStatusMessage )
void DIALOG_RULE_CHECK_CONTROL::OnEngineProgress( double aProgress, wxString aStatusMessage )
{
m_progressBar->SetValue( 100 * aProgress );
m_txtStatus->SetLabel( aStatusMessage );
......
......@@ -44,6 +44,10 @@ public:
bool TransferDataFromWindow() override;
virtual void OnEngineFinished( bool aChecksPassed );
virtual void OnEngineProgress( double aProgress, wxString aStatusMessage );
protected:
virtual void OnReportCheckBoxClicked( wxCommandEvent& event ) override;
......@@ -57,11 +61,6 @@ protected:
virtual void OnStartChecksClick( wxCommandEvent& event ) override;
virtual void onEngineFinished( bool aChecksPassed );
virtual void onEngineProgress( double aProgress, wxString aStatusMessage );
protected:
/// Handler to the manager that spawned this dialog
RULE_CHECK_MANAGER_BASE* m_manager;
......
......@@ -123,8 +123,13 @@ protected:
/// Can be overridden to add some logic to RunChecks() before the engine starts
virtual void onRunChecks() {}
/// Can be overridden to add some logic after the checker completes (callback)
virtual void onChecksCompleted() {}
virtual void onEngineFinished( bool aChecksPassed )
{
}
virtual void onEngineProgress( double aProgress, wxString aStatusMessage )
{
}
};
#endif
......@@ -50,33 +50,6 @@ DIALOG_ERC_CONTROL::~DIALOG_ERC_CONTROL()
}
void DIALOG_ERC_CONTROL::onEngineFinished( bool aChecksPassed )
{
DIALOG_RULE_CHECK_CONTROL::onEngineFinished( aChecksPassed );
auto view = m_editFrame->GetCanvas()->GetView();
for( const auto& violation : getManager()->GetEngine<ERC_ENGINE>()->GetViolations() )
{
EDA_ITEM* first = violation->FirstItem();
EDA_ITEM* second = violation->SecondItem();
wxASSERT( first );
first->AddViolation( violation );
view->Update( first );
if( second )
{
second->AddViolation( violation );
view->Update( second );
}
}
m_editFrame->GetCanvas()->Refresh();
}
ERC_MANAGER* DIALOG_ERC_CONTROL::getManager()
{
return static_cast<ERC_MANAGER*>( m_manager );
......
......@@ -34,10 +34,6 @@ public:
~DIALOG_ERC_CONTROL();
protected:
void onEngineFinished( bool aChecksPassed ) override;
private:
ERC_MANAGER* getManager();
......
......@@ -43,12 +43,6 @@ bool ERC_ENGINE::Start()
}
double ERC_ENGINE::GetProgress()
{
return 1.0;
}
void ERC_ENGINE::WaitForFinish()
{
try
......
......@@ -41,8 +41,6 @@ public:
bool Start() override;
double GetProgress() override;
void WaitForFinish();
void Abort() override;
......
......@@ -286,7 +286,10 @@ SCH_PAINTER::SHADOW_TYPE SCH_PAINTER::getShadowType( const EDA_ITEM* aItem, int
if( aLayer != LAYER_SELECTION_SHADOWS )
return SHADOW_TYPE::NONE;
SHADOW_TYPE shadow = aItem->IsSelected() ? SHADOW_TYPE::SELECTION : SHADOW_TYPE::NONE;
if( aItem->IsSelected() )
return SHADOW_TYPE::SELECTION;
SHADOW_TYPE shadow = SHADOW_TYPE::NONE;
if( !aItem->GetViolationsList().empty() )
{
......
......@@ -24,6 +24,7 @@
#include <erc/erc_violation.h>
#include <id.h>
#include <sch_edit_frame.h>
#include <tool/tool_manager.h>
#include <tools/ee_actions.h>
#include <tools/erc_manager.h>
......@@ -46,6 +47,16 @@ void ERC_MANAGER::Reset( RESET_REASON aReason )
m_engine = new ERC_ENGINE;
static_cast<ERC_ENGINE*>( m_engine )->SetEditFrame( m_schFrame );
m_engine->SetCallbacks(
[&]( bool aResult )
{
onEngineFinished( aResult );
},
[&]( double aProgress, const wxString& aMsg )
{
onEngineProgress( aProgress, aMsg );
} );
}
......@@ -81,6 +92,48 @@ void ERC_MANAGER::ClearViolations()
}
int ERC_MANAGER::OnERCUpdate( const TOOL_EVENT& aEvent )
{
if( aEvent.Matches( ProgressEvent ) )
{
std::lock_guard<std::mutex> lock( m_mutex );
if( m_controlDialog )
m_controlDialog->OnEngineProgress( m_progress.load(), m_status );
return 0;
}
wxASSERT( aEvent.Matches( FinishedEvent ) );
if( m_controlDialog )
m_controlDialog->OnEngineFinished( aEvent.Parameter<bool>() );
auto view = m_schFrame->GetCanvas()->GetView();
for( const auto& violation : GetEngine<ERC_ENGINE>()->GetViolations() )
{
EDA_ITEM* first = violation->FirstItem();
EDA_ITEM* second = violation->SecondItem();
wxASSERT( first );
first->AddViolation( violation );
view->Update( first );
if( second )
{
second->AddViolation( violation );
view->Update( second );
}
}
m_schFrame->GetCanvas()->Refresh();
return 0;
}
void ERC_MANAGER::createControlDialog( wxWindow* aParent )
{
m_controlDialog = new DIALOG_ERC_CONTROL( this, m_schFrame, ID_DIALOG_ERC );
......@@ -91,4 +144,35 @@ void ERC_MANAGER::setTransitions()
{
if( ADVANCED_CFG::GetCfg().m_newErc )
Go( &ERC_MANAGER::ShowControlDialog, EE_ACTIONS::runERC.MakeEvent() );
Go( &ERC_MANAGER::OnERCUpdate, ProgressEvent );
Go( &ERC_MANAGER::OnERCUpdate, FinishedEvent );
}
void ERC_MANAGER::onEngineProgress( double aProgress, wxString aStatusMessage )
{
m_progress.store( aProgress );
std::lock_guard<std::mutex> lock( m_mutex );
m_status = aStatusMessage;
TOOL_EVENT evt = ProgressEvent;
m_toolMgr->PostEvent( evt );
}
void ERC_MANAGER::onEngineFinished( bool aChecksPassed )
{
TOOL_EVENT evt = FinishedEvent;
evt.SetParameter<bool>( aChecksPassed );
m_toolMgr->PostEvent( evt );
}
const TOOL_EVENT ERC_MANAGER::ProgressEvent(
TC_MESSAGE, TA_ACTION, "eeschema.ERCManager.progress" );
const TOOL_EVENT ERC_MANAGER::FinishedEvent(
TC_MESSAGE, TA_ACTION, "eeschema.ERCManager.finished" );
......@@ -42,12 +42,29 @@ public:
void ClearViolations() override;
int OnERCUpdate( const TOOL_EVENT& aEvent );
const static TOOL_EVENT ProgressEvent;
const static TOOL_EVENT FinishedEvent;
protected:
void onEngineFinished( bool aChecksPassed ) override;
void onEngineProgress( double aProgress, wxString aStatusMessage ) override;
private:
void createControlDialog( wxWindow* aParent ) override;
void setTransitions() override;
SCH_EDIT_FRAME* m_schFrame;
std::atomic<double> m_progress;
std::mutex m_mutex;
wxString m_status;
};
#endif
......@@ -46,8 +46,6 @@ public:
m_progressCallback = std::move( aProgressCallback );
}
virtual double GetProgress() = 0;
virtual void Abort() = 0;
std::vector<VIOLATION*>& GetViolations() { return m_violations; }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment