Fix transient SPICE source field check logic

Fixes: lp:1743486
https://bugs.launchpad.net/kicad/+bug/1743486
This commit is contained in:
Dan Weatherill 2018-01-16 20:45:16 +00:00 committed by Maciej Suminski
parent c1649b1138
commit 590cac9d55
1 changed files with 29 additions and 31 deletions

View File

@ -535,43 +535,41 @@ bool DIALOG_SPICE_MODEL::generatePowerSource( wxString& aTarget ) const
if( genericProcessing ) if( genericProcessing )
{ {
bool finished = false;
unsigned int paramCounter = 0;
trans += "("; trans += "(";
for( auto textCtrl : genericControls ) auto isempty = [] ( wxTextCtrl* ctrl ) {
return empty( ctrl );
};
auto first_empty = std::find_if( genericControls.begin(), genericControls.end(), isempty );
if( std::distance( first_empty, genericControls.end() ) == 0 )
{ {
if( empty( textCtrl ) ) // all empty
{ useTrans = false;
finished = true; }
else if( std::distance( genericControls.begin(), first_empty ) < genericReqParamsCount )
if( paramCounter < genericReqParamsCount ) {
{ DisplayError( nullptr,
if( paramCounter == 0 ) wxString::Format( wxT( "You need to specify at least the "
{ "first %d parameters for the transient source" ),
// It is fine, no parameters were entered
useTrans = false;
break;
}
DisplayError( NULL,
wxString::Format( wxT( "You need to specify at least the "
"first %d parameters for the transient source" ),
genericReqParamsCount ) ); genericReqParamsCount ) );
return false; return false;
} }
} else if( std::find_if_not( first_empty, genericControls.end(),
else if( finished ) isempty ) != genericControls.end() )
{ {
DisplayError( NULL, wxT( "You cannot leave interleaved blank " DisplayError( nullptr, wxT( "You cannot leave interleaved blank "
"spaces for the transient source" ) ); "spaces for the transient source" ) );
return false; return false;
} }
else
trans += wxString::Format( "%s ", textCtrl->GetValue() ); {
++paramCounter; std::for_each( genericControls.begin(), first_empty,
[&trans] ( wxTextCtrl* ctrl ) {
trans += wxString::Format( "%s ", ctrl->GetValue() );
} );
} }
trans.Trim(); trans.Trim();