Remove GUI dialogs from PCB plugin.

This commit is contained in:
Jeff Young 2023-04-01 11:37:07 +01:00
parent aaae50f2aa
commit 04cdca837e
1 changed files with 82 additions and 77 deletions

View File

@ -907,40 +907,36 @@ BOARD* PCB_PARSER::parseBOARD_unchecked()
if( m_undefinedLayers.size() > 0 ) if( m_undefinedLayers.size() > 0 )
{ {
if( Pgm().IsGUI() ) PCB_LAYER_ID destLayer = Cmts_User;
wxString msg, undefinedLayerNames, destLayerName;
for( const wxString& layerName : m_undefinedLayers )
{ {
bool deleteItems; if( !undefinedLayerNames.IsEmpty() )
std::vector<BOARD_ITEM*> deleteList; undefinedLayerNames += wxT( ", " );
wxString msg = wxString::Format( _( "Items found on undefined layers. Do you wish to\n"
"rescue them to the User.Comments layer?" ) );
wxString details = wxString::Format( _( "Undefined layers:" ) );
for( const wxString& undefinedLayer : m_undefinedLayers ) undefinedLayerNames += layerName;
details += wxT( "\n " ) + undefinedLayer; }
wxRichMessageDialog dlg( nullptr, msg, _( "Warning" ), destLayerName = m_board->GetLayerName( destLayer );
wxYES_NO | wxCANCEL | wxCENTRE | wxICON_WARNING
| wxSTAY_ON_TOP );
dlg.ShowDetailedText( details );
dlg.SetYesNoCancelLabels( _( "Rescue" ), _( "Delete" ), _( "Cancel" ) );
switch( dlg.ShowModal() ) if( Pgm().IsGUI() && m_queryUserCallback )
{ {
case wxID_YES: deleteItems = false; break; msg.Printf( _( "Items found on undefined layers (%s).\n"
case wxID_NO: deleteItems = true; break; "Do you wish to rescue them to the %s layer?" ),
case wxID_CANCEL: undefinedLayerNames,
default: THROW_IO_ERROR( wxT( "CANCEL" ) ); destLayerName );
if( !(*m_queryUserCallback)( _( "Undefined Layers Warning" ), wxICON_WARNING, msg,
_( "Rescue" ) ) )
{
THROW_IO_ERROR( wxT( "CANCEL" ) );
} }
auto visitItem = [&]( BOARD_ITEM* curr_item ) auto visitItem = [&]( BOARD_ITEM* curr_item )
{ {
if( curr_item->GetLayer() == Rescue ) if( curr_item->GetLayer() == Rescue )
{ curr_item->SetLayer( destLayer );
if( deleteItems )
deleteList.push_back( curr_item );
else
curr_item->SetLayer( Cmts_User );
}
}; };
for( PCB_TRACK* track : m_board->Tracks() ) for( PCB_TRACK* track : m_board->Tracks() )
@ -956,10 +952,6 @@ BOARD* PCB_PARSER::parseBOARD_unchecked()
via->LayerPair( &top_layer, &bottom_layer ); via->LayerPair( &top_layer, &bottom_layer );
if( top_layer == Rescue || bottom_layer == Rescue ) if( top_layer == Rescue || bottom_layer == Rescue )
{
if( deleteItems )
deleteList.push_back( via );
else
{ {
if( top_layer == Rescue ) if( top_layer == Rescue )
top_layer = F_Cu; top_layer = F_Cu;
@ -970,7 +962,6 @@ BOARD* PCB_PARSER::parseBOARD_unchecked()
via->SetLayerPair( top_layer, bottom_layer ); via->SetLayerPair( top_layer, bottom_layer );
} }
} }
}
else else
{ {
visitItem( track ); visitItem( track );
@ -992,14 +983,12 @@ BOARD* PCB_PARSER::parseBOARD_unchecked()
visitItem( zone ); visitItem( zone );
} }
for( BOARD_ITEM* curr_item : deleteList )
m_board->Delete( curr_item );
m_undefinedLayers.clear(); m_undefinedLayers.clear();
} }
else else
{ {
THROW_IO_ERROR( wxT( "One or more undefined layers was found, open the project in the PCB Editor to resolve" ) ); THROW_IO_ERROR( wxT( "One or more undefined undefinedLayerNames was found; "
"open the board in the PCB Editor to resolve." ) );
} }
} }
@ -1035,26 +1024,25 @@ void PCB_PARSER::resolveGroups( BOARD_ITEM* aParent )
// //
// First add all group objects so subsequent GetItem() calls for nested groups work. // First add all group objects so subsequent GetItem() calls for nested groups work.
for( size_t idx = 0; idx < m_groupInfos.size(); idx++ ) for( const GROUP_INFO& groupInfo : m_groupInfos )
{ {
GROUP_INFO& aGrp = m_groupInfos[idx]; PCB_GROUP* group = new PCB_GROUP( groupInfo.parent );
PCB_GROUP* group = new PCB_GROUP( aGrp.parent );
group->SetName( aGrp.name ); group->SetName( groupInfo.name );
const_cast<KIID&>( group->m_Uuid ) = aGrp.uuid; const_cast<KIID&>( group->m_Uuid ) = groupInfo.uuid;
if( aGrp.locked ) if( groupInfo.locked )
group->SetLocked( true ); group->SetLocked( true );
if( aGrp.parent->Type() == PCB_FOOTPRINT_T ) if( groupInfo.parent->Type() == PCB_FOOTPRINT_T )
static_cast<FOOTPRINT*>( aGrp.parent )->Add( group, ADD_MODE::INSERT, true ); static_cast<FOOTPRINT*>( groupInfo.parent )->Add( group, ADD_MODE::INSERT, true );
else else
static_cast<BOARD*>( aGrp.parent )->Add( group, ADD_MODE::INSERT, true ); static_cast<BOARD*>( groupInfo.parent )->Add( group, ADD_MODE::INSERT, true );
} }
wxString error; wxString error;
for( PCB_PARSER::GROUP_INFO& groupInfo : m_groupInfos ) for( const GROUP_INFO& groupInfo : m_groupInfos )
{ {
if( PCB_GROUP* group = dynamic_cast<PCB_GROUP*>( getItem( groupInfo.uuid ) ) ) if( PCB_GROUP* group = dynamic_cast<PCB_GROUP*>( getItem( groupInfo.uuid ) ) )
{ {
@ -2156,27 +2144,26 @@ void PCB_PARSER::parseSetup()
{ {
if( m_showLegacy5ZoneWarning ) if( m_showLegacy5ZoneWarning )
{ {
if( Pgm().IsGUI() ) if( Pgm().IsGUI() && m_queryUserCallback )
{ {
// Thick outline fill mode no longer supported. Make sure user is OK with // Thick outline fill mode no longer supported. Make sure user is OK with
// converting fills. // converting fills.
KIDIALOG dlg( nullptr, if( !(*m_queryUserCallback)(
_( "The legacy zone fill strategy is no longer " _( "Legacy Zone Warning" ), wxICON_WARNING,
"supported.\nConvert zones to smoothed polygon " _( "The legacy zone fill strategy is no longer supported.\n"
"fills?" ), "Convert zones to smoothed polygon fills?" ),
_( "Legacy Zone Warning" ), wxYES_NO | wxICON_WARNING ); _( "Convert" ) ) )
{
dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
if( dlg.ShowModal() == wxID_NO )
THROW_IO_ERROR( wxT( "CANCEL" ) ); THROW_IO_ERROR( wxT( "CANCEL" ) );
}
m_showLegacy5ZoneWarning = false;
} }
else else
{ {
THROW_IO_ERROR( wxT( "Legacy zone fill strategy was found, open the project in the PCB Editor to resolve" ) ); THROW_IO_ERROR( wxT( "Legacy zone fill strategy was found; "
"open the board in the PCB Editor to resolve." ) );
} }
m_showLegacy5ZoneWarning = false;
} }
} }
@ -5098,7 +5085,9 @@ ZONE* PCB_PARSER::parseZONE( BOARD_ITEM_CONTAINER* aParent )
case T_filled_areas_thickness: case T_filled_areas_thickness:
if( parseBool() ) if( parseBool() )
{ {
if( m_showLegacy5ZoneWarning && m_queryUserCallback ) if( m_showLegacy5ZoneWarning )
{
if( Pgm().IsGUI() && m_queryUserCallback )
{ {
if( !(*m_queryUserCallback)( if( !(*m_queryUserCallback)(
_( "Legacy Zone Warning" ), wxICON_WARNING, _( "Legacy Zone Warning" ), wxICON_WARNING,
@ -5109,8 +5098,15 @@ ZONE* PCB_PARSER::parseZONE( BOARD_ITEM_CONTAINER* aParent )
THROW_IO_ERROR( wxT( "CANCEL" ) ); THROW_IO_ERROR( wxT( "CANCEL" ) );
} }
} }
else
{
THROW_IO_ERROR( wxT( "Legacy zone fill strategy was found; "
"open the board in the PCB Editor to resolve." ) );
}
m_showLegacy5ZoneWarning = false; m_showLegacy5ZoneWarning = false;
}
zone->SetFlags( CANDIDATE ); zone->SetFlags( CANDIDATE );
dropFilledPolygons = true; dropFilledPolygons = true;
} }
@ -5138,7 +5134,9 @@ ZONE* PCB_PARSER::parseZONE( BOARD_ITEM_CONTAINER* aParent )
if( token == T_segment ) // deprecated if( token == T_segment ) // deprecated
{ {
if( m_showLegacySegmentZoneWarning && m_queryUserCallback ) if( m_showLegacySegmentZoneWarning )
{
if( Pgm().IsGUI() && m_queryUserCallback )
{ {
if( !(*m_queryUserCallback)( if( !(*m_queryUserCallback)(
_( "Legacy Zone Warning" ), wxICON_WARNING, _( "Legacy Zone Warning" ), wxICON_WARNING,
@ -5149,8 +5147,15 @@ ZONE* PCB_PARSER::parseZONE( BOARD_ITEM_CONTAINER* aParent )
THROW_IO_ERROR( wxT( "CANCEL" ) ); THROW_IO_ERROR( wxT( "CANCEL" ) );
} }
} }
else
{
THROW_IO_ERROR( wxT( "Legacy segment zone fill strategy was found; "
"open the board in the PCB Editor to resolve." ) );
}
m_showLegacySegmentZoneWarning = false; m_showLegacySegmentZoneWarning = false;
}
zone->SetFlags( CANDIDATE ); zone->SetFlags( CANDIDATE );
zone->SetFillMode( ZONE_FILL_MODE::POLYGONS ); zone->SetFillMode( ZONE_FILL_MODE::POLYGONS );
m_board->SetModified(); m_board->SetModified();