mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-09-14 02:03:12 +02:00
Compare commits
4 Commits
9dd5edbab6
...
c04e2e8177
Author | SHA1 | Date | |
---|---|---|---|
|
c04e2e8177 | ||
|
36e38cd60a | ||
|
5fdfff2b9c | ||
|
733a379ca3 |
@ -289,13 +289,14 @@ bool FIELD_VALIDATOR::Validate( wxWindow* aParent )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool FIELD_VALIDATOR::DoValidate( const wxString& aValue, wxWindow* aParent )
|
wxString GetFieldValidationErrorMessage( FIELD_T aFieldId, const wxString& aValue )
|
||||||
{
|
{
|
||||||
wxString msg;
|
FIELD_VALIDATOR validator( aFieldId );
|
||||||
|
wxString msg;
|
||||||
|
|
||||||
if( HasFlag( wxFILTER_EMPTY ) && aValue.empty() )
|
if( validator.HasFlag( wxFILTER_EMPTY ) && aValue.empty() )
|
||||||
{
|
{
|
||||||
switch( m_fieldId )
|
switch( aFieldId )
|
||||||
{
|
{
|
||||||
case FIELD_T::SHEET_NAME: msg = _( "A sheet must have a name." ); break;
|
case FIELD_T::SHEET_NAME: msg = _( "A sheet must have a name." ); break;
|
||||||
case FIELD_T::SHEET_FILENAME: msg = _( "A sheet must have a file specified." ); break;
|
case FIELD_T::SHEET_FILENAME: msg = _( "A sheet must have a file specified." ); break;
|
||||||
@ -303,11 +304,11 @@ bool FIELD_VALIDATOR::DoValidate( const wxString& aValue, wxWindow* aParent )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( HasFlag( wxFILTER_EXCLUDE_CHAR_LIST ) && ContainsExcludedCharacters( aValue ) )
|
if( msg.empty() && validator.HasFlag( wxFILTER_EXCLUDE_CHAR_LIST ) )
|
||||||
{
|
{
|
||||||
wxArrayString badCharsFound;
|
wxArrayString badCharsFound;
|
||||||
|
|
||||||
for( const wxUniCharRef& excludeChar : GetCharExcludes() )
|
for( const wxUniCharRef& excludeChar : validator.GetCharExcludes() )
|
||||||
{
|
{
|
||||||
if( aValue.Find( excludeChar ) != wxNOT_FOUND )
|
if( aValue.Find( excludeChar ) != wxNOT_FOUND )
|
||||||
{
|
{
|
||||||
@ -324,68 +325,83 @@ bool FIELD_VALIDATOR::DoValidate( const wxString& aValue, wxWindow* aParent )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString badChars;
|
if( !badCharsFound.IsEmpty() )
|
||||||
|
|
||||||
for( size_t i = 0; i < badCharsFound.GetCount(); i++ )
|
|
||||||
{
|
{
|
||||||
if( !badChars.IsEmpty() )
|
wxString badChars;
|
||||||
|
|
||||||
|
for( size_t i = 0; i < badCharsFound.GetCount(); i++ )
|
||||||
{
|
{
|
||||||
if( badCharsFound.GetCount() == 2 )
|
if( !badChars.IsEmpty() )
|
||||||
{
|
{
|
||||||
badChars += _( " or " );
|
if( badCharsFound.GetCount() == 2 )
|
||||||
}
|
{
|
||||||
else
|
badChars += _( " or " );
|
||||||
{
|
}
|
||||||
if( i < badCharsFound.GetCount() - 2 )
|
|
||||||
badChars += _( ", or " );
|
|
||||||
else
|
else
|
||||||
badChars += wxT( ", " );
|
{
|
||||||
|
if( i < badCharsFound.GetCount() - 2 )
|
||||||
|
badChars += _( ", or " );
|
||||||
|
else
|
||||||
|
badChars += wxT( ", " );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
badChars += badCharsFound.Item( i );
|
||||||
}
|
}
|
||||||
|
|
||||||
badChars += badCharsFound.Item( i );
|
switch( aFieldId )
|
||||||
|
{
|
||||||
|
case FIELD_T::REFERENCE:
|
||||||
|
msg.Printf( _( "The reference designator cannot contain %s character(s)." ), badChars );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FIELD_T::VALUE:
|
||||||
|
msg.Printf( _( "The value field cannot contain %s character(s)." ), badChars );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FIELD_T::FOOTPRINT:
|
||||||
|
msg.Printf( _( "The footprint field cannot contain %s character(s)." ), badChars );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FIELD_T::DATASHEET:
|
||||||
|
msg.Printf( _( "The datasheet field cannot contain %s character(s)." ), badChars );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FIELD_T::SHEET_NAME:
|
||||||
|
msg.Printf( _( "The sheet name cannot contain %s character(s)." ), badChars );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FIELD_T::SHEET_FILENAME:
|
||||||
|
msg.Printf( _( "The sheet filename cannot contain %s character(s)." ), badChars );
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
msg.Printf( _( "The field cannot contain %s character(s)." ), badChars );
|
||||||
|
break;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch( m_fieldId )
|
if( msg.empty() )
|
||||||
|
{
|
||||||
|
if( aFieldId == FIELD_T::REFERENCE && aValue.Contains( wxT( "${" ) ) )
|
||||||
{
|
{
|
||||||
case FIELD_T::REFERENCE:
|
msg.Printf( _( "The reference designator cannot contain text variable references" ) );
|
||||||
msg.Printf( _( "The reference designator cannot contain %s character(s)." ), badChars );
|
}
|
||||||
break;
|
else if( aFieldId == FIELD_T::REFERENCE && UTIL::GetRefDesPrefix( aValue ).IsEmpty() )
|
||||||
|
{
|
||||||
case FIELD_T::VALUE:
|
msg.Printf( _( "References must start with a letter." ) );
|
||||||
msg.Printf( _( "The value field cannot contain %s character(s)." ), badChars );
|
}
|
||||||
break;
|
|
||||||
|
|
||||||
case FIELD_T::FOOTPRINT:
|
|
||||||
msg.Printf( _( "The footprint field cannot contain %s character(s)." ), badChars );
|
|
||||||
break;
|
|
||||||
|
|
||||||
case FIELD_T::DATASHEET:
|
|
||||||
msg.Printf( _( "The datasheet field cannot contain %s character(s)." ), badChars );
|
|
||||||
break;
|
|
||||||
|
|
||||||
case FIELD_T::SHEET_NAME:
|
|
||||||
msg.Printf( _( "The sheet name cannot contain %s character(s)." ), badChars );
|
|
||||||
break;
|
|
||||||
|
|
||||||
case FIELD_T::SHEET_FILENAME:
|
|
||||||
msg.Printf( _( "The sheet filename cannot contain %s character(s)." ), badChars );
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
msg.Printf( _( "The field cannot contain %s character(s)." ), badChars );
|
|
||||||
break;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
else if( m_fieldId == FIELD_T::REFERENCE && aValue.Contains( wxT( "${" ) ) )
|
|
||||||
{
|
|
||||||
msg.Printf( _( "The reference designator cannot contain text variable references" ) );
|
|
||||||
}
|
|
||||||
else if( m_fieldId == FIELD_T::REFERENCE && UTIL::GetRefDesPrefix( aValue ).IsEmpty() )
|
|
||||||
{
|
|
||||||
msg.Printf( _( "References must start with a letter." ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool FIELD_VALIDATOR::DoValidate( const wxString& aValue, wxWindow* aParent )
|
||||||
|
{
|
||||||
|
wxString msg = GetFieldValidationErrorMessage( m_fieldId, aValue );
|
||||||
|
|
||||||
if( !msg.empty() )
|
if( !msg.empty() )
|
||||||
{
|
{
|
||||||
if( m_validatorWindow )
|
if( m_validatorWindow )
|
||||||
|
@ -198,8 +198,11 @@ void SCH_LINE::Show( int nestLevel, std::ostream& os ) const
|
|||||||
|
|
||||||
std::vector<int> SCH_LINE::ViewGetLayers() const
|
std::vector<int> SCH_LINE::ViewGetLayers() const
|
||||||
{
|
{
|
||||||
return { LAYER_DANGLING, m_layer, LAYER_SELECTION_SHADOWS, LAYER_NET_COLOR_HIGHLIGHT,
|
if( IsWire() || IsBus() )
|
||||||
LAYER_OP_VOLTAGES };
|
return { LAYER_DANGLING, m_layer, LAYER_SELECTION_SHADOWS, LAYER_NET_COLOR_HIGHLIGHT,
|
||||||
|
LAYER_OP_VOLTAGES };
|
||||||
|
|
||||||
|
return { LAYER_DANGLING, m_layer, LAYER_SELECTION_SHADOWS, LAYER_OP_VOLTAGES };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1825,6 +1825,9 @@ void SCH_PAINTER::draw( const SCH_LINE* aLine, int aLayer )
|
|||||||
if( !highlightNetclassColors && drawingNetColorHighlights )
|
if( !highlightNetclassColors && drawingNetColorHighlights )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if( drawingNetColorHighlights && !( aLine->IsWire() || aLine->IsBus() ) )
|
||||||
|
return;
|
||||||
|
|
||||||
if( m_schSettings.m_OverrideItemColors && drawingNetColorHighlights )
|
if( m_schSettings.m_OverrideItemColors && drawingNetColorHighlights )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -46,6 +46,8 @@
|
|||||||
#include <settings/color_settings.h>
|
#include <settings/color_settings.h>
|
||||||
#include <settings/settings_manager.h>
|
#include <settings/settings_manager.h>
|
||||||
#include <trace_helpers.h>
|
#include <trace_helpers.h>
|
||||||
|
#include <validators.h>
|
||||||
|
#include <properties/property_validators.h>
|
||||||
#include <pgm_base.h>
|
#include <pgm_base.h>
|
||||||
#include <wx/log.h>
|
#include <wx/log.h>
|
||||||
|
|
||||||
@ -1657,7 +1659,21 @@ static struct SCH_SHEET_DESC
|
|||||||
propMgr.InheritsAfter( TYPE_HASH( SCH_SHEET ), TYPE_HASH( SCH_ITEM ) );
|
propMgr.InheritsAfter( TYPE_HASH( SCH_SHEET ), TYPE_HASH( SCH_ITEM ) );
|
||||||
|
|
||||||
propMgr.AddProperty( new PROPERTY<SCH_SHEET, wxString>( _HKI( "Sheet Name" ),
|
propMgr.AddProperty( new PROPERTY<SCH_SHEET, wxString>( _HKI( "Sheet Name" ),
|
||||||
&SCH_SHEET::SetName, &SCH_SHEET::GetName ) );
|
&SCH_SHEET::SetName, &SCH_SHEET::GetName ) )
|
||||||
|
.SetValidator( []( const wxAny&& aValue, EDA_ITEM* ) -> VALIDATOR_RESULT
|
||||||
|
{
|
||||||
|
wxString value;
|
||||||
|
|
||||||
|
if( !aValue.GetAs( &value ) )
|
||||||
|
return {};
|
||||||
|
|
||||||
|
wxString msg = GetFieldValidationErrorMessage( FIELD_T::SHEET_NAME, value );
|
||||||
|
|
||||||
|
if( msg.empty() )
|
||||||
|
return {};
|
||||||
|
|
||||||
|
return std::make_unique<VALIDATION_ERROR_MSG>( msg );
|
||||||
|
} );
|
||||||
|
|
||||||
propMgr.AddProperty( new PROPERTY<SCH_SHEET, int>( _HKI( "Border Width" ),
|
propMgr.AddProperty( new PROPERTY<SCH_SHEET, int>( _HKI( "Border Width" ),
|
||||||
&SCH_SHEET::SetBorderWidth, &SCH_SHEET::GetBorderWidth,
|
&SCH_SHEET::SetBorderWidth, &SCH_SHEET::GetBorderWidth,
|
||||||
|
@ -162,5 +162,11 @@ private:
|
|||||||
FIELD_T m_fieldId;
|
FIELD_T m_fieldId;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the error message if @a aValue is invalid for @a aFieldId.
|
||||||
|
* Returns an empty string when the value is valid.
|
||||||
|
*/
|
||||||
|
wxString GetFieldValidationErrorMessage( FIELD_T aFieldId, const wxString& aValue );
|
||||||
|
|
||||||
|
|
||||||
#endif // #ifndef VALIDATORS_H
|
#endif // #ifndef VALIDATORS_H
|
||||||
|
@ -54,6 +54,56 @@ void TEMPLATE_SELECTION_PANEL::AddTemplateWidget( TEMPLATE_WIDGET* aTemplateWidg
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Sort the widgets alphabetically, leaving Default at the top
|
||||||
|
void TEMPLATE_SELECTION_PANEL::SortAlphabetically()
|
||||||
|
{
|
||||||
|
std::vector<TEMPLATE_WIDGET*> sortedList;
|
||||||
|
TEMPLATE_WIDGET* default_temp = nullptr;
|
||||||
|
size_t count = m_SizerChoice->GetItemCount();
|
||||||
|
|
||||||
|
if( count <= 1 )
|
||||||
|
return;
|
||||||
|
|
||||||
|
for( size_t idx = 0; idx < count; idx++ )
|
||||||
|
{
|
||||||
|
wxSizerItem* item = m_SizerChoice->GetItem( idx );
|
||||||
|
if( item && item->IsWindow() )
|
||||||
|
{
|
||||||
|
TEMPLATE_WIDGET* temp = static_cast<TEMPLATE_WIDGET*>( item->GetWindow() );
|
||||||
|
|
||||||
|
const wxString title = *temp->GetTemplate()->GetTitle();
|
||||||
|
|
||||||
|
if( default_temp == nullptr && title.CmpNoCase( "default" ) == 0 )
|
||||||
|
default_temp = temp;
|
||||||
|
else
|
||||||
|
sortedList.push_back( temp );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::sort(
|
||||||
|
sortedList.begin(), sortedList.end(),
|
||||||
|
[]( TEMPLATE_WIDGET* aWidgetA, TEMPLATE_WIDGET* aWidgetB ) -> bool
|
||||||
|
{
|
||||||
|
const wxString* a = aWidgetA->GetTemplate()->GetTitle();
|
||||||
|
const wxString* b = aWidgetB->GetTemplate()->GetTitle();
|
||||||
|
|
||||||
|
return ( *a ).CmpNoCase( *b ) < 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
m_SizerChoice->Clear( false );
|
||||||
|
|
||||||
|
if( default_temp != nullptr )
|
||||||
|
m_SizerChoice->Add( default_temp );
|
||||||
|
|
||||||
|
for (TEMPLATE_WIDGET* temp : sortedList)
|
||||||
|
{
|
||||||
|
m_SizerChoice->Add( temp );
|
||||||
|
}
|
||||||
|
|
||||||
|
Layout();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
TEMPLATE_WIDGET::TEMPLATE_WIDGET( wxWindow* aParent, DIALOG_TEMPLATE_SELECTOR* aDialog ) :
|
TEMPLATE_WIDGET::TEMPLATE_WIDGET( wxWindow* aParent, DIALOG_TEMPLATE_SELECTOR* aDialog ) :
|
||||||
TEMPLATE_WIDGET_BASE( aParent )
|
TEMPLATE_WIDGET_BASE( aParent )
|
||||||
{
|
{
|
||||||
@ -337,6 +387,7 @@ void DIALOG_TEMPLATE_SELECTOR::buildPageContent( const wxString& aPath, int aPag
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_panels[aPage]->SortAlphabetically();
|
||||||
Layout();
|
Layout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,6 +81,8 @@ public:
|
|||||||
|
|
||||||
void AddTemplateWidget( TEMPLATE_WIDGET* aTemplateWidget );
|
void AddTemplateWidget( TEMPLATE_WIDGET* aTemplateWidget );
|
||||||
|
|
||||||
|
void SortAlphabetically();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
wxNotebookPage* m_parent;
|
wxNotebookPage* m_parent;
|
||||||
wxString m_templatesPath; ///< the path to access to the folder
|
wxString m_templatesPath; ///< the path to access to the folder
|
||||||
|
Loading…
x
Reference in New Issue
Block a user