Add infobar error message for Autoplace when board not defined.

Fixes https://gitlab.com/kicad/code/kicad/issues/5425
This commit is contained in:
Jeff Young 2020-08-31 12:54:07 +01:00
parent d0479eb92c
commit 091f769106
5 changed files with 17 additions and 31 deletions

View File

@ -124,7 +124,7 @@ public:
* of time.
*
* @param aMessage is the message to display
* @param aTime is the amount of time to show the infobar
* @param aTime is the amount of time in microseconds to show the infobar
* @param aFlags is the flag containing the icon to display on the left side of the infobar
*/
void ShowMessageFor( const wxString& aMessage, int aTime, int aFlags = wxICON_INFORMATION );

View File

@ -257,7 +257,7 @@ set( PCBNEW_CLASS_SRCS
autorouter/spread_footprints.cpp
autorouter/ar_autoplacer.cpp
autorouter/ar_matrix.cpp
autorouter/autoplacer_tool.cpp
autorouter/autoplace_tool.cpp
action_plugin.cpp
array_creator.cpp

View File

@ -880,14 +880,13 @@ void AR_AUTOPLACER::drawPlacementRoutingMatrix( )
}
AR_RESULT AR_AUTOPLACER::AutoplaceModules( std::vector<MODULE*> aModules,
BOARD_COMMIT* aCommit, bool aPlaceOffboardModules )
AR_RESULT AR_AUTOPLACER::AutoplaceModules( std::vector<MODULE*>& aModules, BOARD_COMMIT* aCommit,
bool aPlaceOffboardModules )
{
wxPoint PosOK;
wxPoint memopos;
int error;
wxPoint memopos;
int error;
MODULE* module = nullptr;
bool cancelled = false;
bool cancelled = false;
memopos = m_curPosition;
@ -908,32 +907,30 @@ AR_RESULT AR_AUTOPLACER::AutoplaceModules( std::vector<MODULE*> aModules,
m->SetNeedsPlaced( false );
}
std::vector<MODULE *> offboardMods;
std::vector<MODULE*> offboardMods;
if( aPlaceOffboardModules )
{
for ( auto m : m_board->Modules() )
for( MODULE* m : m_board->Modules() )
{
if( !m_matrix.m_BrdBox.Contains( m->GetPosition() ) )
{
offboardMods.push_back( m );
}
}
}
for ( auto m : aModules )
for( MODULE* m : aModules )
{
m->SetNeedsPlaced( true );
aCommit->Modify(m);
}
for ( auto m : offboardMods )
for( MODULE* m : offboardMods )
{
m->SetNeedsPlaced( true );
aCommit->Modify(m);
}
for ( auto m : m_board->Modules() )
for( MODULE* m : m_board->Modules() )
{
if( m->NeedsPlaced() ) // Erase from screen
moduleCount++;
@ -972,7 +969,6 @@ AR_RESULT AR_AUTOPLACER::AutoplaceModules( std::vector<MODULE*> aModules,
double bestScore = m_minCost;
double bestRotation = 0.0;
int rotAllowed;
PosOK = m_curPosition;
if( error == AR_ABORT_PLACEMENT )
goto end_of_tst;
@ -988,7 +984,6 @@ AR_RESULT AR_AUTOPLACER::AutoplaceModules( std::vector<MODULE*> aModules,
if( bestScore > m_minCost ) // This orientation is better.
{
PosOK = m_curPosition;
bestScore = m_minCost;
bestRotation = 1800.0;
}
@ -1012,7 +1007,6 @@ AR_RESULT AR_AUTOPLACER::AutoplaceModules( std::vector<MODULE*> aModules,
if( bestScore > m_minCost ) // This orientation is better.
{
PosOK = m_curPosition;
bestScore = m_minCost;
bestRotation = 900.0;
}
@ -1034,7 +1028,6 @@ AR_RESULT AR_AUTOPLACER::AutoplaceModules( std::vector<MODULE*> aModules,
if( bestScore > m_minCost ) // This orientation is better.
{
PosOK = m_curPosition;
bestScore = m_minCost;
bestRotation = 2700.0;
}
@ -1090,10 +1083,8 @@ end_of_tst:
m_matrix.UnInitRoutingMatrix();
for ( auto m : m_board->Modules() )
{
for( MODULE* m : m_board->Modules() )
m->CalculateBoundingBox();
}
return cancelled ? AR_CANCELLED : AR_COMPLETED;
}

View File

@ -59,8 +59,8 @@ class AR_AUTOPLACER
public:
AR_AUTOPLACER( BOARD* aBoard );
AR_RESULT AutoplaceModules( std::vector<MODULE*> aModules, BOARD_COMMIT* aCommit,
bool aPlaceOffboardModules = false );
AR_RESULT AutoplaceModules( std::vector<MODULE*>& aModules, BOARD_COMMIT* aCommit,
bool aPlaceOffboardModules = false );
/**
* Set a VIEW overlay to draw items during a autoplace session.

View File

@ -23,17 +23,12 @@
#include <board_commit.h>
//#include <confirm.h>
//#include <tool/tool_manager.h>
//#include <view/view_controls.h>
//#include <bitmaps.h>
//#include <class_module.h>
#include <tools/pcb_actions.h>
#include <widgets/infobar.h>
#include <widgets/progress_reporter.h>
#include "ar_autoplacer.h"
#include "autoplacer_tool.h"
#include "autoplace_tool.h"
AUTOPLACE_TOOL::AUTOPLACE_TOOL() : PCB_TOOL_BASE( "pcbnew.Autoplacer" )
@ -73,7 +68,7 @@ int AUTOPLACE_TOOL::autoplace( std::vector<MODULE*>& aModules, bool aPlaceOffboa
wxString msg = wxString::Format( _( "Board edges must be defined on the %s layer." ),
LayerName( Edge_Cuts ) );
frame()->GetInfoBar()->ShowMessageFor( msg, 4000, wxICON_ERROR );
frame()->GetInfoBar()->ShowMessageFor( msg, 5000, wxICON_ERROR );
return 0;
}