Collapse LIB_FIELD into SCH_FIELD.

This commit is contained in:
Jeff Young 2024-04-12 22:00:41 +01:00
parent c241796968
commit d77eae3e7e
84 changed files with 1320 additions and 2439 deletions

View File

@ -79,7 +79,6 @@ KICAD_T FromProtoEnum( types::KiCadObjectType aValue )
case types::KiCadObjectType::KOT_LIB_TEXT: return LIB_TEXT_T;
case types::KiCadObjectType::KOT_LIB_TEXTBOX: return LIB_TEXTBOX_T;
case types::KiCadObjectType::KOT_LIB_PIN: return LIB_PIN_T;
case types::KiCadObjectType::KOT_LIB_FIELD: return LIB_FIELD_T;
case types::KiCadObjectType::KOT_WSG_LINE: return WSG_LINE_T;
case types::KiCadObjectType::KOT_WSG_RECT: return WSG_RECT_T;
case types::KiCadObjectType::KOT_WSG_POLY: return WSG_POLY_T;
@ -143,7 +142,6 @@ types::KiCadObjectType ToProtoEnum( KICAD_T aValue )
case LIB_TEXT_T: return types::KiCadObjectType::KOT_LIB_TEXT;
case LIB_TEXTBOX_T: return types::KiCadObjectType::KOT_LIB_TEXTBOX;
case LIB_PIN_T: return types::KiCadObjectType::KOT_LIB_PIN;
case LIB_FIELD_T: return types::KiCadObjectType::KOT_LIB_FIELD;
case WSG_LINE_T: return types::KiCadObjectType::KOT_WSG_LINE;
case WSG_RECT_T: return types::KiCadObjectType::KOT_WSG_RECT;
case WSG_POLY_T: return types::KiCadObjectType::KOT_WSG_POLY;

View File

@ -400,7 +400,6 @@ static struct EDA_ITEM_DESC
.Map( LIB_TEXT_T, _HKI( "Text" ) )
.Map( LIB_TEXTBOX_T, _HKI( "Text Box" ) )
.Map( LIB_PIN_T, _HKI( "Pin" ) )
.Map( LIB_FIELD_T, _HKI( "Symbol Field" ) )
.Map( GERBER_LAYOUT_T, _HKI( "Gerber Layout" ) )
.Map( GERBER_DRAW_ITEM_T, _HKI( "Draw Item" ) )

View File

@ -2775,21 +2775,15 @@ wxString CADSTAR_ARCHIVE_PARSER::HandleTextOverbar( wxString aCadstarString )
}
void CADSTAR_ARCHIVE_PARSER::FixTextPositionNoAlignment( EDA_TEXT* aKiCadTextItem )
void CADSTAR_ARCHIVE_PARSER::FixTextPositionNoAlignment( EDA_TEXT* aKiCadTextItem, bool aInvertY )
{
if( !aKiCadTextItem->GetText().IsEmpty() )
{
VECTOR2I positionOffset( 0, aKiCadTextItem->GetInterline() );
RotatePoint( positionOffset, aKiCadTextItem->GetTextAngle() );
EDA_ITEM* textEdaItem = dynamic_cast<EDA_ITEM*>( aKiCadTextItem );
if( textEdaItem &&
( textEdaItem->Type() == LIB_TEXT_T || textEdaItem->Type() == LIB_FIELD_T ) )
{
// Y coordinate increases upwards in the symbol editor
if( aInvertY )
positionOffset.y = -positionOffset.y;
}
//Count num of additional lines
wxString text = aKiCadTextItem->GetText();

View File

@ -1423,7 +1423,7 @@ public:
* provided text element has been initialised with a position and orientation.
* @param aKiCadTextItem a Kicad item to correct
*/
static void FixTextPositionNoAlignment( EDA_TEXT* aKiCadTextItem );
static void FixTextPositionNoAlignment( EDA_TEXT* aKiCadTextItem, bool aInvertY = false );
static wxString generateLibName( const wxString& aRefName, const wxString& aAlternateName );

View File

@ -208,12 +208,18 @@ void TEMPLATES::resolveTemplates()
for( const TEMPLATE_FIELDNAME& global : m_globals )
{
bool overriddenInProject = false;
for( const TEMPLATE_FIELDNAME& project : m_project )
{
if( global.m_Name == project.m_Name )
continue;
{
overriddenInProject = true;
break;
}
}
if( !overriddenInProject )
m_resolved.push_back( global );
}

View File

@ -361,7 +361,6 @@ set( EESCHEMA_SRCS
generate_alias_info.cpp
gfx_import_utils.cpp
picksymbol.cpp
lib_field.cpp
lib_pin.cpp
lib_shape.cpp
lib_symbol.cpp

View File

@ -18,7 +18,6 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <lib_field.h>
#include <lib_pin.h>
#include <lib_shape.h>
#include <lib_symbol.h>
@ -99,7 +98,6 @@ std::unique_ptr<EDA_ITEM> CreateItemForType( KICAD_T aType, EDA_ITEM* aContainer
case LIB_TEXT_T: return std::make_unique<LIB_TEXT>( parentLibSymbol );
case LIB_TEXTBOX_T: return std::make_unique<LIB_TEXTBOX>( parentLibSymbol );
case LIB_PIN_T: return std::make_unique<LIB_PIN>( parentLibSymbol );
case LIB_FIELD_T: return std::make_unique<LIB_FIELD>( parentLibSymbol );
default:
return nullptr;

View File

@ -285,7 +285,7 @@ void DIALOG_CHANGE_SYMBOLS::updateFieldsList()
// Load non-mandatory fields from all matching symbols and their library symbols
std::vector<SCH_FIELD*> fields;
std::vector<LIB_FIELD*> libFields;
std::vector<SCH_FIELD*> libFields;
std::set<wxString> fieldNames;
for( SCH_SHEET_PATH& instance : hierarchy )
@ -415,7 +415,7 @@ void DIALOG_CHANGE_SYMBOLS::onOkButtonClicked( wxCommandEvent& aEvent )
{
if( i < MANDATORY_FIELDS )
{
LIB_FIELD dummy_field( i );
SCH_FIELD dummy_field( nullptr, i );
m_updateFields.insert( dummy_field.GetCanonicalName() );
}
else
@ -636,7 +636,7 @@ int DIALOG_CHANGE_SYMBOLS::processSymbols( SCH_COMMIT* aCommit,
for( unsigned i = 0; i < symbol->GetFields().size(); ++i )
{
SCH_FIELD& field = symbol->GetFields()[i];
LIB_FIELD* libField = nullptr;
SCH_FIELD* libField = nullptr;
// Mandatory fields always exist in m_updateFields, but these names can be translated.
// so use GetCanonicalName().
@ -715,12 +715,12 @@ int DIALOG_CHANGE_SYMBOLS::processSymbols( SCH_COMMIT* aCommit,
}
}
std::vector<LIB_FIELD*> libFields;
std::vector<SCH_FIELD*> libFields;
symbol->GetLibSymbolRef()->GetFields( libFields );
for( unsigned i = MANDATORY_FIELDS; i < libFields.size(); ++i )
{
const LIB_FIELD& libField = *libFields[i];
const SCH_FIELD& libField = *libFields[i];
if( !alg::contains( m_updateFields, libField.GetCanonicalName() ) )
continue;

View File

@ -37,7 +37,6 @@
#include <sch_edit_frame.h>
#include <ee_collectors.h>
#include <sch_symbol.h>
#include <lib_field.h>
#include <template_fieldnames.h>
#include <symbol_library.h>
#include <sch_validators.h>
@ -50,19 +49,20 @@
DIALOG_FIELD_PROPERTIES::DIALOG_FIELD_PROPERTIES( SCH_BASE_FRAME* aParent, const wxString& aTitle,
const EDA_TEXT* aTextItem ) :
const SCH_FIELD* aField ) :
DIALOG_FIELD_PROPERTIES_BASE( aParent, wxID_ANY, aTitle ),
m_posX( aParent, m_xPosLabel, m_xPosCtrl, m_xPosUnits, true ),
m_posY( aParent, m_yPosLabel, m_yPosCtrl, m_yPosUnits, true ),
m_textSize( aParent, m_textSizeLabel, m_textSizeCtrl, m_textSizeUnits, true ),
m_font( nullptr ),
m_firstFocus( true ),
m_scintillaTricks( nullptr )
m_scintillaTricks( nullptr ),
m_field( aField )
{
COLOR_SETTINGS* colorSettings = aParent->GetColorSettings();
COLOR4D schematicBackground = colorSettings->GetColor( LAYER_SCHEMATIC_BACKGROUND );
wxASSERT( aTextItem );
wxASSERT( m_field );
m_note->SetFont( KIUI::GetInfoFont( this ).Italic() );
m_note->Show( false );
@ -134,20 +134,142 @@ DIALOG_FIELD_PROPERTIES::DIALOG_FIELD_PROPERTIES( SCH_BASE_FRAME* aParent, const
m_vAlignCenter->Bind( wxEVT_BUTTON, &DIALOG_FIELD_PROPERTIES::onVAlignButton, this );
m_vAlignBottom->Bind( wxEVT_BUTTON, &DIALOG_FIELD_PROPERTIES::onVAlignButton, this );
m_text = aTextItem->GetText();
m_isItalic = aTextItem->IsItalic();
m_isBold = aTextItem->IsBold();
m_color = aTextItem->GetTextColor();
m_position = aTextItem->GetTextPos();
m_size = aTextItem->GetTextWidth();
m_isVertical = aTextItem->GetTextAngle().IsVertical();
m_verticalJustification = aTextItem->GetVertJustify();
m_horizontalJustification = aTextItem->GetHorizJustify();
m_isVisible = aTextItem->IsVisible();
// show text variable cross-references in a human-readable format
if( aField->Schematic() )
m_text = aField->Schematic()->ConvertKIIDsToRefs( aField->GetText() );
else
m_text = aField->GetText();
// These should be initialized in the child classes implementing dialogs for lib and sch items.
m_isNameVisible = false;
m_allowAutoplace = true;
m_font = m_field->GetFont();
m_isItalic = aField->IsItalic();
m_isBold = aField->IsBold();
m_color = aField->GetTextColor();
m_position = aField->GetTextPos();
m_size = aField->GetTextWidth();
m_isVertical = aField->GetTextAngle().IsVertical();
m_verticalJustification = aField->GetVertJustify();
m_horizontalJustification = aField->GetHorizJustify();
m_isVisible = aField->IsVisible();
m_isSheetFilename = false;
if( aField->GetParent() && aField->GetParent()->Type() == LIB_SYMBOL_T )
{
const LIB_SYMBOL* symbol = static_cast<const LIB_SYMBOL*>( aField->GetParentSymbol() );
/*
* Symbol netlist format:
* pinNumber pinName <tab> pinNumber pinName...
* fpFilter fpFilter...
*/
wxString netlist;
std::vector<LIB_PIN*> pinList;
symbol->GetPins( pinList, 0, 1 ); // All units, but a single convert
wxArrayString pins;
for( LIB_PIN* pin : pinList )
pins.push_back( pin->GetNumber() + ' ' + pin->GetShownName() );
if( !pins.IsEmpty() )
netlist << EscapeString( wxJoin( pins, '\t' ), CTX_LINE );
netlist << wxS( "\r" );
wxArrayString fpFilters = symbol->GetFPFilters();
if( !fpFilters.IsEmpty() )
netlist << EscapeString( wxJoin( fpFilters, ' ' ), CTX_LINE );
netlist << wxS( "\r" );
m_netlist = netlist;
}
else if( aField->GetParent() && aField->GetParent()->Type() == SCH_SYMBOL_T )
{
const SCH_SYMBOL* symbol = static_cast<const SCH_SYMBOL*>( aField->GetParentSymbol() );
SCH_SHEET_PATH sheetPath = static_cast<SCH_EDIT_FRAME*>( aParent )->GetCurrentSheet();
m_fieldId = aField->GetId();
/*
* Symbol netlist format:
* pinNumber pinName <tab> pinNumber pinName...
* fpFilter fpFilter...
*/
wxString netlist;
wxArrayString pins;
for( SCH_PIN* pin : symbol->GetPins( &sheetPath ) )
pins.push_back( pin->GetNumber() + ' ' + pin->GetShownName() );
if( !pins.IsEmpty() )
netlist << EscapeString( wxJoin( pins, '\t' ), CTX_LINE );
netlist << wxS( "\r" );
wxArrayString fpFilters = symbol->GetLibSymbolRef()->GetFPFilters();
if( !fpFilters.IsEmpty() )
netlist << EscapeString( wxJoin( fpFilters, ' ' ), CTX_LINE );
netlist << wxS( "\r" );
m_netlist = netlist;
}
else if( aField->GetParent() && aField->GetParent()->Type() == SCH_SHEET_T )
{
switch( aField->GetId() )
{
case SHEETNAME:
m_fieldId = SHEETNAME_V;
break;
case SHEETFILENAME:
m_isSheetFilename = true;
m_fieldId = SHEETFILENAME_V;
m_note->SetLabel( wxString::Format( m_note->GetLabel(),
_( "Sheet filename can only be modified in Sheet Properties dialog." ) ) );
m_note->Show( true );
break;
default:
m_fieldId = SHEETUSERFIELD_V;
break;
}
}
else if( aField->GetParent() && aField->GetParent()->IsType( { SCH_LABEL_LOCATE_ANY_T } ) )
{
m_fieldId = LABELUSERFIELD_V;
}
m_textLabel->SetLabel( aField->GetName() + wxS( ":" ) );
m_position = m_field->GetPosition();
m_isNameVisible = m_field->IsNameShown();
m_allowAutoplace = m_field->CanAutoplace();
m_horizontalJustification = m_field->GetEffectiveHorizJustify();
m_verticalJustification = m_field->GetEffectiveVertJustify();
m_StyledTextCtrl->Bind( wxEVT_STC_CHARADDED,
&DIALOG_FIELD_PROPERTIES::onScintillaCharAdded, this );
m_StyledTextCtrl->Bind( wxEVT_STC_AUTOCOMP_CHAR_DELETED,
&DIALOG_FIELD_PROPERTIES::onScintillaCharAdded, this );
m_nameVisible->Show();
m_cbAllowAutoPlace->Show();
init();
if( m_isSheetFilename || m_field->IsNamedVariable() )
{
m_StyledTextCtrl->Enable( false );
m_TextCtrl->Enable( false );
}
}
@ -414,63 +536,7 @@ void DIALOG_FIELD_PROPERTIES::updateText( EDA_TEXT* aText )
}
DIALOG_LIB_FIELD_PROPERTIES::DIALOG_LIB_FIELD_PROPERTIES( SCH_BASE_FRAME* aParent,
const wxString& aTitle,
const LIB_FIELD* aField ) :
DIALOG_FIELD_PROPERTIES( aParent, aTitle, aField )
{
m_fieldId = aField->GetId();
m_isNameVisible = aField->IsNameShown();
m_allowAutoplace = aField->CanAutoplace();
if( m_fieldId == VALUE_FIELD )
m_text = UnescapeString( aField->GetText() );
if( m_fieldId == FOOTPRINT_FIELD )
{
const LIB_SYMBOL* parentSymbol = static_cast<const LIB_SYMBOL*>( aField->GetParentSymbol() );
/*
* Symbol netlist format:
* pinNumber pinName <tab> pinNumber pinName...
* fpFilter fpFilter...
*/
wxString netlist;
std::vector<LIB_PIN*> pinList;
parentSymbol->GetPins( pinList, 0, 1 ); // All units, but a single convert
wxArrayString pins;
for( LIB_PIN* pin : pinList )
pins.push_back( pin->GetNumber() + ' ' + pin->GetShownName() );
if( !pins.IsEmpty() )
netlist << EscapeString( wxJoin( pins, '\t' ), CTX_LINE );
netlist << wxS( "\r" );
wxArrayString fpFilters = parentSymbol->GetFPFilters();
if( !fpFilters.IsEmpty() )
netlist << EscapeString( wxJoin( fpFilters, ' ' ), CTX_LINE );
netlist << wxS( "\r" );
m_netlist = netlist;
}
m_font = aField->GetFont();
m_nameVisible->Show();
m_cbAllowAutoPlace->Show();
init();
}
void DIALOG_LIB_FIELD_PROPERTIES::UpdateField( LIB_FIELD* aField )
void DIALOG_FIELD_PROPERTIES::UpdateField( SCH_FIELD* aField )
{
aField->SetText( m_text );
@ -485,113 +551,13 @@ void DIALOG_LIB_FIELD_PROPERTIES::UpdateField( LIB_FIELD* aField )
}
DIALOG_SCH_FIELD_PROPERTIES::DIALOG_SCH_FIELD_PROPERTIES( SCH_EDIT_FRAME* aParent,
const wxString& aTitle,
const SCH_FIELD* aField ) :
DIALOG_FIELD_PROPERTIES( aParent, aTitle, aField ),
m_field( aField )
{
m_isSheetFilename = false;
if( aField->GetParent() && aField->GetParent()->Type() == SCH_SYMBOL_T )
{
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( aField->GetParent() );
SCH_SHEET_PATH sheetPath = aParent->GetCurrentSheet();
m_fieldId = aField->GetId();
/*
* Symbol netlist format:
* pinNumber pinName <tab> pinNumber pinName...
* fpFilter fpFilter...
*/
wxString netlist;
wxArrayString pins;
for( SCH_PIN* pin : symbol->GetPins( &sheetPath ) )
pins.push_back( pin->GetNumber() + ' ' + pin->GetShownName() );
if( !pins.IsEmpty() )
netlist << EscapeString( wxJoin( pins, '\t' ), CTX_LINE );
netlist << wxS( "\r" );
wxArrayString fpFilters = symbol->GetLibSymbolRef()->GetFPFilters();
if( !fpFilters.IsEmpty() )
netlist << EscapeString( wxJoin( fpFilters, ' ' ), CTX_LINE );
netlist << wxS( "\r" );
m_netlist = netlist;
}
else if( aField->GetParent() && aField->GetParent()->Type() == SCH_SHEET_T )
{
switch( aField->GetId() )
{
case SHEETNAME:
m_fieldId = SHEETNAME_V;
break;
case SHEETFILENAME:
m_isSheetFilename = true;
m_fieldId = SHEETFILENAME_V;
m_note->SetLabel( wxString::Format( m_note->GetLabel(),
_( "Sheet filename can only be modified in Sheet Properties dialog." ) ) );
m_note->Show( true );
break;
default:
m_fieldId = SHEETUSERFIELD_V;
break;
}
}
else if( aField->GetParent() && aField->GetParent()->IsType( { SCH_LABEL_LOCATE_ANY_T } ) )
{
m_fieldId = LABELUSERFIELD_V;
}
// show text variable cross-references in a human-readable format
m_text = aField->Schematic()->ConvertKIIDsToRefs( aField->GetText() );
m_font = m_field->GetFont();
m_textLabel->SetLabel( aField->GetName() + wxS( ":" ) );
m_position = m_field->GetPosition();
m_isNameVisible = m_field->IsNameShown();
m_allowAutoplace = m_field->CanAutoplace();
m_horizontalJustification = m_field->GetEffectiveHorizJustify();
m_verticalJustification = m_field->GetEffectiveVertJustify();
m_StyledTextCtrl->Bind( wxEVT_STC_CHARADDED, &DIALOG_SCH_FIELD_PROPERTIES::onScintillaCharAdded,
this );
m_StyledTextCtrl->Bind( wxEVT_STC_AUTOCOMP_CHAR_DELETED,
&DIALOG_SCH_FIELD_PROPERTIES::onScintillaCharAdded, this );
m_nameVisible->Show();
m_cbAllowAutoPlace->Show();
init();
if( m_isSheetFilename || m_field->IsNamedVariable() )
{
m_StyledTextCtrl->Enable( false );
m_TextCtrl->Enable( false );
}
}
void DIALOG_SCH_FIELD_PROPERTIES::onScintillaCharAdded( wxStyledTextEvent &aEvent )
void DIALOG_FIELD_PROPERTIES::onScintillaCharAdded( wxStyledTextEvent &aEvent )
{
m_field->OnScintillaCharAdded( m_scintillaTricks, aEvent );
}
void DIALOG_SCH_FIELD_PROPERTIES::UpdateField( SCH_COMMIT* aCommit, SCH_FIELD* aField,
void DIALOG_FIELD_PROPERTIES::UpdateField( SCH_COMMIT* aCommit, SCH_FIELD* aField,
SCH_SHEET_PATH* aSheetPath )
{
SCH_EDIT_FRAME* editFrame = dynamic_cast<SCH_EDIT_FRAME*>( GetParent() );

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2016 Wayne Stambaugh, stambaughw@gmail.com
* Copyright (C) 2004-2022 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2004-2024 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -28,8 +28,6 @@
#include <dialog_field_properties_base.h>
#include <widgets/unit_binder.h>
#include <lib_field.h>
#include <template_fieldnames.h>
class SCH_BASE_FRAME;
class SCH_FIELD;
@ -39,8 +37,6 @@ class SCH_COMMIT;
/**
* A base class to edit schematic and symbol library fields.
*
* This class is setup in expectation of its children possibly using Kiway player so
* #DIALOG_SHIM::ShowQuasiModal is required when calling any subclasses.
*/
@ -48,22 +44,28 @@ class DIALOG_FIELD_PROPERTIES : public DIALOG_FIELD_PROPERTIES_BASE
{
public:
DIALOG_FIELD_PROPERTIES( SCH_BASE_FRAME* aParent, const wxString& aTitle,
const EDA_TEXT* aTextItem );
const SCH_FIELD* aField );
~DIALOG_FIELD_PROPERTIES() override;
bool TransferDataToWindow() override;
bool TransferDataFromWindow() override;
SCH_BASE_FRAME* GetParent() { return dynamic_cast< SCH_BASE_FRAME* >( wxDialog::GetParent() ); }
SCH_BASE_FRAME* GetParent() { return dynamic_cast<SCH_BASE_FRAME*>( wxDialog::GetParent() ); }
const wxString& GetText() const { return m_text; }
void UpdateField( SCH_FIELD* aField );
void UpdateField( SCH_COMMIT* aCommit, SCH_FIELD* aField, SCH_SHEET_PATH* aSheetPath );
protected:
void init();
void updateText( EDA_TEXT* aText );
void onScintillaCharAdded( wxStyledTextEvent &aEvent );
/**
* Handle the select button next to the text value field. The current assumption
* is that this event will only be enabled for footprint type fields. In the future
@ -78,7 +80,7 @@ protected:
* Used to select the variant part of some text fields (for instance, the question mark
* or number in a reference).
*/
virtual void OnSetFocusText( wxFocusEvent& event ) override;
void OnSetFocusText( wxFocusEvent& event ) override;
void onOrientButton( wxCommandEvent &aEvent );
void onHAlignButton( wxCommandEvent &aEvent );
@ -108,44 +110,7 @@ protected:
SCINTILLA_TRICKS* m_scintillaTricks;
std::string m_netlist;
};
/**
* Handle editing a single symbol field in the symbol editor.
*
* @note Use ShowQuasiModal when calling this class!
*/
class DIALOG_LIB_FIELD_PROPERTIES : public DIALOG_FIELD_PROPERTIES
{
public:
DIALOG_LIB_FIELD_PROPERTIES( SCH_BASE_FRAME* aParent, const wxString& aTitle,
const LIB_FIELD* aField );
~DIALOG_LIB_FIELD_PROPERTIES() {}
void UpdateField( LIB_FIELD* aField );
};
/**
* Handle editing a single symbol field in the schematic editor.
*
* @note Use ShowQuasiModal when calling this class!
*/
class DIALOG_SCH_FIELD_PROPERTIES : public DIALOG_FIELD_PROPERTIES
{
public:
DIALOG_SCH_FIELD_PROPERTIES( SCH_EDIT_FRAME* aParent, const wxString& aTitle,
const SCH_FIELD* aField );
~DIALOG_SCH_FIELD_PROPERTIES() {}
void onScintillaCharAdded( wxStyledTextEvent &aEvent );
void UpdateField( SCH_COMMIT* aCommit, SCH_FIELD* aField, SCH_SHEET_PATH* aSheetPath );
private:
const SCH_FIELD* m_field;
bool m_isSheetFilename;
};

View File

@ -54,7 +54,7 @@ DIALOG_LABEL_PROPERTIES::DIALOG_LABEL_PROPERTIES( SCH_EDIT_FRAME* aParent, SCH_L
COLOR_SETTINGS* colorSettings = m_Parent->GetColorSettings();
COLOR4D schematicBackground = colorSettings->GetColor( LAYER_SCHEMATIC_BACKGROUND );
m_fields = new FIELDS_GRID_TABLE<SCH_FIELD>( this, aParent, m_grid, m_currentLabel );
m_fields = new FIELDS_GRID_TABLE( this, aParent, m_grid, m_currentLabel );
m_width = 100; // Will be later set to a better value
m_delayedFocusRow = -1;
m_delayedFocusColumn = FDC_VALUE;
@ -407,7 +407,7 @@ static bool positioningChanged( const SCH_FIELD& a, const SCH_FIELD& b )
}
static bool positioningChanged( FIELDS_GRID_TABLE<SCH_FIELD>* a, std::vector<SCH_FIELD>& b )
static bool positioningChanged( FIELDS_GRID_TABLE* a, std::vector<SCH_FIELD>& b )
{
for( size_t i = 0; i < a->size() && i < b.size(); ++i )
{

View File

@ -70,7 +70,7 @@ private:
wxTextEntry* m_activeTextEntry;
SCH_NETNAME_VALIDATOR m_netNameValidator;
FIELDS_GRID_TABLE<SCH_FIELD>* m_fields;
FIELDS_GRID_TABLE* m_fields;
std::bitset<64> m_shownColumns;
UNIT_BINDER m_textSize;

View File

@ -62,7 +62,7 @@ DIALOG_LIB_SYMBOL_PROPERTIES::DIALOG_LIB_SYMBOL_PROPERTIES( SYMBOL_EDIT_FRAME* a
{
// Give a bit more room for combobox editors
m_grid->SetDefaultRowSize( m_grid->GetDefaultRowSize() + 4 );
m_fields = new FIELDS_GRID_TABLE<LIB_FIELD>( this, aParent, m_grid, m_libEntry );
m_fields = new FIELDS_GRID_TABLE( this, aParent, m_grid, m_libEntry );
m_grid->SetTable( m_fields );
m_grid->PushEventHandler( new FIELDS_GRID_TRICKS( m_grid, this,
[&]( wxCommandEvent& aEvent )
@ -256,7 +256,7 @@ bool DIALOG_LIB_SYMBOL_PROPERTIES::Validate()
// Check for missing field names.
for( int ii = MANDATORY_FIELDS; ii < (int) m_fields->size(); ++ii )
{
LIB_FIELD& field = m_fields->at( ii );
SCH_FIELD& field = m_fields->at( ii );
wxString fieldName = field.GetName( false );
if( fieldName.IsEmpty() && !field.GetText().IsEmpty() )
@ -359,7 +359,7 @@ bool DIALOG_LIB_SYMBOL_PROPERTIES::TransferDataFromWindow()
for( int ii = m_fields->GetNumberRows() - 1; ii >= MANDATORY_FIELDS; ii-- )
{
LIB_FIELD& field = m_fields->at( ii );
SCH_FIELD& field = m_fields->at( ii );
const wxString& fieldName = field.GetCanonicalName();
if( fieldName.IsEmpty() && field.GetText().IsEmpty() )
@ -512,7 +512,7 @@ void DIALOG_LIB_SYMBOL_PROPERTIES::OnAddField( wxCommandEvent& event )
SYMBOL_EDITOR_SETTINGS* settings = m_Parent->GetSettings();
int fieldID = (int) m_fields->size();
LIB_FIELD newField( m_libEntry, fieldID );
SCH_FIELD newField( m_libEntry, fieldID );
newField.SetTextSize( VECTOR2I( schIUScale.MilsToIU( settings->m_Defaults.text_size ),
schIUScale.MilsToIU( settings->m_Defaults.text_size ) ) );
@ -587,7 +587,7 @@ void DIALOG_LIB_SYMBOL_PROPERTIES::OnMoveUp( wxCommandEvent& event )
if( i > MANDATORY_FIELDS )
{
LIB_FIELD tmp = m_fields->at( (unsigned) i );
SCH_FIELD tmp = m_fields->at( (unsigned) i );
m_fields->erase( m_fields->begin() + i, m_fields->begin() + i + 1 );
m_fields->insert( m_fields->begin() + i - 1, tmp );
m_grid->ForceRefresh();
@ -613,7 +613,7 @@ void DIALOG_LIB_SYMBOL_PROPERTIES::OnMoveDown( wxCommandEvent& event )
if( i >= MANDATORY_FIELDS && i + 1 < m_fields->GetNumberRows() )
{
LIB_FIELD tmp = m_fields->at( (unsigned) i );
SCH_FIELD tmp = m_fields->at( (unsigned) i );
m_fields->erase( m_fields->begin() + i, m_fields->begin() + i + 1 );
m_fields->insert( m_fields->begin() + i + 1, tmp );
m_grid->ForceRefresh();
@ -635,9 +635,9 @@ void DIALOG_LIB_SYMBOL_PROPERTIES::OnEditSpiceModel( wxCommandEvent& event )
if( !m_grid->CommitPendingChanges() )
return;
std::vector<LIB_FIELD> fields;
std::vector<SCH_FIELD> fields;
for( const LIB_FIELD& field : *m_fields )
for( const SCH_FIELD& field : *m_fields )
fields.emplace_back( field );
DIALOG_SIM_MODEL dialog( this, m_parentFrame, *m_libEntry, fields );
@ -646,11 +646,11 @@ void DIALOG_LIB_SYMBOL_PROPERTIES::OnEditSpiceModel( wxCommandEvent& event )
return;
// Add in any new fields
for( const LIB_FIELD& editedField : fields )
for( const SCH_FIELD& editedField : fields )
{
bool found = false;
for( LIB_FIELD& existingField : *m_fields )
for( SCH_FIELD& existingField : *m_fields )
{
if( existingField.GetName() == editedField.GetName() )
{
@ -671,10 +671,10 @@ void DIALOG_LIB_SYMBOL_PROPERTIES::OnEditSpiceModel( wxCommandEvent& event )
// Remove any deleted fields
for( int ii = (int) m_fields->size() - 1; ii >= 0; --ii )
{
LIB_FIELD& existingField = m_fields->at( ii );
SCH_FIELD& existingField = m_fields->at( ii );
bool found = false;
for( LIB_FIELD& editedField : fields )
for( SCH_FIELD& editedField : fields )
{
if( editedField.GetName() == existingField.GetName() )
{

View File

@ -78,7 +78,7 @@ public:
SYMBOL_EDIT_FRAME* m_Parent;
LIB_SYMBOL* m_libEntry;
FIELDS_GRID_TABLE<LIB_FIELD>* m_fields;
FIELDS_GRID_TABLE* m_fields;
UNIT_BINDER m_pinNameOffset;

View File

@ -57,7 +57,7 @@ DIALOG_SHEET_PROPERTIES::DIALOG_SHEET_PROPERTIES( SCH_EDIT_FRAME* aParent, SCH_S
m_dummySheetNameField( VECTOR2I( -1, -1 ), SHEETNAME, &m_dummySheet )
{
m_sheet = aSheet;
m_fields = new FIELDS_GRID_TABLE<SCH_FIELD>( this, aParent, m_grid, m_sheet );
m_fields = new FIELDS_GRID_TABLE( this, aParent, m_grid, m_sheet );
m_delayedFocusRow = SHEETNAME;
m_delayedFocusColumn = FDC_VALUE;
@ -246,7 +246,7 @@ static bool positioningChanged( const SCH_FIELD& a, const SCH_FIELD& b )
}
static bool positioningChanged( FIELDS_GRID_TABLE<SCH_FIELD>* a, std::vector<SCH_FIELD>& b )
static bool positioningChanged( FIELDS_GRID_TABLE* a, std::vector<SCH_FIELD>& b )
{
for( size_t i = 0; i < SHEET_MANDATORY_FIELDS; ++i )
{

View File

@ -74,7 +74,7 @@ private:
int m_delayedFocusColumn;
std::bitset<64> m_shownColumns;
FIELDS_GRID_TABLE<SCH_FIELD>* m_fields;
FIELDS_GRID_TABLE* m_fields;
UNIT_BINDER m_borderWidth;
SCH_SHEET m_dummySheet;

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 2022 Mikolaj Wielgus
* Copyright (C) 2022 CERN
* Copyright (C) 2022-2023 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2022-2024 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -27,7 +27,6 @@
#include <dialog_sim_model.h>
#include <sim/sim_property.h>
#include <sim/sim_library_kibis.h>
#include <sim/sim_library_spice.h>
#include <sim/sim_model.h>
#include <sim/sim_model_kibis.h>
#include <sim/sim_model_raw_spice.h>
@ -41,7 +40,6 @@
#include <string_utils.h>
#include <locale_io.h>
#include <wx/filedlg.h>
#include <wx/textfile.h>
#include <fmt/format.h>
#include <sch_edit_frame.h>
#include <sim/sim_model_l_mutual.h>
@ -61,10 +59,9 @@ bool equivalent( SIM_MODEL::DEVICE_T a, SIM_MODEL::DEVICE_T b )
};
template <typename T_symbol, typename T_field>
DIALOG_SIM_MODEL<T_symbol, T_field>::DIALOG_SIM_MODEL( wxWindow* aParent, EDA_BASE_FRAME* aFrame,
T_symbol& aSymbol,
std::vector<T_field>& aFields ) :
template <typename T>
DIALOG_SIM_MODEL<T>::DIALOG_SIM_MODEL( wxWindow* aParent, EDA_BASE_FRAME* aFrame, T& aSymbol,
std::vector<SCH_FIELD>& aFields ) :
DIALOG_SIM_MODEL_BASE( aParent ),
m_frame( aFrame ),
m_symbol( aSymbol ),
@ -140,8 +137,8 @@ DIALOG_SIM_MODEL<T_symbol, T_field>::DIALOG_SIM_MODEL( wxWindow* aParent, EDA_BA
}
template <typename T_symbol, typename T_field>
DIALOG_SIM_MODEL<T_symbol, T_field>::~DIALOG_SIM_MODEL()
template <typename T>
DIALOG_SIM_MODEL<T>::~DIALOG_SIM_MODEL()
{
// Disable all properties. This is necessary because some of their methods are called after
// destruction of DIALOG_SIM_MODEL, oddly. When disabled, they never access their models.
@ -163,8 +160,8 @@ DIALOG_SIM_MODEL<T_symbol, T_field>::~DIALOG_SIM_MODEL()
}
template <typename T_symbol, typename T_field>
bool DIALOG_SIM_MODEL<T_symbol, T_field>::TransferDataToWindow()
template <typename T>
bool DIALOG_SIM_MODEL<T>::TransferDataToWindow()
{
wxCommandEvent dummyEvent;
wxString deviceType;
@ -179,7 +176,7 @@ bool DIALOG_SIM_MODEL<T_symbol, T_field>::TransferDataToWindow()
auto setFieldValue =
[&]( const wxString& aFieldName, const wxString& aValue )
{
for( T_field& field : m_fields )
for( SCH_FIELD& field : m_fields )
{
if( field.GetName() == aFieldName )
{
@ -343,8 +340,8 @@ bool DIALOG_SIM_MODEL<T_symbol, T_field>::TransferDataToWindow()
}
template <typename T_symbol, typename T_field>
bool DIALOG_SIM_MODEL<T_symbol, T_field>::TransferDataFromWindow()
template <typename T>
bool DIALOG_SIM_MODEL<T>::TransferDataFromWindow()
{
m_pinAssignmentsGrid->CommitPendingChanges();
m_paramGrid->GetGrid()->CommitChangesFromEditor();
@ -424,8 +421,8 @@ bool DIALOG_SIM_MODEL<T_symbol, T_field>::TransferDataFromWindow()
}
template <typename T_symbol, typename T_field>
void DIALOG_SIM_MODEL<T_symbol, T_field>::updateWidgets()
template <typename T>
void DIALOG_SIM_MODEL<T>::updateWidgets()
{
// always enable the library browser button -- it makes for fewer clicks if the user has a
// whole bunch of inferred passives that they want to specify library models for
@ -474,8 +471,8 @@ void DIALOG_SIM_MODEL<T_symbol, T_field>::updateWidgets()
}
template <typename T_symbol, typename T_field>
void DIALOG_SIM_MODEL<T_symbol, T_field>::updateIbisWidgets( SIM_MODEL* aModel )
template <typename T>
void DIALOG_SIM_MODEL<T>::updateIbisWidgets( SIM_MODEL* aModel )
{
SIM_MODEL_KIBIS* modelkibis = isIbisLoaded() ? dynamic_cast<SIM_MODEL_KIBIS*>( aModel )
: nullptr;
@ -518,8 +515,8 @@ void DIALOG_SIM_MODEL<T_symbol, T_field>::updateIbisWidgets( SIM_MODEL* aModel )
}
template <typename T_symbol, typename T_field>
void DIALOG_SIM_MODEL<T_symbol, T_field>::updateBuiltinModelWidgets( SIM_MODEL* aModel )
template <typename T>
void DIALOG_SIM_MODEL<T>::updateBuiltinModelWidgets( SIM_MODEL* aModel )
{
// Change the Type choice to match the current device type.
if( aModel != m_prevModel )
@ -592,8 +589,8 @@ void DIALOG_SIM_MODEL<T_symbol, T_field>::updateBuiltinModelWidgets( SIM_MODEL*
}
template <typename T_symbol, typename T_field>
void DIALOG_SIM_MODEL<T_symbol, T_field>::updateModelParamsTab( SIM_MODEL* aModel )
template <typename T>
void DIALOG_SIM_MODEL<T>::updateModelParamsTab( SIM_MODEL* aModel )
{
if( aModel != m_prevModel )
{
@ -689,8 +686,8 @@ void DIALOG_SIM_MODEL<T_symbol, T_field>::updateModelParamsTab( SIM_MODEL* aMode
}
template <typename T_symbol, typename T_field>
void DIALOG_SIM_MODEL<T_symbol, T_field>::updateModelCodeTab( SIM_MODEL* aModel )
template <typename T>
void DIALOG_SIM_MODEL<T>::updateModelCodeTab( SIM_MODEL* aModel )
{
if( dynamic_cast<SIM_MODEL_SPICE_FALLBACK*>( aModel ) )
return;
@ -710,9 +707,8 @@ void DIALOG_SIM_MODEL<T_symbol, T_field>::updateModelCodeTab( SIM_MODEL* aModel
}
template <typename T_symbol, typename T_field>
void DIALOG_SIM_MODEL<T_symbol, T_field>::updatePinAssignments( SIM_MODEL* aModel,
bool aForceUpdatePins )
template <typename T>
void DIALOG_SIM_MODEL<T>::updatePinAssignments( SIM_MODEL* aModel, bool aForceUpdatePins )
{
if( m_pinAssignmentsGrid->GetNumberRows() == 0 )
{
@ -795,8 +791,8 @@ void DIALOG_SIM_MODEL<T_symbol, T_field>::updatePinAssignments( SIM_MODEL* aMode
}
template <typename T_symbol, typename T_field>
void DIALOG_SIM_MODEL<T_symbol, T_field>::removeOrphanedPinAssignments( SIM_MODEL* aModel )
template <typename T>
void DIALOG_SIM_MODEL<T>::removeOrphanedPinAssignments( SIM_MODEL* aModel )
{
for( int i = 0; i < aModel->GetPinCount(); ++i )
{
@ -806,9 +802,8 @@ void DIALOG_SIM_MODEL<T_symbol, T_field>::removeOrphanedPinAssignments( SIM_MODE
}
template <typename T_symbol, typename T_field>
bool DIALOG_SIM_MODEL<T_symbol, T_field>::loadLibrary( const wxString& aLibraryPath,
bool aForceReload )
template <typename T>
bool DIALOG_SIM_MODEL<T>::loadLibrary( const wxString& aLibraryPath, bool aForceReload )
{
if( m_prevLibrary == aLibraryPath && !aForceReload )
return true;
@ -863,9 +858,8 @@ bool DIALOG_SIM_MODEL<T_symbol, T_field>::loadLibrary( const wxString& aLibraryP
}
template <typename T_symbol, typename T_field>
void DIALOG_SIM_MODEL<T_symbol, T_field>::addParamPropertyIfRelevant( SIM_MODEL* aModel,
int aParamIndex )
template <typename T>
void DIALOG_SIM_MODEL<T>::addParamPropertyIfRelevant( SIM_MODEL* aModel, int aParamIndex )
{
if( aModel->GetParam( aParamIndex ).info.dir == SIM_MODEL::PARAM::DIR_OUT )
return;
@ -943,9 +937,8 @@ void DIALOG_SIM_MODEL<T_symbol, T_field>::addParamPropertyIfRelevant( SIM_MODEL*
}
template <typename T_symbol, typename T_field>
wxPGProperty* DIALOG_SIM_MODEL<T_symbol, T_field>::newParamProperty( SIM_MODEL* aModel ,
int aParamIndex ) const
template <typename T>
wxPGProperty* DIALOG_SIM_MODEL<T>::newParamProperty( SIM_MODEL* aModel, int aParamIndex ) const
{
const SIM_MODEL::PARAM& param = aModel->GetParam( aParamIndex );
wxString paramDescription;
@ -1066,8 +1059,8 @@ wxPGProperty* DIALOG_SIM_MODEL<T_symbol, T_field>::newParamProperty( SIM_MODEL*
}
template <typename T_symbol, typename T_field>
int DIALOG_SIM_MODEL<T_symbol, T_field>::findSymbolPinRow( const wxString& aSymbolPinNumber ) const
template <typename T>
int DIALOG_SIM_MODEL<T>::findSymbolPinRow( const wxString& aSymbolPinNumber ) const
{
for( int row = 0; row < static_cast<int>( m_sortedPartPins.size() ); ++row )
{
@ -1081,8 +1074,8 @@ int DIALOG_SIM_MODEL<T_symbol, T_field>::findSymbolPinRow( const wxString& aSymb
}
template <typename T_symbol, typename T_field>
SIM_MODEL& DIALOG_SIM_MODEL<T_symbol, T_field>::curModel() const
template <typename T>
SIM_MODEL& DIALOG_SIM_MODEL<T>::curModel() const
{
if( m_rbLibraryModel->GetValue() )
{
@ -1101,8 +1094,8 @@ SIM_MODEL& DIALOG_SIM_MODEL<T_symbol, T_field>::curModel() const
}
template <typename T_symbol, typename T_field>
const SIM_LIBRARY* DIALOG_SIM_MODEL<T_symbol, T_field>::library() const
template <typename T>
const SIM_LIBRARY* DIALOG_SIM_MODEL<T>::library() const
{
if( m_libraryModelsMgr.GetLibraries().size() == 1 )
return &m_libraryModelsMgr.GetLibraries().begin()->second.get();
@ -1111,8 +1104,8 @@ const SIM_LIBRARY* DIALOG_SIM_MODEL<T_symbol, T_field>::library() const
}
template <typename T_symbol, typename T_field>
wxString DIALOG_SIM_MODEL<T_symbol, T_field>::getSymbolPinString( int symbolPinIndex ) const
template <typename T>
wxString DIALOG_SIM_MODEL<T>::getSymbolPinString( int symbolPinIndex ) const
{
LIB_PIN* pin = m_sortedPartPins.at( symbolPinIndex );
wxString pinNumber;
@ -1131,9 +1124,8 @@ wxString DIALOG_SIM_MODEL<T_symbol, T_field>::getSymbolPinString( int symbolPinI
}
template <typename T_symbol, typename T_field>
wxString DIALOG_SIM_MODEL<T_symbol, T_field>::getModelPinString( SIM_MODEL* aModel,
int aModelPinIndex ) const
template <typename T>
wxString DIALOG_SIM_MODEL<T>::getModelPinString( SIM_MODEL* aModel, int aModelPinIndex ) const
{
const wxString& pinName = aModel->GetPin( aModelPinIndex ).name;
@ -1148,8 +1140,8 @@ wxString DIALOG_SIM_MODEL<T_symbol, T_field>::getModelPinString( SIM_MODEL* aMod
}
template <typename T_symbol, typename T_field>
int DIALOG_SIM_MODEL<T_symbol, T_field>::getModelPinIndex( const wxString& aModelPinString ) const
template <typename T>
int DIALOG_SIM_MODEL<T>::getModelPinIndex( const wxString& aModelPinString ) const
{
if( aModelPinString == "Not Connected" )
return SIM_MODEL::PIN::NOT_CONNECTED;
@ -1166,24 +1158,24 @@ int DIALOG_SIM_MODEL<T_symbol, T_field>::getModelPinIndex( const wxString& aMode
}
template <typename T_symbol, typename T_field>
void DIALOG_SIM_MODEL<T_symbol, T_field>::onRadioButton( wxCommandEvent& aEvent )
template <typename T>
void DIALOG_SIM_MODEL<T>::onRadioButton( wxCommandEvent& aEvent )
{
m_prevModel = nullptr; // Ensure the Model panel will be rebuild after updating other params.
updateWidgets();
}
template <typename T_symbol, typename T_field>
void DIALOG_SIM_MODEL<T_symbol, T_field>::onLibrarayPathText( wxCommandEvent& aEvent )
template <typename T>
void DIALOG_SIM_MODEL<T>::onLibrarayPathText( wxCommandEvent& aEvent )
{
m_rbLibraryModel->SetValue( true );
updateWidgets();
}
template <typename T_symbol, typename T_field>
void DIALOG_SIM_MODEL<T_symbol, T_field>::onLibraryPathTextEnter( wxCommandEvent& aEvent )
template <typename T>
void DIALOG_SIM_MODEL<T>::onLibraryPathTextEnter( wxCommandEvent& aEvent )
{
if( m_rbLibraryModel->GetValue() )
{
@ -1205,8 +1197,8 @@ void DIALOG_SIM_MODEL<T_symbol, T_field>::onLibraryPathTextEnter( wxCommandEvent
}
template <typename T_symbol, typename T_field>
void DIALOG_SIM_MODEL<T_symbol, T_field>::onLibraryPathTextKillFocus( wxFocusEvent& aEvent )
template <typename T>
void DIALOG_SIM_MODEL<T>::onLibraryPathTextKillFocus( wxFocusEvent& aEvent )
{
if( !m_inKillFocus )
{
@ -1220,8 +1212,8 @@ void DIALOG_SIM_MODEL<T_symbol, T_field>::onLibraryPathTextKillFocus( wxFocusEve
}
template <typename T_symbol, typename T_field>
void DIALOG_SIM_MODEL<T_symbol, T_field>::onBrowseButtonClick( wxCommandEvent& aEvent )
template <typename T>
void DIALOG_SIM_MODEL<T>::onBrowseButtonClick( wxCommandEvent& aEvent )
{
static wxString s_mruPath;
@ -1246,8 +1238,8 @@ void DIALOG_SIM_MODEL<T_symbol, T_field>::onBrowseButtonClick( wxCommandEvent& a
}
template <typename T_symbol, typename T_field>
void DIALOG_SIM_MODEL<T_symbol, T_field>::onModelNameChoice( wxCommandEvent& aEvent )
template <typename T>
void DIALOG_SIM_MODEL<T>::onModelNameChoice( wxCommandEvent& aEvent )
{
if( isIbisLoaded() )
{
@ -1270,8 +1262,8 @@ void DIALOG_SIM_MODEL<T_symbol, T_field>::onModelNameChoice( wxCommandEvent& aEv
}
template <typename T_symbol, typename T_field>
void DIALOG_SIM_MODEL<T_symbol, T_field>::onPinCombobox( wxCommandEvent& aEvent )
template <typename T>
void DIALOG_SIM_MODEL<T>::onPinCombobox( wxCommandEvent& aEvent )
{
wxArrayString modelLabels;
@ -1300,8 +1292,8 @@ void DIALOG_SIM_MODEL<T_symbol, T_field>::onPinCombobox( wxCommandEvent& aEvent
}
template <typename T_symbol, typename T_field>
void DIALOG_SIM_MODEL<T_symbol, T_field>::onPinComboboxTextEnter( wxCommandEvent& aEvent )
template <typename T>
void DIALOG_SIM_MODEL<T>::onPinComboboxTextEnter( wxCommandEvent& aEvent )
{
m_pinCombobox->SetSelection( m_pinCombobox->FindString( m_pinCombobox->GetValue() ) );
@ -1309,21 +1301,21 @@ void DIALOG_SIM_MODEL<T_symbol, T_field>::onPinComboboxTextEnter( wxCommandEvent
}
template <typename T_symbol, typename T_field>
void DIALOG_SIM_MODEL<T_symbol, T_field>::onPinModelCombobox( wxCommandEvent& aEvent )
template <typename T>
void DIALOG_SIM_MODEL<T>::onPinModelCombobox( wxCommandEvent& aEvent )
{
updateWidgets();
}
template <typename T_symbol, typename T_field>
void DIALOG_SIM_MODEL<T_symbol, T_field>::onPinModelComboboxTextEnter( wxCommandEvent& aEvent )
template <typename T>
void DIALOG_SIM_MODEL<T>::onPinModelComboboxTextEnter( wxCommandEvent& aEvent )
{
m_pinModelCombobox->SetSelection( m_pinModelCombobox->FindString( m_pinModelCombobox->GetValue() ) );
}
template <typename T_symbol, typename T_field>
void DIALOG_SIM_MODEL<T_symbol, T_field>::onDifferentialCheckbox( wxCommandEvent& aEvent )
template <typename T>
void DIALOG_SIM_MODEL<T>::onDifferentialCheckbox( wxCommandEvent& aEvent )
{
SIM_MODEL_KIBIS* modelkibis = dynamic_cast<SIM_MODEL_KIBIS*>( &curModel() );
@ -1336,8 +1328,8 @@ void DIALOG_SIM_MODEL<T_symbol, T_field>::onDifferentialCheckbox( wxCommandEvent
}
template <typename T_symbol, typename T_field>
void DIALOG_SIM_MODEL<T_symbol, T_field>::onDeviceTypeChoice( wxCommandEvent& aEvent )
template <typename T>
void DIALOG_SIM_MODEL<T>::onDeviceTypeChoice( wxCommandEvent& aEvent )
{
m_rbBuiltinModel->SetValue( true );
@ -1354,8 +1346,8 @@ void DIALOG_SIM_MODEL<T_symbol, T_field>::onDeviceTypeChoice( wxCommandEvent& aE
}
template <typename T_symbol, typename T_field>
void DIALOG_SIM_MODEL<T_symbol, T_field>::onWaveformChoice( wxCommandEvent& aEvent )
template <typename T>
void DIALOG_SIM_MODEL<T>::onWaveformChoice( wxCommandEvent& aEvent )
{
SIM_MODEL::DEVICE_T deviceType = curModel().GetDeviceType();
wxString typeDescription = m_waveformChoice->GetStringSelection();
@ -1393,8 +1385,8 @@ void DIALOG_SIM_MODEL<T_symbol, T_field>::onWaveformChoice( wxCommandEvent& aEve
}
template <typename T_symbol, typename T_field>
void DIALOG_SIM_MODEL<T_symbol, T_field>::onTypeChoice( wxCommandEvent& aEvent )
template <typename T>
void DIALOG_SIM_MODEL<T>::onTypeChoice( wxCommandEvent& aEvent )
{
SIM_MODEL::DEVICE_T deviceType = curModel().GetDeviceType();
wxString typeDescription = m_deviceSubtypeChoice->GetStringSelection();
@ -1414,15 +1406,15 @@ void DIALOG_SIM_MODEL<T_symbol, T_field>::onTypeChoice( wxCommandEvent& aEvent )
}
template <typename T_symbol, typename T_field>
void DIALOG_SIM_MODEL<T_symbol, T_field>::onPageChanging( wxBookCtrlEvent& event )
template <typename T>
void DIALOG_SIM_MODEL<T>::onPageChanging( wxBookCtrlEvent& event )
{
updateModelCodeTab( &curModel() );
}
template <typename T_symbol, typename T_field>
void DIALOG_SIM_MODEL<T_symbol, T_field>::onPinAssignmentsGridCellChange( wxGridEvent& aEvent )
template <typename T>
void DIALOG_SIM_MODEL<T>::onPinAssignmentsGridCellChange( wxGridEvent& aEvent )
{
int symbolPinIndex = aEvent.GetRow();
wxString oldModelPinName = aEvent.GetString();
@ -1446,8 +1438,8 @@ void DIALOG_SIM_MODEL<T_symbol, T_field>::onPinAssignmentsGridCellChange( wxGrid
}
template <typename T_symbol, typename T_field>
void DIALOG_SIM_MODEL<T_symbol, T_field>::onPinAssignmentsGridSize( wxSizeEvent& aEvent )
template <typename T>
void DIALOG_SIM_MODEL<T>::onPinAssignmentsGridSize( wxSizeEvent& aEvent )
{
wxGridUpdateLocker deferRepaintsTillLeavingScope( m_pinAssignmentsGrid );
@ -1459,8 +1451,8 @@ void DIALOG_SIM_MODEL<T_symbol, T_field>::onPinAssignmentsGridSize( wxSizeEvent&
}
template <typename T_symbol, typename T_field>
void DIALOG_SIM_MODEL<T_symbol, T_field>::onParamGridSetFocus( wxFocusEvent& aEvent )
template <typename T>
void DIALOG_SIM_MODEL<T>::onParamGridSetFocus( wxFocusEvent& aEvent )
{
// By default, when a property grid is focused, the textbox is not immediately focused until
// Tab key is pressed. This is inconvenient, so we fix that here.
@ -1483,8 +1475,8 @@ void DIALOG_SIM_MODEL<T_symbol, T_field>::onParamGridSetFocus( wxFocusEvent& aEv
}
template <typename T_symbol, typename T_field>
void DIALOG_SIM_MODEL<T_symbol, T_field>::onParamGridSelectionChange( wxPropertyGridEvent& aEvent )
template <typename T>
void DIALOG_SIM_MODEL<T>::onParamGridSelectionChange( wxPropertyGridEvent& aEvent )
{
wxPropertyGrid* grid = m_paramGrid->GetGrid();
@ -1546,8 +1538,8 @@ void DIALOG_SIM_MODEL<T_symbol, T_field>::onParamGridSelectionChange( wxProperty
}
template <typename T_symbol, typename T_field>
void DIALOG_SIM_MODEL<T_symbol, T_field>::onUpdateUI( wxUpdateUIEvent& aEvent )
template <typename T>
void DIALOG_SIM_MODEL<T>::onUpdateUI( wxUpdateUIEvent& aEvent )
{
// This is currently patched in wxPropertyGrid::ScrollWindow() in the Mac wxWidgets fork.
// However, we may need this version if it turns out to be an issue on other platforms and
@ -1572,8 +1564,8 @@ void DIALOG_SIM_MODEL<T_symbol, T_field>::onUpdateUI( wxUpdateUIEvent& aEvent )
}
template <typename T_symbol, typename T_field>
void DIALOG_SIM_MODEL<T_symbol, T_field>::adjustParamGridColumns( int aWidth, bool aForce )
template <typename T>
void DIALOG_SIM_MODEL<T>::adjustParamGridColumns( int aWidth, bool aForce )
{
wxPropertyGrid* grid = m_paramGridMgr->GetGrid();
int margin = 15;
@ -1608,8 +1600,8 @@ void DIALOG_SIM_MODEL<T_symbol, T_field>::adjustParamGridColumns( int aWidth, bo
}
template <typename T_symbol, typename T_field>
void DIALOG_SIM_MODEL<T_symbol, T_field>::onSizeParamGrid( wxSizeEvent& event )
template <typename T>
void DIALOG_SIM_MODEL<T>::onSizeParamGrid( wxSizeEvent& event )
{
adjustParamGridColumns( event.GetSize().GetX(), false );
@ -1618,5 +1610,5 @@ void DIALOG_SIM_MODEL<T_symbol, T_field>::onSizeParamGrid( wxSizeEvent& event )
template class DIALOG_SIM_MODEL<SCH_SYMBOL, SCH_FIELD>;
template class DIALOG_SIM_MODEL<LIB_SYMBOL, LIB_FIELD>;
template class DIALOG_SIM_MODEL<SCH_SYMBOL>;
template class DIALOG_SIM_MODEL<LIB_SYMBOL>;

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2022 Mikolaj Wielgus
* Copyright (C) 2022-2023 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2022-2024 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -41,7 +41,7 @@
// wxPG_NATIVE_DOUBLE_BUFFERING flag is not set.
// 2. wxPropertyGridManager->ShowHeader() segfaults when called from this dialog's constructor.
template <typename T_symbol, typename T_field>
template <typename T>
class DIALOG_SIM_MODEL : public DIALOG_SIM_MODEL_BASE
{
public:
@ -61,8 +61,8 @@ public:
MODEL
};
DIALOG_SIM_MODEL( wxWindow* aParent, EDA_BASE_FRAME* aFrame, T_symbol& aSymbol,
std::vector<T_field>& aFields );
DIALOG_SIM_MODEL( wxWindow* aParent, EDA_BASE_FRAME* aFrame, T& aSymbol,
std::vector<SCH_FIELD>& aFields );
~DIALOG_SIM_MODEL();
@ -122,8 +122,8 @@ private:
private:
EDA_BASE_FRAME* m_frame;
T_symbol& m_symbol;
std::vector<T_field>& m_fields;
T& m_symbol;
std::vector<SCH_FIELD>& m_fields;
SIM_LIB_MGR m_libraryModelsMgr;
SIM_LIB_MGR m_builtinModelsMgr;

View File

@ -356,7 +356,7 @@ DIALOG_SYMBOL_PROPERTIES::DIALOG_SYMBOL_PROPERTIES( SCH_EDIT_FRAME* aParent,
// so we need to handle m_part == nullptr
// wxASSERT( m_part );
m_fields = new FIELDS_GRID_TABLE<SCH_FIELD>( this, aParent, m_fieldsGrid, m_symbol );
m_fields = new FIELDS_GRID_TABLE( this, aParent, m_fieldsGrid, m_symbol );
// Give a bit more room for combobox editors
m_fieldsGrid->SetDefaultRowSize( m_fieldsGrid->GetDefaultRowSize() + 4 );

View File

@ -109,7 +109,7 @@ private:
bool m_editorShown;
std::bitset<64> m_shownColumns;
FIELDS_GRID_TABLE<SCH_FIELD>* m_fields;
FIELDS_GRID_TABLE* m_fields;
SCH_PIN_TABLE_DATA_MODEL* m_dataModel;
};

View File

@ -82,7 +82,7 @@ DIALOG_UPDATE_SYMBOL_FIELDS::~DIALOG_UPDATE_SYMBOL_FIELDS()
void DIALOG_UPDATE_SYMBOL_FIELDS::updateFieldsList()
{
// Load non-mandatory fields from the parent part
std::vector<LIB_FIELD*> libFields;
std::vector<SCH_FIELD*> libFields;
std::set<wxString> fieldNames;
std::unique_ptr<LIB_SYMBOL> flattenedParent = m_symbol->GetParent().lock()->Flatten();
@ -143,14 +143,14 @@ void DIALOG_UPDATE_SYMBOL_FIELDS::onOkButtonClicked( wxCommandEvent& aEvent )
bool resetEffects = m_resetFieldEffects->GetValue();
bool resetPositions = m_resetFieldPositions->GetValue();
std::vector<LIB_FIELD> fields;
std::vector<LIB_FIELD> result;
std::vector<SCH_FIELD> fields;
std::vector<SCH_FIELD> result;
m_symbol->GetFields( fields );
for( LIB_FIELD& field : fields )
for( SCH_FIELD& field : fields )
{
bool copy = true;
LIB_FIELD* parentField = nullptr;
SCH_FIELD* parentField = nullptr;
if( alg::contains( m_updateFields, field.GetName() ) )
{
@ -195,12 +195,12 @@ void DIALOG_UPDATE_SYMBOL_FIELDS::onOkButtonClicked( wxCommandEvent& aEvent )
result.emplace_back( std::move( field ) );
}
std::vector<LIB_FIELD*> parentFields;
std::vector<SCH_FIELD*> parentFields;
int idx = result.size();
flattenedParent->GetFields( parentFields );
for( LIB_FIELD* parentField : parentFields )
for( SCH_FIELD* parentField : parentFields )
{
if( !alg::contains( m_updateFields, parentField->GetName() ) )
continue;
@ -208,7 +208,7 @@ void DIALOG_UPDATE_SYMBOL_FIELDS::onOkButtonClicked( wxCommandEvent& aEvent )
if( !m_symbol->FindField( parentField->GetName() ) )
{
result.emplace_back( m_symbol, idx++ );
LIB_FIELD* newField = &result.back();
SCH_FIELD* newField = &result.back();
newField->SetName( parentField->GetCanonicalName() );
newField->SetText( parentField->GetText() );

View File

@ -359,13 +359,13 @@ void PANEL_EESCHEMA_COLOR_SETTINGS::createPreviewItems()
LIB_SYMBOL* symbol = new LIB_SYMBOL( wxEmptyString );
VECTOR2I p( 2625, -1600 );
LIB_FIELD& ref = symbol->GetReferenceField();
SCH_FIELD& ref = symbol->GetReferenceField();
ref.SetText( wxT( "U1" ) );
ref.SetPosition( MILS_POINT( p.x + 30, p.y + 260 ) );
ref.SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
LIB_FIELD& value = symbol->GetValueField();
SCH_FIELD& value = symbol->GetValueField();
value.SetText( wxT( "OPA604" ) );
value.SetPosition( MILS_POINT( p.x + 30, p.y + 180 ) );

View File

@ -126,9 +126,8 @@ static wxString netList( LIB_SYMBOL* aSymbol )
}
template <class T>
FIELDS_GRID_TABLE<T>::FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_BASE_FRAME* aFrame,
WX_GRID* aGrid, LIB_SYMBOL* aSymbol ) :
FIELDS_GRID_TABLE::FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_BASE_FRAME* aFrame, WX_GRID* aGrid,
LIB_SYMBOL* aSymbol ) :
m_frame( aFrame ),
m_dialog( aDialog ),
m_grid( aGrid ),
@ -147,9 +146,8 @@ FIELDS_GRID_TABLE<T>::FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_BASE_FRAME* a
}
template <class T>
FIELDS_GRID_TABLE<T>::FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_EDIT_FRAME* aFrame,
WX_GRID* aGrid, SCH_SYMBOL* aSymbol ) :
FIELDS_GRID_TABLE::FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_EDIT_FRAME* aFrame, WX_GRID* aGrid,
SCH_SYMBOL* aSymbol ) :
m_frame( aFrame ),
m_dialog( aDialog ),
m_grid( aGrid ),
@ -168,9 +166,8 @@ FIELDS_GRID_TABLE<T>::FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_EDIT_FRAME* a
}
template <class T>
FIELDS_GRID_TABLE<T>::FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_EDIT_FRAME* aFrame,
WX_GRID* aGrid, SCH_SHEET* aSheet ) :
FIELDS_GRID_TABLE::FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_EDIT_FRAME* aFrame, WX_GRID* aGrid,
SCH_SHEET* aSheet ) :
m_frame( aFrame ),
m_dialog( aDialog ),
m_grid( aGrid ),
@ -188,9 +185,8 @@ FIELDS_GRID_TABLE<T>::FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_EDIT_FRAME* a
}
template <class T>
FIELDS_GRID_TABLE<T>::FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_EDIT_FRAME* aFrame,
WX_GRID* aGrid, SCH_LABEL_BASE* aLabel ) :
FIELDS_GRID_TABLE::FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_EDIT_FRAME* aFrame, WX_GRID* aGrid,
SCH_LABEL_BASE* aLabel ) :
m_frame( aFrame ),
m_dialog( aDialog ),
m_grid( aGrid ),
@ -208,8 +204,7 @@ FIELDS_GRID_TABLE<T>::FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_EDIT_FRAME* a
}
template <class T>
void FIELDS_GRID_TABLE<T>::initGrid( WX_GRID* aGrid )
void FIELDS_GRID_TABLE::initGrid( WX_GRID* aGrid )
{
// Build the various grid cell attributes.
// NOTE: validators and cellAttrs are member variables to get the destruction order
@ -230,7 +225,13 @@ void FIELDS_GRID_TABLE<T>::initGrid( WX_GRID* aGrid )
m_valueAttr = new wxGridCellAttr;
if constexpr ( std::is_same_v<T, SCH_FIELD> )
if( m_parentType == LIB_SYMBOL_T )
{
GRID_CELL_TEXT_EDITOR* valueEditor = new GRID_CELL_TEXT_EDITOR();
valueEditor->SetValidator( m_valueValidator );
m_valueAttr->SetEditor( valueEditor );
}
else
{
GRID_CELL_STC_EDITOR* valueEditor = new GRID_CELL_STC_EDITOR( true,
[this]( wxStyledTextEvent& aEvent, SCINTILLA_TRICKS* aScintillaTricks )
@ -240,12 +241,6 @@ void FIELDS_GRID_TABLE<T>::initGrid( WX_GRID* aGrid )
} );
m_valueAttr->SetEditor( valueEditor );
}
else
{
GRID_CELL_TEXT_EDITOR* valueEditor = new GRID_CELL_TEXT_EDITOR();
valueEditor->SetValidator( m_valueValidator );
m_valueAttr->SetEditor( valueEditor );
}
m_footprintAttr = new wxGridCellAttr;
GRID_CELL_FPID_EDITOR* fpIdEditor = new GRID_CELL_FPID_EDITOR( m_dialog, m_symbolNetlist );
@ -341,12 +336,11 @@ void FIELDS_GRID_TABLE<T>::initGrid( WX_GRID* aGrid )
m_eval = std::make_unique<NUMERIC_EVALUATOR>( m_frame->GetUserUnits() );
m_frame->Bind( EDA_EVT_UNITS_CHANGED, &FIELDS_GRID_TABLE<T>::onUnitsChanged, this );
m_frame->Bind( EDA_EVT_UNITS_CHANGED, &FIELDS_GRID_TABLE::onUnitsChanged, this );
}
template <class T>
FIELDS_GRID_TABLE<T>::~FIELDS_GRID_TABLE()
FIELDS_GRID_TABLE::~FIELDS_GRID_TABLE()
{
m_readOnlyAttr->DecRef();
m_fieldNameAttr->DecRef();
@ -364,12 +358,11 @@ FIELDS_GRID_TABLE<T>::~FIELDS_GRID_TABLE()
m_fontAttr->DecRef();
m_colorAttr->DecRef();
m_frame->Unbind( EDA_EVT_UNITS_CHANGED, &FIELDS_GRID_TABLE<T>::onUnitsChanged, this );
m_frame->Unbind( EDA_EVT_UNITS_CHANGED, &FIELDS_GRID_TABLE::onUnitsChanged, this );
}
template <class T>
void FIELDS_GRID_TABLE<T>::onUnitsChanged( wxCommandEvent& aEvent )
void FIELDS_GRID_TABLE::onUnitsChanged( wxCommandEvent& aEvent )
{
if( GetView() )
GetView()->ForceRefresh();
@ -378,8 +371,7 @@ void FIELDS_GRID_TABLE<T>::onUnitsChanged( wxCommandEvent& aEvent )
}
template <class T>
wxString FIELDS_GRID_TABLE<T>::GetColLabelValue( int aCol )
wxString FIELDS_GRID_TABLE::GetColLabelValue( int aCol )
{
switch( aCol )
{
@ -403,8 +395,7 @@ wxString FIELDS_GRID_TABLE<T>::GetColLabelValue( int aCol )
}
template <class T>
bool FIELDS_GRID_TABLE<T>::CanGetValueAs( int aRow, int aCol, const wxString& aTypeName )
bool FIELDS_GRID_TABLE::CanGetValueAs( int aRow, int aCol, const wxString& aTypeName )
{
switch( aCol )
{
@ -434,15 +425,13 @@ bool FIELDS_GRID_TABLE<T>::CanGetValueAs( int aRow, int aCol, const wxString& aT
}
template <class T>
bool FIELDS_GRID_TABLE<T>::CanSetValueAs( int aRow, int aCol, const wxString& aTypeName )
bool FIELDS_GRID_TABLE::CanSetValueAs( int aRow, int aCol, const wxString& aTypeName )
{
return CanGetValueAs( aRow, aCol, aTypeName );
}
template <class T>
wxGridCellAttr* FIELDS_GRID_TABLE<T>::GetAttr( int aRow, int aCol, wxGridCellAttr::wxAttrKind )
wxGridCellAttr* FIELDS_GRID_TABLE::GetAttr( int aRow, int aCol, wxGridCellAttr::wxAttrKind )
{
wxGridCellAttr* tmp;
@ -570,13 +559,12 @@ wxGridCellAttr* FIELDS_GRID_TABLE<T>::GetAttr( int aRow, int aCol, wxGridCellAtt
}
template <class T>
wxString FIELDS_GRID_TABLE<T>::GetValue( int aRow, int aCol )
wxString FIELDS_GRID_TABLE::GetValue( int aRow, int aCol )
{
wxCHECK( aRow < GetNumberRows(), wxEmptyString );
wxGrid* grid = GetView();
const T& field = this->at( (size_t) aRow );
const SCH_FIELD& field = this->at( (size_t) aRow );
if( grid->GetGridCursorRow() == aRow && grid->GetGridCursorCol() == aCol
&& grid->IsCellEditControlShown() )
@ -690,11 +678,10 @@ wxString FIELDS_GRID_TABLE<T>::GetValue( int aRow, int aCol )
}
template <class T>
bool FIELDS_GRID_TABLE<T>::GetValueAsBool( int aRow, int aCol )
bool FIELDS_GRID_TABLE::GetValueAsBool( int aRow, int aCol )
{
wxCHECK( aRow < GetNumberRows(), false );
const T& field = this->at( (size_t) aRow );
const SCH_FIELD& field = this->at( (size_t) aRow );
switch( aCol )
{
@ -710,11 +697,10 @@ bool FIELDS_GRID_TABLE<T>::GetValueAsBool( int aRow, int aCol )
}
template <class T>
void FIELDS_GRID_TABLE<T>::SetValue( int aRow, int aCol, const wxString &aValue )
void FIELDS_GRID_TABLE::SetValue( int aRow, int aCol, const wxString &aValue )
{
wxCHECK( aRow < GetNumberRows(), /*void*/ );
T& field = this->at( (size_t) aRow );
SCH_FIELD& field = this->at( (size_t) aRow );
VECTOR2I pos;
wxString value = aValue;
@ -879,11 +865,10 @@ void FIELDS_GRID_TABLE<T>::SetValue( int aRow, int aCol, const wxString &aValue
}
template <class T>
void FIELDS_GRID_TABLE<T>::SetValueAsBool( int aRow, int aCol, bool aValue )
void FIELDS_GRID_TABLE::SetValueAsBool( int aRow, int aCol, bool aValue )
{
wxCHECK( aRow < GetNumberRows(), /*void*/ );
T& field = this->at( (size_t) aRow );
SCH_FIELD& field = this->at( (size_t) aRow );
switch( aCol )
{
@ -916,12 +901,6 @@ void FIELDS_GRID_TABLE<T>::SetValueAsBool( int aRow, int aCol, bool aValue )
}
// Explicit Instantiations
template class FIELDS_GRID_TABLE<SCH_FIELD>;
template class FIELDS_GRID_TABLE<LIB_FIELD>;
void FIELDS_GRID_TRICKS::showPopupMenu( wxMenu& menu, wxGridEvent& aEvent )
{
if( m_grid->GetGridCursorRow() == FOOTPRINT_FIELD && m_grid->GetGridCursorCol() == FDC_VALUE
@ -969,8 +948,7 @@ void FIELDS_GRID_TRICKS::doPopupSelection( wxCommandEvent& event )
}
template <class T>
wxString FIELDS_GRID_TABLE<T>::StringFromBool( bool aValue ) const
wxString FIELDS_GRID_TABLE::StringFromBool( bool aValue ) const
{
if( aValue )
return wxT( "1" );
@ -979,8 +957,7 @@ wxString FIELDS_GRID_TABLE<T>::StringFromBool( bool aValue ) const
}
template <class T>
bool FIELDS_GRID_TABLE<T>::BoolFromString( wxString aValue ) const
bool FIELDS_GRID_TABLE::BoolFromString( wxString aValue ) const
{
if( aValue == wxS( "1" ) )
{

View File

@ -24,7 +24,6 @@
#ifndef FIELDS_GRID_TABLE_H
#define FIELDS_GRID_TABLE_H
#include <sch_validators.h>
#include <wx/grid.h>
#include <sch_symbol.h>
#include <grid_tricks.h>
@ -45,8 +44,8 @@ public:
{}
protected:
virtual void showPopupMenu( wxMenu& menu, wxGridEvent& aEvent ) override;
virtual void doPopupSelection( wxCommandEvent& event ) override;
void showPopupMenu( wxMenu& menu, wxGridEvent& aEvent ) override;
void doPopupSelection( wxCommandEvent& event ) override;
DIALOG_SHIM* m_dlg;
};
@ -73,8 +72,7 @@ enum FIELDS_DATA_COL_ORDER
};
template <class T>
class FIELDS_GRID_TABLE : public wxGridTableBase, public std::vector<T>
class FIELDS_GRID_TABLE : public wxGridTableBase, public std::vector<SCH_FIELD>
{
public:
FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_BASE_FRAME* aFrame, WX_GRID* aGrid,
@ -85,7 +83,7 @@ public:
SCH_SHEET* aSheet );
FIELDS_GRID_TABLE( DIALOG_SHIM* aDialog, SCH_EDIT_FRAME* aFrame, WX_GRID* aGrid,
SCH_LABEL_BASE* aLabel );
~FIELDS_GRID_TABLE();
~FIELDS_GRID_TABLE() override;
int GetNumberRows() override { return (int) this->size(); }
int GetNumberCols() override { return FDC_COUNT; }

View File

@ -161,7 +161,7 @@ protected:
}
wxString GetHtmlFieldRow( const LIB_FIELD& aField ) const
wxString GetHtmlFieldRow( const SCH_FIELD& aField ) const
{
wxString name = aField.GetCanonicalName();
wxString text;
@ -214,11 +214,11 @@ protected:
void SetHtmlFieldTable()
{
wxString fieldtable;
std::vector<LIB_FIELD*> fields;
std::vector<SCH_FIELD*> fields;
m_symbol->GetFields( fields );
for( const LIB_FIELD* field: fields )
for( const SCH_FIELD* field: fields )
fieldtable += GetHtmlFieldRow( *field );
if( m_symbol->IsAlias() )
@ -228,11 +228,11 @@ protected:
// Append all of the unique parent fields if this is an alias.
if( parent )
{
std::vector<LIB_FIELD*> parentFields;
std::vector<SCH_FIELD*> parentFields;
parent->GetFields( parentFields );
for( const LIB_FIELD* parentField : parentFields )
for( const SCH_FIELD* parentField : parentFields )
{
if( m_symbol->FindField( parentField->GetCanonicalName() ) )
continue;

View File

@ -1,691 +0,0 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2022 CERN
* Copyright (C) 2004-2024 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <eda_item.h>
#include <string_utils.h>
#include <sch_draw_panel.h>
#include <eda_draw_frame.h>
#include <plotters/plotter.h>
#include <font/font.h>
#include <trigo.h>
#include <base_units.h>
#include <widgets/msgpanel.h>
#include <bitmaps.h>
#include <lib_symbol.h>
#include <transform.h>
#include <template_fieldnames.h>
#include <settings/color_settings.h>
LIB_FIELD::LIB_FIELD( SCH_ITEM* aParent, int aId, const wxString& aName ) :
SCH_ITEM( aParent, LIB_FIELD_T ),
EDA_TEXT( schIUScale )
{
Init( aId );
m_name = aName;
}
LIB_FIELD::LIB_FIELD( int aId ) :
SCH_ITEM( nullptr, LIB_FIELD_T ),
EDA_TEXT( schIUScale )
{
Init( aId );
}
LIB_FIELD::LIB_FIELD( int aId, const wxString& aName ) :
SCH_ITEM( nullptr, LIB_FIELD_T ),
EDA_TEXT( schIUScale )
{
Init( aId );
m_name = aName;
}
LIB_FIELD& LIB_FIELD::operator=( const LIB_FIELD& field )
{
m_id = field.m_id;
m_name = field.m_name;
m_parent = field.m_parent;
m_autoAdded = field.m_autoAdded;
m_showName = field.m_showName;
m_allowAutoPlace = field.m_allowAutoPlace;
m_showInChooser = field.m_showInChooser;
SetText( field.GetText() );
SetAttributes( field );
return *this;
}
void LIB_FIELD::Init( int aId )
{
m_id = aId;
SetTextAngle( ANGLE_HORIZONTAL ); // constructor already did this.
// Fields in RAM must always have names, because we are trying to get less dependent on
// field ids and more dependent on names. Plus assumptions are made in the field editors.
m_name = TEMPLATE_FIELDNAME::GetDefaultFieldName( aId );
// By contrast, VALUE and REFERENCE are are always constructed as initially visible, and
// template fieldsnames' initial visibility is controlled by the template fieldname config.
if( aId != VALUE_FIELD && aId != REFERENCE_FIELD && aId < MANDATORY_FIELDS )
SetVisible( false );
m_autoAdded = false;
m_showName = false;
m_allowAutoPlace = true;
m_showInChooser = true;
}
void LIB_FIELD::SetId( int aId )
{
m_id = aId;
}
int LIB_FIELD::GetPenWidth() const
{
return GetEffectiveTextPenWidth();
}
KIFONT::FONT* LIB_FIELD::getDrawFont() const
{
KIFONT::FONT* font = EDA_TEXT::GetFont();
if( !font )
font = KIFONT::FONT::GetFont( GetDefaultFont(), IsBold(), IsItalic() );
return font;
}
void LIB_FIELD::Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBodyStyle,
const VECTOR2I& aOffset, bool aForceNoFill, bool aDimmed )
{
wxDC* DC = aSettings->GetPrintDC();
COLOR4D color = aSettings->GetLayerColor( IsVisible() ? GetDefaultLayer() : LAYER_HIDDEN );
COLOR4D bg = aSettings->GetBackgroundColor();
bool blackAndWhiteMode = GetGRForceBlackPenState();
int penWidth = GetEffectivePenWidth( aSettings );
VECTOR2I text_pos = aSettings->TransformCoordinate( GetTextPos() ) + aOffset;
if( blackAndWhiteMode || bg == COLOR4D::UNSPECIFIED )
bg = COLOR4D::WHITE;
if( !blackAndWhiteMode && GetTextColor() != COLOR4D::UNSPECIFIED )
color = GetTextColor();
if( aDimmed )
{
color.Desaturate( );
color = color.Mix( bg, 0.5f );
}
KIFONT::FONT* font = GetFont();
if( !font )
font = KIFONT::FONT::GetFont( aSettings->GetDefaultFont(), IsBold(), IsItalic() );
GRPrintText( DC, text_pos, color, GetText(), GetTextAngle(), GetTextSize(), GetHorizJustify(),
GetVertJustify(), penWidth, IsItalic(), IsBold(), font, GetFontMetrics() );
}
bool LIB_FIELD::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
{
// Because HitTest is mainly used to select the field return false if it is empty
if( GetText().IsEmpty() )
return false;
// Build a temporary copy of the text for hit testing
EDA_TEXT tmp_text( *this );
// Reference designator text has one or 2 additional character (displays U? or U?A)
if( m_id == REFERENCE_FIELD )
{
const LIB_SYMBOL* parent = dynamic_cast<const LIB_SYMBOL*>( m_parent );
wxString extended_text = tmp_text.GetText();
extended_text.Append('?');
if ( parent && parent->GetUnitCount() > 1 )
extended_text.Append('A');
tmp_text.SetText( extended_text );
}
tmp_text.SetTextPos( DefaultTransform.TransformCoordinate( GetTextPos() ) );
// The text orientation may need to be flipped if the transformation matrix causes xy axes
// to be flipped. This simple algo works only for schematic matrix (rot 90 or/and mirror)
bool t1 = ( DefaultTransform.x1 != 0 ) ^ ( GetTextAngle() != ANGLE_HORIZONTAL );
tmp_text.SetTextAngle( t1 ? ANGLE_HORIZONTAL : ANGLE_VERTICAL );
return tmp_text.TextHitTest( aPosition, aAccuracy );
}
bool LIB_FIELD::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
{
if( m_flags & (STRUCT_DELETED | SKIP_STRUCT ) )
return false;
BOX2I sel = aRect;
if ( aAccuracy )
sel.Inflate( aAccuracy );
if( aContained )
return sel.Contains( GetBoundingBox() );
return sel.Intersects( GetBoundingBox() );
}
EDA_ITEM* LIB_FIELD::Clone() const
{
return new LIB_FIELD( *this );
}
void LIB_FIELD::Copy( LIB_FIELD* aTarget ) const
{
aTarget->m_name = m_name;
aTarget->m_showName = m_showName;
aTarget->m_allowAutoPlace = m_allowAutoPlace;
aTarget->m_showInChooser = m_showInChooser;
aTarget->CopyText( *this );
aTarget->SetAttributes( *this );
aTarget->SetParent( m_parent );
aTarget->SetAutoAdded( IsAutoAdded() );
}
int LIB_FIELD::compare( const SCH_ITEM& aOther, int aCompareFlags ) const
{
wxASSERT( aOther.Type() == LIB_FIELD_T );
int retv = SCH_ITEM::compare( aOther, aCompareFlags );
if( retv )
return retv;
const LIB_FIELD* tmp = ( LIB_FIELD* ) &aOther;
// Equality test will vary depending whether or not the field is mandatory. Otherwise,
// sorting is done by ordinal.
if( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::EQUALITY )
{
// Mandatory fields have fixed ordinals and their names can vary due to translated field
// names. Optional fields have fixed names and their ordinals can vary.
if( IsMandatory() )
{
if( m_id != tmp->m_id )
return m_id - tmp->m_id;
}
else
{
retv = m_name.Cmp( tmp->m_name );
if( retv )
return retv;
}
}
else // assume we're sorting
{
if( m_id != tmp->m_id )
return m_id - tmp->m_id;
}
bool ignoreFieldText = false;
if( m_id == REFERENCE_FIELD && !( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::EQUALITY ) )
ignoreFieldText = true;
if( m_id == VALUE_FIELD && ( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::ERC ) )
ignoreFieldText = true;
if( !ignoreFieldText )
{
retv = GetText().CmpNoCase( tmp->GetText() );
if( retv != 0 )
return retv;
}
if( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::EQUALITY )
{
if( GetTextPos().x != tmp->GetTextPos().x )
return GetTextPos().x - tmp->GetTextPos().x;
if( GetTextPos().y != tmp->GetTextPos().y )
return GetTextPos().y - tmp->GetTextPos().y;
}
if( GetTextWidth() != tmp->GetTextWidth() )
return GetTextWidth() - tmp->GetTextWidth();
if( GetTextHeight() != tmp->GetTextHeight() )
return GetTextHeight() - tmp->GetTextHeight();
return 0;
}
void LIB_FIELD::Move( const VECTOR2I& aOffset )
{
EDA_TEXT::Offset( aOffset );
}
void LIB_FIELD::SetPosition( const VECTOR2I& newPosition )
{
EDA_TEXT::SetTextPos( newPosition );
}
void LIB_FIELD::MirrorHorizontally( int aCenter )
{
int x = GetTextPos().x;
x -= aCenter;
x *= -1;
x += aCenter;
SetTextX( x );
}
void LIB_FIELD::MirrorVertically( int aCenter )
{
int y = GetTextPos().y;
y -= aCenter;
y *= -1;
y += aCenter;
SetTextY( y );
}
void LIB_FIELD::Rotate( const VECTOR2I& center, bool aRotateCCW )
{
EDA_ANGLE rot_angle = aRotateCCW ? -ANGLE_90 : ANGLE_90;
VECTOR2I pt = GetTextPos();
RotatePoint( pt, center, rot_angle );
SetTextPos( pt );
SetTextAngle( GetTextAngle() != ANGLE_HORIZONTAL ? ANGLE_HORIZONTAL : ANGLE_VERTICAL );
}
void LIB_FIELD::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed )
{
if( GetText().IsEmpty() || aBackground )
return;
SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter );
if( !IsVisible() && !renderSettings->m_ShowHiddenFields )
return;
// Calculate the text orientation, according to the symbol orientation/mirror.
EDA_ANGLE orient = GetTextAngle();
if( renderSettings->m_Transform.y1 ) // Rotate symbol 90 deg.
{
if( orient.IsHorizontal() )
orient = ANGLE_VERTICAL;
else
orient = ANGLE_HORIZONTAL;
}
BOX2I bbox = GetBoundingBox();
bbox.RevertYAxis();
GR_TEXT_H_ALIGN_T hjustify = GR_TEXT_H_ALIGN_CENTER;
GR_TEXT_V_ALIGN_T vjustify = GR_TEXT_V_ALIGN_CENTER;
VECTOR2I textpos = renderSettings->TransformCoordinate( bbox.Centre() ) + aOffset;
COLOR4D color;
COLOR4D bg;
if( aPlotter->GetColorMode() )
{
if( GetTextColor() != COLOR4D::UNSPECIFIED )
color = GetTextColor();
else
color = renderSettings->GetLayerColor( GetDefaultLayer() );
bg = renderSettings->GetBackgroundColor();
if( bg == COLOR4D::UNSPECIFIED )
bg = COLOR4D::WHITE;
}
else
{
color = COLOR4D::BLACK;
bg = COLOR4D::WHITE;
}
if( aDimmed )
{
color.Desaturate( );
color = color.Mix( bg, 0.5f );
}
int penWidth = GetEffectivePenWidth( renderSettings );
KIFONT::FONT* font = GetFont();
if( !font )
font = KIFONT::FONT::GetFont( renderSettings->GetDefaultFont(), IsBold(), IsItalic() );
TEXT_ATTRIBUTES attrs = GetAttributes();
attrs.m_StrokeWidth = penWidth;
attrs.m_Halign = hjustify;
attrs.m_Valign = vjustify;
attrs.m_Angle = orient;
attrs.m_Multiline = false;
aPlotter->PlotText( textpos, color, GetShownText( true ), attrs, font, GetFontMetrics() );
}
wxString LIB_FIELD::GetFullText( int unit ) const
{
if( m_id != REFERENCE_FIELD )
return GetText();
wxString text = GetText();
text << wxT( "?" );
if( GetParentSymbol() && GetParentSymbol()->IsMulti() )
text << LIB_SYMBOL::LetterSubReference( unit, 'A' );
return text;
}
wxString LIB_FIELD::GetShownText( bool aAllowExtraText, int aDepth ) const
{
wxString text = EDA_TEXT::GetShownText( aAllowExtraText, aDepth );
if( IsNameShown() && aAllowExtraText )
text = GetName() << wxT( ": " ) << text;
return text;
}
const BOX2I LIB_FIELD::GetBoundingBox() const
{
/* Y coordinates for LIB_ITEMS are bottom to top, so we must invert the Y position when
* calling GetTextBox() that works using top to bottom Y axis orientation.
*/
BOX2I bbox = GetTextBox( -1, true );
bbox.RevertYAxis();
// We are using now a bottom to top Y axis.
VECTOR2I orig = bbox.GetOrigin();
VECTOR2I end = bbox.GetEnd();
RotatePoint( orig, GetTextPos(), -GetTextAngle() );
RotatePoint( end, GetTextPos(), -GetTextAngle() );
bbox.SetOrigin( orig );
bbox.SetEnd( end );
// We are using now a top to bottom Y axis:
bbox.RevertYAxis();
return bbox;
}
void LIB_FIELD::ViewGetLayers( int aLayers[], int& aCount ) const
{
aCount = 2;
switch( m_id )
{
case REFERENCE_FIELD: aLayers[0] = LAYER_REFERENCEPART; break;
case VALUE_FIELD: aLayers[0] = LAYER_VALUEPART; break;
default: aLayers[0] = LAYER_FIELDS; break;
}
aLayers[1] = LAYER_SELECTION_SHADOWS;
}
SCH_LAYER_ID LIB_FIELD::GetDefaultLayer() const
{
switch( m_id )
{
case REFERENCE_FIELD: return LAYER_REFERENCEPART;
case VALUE_FIELD: return LAYER_VALUEPART;
default: return LAYER_FIELDS;
}
}
wxString LIB_FIELD::GetName( bool aUseDefaultName ) const
{
if( m_name.IsEmpty() && aUseDefaultName )
return TEMPLATE_FIELDNAME::GetDefaultFieldName( m_id );
return m_name;
}
wxString LIB_FIELD::GetCanonicalName() const
{
if( m_id < MANDATORY_FIELDS )
return GetCanonicalFieldName( m_id );
return m_name;
}
void LIB_FIELD::SetName( const wxString& aName )
{
// Mandatory field names are fixed.
if( IsMandatory() )
{
wxFAIL_MSG( wxS( "trying to set a MANDATORY_FIELD's name\n" ) );
return;
}
m_name = aName;
}
wxString LIB_FIELD::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const
{
return wxString::Format( "%s '%s'",
UnescapeString( GetName() ),
KIUI::EllipsizeMenuText( GetText() ) );
}
void LIB_FIELD::BeginEdit( const VECTOR2I& aPosition )
{
SetTextPos( aPosition );
}
void LIB_FIELD::CalcEdit( const VECTOR2I& aPosition )
{
SetTextPos( aPosition );
}
void LIB_FIELD::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
{
wxString msg;
getSymbolEditorMsgPanelInfo( aFrame, aList );
// Don't use GetShownText(); we want to see the variable references here
aList.emplace_back( _( "Field" ), UnescapeString( GetName() ) );
// Don't use GetShownText() here; we want to show the user the variable references
aList.emplace_back( _( "Text" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) );
aList.emplace_back( _( "Visible" ), IsVisible() ? _( "Yes" ) : _( "No" ) );
aList.emplace_back( _( "Font" ), GetFont() ? GetFont()->GetName() : _( "Default" ) );
aList.emplace_back( _( "Style" ), GetTextStyleName() );
aList.emplace_back( _( "Text Size" ), aFrame->MessageTextFromValue( GetTextWidth() ) );
switch ( GetHorizJustify() )
{
case GR_TEXT_H_ALIGN_LEFT: msg = _( "Left" ); break;
case GR_TEXT_H_ALIGN_CENTER: msg = _( "Center" ); break;
case GR_TEXT_H_ALIGN_RIGHT: msg = _( "Right" ); break;
case GR_TEXT_H_ALIGN_INDETERMINATE: msg = INDETERMINATE_STATE; break;
}
aList.emplace_back( _( "H Justification" ), msg );
switch ( GetVertJustify() )
{
case GR_TEXT_V_ALIGN_TOP: msg = _( "Top" ); break;
case GR_TEXT_V_ALIGN_CENTER: msg = _( "Center" ); break;
case GR_TEXT_V_ALIGN_BOTTOM: msg = _( "Bottom" ); break;
case GR_TEXT_V_ALIGN_INDETERMINATE: msg = INDETERMINATE_STATE; break;
}
aList.emplace_back( _( "V Justification" ), msg );
}
BITMAPS LIB_FIELD::GetMenuImage() const
{
return BITMAPS::move;
}
bool LIB_FIELD::IsMandatory() const
{
return m_id >= 0 && m_id < MANDATORY_FIELDS;
}
bool LIB_FIELD::operator==( const SCH_ITEM& aItem ) const
{
if( aItem.Type() != LIB_FIELD_T )
return false;
const LIB_FIELD& field = static_cast<const LIB_FIELD&>( aItem );
if( m_id != field.m_id )
return false;
if( m_name != field.m_name )
return false;
if( !m_parent || !aItem.GetParentSymbol() )
return false;
if( m_parent->m_Uuid != aItem.GetParentSymbol()->m_Uuid )
return false;
if( m_id < MANDATORY_FIELDS )
return true;
if( m_Uuid == field.m_Uuid )
return true;
return EDA_TEXT::operator==( field );
}
double LIB_FIELD::Similarity( const SCH_ITEM& aItem ) const
{
if( aItem.Type() != LIB_FIELD_T )
return 0.0;
const LIB_FIELD& field = static_cast<const LIB_FIELD&>( aItem );
if( m_id != field.m_id && m_id < MANDATORY_FIELDS )
return 0.0;
if( !m_parent || !aItem.GetParentSymbol() )
return false;
if( m_parent->m_Uuid != aItem.GetParentSymbol()->m_Uuid )
return 0.0;
if( m_id < MANDATORY_FIELDS )
return 1.0;
if( m_Uuid == field.m_Uuid )
return 1.0;
double similarity = SimilarityBase( field );
similarity *= EDA_TEXT::Similarity( field );
return similarity;
}
static struct LIB_FIELD_DESC
{
LIB_FIELD_DESC()
{
PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
REGISTER_TYPE( LIB_FIELD );
propMgr.AddTypeCast( new TYPE_CAST<LIB_FIELD, SCH_ITEM> );
propMgr.AddTypeCast( new TYPE_CAST<LIB_FIELD, EDA_TEXT> );
propMgr.InheritsAfter( TYPE_HASH( LIB_FIELD ), TYPE_HASH( SCH_ITEM ) );
propMgr.InheritsAfter( TYPE_HASH( LIB_FIELD ), TYPE_HASH( EDA_TEXT ) );
propMgr.AddProperty( new PROPERTY<LIB_FIELD, bool>( _HKI( "Show Field Name" ),
&LIB_FIELD::SetNameShown, &LIB_FIELD::IsNameShown ) );
propMgr.AddProperty( new PROPERTY<LIB_FIELD, bool>( _HKI( "Allow Autoplacement" ),
&LIB_FIELD::SetCanAutoplace, &LIB_FIELD::CanAutoplace ) );
propMgr.Mask( TYPE_HASH( LIB_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Hyperlink" ) );
propMgr.Mask( TYPE_HASH( LIB_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Thickness" ) );
propMgr.Mask( TYPE_HASH( LIB_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Mirrored" ) );
propMgr.Mask( TYPE_HASH( LIB_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Visible" ) );
propMgr.Mask( TYPE_HASH( LIB_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Width" ) );
propMgr.Mask( TYPE_HASH( LIB_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Height" ) );
propMgr.Mask( TYPE_HASH( LIB_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Orientation" ) );
}
} _LIB_FIELD_DESC;

View File

@ -1,242 +0,0 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2022 CERN
* Copyright (C) 2004-2022 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file lib_field.h
*/
#ifndef CLASS_LIBENTRY_FIELDS_H
#define CLASS_LIBENTRY_FIELDS_H
#include <eda_text.h>
#include <sch_item.h>
class SCH_IO_KICAD_LEGACY_LIB_CACHE;
/**
* Field object used in symbol libraries. At least MANDATORY_FIELDS are always present in a
* RAM-resident library symbol. All constructors must ensure this because the symbol property
* editor assumes it.
* <p>
* A field is a string linked to a symbol. Unlike purely graphical text, fields can be used in
* netlist generation and other tools (BOM).
*
* The first 5 fields have a special meaning:
*
* 0 = REFERENCE_FIELD
* 1 = VALUE_FIELD
* 2 = FOOTPRINT_FIELD (default Footprint)
* 3 = DATASHEET_FIELD (user doc link)
* 4 = DESCRIPTION_FIELD
*
* others = free fields
* </p>
*
* @see enum MANDATORY_FIELD_T
*/
class LIB_FIELD : public SCH_ITEM, public EDA_TEXT
{
public:
LIB_FIELD( int aId = 2 );
LIB_FIELD( int aId, const wxString& aName );
LIB_FIELD( SCH_ITEM* aParent, int aId = 2, const wxString& aName = wxEmptyString );
// Do not create a copy constructor. The one generated by the compiler is adequate.
wxString GetClass() const override
{
return wxT( "LIB_FIELD" );
}
static inline bool ClassOf( const EDA_ITEM* aItem )
{
return aItem && aItem->Type() == LIB_FIELD_T;
}
wxString GetFriendlyName() const override
{
return _( "Field" );
}
/**
* Object constructor initialization helper.
*/
void Init( int aId );
/**
* Return the field name (not translated).
*
* The first four field IDs are reserved and therefore always return their respective
* names.
*
* The user definable fields will return FieldN where N is the ID of the field when the
* m_name member is empty unless false is passed to \a aUseDefaultName.
*/
wxString GetName( bool aUseDefaultName = true ) const;
/**
* Get a non-language-specific name for a field which can be used for storage, variable
* look-up, etc.
*/
wxString GetCanonicalName() const;
/**
* Set a user definable field name to \a aName.
*
* Reserved fields such as value and reference are not renamed. If the field name is
* changed, the field modified flag is set. If the field is the child of a symbol, the
* parent symbol's modified flag is also set.
*
* @param aName - User defined field name.
*/
void SetName( const wxString& aName );
int GetId() const { return m_id; }
void SetId( int aId );
int GetPenWidth() const override;
KIFONT::FONT* getDrawFont() const override;
bool IsHorizJustifyFlipped() const { return false; }
bool IsVertJustifyFlipped() const { return false; }
GR_TEXT_H_ALIGN_T GetEffectiveHorizJustify() const { return GetHorizJustify(); }
GR_TEXT_V_ALIGN_T GetEffectiveVertJustify() const { return GetVertJustify(); }
/**
* Copy parameters of this field to another field. Pointers are not copied.
*
* @param aTarget Target field to copy values to.
*/
void Copy( LIB_FIELD* aTarget ) const;
void ViewGetLayers( int aLayers[], int& aCount ) const override;
const BOX2I GetBoundingBox() const override;
void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const override;
LIB_FIELD& operator=( const LIB_FIELD& field );
/**
* Return the text of a field.
*
* If the field is the reference field, the unit number is used to
* create a pseudo reference text. If the base reference field is U,
* the string U?A will be returned for unit = 1.
*
* @param unit - The package unit number. Only effects reference field.
* @return Field text.
*/
wxString GetFullText( int unit = 1 ) const;
wxString GetShownText( bool aAllowExtraText, int aDepth = 0 ) const override;
SCH_LAYER_ID GetDefaultLayer() const;
void BeginEdit( const VECTOR2I& aStartPoint ) override;
void Move( const VECTOR2I& aOffset ) override;
void SetPosition( const VECTOR2I& aPosition ) override;
VECTOR2I GetPosition() const override { return EDA_TEXT::GetTextPos(); }
void MirrorHorizontally( int aCenter ) override;
void MirrorVertically( int aCenter ) override;
void Rotate( const VECTOR2I& aCenter, bool aRotateCCW = true ) override;
void Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBodyStyle,
const VECTOR2I& aOffset, bool aForceNoFill, bool aDimmed ) override;
void Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed ) override;
wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override;
BITMAPS GetMenuImage() const override;
EDA_ITEM* Clone() const override;
bool IsMandatory() const;
bool IsAutoAdded() const { return m_autoAdded; }
void SetAutoAdded( bool aAutoAdded ) { m_autoAdded = aAutoAdded; }
bool IsNameShown() const { return m_showName; }
void SetNameShown( bool aShown = true ) { m_showName = aShown; }
bool CanAutoplace() const { return m_allowAutoPlace; }
void SetCanAutoplace( bool aCanPlace ) { m_allowAutoPlace = aCanPlace; }
bool ShowInChooser() const { return m_showInChooser; }
void SetShowInChooser( bool aShow = true ) { m_showInChooser = aShow; }
double Similarity( const SCH_ITEM& aItem ) const override;
bool operator==( const SCH_ITEM& aItem ) const override;
private:
/**
* @copydoc SCH_ITEM::compare()
*
* The field specific sort order is as follows:
*
* - Field ID, REFERENCE, VALUE, etc.
* - Field string, case insensitive compare.
* - Field horizontal (X) position.
* - Field vertical (Y) position.
* - Field width.
* - Field height.
*/
int compare( const SCH_ITEM& aOther, int aCompareFlags = 0 ) const override;
/**
* Calculate the new circle at \a aPosition when editing.
*
* @param aPosition - The position to edit the circle in drawing coordinates.
*/
void CalcEdit( const VECTOR2I& aPosition ) override;
friend class SCH_IO_KICAD_LEGACY_LIB_CACHE; // Required to access m_name.
int m_id; ///< @see enum MANDATORY_FIELD_T
wxString m_name; ///< Name (not the field text value itself, that is #EDA_TEXT::m_Text)
bool m_autoAdded; ///< Was this field automatically added to a LIB_SYMBOL?
bool m_showName; ///< Render the field's name in addition to its value
bool m_allowAutoPlace; ///< This field can be autoplaced when converted to a SCH_FIELD
bool m_showInChooser; ///< This field is available as a data column for the chooser
};
#endif // CLASS_LIBENTRY_FIELDS_H

View File

@ -70,9 +70,9 @@ std::vector<SEARCH_TERM> LIB_SYMBOL::GetSearchTerms()
void LIB_SYMBOL::GetChooserFields( std::map<wxString, wxString>& aColumnMap )
{
for( SCH_ITEM& item : m_drawings[ LIB_FIELD_T ] )
for( SCH_ITEM& item : m_drawings[ SCH_FIELD_T ] )
{
LIB_FIELD* field = static_cast<LIB_FIELD*>( &item );
SCH_FIELD* field = static_cast<SCH_FIELD*>( &item );
if( field->ShowInChooser() )
aColumnMap[field->GetName()] = field->EDA_TEXT::GetShownText( false );
@ -107,9 +107,10 @@ LIB_SYMBOL::LIB_SYMBOL( const wxString& aName, LIB_SYMBOL* aParent, SYMBOL_LIB*
// Add the MANDATORY_FIELDS in RAM only. These are assumed to be present
// when the field editors are invoked.
m_drawings[LIB_FIELD_T].reserve( MANDATORY_FIELDS );
m_drawings[SCH_FIELD_T].reserve( MANDATORY_FIELDS );
for( int i = 0; i < MANDATORY_FIELDS; i++ )
m_drawings[LIB_FIELD_T].push_back( new LIB_FIELD( this, i ) );
m_drawings[SCH_FIELD_T].push_back( new SCH_FIELD( this, i ) );
SetName( aName );
@ -279,7 +280,7 @@ int LIB_SYMBOL::Compare( const LIB_SYMBOL& aRhs, int aCompareFlags, REPORTER* aR
{
if( it->Type() == LIB_SHAPE_T )
aShapes.insert( &(*it) );
else if( it->Type() == LIB_FIELD_T )
else if( it->Type() == SCH_FIELD_T )
aFields.insert( &(*it) );
else if( it->Type() == LIB_PIN_T )
aPins.insert( &(*it) );
@ -293,7 +294,7 @@ int LIB_SYMBOL::Compare( const LIB_SYMBOL& aRhs, int aCompareFlags, REPORTER* aR
{
if( it->Type() == LIB_SHAPE_T )
bShapes.insert( &(*it) );
else if( it->Type() == LIB_FIELD_T )
else if( it->Type() == SCH_FIELD_T )
bFields.insert( &(*it) );
else if( it->Type() == LIB_PIN_T )
bPins.insert( &(*it) );
@ -359,11 +360,11 @@ int LIB_SYMBOL::Compare( const LIB_SYMBOL& aRhs, int aCompareFlags, REPORTER* aR
for( const SCH_ITEM* aFieldItem : aFields )
{
const LIB_FIELD* aField = static_cast<const LIB_FIELD*>( aFieldItem );
const LIB_FIELD* bField = nullptr;
const SCH_FIELD* aField = static_cast<const SCH_FIELD*>( aFieldItem );
const SCH_FIELD* bField = nullptr;
int tmp = 0;
if( aField->GetId() >= 0 && aField->GetId() < MANDATORY_FIELDS )
if( aField->IsMandatory() )
bField = aRhs.GetFieldById( aField->GetId() );
else
bField = aRhs.FindField( aField->GetName() );
@ -598,20 +599,18 @@ std::unique_ptr< LIB_SYMBOL > LIB_SYMBOL::Flatten() const
}
// Grab all the rest of derived symbol fields.
for( const SCH_ITEM& item : m_drawings[ LIB_FIELD_T ] )
for( const SCH_ITEM& item : m_drawings[ SCH_FIELD_T ] )
{
const LIB_FIELD* aliasField = dynamic_cast<const LIB_FIELD*>( &item );
wxCHECK2( aliasField, continue );
const SCH_FIELD* aliasField = static_cast<const SCH_FIELD*>( &item );
// Mandatory fields were already resolved.
if( aliasField->IsMandatory() )
continue;
LIB_FIELD* newField = new LIB_FIELD( *aliasField );
SCH_FIELD* newField = new SCH_FIELD( *aliasField );
newField->SetParent( retv.get() );
LIB_FIELD* parentField = retv->FindField( aliasField->GetName() );
SCH_FIELD* parentField = retv->FindField( aliasField->GetName() );
if( !parentField ) // Derived symbol field does not exist in parent symbol.
{
@ -744,25 +743,20 @@ void LIB_SYMBOL::Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBo
if( aBodyStyle && item.m_bodyStyle && ( item.m_bodyStyle != aBodyStyle ) )
continue;
if( item.Type() == LIB_FIELD_T )
{
LIB_FIELD& field = static_cast<LIB_FIELD&>( item );
if( field.IsVisible() && !aSettings->m_ShowVisibleFields )
continue;
if( !field.IsVisible() && !aSettings->m_ShowHiddenFields )
continue;
}
if( item.Type() == LIB_PIN_T )
{
item.Print( aSettings, aUnit, aBodyStyle, aOffset, aForceNoFill, aDimmed );
}
else if( item.Type() == LIB_FIELD_T )
else if( item.Type() == SCH_FIELD_T )
{
SCH_FIELD& field = static_cast<SCH_FIELD&>( item );
if( ( field.IsVisible() && aSettings->m_ShowVisibleFields )
|| ( !field.IsVisible() && aSettings->m_ShowHiddenFields ) )
{
item.Print( aSettings, aUnit, aBodyStyle, aOffset, aForceNoFill, aDimmed );
}
}
else if( item.Type() == LIB_SHAPE_T )
{
LIB_SHAPE& shape = static_cast<LIB_SHAPE&>( item );
@ -842,7 +836,7 @@ void LIB_SYMBOL::Plot( PLOTTER *aPlotter, bool aBackground, const SCH_PLOT_OPTS&
// LIB_FIELDs are not plotted here, because this plot function is used to plot schematic
// items which have their own SCH_FIELDs
if( item.Type() == LIB_FIELD_T )
if( item.Type() == SCH_FIELD_T )
continue;
if( aUnit && item.m_unit && ( item.m_unit != aUnit ) )
@ -876,27 +870,20 @@ void LIB_SYMBOL::PlotFields( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT
aPlotter->SetColor( color );
for( SCH_ITEM& item : m_drawings )
for( SCH_ITEM& item : m_drawings[ SCH_FIELD_T ] )
{
if( item.Type() != LIB_FIELD_T )
continue;
LIB_FIELD& field = static_cast<LIB_FIELD&>( item );
SCH_FIELD& field = static_cast<SCH_FIELD&>( item );
if( !renderSettings->m_ShowHiddenFields && !field.IsVisible() )
continue;
// The reference is a special case: we should change the basic text
// to add '?' and the part id
wxString tmp = field.GetShownText( true );
if( field.GetId() == REFERENCE_FIELD )
{
wxString text = field.GetFullText( aUnit );
field.SetText( text );
}
wxString tmp = field.GetText();
field.SetText( field.GetFullText( aUnit ) );
item.Plot( aPlotter, aBackground, aPlotOpts, aUnit, aBodyStyle, aOffset, aDimmed );
field.SetText( tmp );
}
}
@ -950,9 +937,9 @@ void LIB_SYMBOL::RemoveDrawItem( SCH_ITEM* aItem )
// none of the MANDATORY_FIELDS may be removed in RAM, but they may be
// omitted when saving to disk.
if( aItem->Type() == LIB_FIELD_T )
if( aItem->Type() == SCH_FIELD_T )
{
if( static_cast<LIB_FIELD*>( aItem )->IsMandatory() )
if( static_cast<SCH_FIELD*>( aItem )->IsMandatory() )
return;
}
@ -1028,13 +1015,10 @@ int LIB_SYMBOL::GetPinCount()
LIB_PIN* LIB_SYMBOL::GetPin( const wxString& aNumber, int aUnit, int aBodyStyle ) const
{
std::vector<LIB_PIN*> pinList;
GetPins( pinList, aUnit, aBodyStyle );
for( LIB_PIN* pin : pinList )
{
wxASSERT( pin->Type() == LIB_PIN_T );
if( aNumber == pin->GetNumber() )
return pin;
}
@ -1123,9 +1107,9 @@ const BOX2I LIB_SYMBOL::GetUnitBoundingBox( int aUnit, int aBodyStyle,
if( item.m_bodyStyle > 0 && aBodyStyle > 0 && aBodyStyle != item.m_bodyStyle )
continue;
if( aIgnoreHiddenFields && ( item.Type() == LIB_FIELD_T )
&& !( (LIB_FIELD&) item ).IsVisible() )
if( aIgnoreHiddenFields && item.Type() == SCH_FIELD_T )
{
if( !static_cast<const SCH_FIELD&>( item ).IsVisible() )
continue;
}
@ -1152,7 +1136,7 @@ const BOX2I LIB_SYMBOL::GetBodyBoundingBox( int aUnit, int aBodyStyle, bool aInc
if( item.IsPrivate() && !aIncludePrivateItems )
continue;
if( item.Type() == LIB_FIELD_T )
if( item.Type() == SCH_FIELD_T )
continue;
if( item.Type() == LIB_PIN_T )
@ -1182,24 +1166,24 @@ const BOX2I LIB_SYMBOL::GetBodyBoundingBox( int aUnit, int aBodyStyle, bool aInc
void LIB_SYMBOL::deleteAllFields()
{
m_drawings[ LIB_FIELD_T ].clear();
m_drawings[ SCH_FIELD_T ].clear();
}
void LIB_SYMBOL::AddField( LIB_FIELD* aField )
void LIB_SYMBOL::AddField( SCH_FIELD* aField )
{
AddDrawItem( aField );
}
void LIB_SYMBOL::SetFields( const std::vector<LIB_FIELD>& aFields )
void LIB_SYMBOL::SetFields( const std::vector<SCH_FIELD>& aFieldsList )
{
deleteAllFields();
for( const LIB_FIELD& src : aFields )
for( const SCH_FIELD& src : aFieldsList )
{
// drawings is a ptr_vector, new and copy an object on the heap.
LIB_FIELD* field = new LIB_FIELD( src );
SCH_FIELD* field = new SCH_FIELD( src );
field->SetParent( this );
m_drawings.push_back( field );
@ -1209,16 +1193,16 @@ void LIB_SYMBOL::SetFields( const std::vector<LIB_FIELD>& aFields )
}
void LIB_SYMBOL::GetFields( std::vector<LIB_FIELD*>& aList )
void LIB_SYMBOL::GetFields( std::vector<SCH_FIELD*>& aList )
{
// Grab the MANDATORY_FIELDS first, in expected order given by enum MANDATORY_FIELD_T
for( int id = 0; id < MANDATORY_FIELDS; ++id )
aList.push_back( GetFieldById( id ) );
// Now grab all the rest of fields.
for( SCH_ITEM& item : m_drawings[ LIB_FIELD_T ] )
for( SCH_ITEM& item : m_drawings[ SCH_FIELD_T ] )
{
LIB_FIELD* field = static_cast<LIB_FIELD*>( &item );
SCH_FIELD* field = static_cast<SCH_FIELD*>( &item );
if( !field->IsMandatory() )
aList.push_back( field );
@ -1226,16 +1210,16 @@ void LIB_SYMBOL::GetFields( std::vector<LIB_FIELD*>& aList )
}
void LIB_SYMBOL::GetFields( std::vector<LIB_FIELD>& aList )
void LIB_SYMBOL::GetFields( std::vector<SCH_FIELD>& aList )
{
// Grab the MANDATORY_FIELDS first, in expected order given by enum MANDATORY_FIELD_T
for( int id = 0; id < MANDATORY_FIELDS; ++id )
aList.push_back( *GetFieldById( id ) );
// Now grab all the rest of fields.
for( SCH_ITEM& item : m_drawings[ LIB_FIELD_T ] )
for( SCH_ITEM& item : m_drawings[ SCH_FIELD_T ] )
{
LIB_FIELD* field = static_cast<LIB_FIELD*>( &item );
SCH_FIELD* field = static_cast<SCH_FIELD*>( &item );
if( !field->IsMandatory() )
aList.push_back( *field );
@ -1243,11 +1227,11 @@ void LIB_SYMBOL::GetFields( std::vector<LIB_FIELD>& aList )
}
LIB_FIELD* LIB_SYMBOL::GetFieldById( int aId ) const
SCH_FIELD* LIB_SYMBOL::GetFieldById( int aId ) const
{
for( const SCH_ITEM& item : m_drawings[ LIB_FIELD_T ] )
for( const SCH_ITEM& item : m_drawings[ SCH_FIELD_T ] )
{
LIB_FIELD* field = ( LIB_FIELD* ) &item;
SCH_FIELD* field = ( SCH_FIELD* ) &item;
if( field->GetId() == aId )
return field;
@ -1257,19 +1241,19 @@ LIB_FIELD* LIB_SYMBOL::GetFieldById( int aId ) const
}
LIB_FIELD* LIB_SYMBOL::FindField( const wxString& aFieldName, bool aCaseInsensitive )
SCH_FIELD* LIB_SYMBOL::FindField( const wxString& aFieldName, bool aCaseInsensitive )
{
for( SCH_ITEM& item : m_drawings[ LIB_FIELD_T ] )
for( SCH_ITEM& item : m_drawings[ SCH_FIELD_T ] )
{
if( aCaseInsensitive )
{
if( static_cast<LIB_FIELD*>( &item )->GetCanonicalName().Upper() == aFieldName.Upper() )
return static_cast<LIB_FIELD*>( &item );
if( static_cast<SCH_FIELD*>( &item )->GetCanonicalName().Upper() == aFieldName.Upper() )
return static_cast<SCH_FIELD*>( &item );
}
else
{
if( static_cast<LIB_FIELD*>( &item )->GetCanonicalName() == aFieldName )
return static_cast<LIB_FIELD*>( &item );
if( static_cast<SCH_FIELD*>( &item )->GetCanonicalName() == aFieldName )
return static_cast<SCH_FIELD*>( &item );
}
}
@ -1277,12 +1261,12 @@ LIB_FIELD* LIB_SYMBOL::FindField( const wxString& aFieldName, bool aCaseInsensit
}
const LIB_FIELD* LIB_SYMBOL::FindField( const wxString& aFieldName,
const SCH_FIELD* LIB_SYMBOL::FindField( const wxString& aFieldName,
bool aCaseInsensitive ) const
{
for( const SCH_ITEM& item : m_drawings[ LIB_FIELD_T ] )
for( const SCH_ITEM& item : m_drawings[ SCH_FIELD_T ] )
{
const LIB_FIELD& field = static_cast<const LIB_FIELD&>( item );
const SCH_FIELD& field = static_cast<const SCH_FIELD&>( item );
if( aCaseInsensitive )
{
@ -1300,41 +1284,41 @@ const LIB_FIELD* LIB_SYMBOL::FindField( const wxString& aFieldName,
}
LIB_FIELD& LIB_SYMBOL::GetValueField() const
SCH_FIELD& LIB_SYMBOL::GetValueField() const
{
LIB_FIELD* field = GetFieldById( VALUE_FIELD );
SCH_FIELD* field = GetFieldById( VALUE_FIELD );
wxASSERT( field != nullptr );
return *field;
}
LIB_FIELD& LIB_SYMBOL::GetReferenceField() const
SCH_FIELD& LIB_SYMBOL::GetReferenceField() const
{
LIB_FIELD* field = GetFieldById( REFERENCE_FIELD );
SCH_FIELD* field = GetFieldById( REFERENCE_FIELD );
wxASSERT( field != nullptr );
return *field;
}
LIB_FIELD& LIB_SYMBOL::GetFootprintField() const
SCH_FIELD& LIB_SYMBOL::GetFootprintField() const
{
LIB_FIELD* field = GetFieldById( FOOTPRINT_FIELD );
SCH_FIELD* field = GetFieldById( FOOTPRINT_FIELD );
wxASSERT( field != nullptr );
return *field;
}
LIB_FIELD& LIB_SYMBOL::GetDatasheetField() const
SCH_FIELD& LIB_SYMBOL::GetDatasheetField() const
{
LIB_FIELD* field = GetFieldById( DATASHEET_FIELD );
SCH_FIELD* field = GetFieldById( DATASHEET_FIELD );
wxASSERT( field != nullptr );
return *field;
}
LIB_FIELD& LIB_SYMBOL::GetDescriptionField() const
SCH_FIELD& LIB_SYMBOL::GetDescriptionField() const
{
LIB_FIELD* field = GetFieldById( DESCRIPTION_FIELD );
SCH_FIELD* field = GetFieldById( DESCRIPTION_FIELD );
wxASSERT( field != nullptr );
return *field;
}
@ -1378,9 +1362,9 @@ int LIB_SYMBOL::UpdateFieldOrdinals()
int retv = 0;
int lastOrdinal = MANDATORY_FIELDS;
for( SCH_ITEM& item : m_drawings[ LIB_FIELD_T ] )
for( SCH_ITEM& item : m_drawings[ SCH_FIELD_T ] )
{
LIB_FIELD* field = static_cast<LIB_FIELD*>( &item );
SCH_FIELD* field = static_cast<SCH_FIELD*>( &item );
// Mandatory fields were already resolved always have the same ordinal values.
if( field->IsMandatory() )
@ -1503,11 +1487,10 @@ SCH_ITEM* LIB_SYMBOL::LocateDrawItem( int aUnit, int aBodyStyle, KICAD_T aType,
* because this function uses DefaultTransform as orient/mirror matrix
* we temporary copy aTransform in DefaultTransform
*/
SCH_ITEM* item;
TRANSFORM transform = DefaultTransform;
DefaultTransform = aTransform;
item = LocateDrawItem( aUnit, aBodyStyle, aType, aPoint );
SCH_ITEM* item = LocateDrawItem( aUnit, aBodyStyle, aType, aPoint );
// Restore matrix
DefaultTransform = transform;
@ -1602,12 +1585,8 @@ void LIB_SYMBOL::SetHasAlternateBodyStyle( bool aHasAlternate, bool aDuplicatePi
{
std::vector<SCH_ITEM*> tmp; // Temporarily store the duplicated pins here.
for( SCH_ITEM& item : m_drawings )
for( SCH_ITEM& item : m_drawings[ LIB_PIN_T ] )
{
// Only pins are duplicated.
if( item.Type() != LIB_PIN_T )
continue;
if( item.m_bodyStyle == 1 )
{
SCH_ITEM* newItem = item.Duplicate();
@ -1645,7 +1624,7 @@ std::vector<SCH_ITEM*> LIB_SYMBOL::GetUnitDrawItems( int aUnit, int aBodyStyle )
for( SCH_ITEM& item : m_drawings )
{
if( item.Type() == LIB_FIELD_T )
if( item.Type() == SCH_FIELD_T )
continue;
if( ( aBodyStyle == -1 && item.GetUnit() == aUnit )
@ -1660,13 +1639,13 @@ std::vector<SCH_ITEM*> LIB_SYMBOL::GetUnitDrawItems( int aUnit, int aBodyStyle )
}
std::vector<struct LIB_SYMBOL_UNIT> LIB_SYMBOL::GetUnitDrawItems()
std::vector<LIB_SYMBOL_UNIT> LIB_SYMBOL::GetUnitDrawItems()
{
std::vector<struct LIB_SYMBOL_UNIT> units;
std::vector<LIB_SYMBOL_UNIT> units;
for( SCH_ITEM& item : m_drawings )
{
if( item.Type() == LIB_FIELD_T )
if( item.Type() == SCH_FIELD_T )
continue;
int unit = item.GetUnit();
@ -1680,7 +1659,7 @@ std::vector<struct LIB_SYMBOL_UNIT> LIB_SYMBOL::GetUnitDrawItems()
if( it == units.end() )
{
struct LIB_SYMBOL_UNIT newUnit;
LIB_SYMBOL_UNIT newUnit;
newUnit.m_unit = item.GetUnit();
newUnit.m_bodyStyle = item.GetBodyStyle();
newUnit.m_items.push_back( &item );

View File

@ -29,8 +29,8 @@
#include <general.h>
#include <symbol.h>
#include <sch_field.h>
#include <lib_tree_item.h>
#include <lib_field.h>
#include <vector>
#include <core/multivector.h>
@ -39,14 +39,13 @@ class OUTPUTFORMATTER;
class REPORTER;
class SYMBOL_LIB;
class LIB_SYMBOL;
class LIB_FIELD;
class LIB_PIN;
class TEST_LIB_SYMBOL_FIXTURE;
typedef std::shared_ptr<LIB_SYMBOL> LIB_SYMBOL_SPTR; ///< shared pointer to LIB_SYMBOL
typedef std::weak_ptr<LIB_SYMBOL> LIB_SYMBOL_REF; ///< weak pointer to LIB_SYMBOL
typedef MULTIVECTOR<SCH_ITEM, LIB_SHAPE_T, LIB_FIELD_T> LIB_ITEMS_CONTAINER;
typedef MULTIVECTOR<SCH_ITEM, SCH_FIELD_T, LIB_PIN_T> LIB_ITEMS_CONTAINER;
typedef LIB_ITEMS_CONTAINER::ITEM_PTR_VECTOR LIB_ITEMS;
@ -269,22 +268,22 @@ public:
*
* @param aFieldsList is a set of fields to import, removing all previous fields.
*/
void SetFields( const std::vector<LIB_FIELD>& aFieldsList );
void SetFields( const std::vector<SCH_FIELD>& aFieldsList );
/**
* Return a list of fields within this symbol.
*
* @param aList - List to add fields to
*/
void GetFields( std::vector<LIB_FIELD*>& aList );
void GetFields( std::vector<LIB_FIELD>& aList );
void GetFields( std::vector<SCH_FIELD*>& aList );
void GetFields( std::vector<SCH_FIELD>& aList );
/**
* Add a field. Takes ownership of the pointer.
*/
void AddField( LIB_FIELD* aField );
void AddField( SCH_FIELD* aField );
void AddField( LIB_FIELD& aField ) { AddField( new LIB_FIELD( aField ) ); }
void AddField( SCH_FIELD& aField ) { AddField( new SCH_FIELD( aField ) ); }
/**
* Find a field within this symbol matching \a aFieldName and returns it
@ -294,9 +293,9 @@ public:
*
* @return the field if found or NULL if the field was not found.
*/
LIB_FIELD* FindField( const wxString& aFieldName, bool aCaseInsensitive = false );
SCH_FIELD* FindField( const wxString& aFieldName, bool aCaseInsensitive = false );
const LIB_FIELD* FindField( const wxString& aFieldName,
const SCH_FIELD* FindField( const wxString& aFieldName,
bool aCaseInsensitive = false ) const;
/**
@ -305,22 +304,22 @@ public:
* @param aId - Id of field to return.
* @return The field if found, otherwise NULL.
*/
LIB_FIELD* GetFieldById( int aId ) const;
SCH_FIELD* GetFieldById( int aId ) const;
/** Return reference to the value field. */
LIB_FIELD& GetValueField() const;
SCH_FIELD& GetValueField() const;
/** Return reference to the reference designator field. */
LIB_FIELD& GetReferenceField() const;
SCH_FIELD& GetReferenceField() const;
/** Return reference to the footprint field */
LIB_FIELD& GetFootprintField() const;
SCH_FIELD& GetFootprintField() const;
/** Return reference to the datasheet field. */
LIB_FIELD& GetDatasheetField() const;
SCH_FIELD& GetDatasheetField() const;
/** Return reference to the description field. */
LIB_FIELD& GetDescriptionField() const;
SCH_FIELD& GetDescriptionField() const;
wxString GetPrefix();
@ -378,9 +377,9 @@ public:
*/
void RemoveDrawItem( SCH_ITEM* aItem );
void RemoveField( LIB_FIELD* aField ) { RemoveDrawItem( aField ); }
void RemoveField( SCH_FIELD* aField ) { RemoveDrawItem( aField ); }
size_t GetFieldCount() const { return m_drawings.size( LIB_FIELD_T ); }
size_t GetFieldCount() const { return m_drawings.size( SCH_FIELD_T ); }
/**
* Return a list of pin object pointers from the draw item list.
@ -591,7 +590,7 @@ public:
/**
* Return a list of SCH_ITEM objects separated by unit and convert number.
*
* @note This does not include LIB_FIELD objects since they are not associated with
* @note This does not include SCH_FIELD objects since they are not associated with
* unit and/or convert numbers.
*/
std::vector<struct LIB_SYMBOL_UNIT> GetUnitDrawItems();
@ -599,7 +598,7 @@ public:
/**
* Return a list of item pointers for \a aUnit and \a aBodyStyle for this symbol.
*
* @note #LIB_FIELD objects are not included.
* @note #SCH_FIELD objects are not included.
*
* @param aUnit is the unit number of the item, -1 includes all units.
* @param aBodyStyle is the alternate body styple of the item, -1 includes all body styles.

View File

@ -33,7 +33,7 @@
* Define a symbol library graphical text item.
*
* This is only a graphical text item. Field text like the reference designator,
* symbol value, etc. are not LIB_TEXT items. See the #LIB_FIELD class for the
* symbol value, etc. are not LIB_TEXT items. See the #SCH_FIELD class for the
* field item definition.
*/
class LIB_TEXT : public SCH_ITEM, public EDA_TEXT

View File

@ -662,7 +662,7 @@ wxString NETLIST_EXPORTER_ALLEGRO::getGroupField( int aGroupIndex, const wxArray
for( const wxString& field : aFieldArray )
{
if( LIB_FIELD* fld = sym->GetLibSymbolRef()->FindField( field, true ) )
if( SCH_FIELD* fld = sym->GetLibSymbolRef()->FindField( field, true ) )
{
wxString fieldText = fld->GetShownText( false, 0 );

View File

@ -572,7 +572,7 @@ XNODE* NETLIST_EXPORTER_XML::makeLibParts()
XNODE* xlibparts = node( wxT( "libparts" ) ); // auto_ptr
std::vector<LIB_PIN*> pinList;
std::vector<LIB_FIELD*> fieldList;
std::vector<SCH_FIELD*> fieldList;
m_libraries.clear();
@ -613,7 +613,7 @@ XNODE* NETLIST_EXPORTER_XML::makeLibParts()
XNODE* xfields;
xlibpart->AddChild( xfields = node( "fields" ) );
for( const LIB_FIELD* field : fieldList )
for( const SCH_FIELD* field : fieldList )
{
XNODE* xfield;
xfields->AddChild( xfield = node( wxT( "field" ), field->GetText() ) );

View File

@ -413,10 +413,7 @@ EDA_ITEM* SCH_COMMIT::parentObject( EDA_ITEM* aItem ) const
{
EDA_ITEM* parent = aItem->GetParent();
if( parent && parent->Type() == SCH_SYMBOL_T )
return parent;
if( parent && parent->Type() == LIB_SYMBOL_T )
if( parent && ( parent->Type() == SCH_SYMBOL_T || parent->Type() == LIB_SYMBOL_T ) )
return parent;
if( m_isLibEditor )

View File

@ -34,14 +34,11 @@
#include <wx/menu.h>
#include <base_units.h>
#include <common.h> // for ExpandTextVars
#include <eda_item.h>
#include <sch_edit_frame.h>
#include <plotters/plotter.h>
#include <bitmaps.h>
#include <core/kicad_algo.h>
#include <core/mirror.h>
#include <kiway.h>
#include <general.h>
#include <symbol_library.h>
#include <sch_symbol.h>
#include <sch_field.h>
@ -50,8 +47,6 @@
#include <settings/color_settings.h>
#include <string_utils.h>
#include <trace_helpers.h>
#include <trigo.h>
#include <eeschema_id.h>
#include <tool/tool_manager.h>
#include <tools/sch_navigate_tool.h>
#include <font/outline_font.h>
@ -64,17 +59,23 @@ SCH_FIELD::SCH_FIELD( const VECTOR2I& aPos, int aFieldId, SCH_ITEM* aParent,
m_id( 0 ),
m_showName( false ),
m_allowAutoPlace( true ),
m_autoAdded( false ),
m_showInChooser( true ),
m_renderCacheValid( false ),
m_lastResolvedColor( COLOR4D::UNSPECIFIED )
{
if( aName.IsEmpty() )
SetName( TEMPLATE_FIELDNAME::GetDefaultFieldName( aFieldId ) );
else
SetName( aName );
SetTextPos( aPos );
SetId( aFieldId ); // will also set the layer
SetVisible( false );
}
SCH_FIELD::SCH_FIELD( SCH_ITEM* aParent, int aFieldId, const wxString& aName ) :
SCH_FIELD::SCH_FIELD( SCH_ITEM* aParent, int aFieldId, const wxString& aName) :
SCH_FIELD( VECTOR2I(), aFieldId, aParent, aName )
{
}
@ -89,6 +90,8 @@ SCH_FIELD::SCH_FIELD( const SCH_FIELD& aField ) :
m_showName = aField.m_showName;
m_allowAutoPlace = aField.m_allowAutoPlace;
m_isNamedVariable = aField.m_isNamedVariable;
m_autoAdded = aField.m_autoAdded;
m_showInChooser = aField.m_showInChooser;
m_renderCache.clear();
@ -142,6 +145,12 @@ EDA_ITEM* SCH_FIELD::Clone() const
}
void SCH_FIELD::Copy( SCH_FIELD* aTarget ) const
{
*aTarget = *this;
}
void SCH_FIELD::SetId( int aId )
{
m_id = aId;
@ -155,7 +164,7 @@ void SCH_FIELD::SetId( int aId )
default: SetLayer( LAYER_SHEETFIELDS ); break;
}
}
else if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
else if( m_parent && ( m_parent->Type() == SCH_SYMBOL_T || m_parent->Type() == LIB_SYMBOL_T ) )
{
switch( m_id )
{
@ -218,6 +227,9 @@ wxString SCH_FIELD::GetShownText( const SCH_SHEET_PATH* aPath, bool aAllowExtraT
if( IsNameShown() && aAllowExtraText )
text = GetShownName() << wxS( ": " ) << text;
if( !aPath )
return text;
if( text == wxS( "~" ) ) // Legacy placeholder for empty string
{
text = wxS( "" );
@ -267,10 +279,24 @@ wxString SCH_FIELD::GetShownText( bool aAllowExtraText, int aDepth ) const
if( SCHEMATIC* schematic = Schematic() )
return GetShownText( &schematic->CurrentSheet(), aAllowExtraText, aDepth );
else
return EDA_TEXT::GetShownText( aAllowExtraText, aDepth );
return GetShownText( nullptr, aAllowExtraText, aDepth );
}
wxString SCH_FIELD::GetFullText( int unit ) const
{
if( GetId() != REFERENCE_FIELD )
return GetText();
wxString text = GetText();
text << wxT( "?" );
if( GetParentSymbol() && GetParentSymbol()->IsMulti() )
text << LIB_SYMBOL::LetterSubReference( unit, 'A' );
return text;
}
int SCH_FIELD::GetPenWidth() const
{
@ -352,16 +378,21 @@ SCH_FIELD::GetRenderCache( const wxString& forResolvedText, const VECTOR2I& forP
void SCH_FIELD::Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBodyStyle,
const VECTOR2I& aOffset, bool aForceNoFill, bool aDimmed )
{
SCH_SHEET_PATH* sheet = &Schematic()->CurrentSheet();
wxString text;
if( Schematic() )
text = GetShownText( &Schematic()->CurrentSheet(), true );
else
text = GetShownText( true );
if( ( !IsVisible() && !IsForceVisible() ) || text.IsEmpty() )
return;
wxDC* DC = aSettings->GetPrintDC();
COLOR4D color = aSettings->GetLayerColor( IsForceVisible() ? LAYER_HIDDEN : m_layer );
bool blackAndWhiteMode = GetGRForceBlackPenState();
VECTOR2I textpos;
int penWidth = GetEffectiveTextPenWidth( aSettings->GetDefaultPenWidth() );
if( ( !IsVisible() && !IsForceVisible() ) || GetShownText( sheet, true ).IsEmpty() )
return;
COLOR4D bg = aSettings->GetBackgroundColor();
if( bg == COLOR4D::UNSPECIFIED || GetGRForceBlackPenState() )
@ -373,58 +404,62 @@ void SCH_FIELD::Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBod
if( !blackAndWhiteMode && GetTextColor() != COLOR4D::UNSPECIFIED )
color = GetTextColor();
if( aDimmed )
{
color.Desaturate( );
color = color.Mix( bg, 0.5f );
}
// Calculate the text orientation according to the symbol orientation.
EDA_ANGLE orient = GetTextAngle();
VECTOR2I textpos = GetTextPos();
GR_TEXT_H_ALIGN_T hjustify = GetHorizJustify();
GR_TEXT_V_ALIGN_T vjustify = GetVertJustify();
KIFONT::FONT* font = GetFont();
if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
if( !font )
font = KIFONT::FONT::GetFont( aSettings->GetDefaultFont(), IsBold(), IsItalic() );
if( m_parent && m_parent->Type() == LIB_SYMBOL_T )
{
SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
textpos = aSettings->TransformCoordinate( GetTextPos() ) + aOffset;
}
else if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
{
/*
* Calculate the text justification, according to the symbol orientation/mirror.
* This is a bit complicated due to cumulative calculations:
* - numerous cases (mirrored or not, rotation)
* - the GRText function will also recalculate H and V justifications according to the
* text orientation.
* - when symbol is mirrored, the text is not mirrored and justifications are complicated
* to calculate so the easier way is to use no justifications (centered text) and use
* GetBoundingBox to know the text coordinate considered as centered
*/
hjustify = GR_TEXT_H_ALIGN_CENTER;
vjustify = GR_TEXT_V_ALIGN_CENTER;
textpos = GetBoundingBox().Centre() + aOffset;
if( parentSymbol && parentSymbol->GetTransform().y1 ) // Rotate symbol 90 degrees.
if( aSettings->m_Transform.y1 ) // Rotate symbol 90 degrees.
{
if( orient == ANGLE_HORIZONTAL )
orient = ANGLE_VERTICAL;
else
orient = ANGLE_HORIZONTAL;
}
if( parentSymbol && parentSymbol->GetDNP() )
{
color.Desaturate();
color = color.Mix( bg, 0.5f );
}
}
KIFONT::FONT* font = GetFont();
if( !font )
font = KIFONT::FONT::GetFont( aSettings->GetDefaultFont(), IsBold(), IsItalic() );
/*
* Calculate the text justification, according to the symbol orientation/mirror.
* This is a bit complicated due to cumulative calculations:
* - numerous cases (mirrored or not, rotation)
* - the GRText function will also recalculate H and V justifications according to the text
* orientation.
* - When a symbol is mirrored, the text is not mirrored and justifications are complicated
* to calculate so the more easily way is to use no justifications (centered text) and use
* GetBoundingBox to know the text coordinate considered as centered
*/
textpos = GetBoundingBox().Centre() + aOffset;
if( GetParent() && GetParent()->Type() == SCH_GLOBAL_LABEL_T )
else if( m_parent && m_parent->Type() == SCH_GLOBAL_LABEL_T )
{
SCH_GLOBALLABEL* label = static_cast<SCH_GLOBALLABEL*>( GetParent() );
textpos += label->GetSchematicTextOffset( aSettings );
}
GRPrintText( DC, textpos, color, GetShownText( sheet, true ), orient, GetTextSize(),
GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_CENTER, penWidth, IsItalic(), IsBold(),
font, GetFontMetrics() );
GRPrintText( DC, textpos, color, text, orient, GetTextSize(), hjustify, vjustify, penWidth,
IsItalic(), IsBold(), font, GetFontMetrics() );
}
void SCH_FIELD::ImportValues( const LIB_FIELD& aSource )
void SCH_FIELD::ImportValues( const SCH_FIELD& aSource )
{
SetAttributes( aSource );
SetNameShown( aSource.IsNameShown() );
@ -434,12 +469,11 @@ void SCH_FIELD::ImportValues( const LIB_FIELD& aSource )
void SCH_FIELD::SwapData( SCH_ITEM* aItem )
{
wxCHECK_RET( aItem && aItem->Type() == SCH_FIELD_T, wxT( "Cannot swap with invalid item." ) );
SCH_ITEM::SwapFlags( aItem );
wxCHECK_RET( ( aItem != nullptr ) && ( aItem->Type() == SCH_FIELD_T ),
wxT( "Cannot swap field data with invalid item." ) );
SCH_FIELD* item = (SCH_FIELD*) aItem;
SCH_FIELD* item = static_cast<SCH_FIELD*>( aItem );
std::swap( m_layer, item->m_layer );
std::swap( m_showName, item->m_showName );
@ -487,6 +521,17 @@ void SCH_FIELD::ViewGetLayers( int aLayers[], int& aCount ) const
}
SCH_LAYER_ID SCH_FIELD::GetDefaultLayer() const
{
switch( m_id )
{
case REFERENCE_FIELD: return LAYER_REFERENCEPART;
case VALUE_FIELD: return LAYER_VALUEPART;
default: return LAYER_FIELDS;
}
}
EDA_ANGLE SCH_FIELD::GetDrawRotation() const
{
// Calculate the text orientation according to the symbol orientation.
@ -511,8 +556,33 @@ EDA_ANGLE SCH_FIELD::GetDrawRotation() const
const BOX2I SCH_FIELD::GetBoundingBox() const
{
// Calculate the text bounding box:
BOX2I bbox = GetTextBox();
BOX2I bbox;
if( m_parent && m_parent->Type() == LIB_SYMBOL_T )
{
/*
* Y coordinates for LIB_ITEMS are bottom to top, so we must invert the Y position
* when calling GetTextBox() that works using top to bottom Y axis orientation.
*/
bbox = GetTextBox( -1, true );
bbox.RevertYAxis();
// We are using now a bottom to top Y axis.
VECTOR2I orig = bbox.GetOrigin();
VECTOR2I end = bbox.GetEnd();
RotatePoint( orig, GetTextPos(), -GetTextAngle() );
RotatePoint( end, GetTextPos(), -GetTextAngle() );
bbox.SetOrigin( orig );
bbox.SetEnd( end );
// We are using now a top to bottom Y axis:
bbox.RevertYAxis();
}
else
{
bbox = GetTextBox();
// Calculate the bounding box position relative to the parent:
VECTOR2I origin = GetParentPosition();
@ -529,8 +599,8 @@ const BOX2I SCH_FIELD::GetBoundingBox() const
{
SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
// Due to the Y axis direction, we must mirror the bounding box,
// relative to the text position:
// Due to the Y axis direction, we must mirror the bounding box, relative to the
// text position:
MIRROR( begin.y, pos.y );
MIRROR( end.y, pos.y );
@ -546,6 +616,7 @@ const BOX2I SCH_FIELD::GetBoundingBox() const
bbox.Move( origin );
bbox.Normalize();
}
return bbox;
}
@ -898,12 +969,50 @@ void SCH_FIELD::Rotate( const VECTOR2I& aCenter, bool aRotateCCW )
VECTOR2I pt = GetPosition();
RotatePoint( pt, aCenter, aRotateCCW ? ANGLE_270 : ANGLE_90 );
SetPosition( pt );
SetTextAngle( GetTextAngle() != ANGLE_HORIZONTAL ? ANGLE_HORIZONTAL : ANGLE_VERTICAL );
}
void SCH_FIELD::MirrorHorizontally( int aCenter )
{
int x = GetTextPos().x;
x -= aCenter;
x *= -1;
x += aCenter;
SetTextX( x );
}
void SCH_FIELD::MirrorVertically( int aCenter )
{
int y = GetTextPos().y;
y -= aCenter;
y *= -1;
y += aCenter;
SetTextY( y );
}
void SCH_FIELD::BeginEdit( const VECTOR2I& aPosition )
{
SetTextPos( aPosition );
}
void SCH_FIELD::CalcEdit( const VECTOR2I& aPosition )
{
SetTextPos( aPosition );
}
wxString SCH_FIELD::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const
{
return wxString::Format( "%s '%s'", GetName(), KIUI::EllipsizeMenuText( GetText() ) );
return wxString::Format( "%s '%s'", UnescapeString( GetName() ), KIUI::EllipsizeMenuText( GetText() ) );
}
@ -1010,53 +1119,42 @@ void SCH_FIELD::SetText( const wxString& aText )
wxString SCH_FIELD::GetName( bool aUseDefaultName ) const
{
if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
if( m_parent && ( m_parent->Type() == SCH_SYMBOL_T || m_parent->Type() == LIB_SYMBOL_T ) )
{
if( m_id >= 0 && m_id < MANDATORY_FIELDS )
if( IsMandatory() )
return GetCanonicalFieldName( m_id );
else if( m_name.IsEmpty() && aUseDefaultName )
return TEMPLATE_FIELDNAME::GetDefaultFieldName( m_id );
else
return m_name;
}
else if( m_parent && m_parent->Type() == SCH_SHEET_T )
{
if( m_id >= 0 && m_id < SHEET_MANDATORY_FIELDS )
if( IsMandatory() )
return SCH_SHEET::GetDefaultFieldName( m_id );
else if( m_name.IsEmpty() && aUseDefaultName )
return SCH_SHEET::GetDefaultFieldName( m_id );
else
return m_name;
}
else if( m_parent && m_parent->IsType( { SCH_LABEL_LOCATE_ANY_T } ) )
{
return SCH_LABEL_BASE::GetDefaultFieldName( m_name, aUseDefaultName );
}
else
{
wxFAIL_MSG( "Unhandled field owner type." );
return m_name;
}
}
wxString SCH_FIELD::GetCanonicalName() const
{
if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
if( m_parent && ( m_parent->Type() == SCH_SYMBOL_T || m_parent->Type() == LIB_SYMBOL_T ) )
{
if( m_id >= 0 && m_id < MANDATORY_FIELDS )
if( IsMandatory() )
return GetCanonicalFieldName( m_id );
else
return m_name;
}
else if( m_parent && m_parent->Type() == SCH_SHEET_T )
{
switch( m_id )
{
case SHEETNAME: return wxT( "Sheetname" );
case SHEETFILENAME: return wxT( "Sheetfile" );
default: return m_name;
}
if( m_id == SHEETNAME )
return wxT( "Sheetname" );
else if( m_id == SHEETFILENAME )
return wxT( "Sheetfile" );
}
else if( m_parent && m_parent->IsType( { SCH_LABEL_LOCATE_ANY_T } ) )
{
@ -1071,27 +1169,15 @@ wxString SCH_FIELD::GetCanonicalName() const
{
return wxT( "Intersheetrefs" );
}
else
{
return m_name;
}
}
else
{
if( m_parent )
{
wxFAIL_MSG( wxString::Format( "Unhandled field owner type (id %d, parent type %d).",
m_id, m_parent->Type() ) );
}
return m_name;
}
}
BITMAPS SCH_FIELD::GetMenuImage() const
{
if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
if( m_parent && ( m_parent->Type() == SCH_SYMBOL_T || m_parent->Type() == LIB_SYMBOL_T ) )
{
switch( m_id )
{
@ -1109,14 +1195,22 @@ BITMAPS SCH_FIELD::GetMenuImage() const
bool SCH_FIELD::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
{
// Do not hit test hidden or empty fields.
if( !IsVisible() || GetShownText( true ).IsEmpty() )
if( ( !IsVisible() && !IsForceVisible() ) || GetShownText( true ).IsEmpty() )
return false;
BOX2I rect = GetBoundingBox();
// Text in symbol editor can have additional chars (ie: reference designators U? or U?A)
if( m_parent && m_parent->Type() == LIB_SYMBOL_T )
{
SCH_FIELD temp( *this );
temp.SetText( GetFullText() );
rect = temp.GetBoundingBox();
}
rect.Inflate( aAccuracy );
if( GetParent() && GetParent()->Type() == SCH_GLOBAL_LABEL_T )
if( m_parent && m_parent->Type() == SCH_GLOBAL_LABEL_T )
{
SCH_GLOBALLABEL* label = static_cast<SCH_GLOBALLABEL*>( GetParent() );
rect.Offset( label->GetSchematicTextOffset( nullptr ) );
@ -1129,7 +1223,10 @@ bool SCH_FIELD::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
bool SCH_FIELD::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
{
// Do not hit test hidden fields.
if( !IsVisible() || GetShownText( true ).IsEmpty() )
if( ( !IsVisible() && !IsForceVisible() ) || GetShownText( true ).IsEmpty() )
return false;
if( m_flags & (STRUCT_DELETED | SKIP_STRUCT ) )
return false;
BOX2I rect = aRect;
@ -1152,9 +1249,14 @@ bool SCH_FIELD::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) co
void SCH_FIELD::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed )
{
SCH_SHEET_PATH* sheet = &Schematic()->CurrentSheet();
wxString text;
if( GetShownText( sheet, true ).IsEmpty() || aBackground )
if( Schematic() )
text = GetShownText( &Schematic()->CurrentSheet(), true );
else
text = GetShownText( true );
if( ( !IsVisible() && !IsForceVisible() ) || text.IsEmpty() || aBackground )
return;
SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter );
@ -1169,6 +1271,12 @@ void SCH_FIELD::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS&
if( aPlotter->GetColorMode() && GetTextColor() != COLOR4D::UNSPECIFIED )
color = GetTextColor();
if( aDimmed )
{
color.Desaturate( );
color = color.Mix( bg, 0.5f );
}
penWidth = std::max( penWidth, renderSettings->GetMinPenWidth() );
// clamp the pen width to be sure the text is readable
@ -1183,17 +1291,7 @@ void SCH_FIELD::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS&
GR_TEXT_H_ALIGN_T hjustify = GetHorizJustify();
GR_TEXT_V_ALIGN_T vjustify = GetVertJustify();
if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
{
SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
if( parentSymbol->GetDNP() )
{
color.Desaturate();
color = color.Mix( bg, 0.5f );
}
if( parentSymbol->GetTransform().y1 ) // Rotate symbol 90 deg.
if( renderSettings->m_Transform.y1 ) // Rotate symbol 90 deg.
{
if( orient.IsHorizontal() )
orient = ANGLE_VERTICAL;
@ -1201,6 +1299,8 @@ void SCH_FIELD::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS&
orient = ANGLE_HORIZONTAL;
}
if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
{
/*
* Calculate the text justification, according to the symbol orientation/mirror. This is
* a bit complicated due to cumulative calculations:
@ -1209,8 +1309,8 @@ void SCH_FIELD::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS&
* to the text orientation
* - when a symbol is mirrored the text is not, and justifications become a nightmare
*
* So the easier way is to use no justifications (centered text) and use GetBoundingBox to
* know the text coordinate considered as centered.
* So the easier way is to use no justifications (centered text) and use GetBoundingBox
* to know the text coordinate considered as centered.
*/
hjustify = GR_TEXT_H_ALIGN_CENTER;
vjustify = GR_TEXT_V_ALIGN_CENTER;
@ -1234,9 +1334,9 @@ void SCH_FIELD::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS&
attrs.m_Angle = orient;
attrs.m_Multiline = false;
aPlotter->PlotText( textpos, color, GetShownText( sheet, true ), attrs, font, GetFontMetrics() );
aPlotter->PlotText( textpos, color, text, attrs, font, GetFontMetrics() );
if( IsHypertext() )
if( IsHypertext() && Schematic() )
{
SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( m_parent );
std::vector<std::pair<wxString, wxString>> pages;
@ -1245,10 +1345,10 @@ void SCH_FIELD::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS&
wxCHECK( label, /* void */ );
label->GetIntersheetRefs( sheet, &pages );
label->GetIntersheetRefs( &Schematic()->CurrentSheet(), &pages );
for( const std::pair<wxString, wxString>& page : pages )
pageHrefs.push_back( wxT( "#" ) + page.first );
for( const auto& [ pageNumber, sheetName ] : pages )
pageHrefs.push_back( wxT( "#" ) + pageNumber );
bbox.Offset( label->GetSchematicTextOffset( renderSettings ) );
@ -1299,7 +1399,16 @@ VECTOR2I SCH_FIELD::GetParentPosition() const
}
bool SCH_FIELD::operator <( const SCH_ITEM& aItem ) const
bool SCH_FIELD::IsMandatory() const
{
if( m_parent && m_parent->Type() == SCH_SHEET_T )
return m_id >= 0 && m_id < SHEET_MANDATORY_FIELDS;
else
return m_id >= 0 && m_id < MANDATORY_FIELDS;
}
bool SCH_FIELD::operator<( const SCH_ITEM& aItem ) const
{
if( Type() != aItem.Type() )
return Type() < aItem.Type();
@ -1335,6 +1444,13 @@ bool SCH_FIELD::operator==(const SCH_ITEM& aOther) const
bool SCH_FIELD::operator==( const SCH_FIELD& aOther ) const
{
// Identical fields of different symbols are not equal.
if( !GetParentSymbol() || !aOther.GetParentSymbol()
|| GetParentSymbol()->m_Uuid != aOther.GetParentSymbol()->m_Uuid )
{
return false;
}
if( GetId() != aOther.GetId() )
return false;
@ -1350,10 +1466,7 @@ bool SCH_FIELD::operator==( const SCH_FIELD& aOther ) const
if( CanAutoplace() != aOther.CanAutoplace() )
return false;
if( GetText() != aOther.GetText() )
return false;
return true;
return EDA_TEXT::operator==( aOther );
}
@ -1378,6 +1491,10 @@ double SCH_FIELD::Similarity( const SCH_ITEM& aOther ) const
similarity *= 0.5;
}
similarity *= SimilarityBase( aOther );
similarity *= EDA_TEXT::Similarity( field );
if( GetPosition() != field.GetPosition() )
similarity *= 0.5;
@ -1390,13 +1507,81 @@ double SCH_FIELD::Similarity( const SCH_ITEM& aOther ) const
if( CanAutoplace() != field.CanAutoplace() )
similarity *= 0.5;
if( GetText() != field.GetText() )
similarity *= Levenshtein( field );
return similarity;
}
int SCH_FIELD::compare( const SCH_ITEM& aOther, int aCompareFlags ) const
{
wxASSERT( aOther.Type() == SCH_FIELD_T );
int retv = SCH_ITEM::compare( aOther, aCompareFlags );
if( retv )
return retv;
const SCH_FIELD* tmp = static_cast<const SCH_FIELD*>( &aOther );
// Equality test will vary depending whether or not the field is mandatory. Otherwise,
// sorting is done by ordinal.
if( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::EQUALITY )
{
// Mandatory fields have fixed ordinals and their names can vary due to translated field
// names. Optional fields have fixed names and their ordinals can vary.
if( IsMandatory() )
{
if( m_id != tmp->m_id )
return m_id - tmp->m_id;
}
else
{
retv = m_name.Cmp( tmp->m_name );
if( retv )
return retv;
}
}
else // assume we're sorting
{
if( m_id != tmp->m_id )
return m_id - tmp->m_id;
}
bool ignoreFieldText = false;
if( m_id == REFERENCE_FIELD && !( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::EQUALITY ) )
ignoreFieldText = true;
if( m_id == VALUE_FIELD && ( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::ERC ) )
ignoreFieldText = true;
if( !ignoreFieldText )
{
retv = GetText().CmpNoCase( tmp->GetText() );
if( retv != 0 )
return retv;
}
if( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::EQUALITY )
{
if( GetTextPos().x != tmp->GetTextPos().x )
return GetTextPos().x - tmp->GetTextPos().x;
if( GetTextPos().y != tmp->GetTextPos().y )
return GetTextPos().y - tmp->GetTextPos().y;
}
if( GetTextWidth() != tmp->GetTextWidth() )
return GetTextWidth() - tmp->GetTextWidth();
if( GetTextHeight() != tmp->GetTextHeight() )
return GetTextHeight() - tmp->GetTextHeight();
return 0;
}
static struct SCH_FIELD_DESC
{
SCH_FIELD_DESC()

View File

@ -34,7 +34,6 @@
#include "scintilla_tricks.h"
class SCH_EDIT_FRAME;
class LIB_FIELD;
/**
@ -59,12 +58,12 @@ public:
SCH_FIELD( const SCH_FIELD& aText );
~SCH_FIELD()
~SCH_FIELD() override
{ }
SCH_FIELD& operator=( const SCH_FIELD& aField );
static inline bool ClassOf( const EDA_ITEM* aItem )
static bool ClassOf( const EDA_ITEM* aItem )
{
return aItem && SCH_FIELD_T == aItem->Type();
}
@ -94,6 +93,11 @@ public:
return false;
}
wxString GetFriendlyName() const override
{
return _( "Field" );
}
bool IsHypertext() const override
{
return GetCanonicalName() == wxT( "Intersheetrefs" );
@ -141,6 +145,17 @@ public:
wxString GetShownText( bool aAllowExtraText, int aDepth = 0 ) const override;
/**
* Return the text of a field.
*
* If the field is the reference field, the unit number is used to create a pseudo reference
* text. If the base reference field is U, the string U?A will be returned for unit = 1.
*
* @param unit - The package unit number. Only effects reference field.
* @return Field text.
*/
wxString GetFullText( int unit = 1 ) const;
/**
* Return true if both the name and value of the field are empty. Whitespace
* does not count as non-empty
@ -168,6 +183,8 @@ public:
void ViewGetLayers( int aLayers[], int& aCount ) const override;
SCH_LAYER_ID GetDefaultLayer() const;
/**
* Adjusters to allow EDA_TEXT to draw/print/etc. text in absolute coords.
*/
@ -201,17 +218,14 @@ public:
void SwapData( SCH_ITEM* aItem ) override;
/**
* Copy parameters from a LIB_FIELD source.
*
* Pointers and specific values (position) are not copied.
*
* @param aSource is the LIB_FIELD to read.
*/
void ImportValues( const LIB_FIELD& aSource );
int GetPenWidth() const override;
bool IsAutoAdded() const { return m_autoAdded; }
void SetAutoAdded( bool aAutoAdded ) { m_autoAdded = aAutoAdded; }
bool ShowInChooser() const { return m_showInChooser; }
void SetShowInChooser( bool aShow = true ) { m_showInChooser = aShow; }
void ClearCaches() override;
void ClearRenderCache() override;
@ -226,27 +240,11 @@ public:
void Rotate( const VECTOR2I& aCenter, bool aRotateCCW ) override;
/**
* @copydoc SCH_ITEM::MirrorVertically()
*
* This overload does nothing. Fields are never mirrored alone. They are moved
* when the parent symbol is mirrored. This function is only needed by the
* pure function of the master class.
*/
void MirrorVertically( int aCenter ) override
{
}
void MirrorVertically( int aCenter ) override;
void MirrorHorizontally( int aCenter ) override;
/**
* @copydoc SCH_ITEM::MirrorHorizontally()
*
* This overload does nothing. Fields are never mirrored alone. They are moved
* when the parent symbol is mirrored. This function is only needed by the
* pure function of the master class.
*/
void MirrorHorizontally( int aCenter ) override
{
}
void BeginEdit( const VECTOR2I& aStartPoint ) override;
void CalcEdit( const VECTOR2I& aPosition ) override;
void OnScintillaCharAdded( SCINTILLA_TRICKS* aScintillaTricks, wxStyledTextEvent &aEvent ) const;
@ -279,6 +277,24 @@ public:
EDA_ITEM* Clone() const override;
/**
* Copy parameters from a SCH_FIELD source.
*
* Pointers and specific values (position) are not copied.
*
* @param aSource is the SCH_FIELD to read.
*/
void ImportValues( const SCH_FIELD& aSource );
/**
* Copy parameters of this field to another field. Pointers are not copied.
*
* @param aTarget Target field to copy values to.
*/
void Copy( SCH_FIELD* aTarget ) const;
bool IsMandatory() const;
bool operator <( const SCH_ITEM& aItem ) const override;
double Similarity( const SCH_ITEM& aItem ) const override;
@ -295,6 +311,20 @@ protected:
const KIFONT::METRICS& getFontMetrics() const override { return GetFontMetrics(); }
/**
* @copydoc SCH_ITEM::compare()
*
* The field specific sort order is as follows:
*
* - Field ID, REFERENCE, VALUE, etc.
* - Field string, case insensitive compare.
* - Field horizontal (X) position.
* - Field vertical (Y) position.
* - Field width.
* - Field height.
*/
int compare( const SCH_ITEM& aOther, int aCompareFlags = 0 ) const override;
private:
int m_id; ///< Field index, @see enum MANDATORY_FIELD_T
@ -305,6 +335,9 @@ private:
bool m_isNamedVariable; ///< If the field name is a variable name, e.g. ${DNP}
///< then the value field is forced to be the same as the name
bool m_autoAdded; ///< Was this field automatically added to a LIB_SYMBOL?
bool m_showInChooser; ///< This field is available as a data column for the chooser
mutable bool m_renderCacheValid;
mutable VECTOR2I m_renderCachePos;
mutable std::vector<std::unique_ptr<KIFONT::GLYPH>> m_renderCache;

View File

@ -3796,7 +3796,7 @@ void SCH_IO_ALTIUM::ParseLibDesignator( const std::map<wxString, wxString>& aPro
for( LIB_SYMBOL* symbol : aSymbol )
{
bool emptyRef = elem.text.IsEmpty();
LIB_FIELD& refField = symbol->GetReferenceField();
SCH_FIELD& refField = symbol->GetReferenceField();
if( emptyRef )
refField.SetText( wxT( "X" ) );
@ -3958,7 +3958,7 @@ void SCH_IO_ALTIUM::ParseLibParameter( const std::map<wxString, wxString>& aProp
for( LIB_SYMBOL* libSymbol : aSymbol )
{
LIB_FIELD* field = nullptr;
SCH_FIELD* field = nullptr;
wxString upperName = elem.name.Upper();
if( upperName == "COMMENT" )
@ -3988,7 +3988,7 @@ void SCH_IO_ALTIUM::ParseLibParameter( const std::map<wxString, wxString>& aProp
while( libSymbol->FindField( fieldName ) )
fieldName = wxString::Format( "%s_%d", fieldNameStem, disambiguate++ );
LIB_FIELD* new_field = new LIB_FIELD( fieldIdx, fieldName );
SCH_FIELD* new_field = new SCH_FIELD( libSymbol, fieldIdx, fieldName );
libSymbol->AddField( new_field );
field = new_field;
}
@ -4046,7 +4046,7 @@ void SCH_IO_ALTIUM::ParseImplementation( const std::map<wxString, wxString>& aPr
LIB_ID fpLibId = AltiumToKiCadLibID( libName, elem.name );
symbol->SetFPFilters( fpFilters );
LIB_FIELD& footprintField = symbol->GetFootprintField();
SCH_FIELD& footprintField = symbol->GetFootprintField();
footprintField.SetText( fpLibId.Format() );
}
@ -4269,7 +4269,7 @@ std::map<wxString,LIB_SYMBOL*> SCH_IO_ALTIUM::ParseLibFile( const ALTIUM_COMPOUN
LIB_SYMBOL* symbol = symbols[ii];
symbol->FixupDrawItems();
LIB_FIELD& valField = symbol->GetValueField();
SCH_FIELD& valField = symbol->GetValueField();
if( valField.GetText().IsEmpty() )
valField.SetText( name );

View File

@ -300,12 +300,12 @@ void CADSTAR_SCH_ARCHIVE_LOADER::copySymbolItems( std::unique_ptr<LIB_SYMBOL>& a
//Copy / override all fields
if( aOverrideFields )
{
std::vector<LIB_FIELD*> fieldsToCopy;
std::vector<SCH_FIELD*> fieldsToCopy;
aSourceSym->GetFields( fieldsToCopy );
for( LIB_FIELD* templateField : fieldsToCopy )
for( SCH_FIELD* templateField : fieldsToCopy )
{
LIB_FIELD* appliedField = addNewFieldToSymbol( templateField->GetName(), aDestSym );
SCH_FIELD* appliedField = addNewFieldToSymbol( templateField->GetName(), aDestSym );
templateField->Copy( appliedField );
}
}
@ -1070,9 +1070,7 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadBusses()
label->SetPosition( nearestPt );
applyTextSettings( label,
bus.BusLabel.TextCodeID,
bus.BusLabel.Alignment,
applyTextSettings( label, bus.BusLabel.TextCodeID, bus.BusLabel.Alignment,
bus.BusLabel.Justification );
// Re-set bus name as it might have been "double-escaped" after applyTextSettings
@ -1115,11 +1113,8 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadNets()
val->SetVisible( true );
val->SetPosition( getKiCadPoint( netTerm.NetLabel.Position ) );
applyTextSettings( val,
netTerm.NetLabel.TextCodeID,
netTerm.NetLabel.Alignment,
netTerm.NetLabel.Justification,
netTerm.NetLabel.OrientAngle,
applyTextSettings( val, netTerm.NetLabel.TextCodeID, netTerm.NetLabel.Alignment,
netTerm.NetLabel.Justification, netTerm.NetLabel.OrientAngle,
netTerm.NetLabel.Mirror );
}
}
@ -1212,9 +1207,7 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadNets()
if( busTerm.HasNetLabel )
{
applyTextSettings( label,
busTerm.NetLabel.TextCodeID,
busTerm.NetLabel.Alignment,
applyTextSettings( label, busTerm.NetLabel.TextCodeID, busTerm.NetLabel.Alignment,
busTerm.NetLabel.Justification );
}
else
@ -1236,9 +1229,7 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadNets()
if( dangler.HasNetLabel )
{
applyTextSettings( label,
dangler.NetLabel.TextCodeID,
dangler.NetLabel.Alignment,
applyTextSettings( label, dangler.NetLabel.TextCodeID, dangler.NetLabel.Alignment,
dangler.NetLabel.Justification );
}
@ -1580,18 +1571,18 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadTextVariables()
}
LIB_FIELD*
SCH_FIELD*
CADSTAR_SCH_ARCHIVE_LOADER::addNewFieldToSymbol( const wxString& aFieldName,
std::unique_ptr<LIB_SYMBOL>& aKiCadSymbol )
{
// First Check if field already exists
LIB_FIELD* existingField = aKiCadSymbol->FindField( aFieldName );
SCH_FIELD* existingField = aKiCadSymbol->FindField( aFieldName );
if( existingField != nullptr )
return existingField;
int newfieldID = aKiCadSymbol->GetFieldCount();
LIB_FIELD* newfield = new LIB_FIELD( aKiCadSymbol.get(), newfieldID );
SCH_FIELD* newfield = new SCH_FIELD( aKiCadSymbol.get(), newfieldID );
newfield->SetName( aFieldName );
newfield->SetVisible( false );
aKiCadSymbol->AddField( newfield );
@ -1713,7 +1704,7 @@ const LIB_SYMBOL* CADSTAR_SCH_ARCHIVE_LOADER::loadSymdef( const SYMDEF_ID& aSymd
libtext->SetMultilineAllowed( true ); // temporarily so that we calculate bbox correctly
applyTextSettings( libtext.get(), csText.TextCodeID, csText.Alignment, csText.Justification,
csText.OrientAngle, csText.Mirror );
csText.OrientAngle, csText.Mirror, true );
// Split out multi line text items into individual text elements
if( csText.Text.Contains( "\n" ) )
@ -1765,7 +1756,7 @@ const LIB_SYMBOL* CADSTAR_SCH_ARCHIVE_LOADER::loadSymdef( const SYMDEF_ID& aSymd
}
// Always add the part name field (even if it doesn't have a specific location defined)
LIB_FIELD* partField = addNewFieldToSymbol( PartNameFieldName, kiSym );
SCH_FIELD* partField = addNewFieldToSymbol( PartNameFieldName, kiSym );
wxCHECK( partField, nullptr );
wxASSERT( partField->GetName() == PartNameFieldName );
@ -1791,7 +1782,7 @@ const LIB_SYMBOL* CADSTAR_SCH_ARCHIVE_LOADER::loadSymdef( const SYMDEF_ID& aSymd
}
wxString attributeName = getAttributeName( attributeId );
LIB_FIELD* field = addNewFieldToSymbol( attributeName, kiSym );
SCH_FIELD* field = addNewFieldToSymbol( attributeName, kiSym );
applyToLibraryFieldAttribute( textLocation, csSym.Origin, field );
}
@ -1805,7 +1796,7 @@ const LIB_SYMBOL* CADSTAR_SCH_ARCHIVE_LOADER::loadSymdef( const SYMDEF_ID& aSymd
}
wxString attributeName = getAttributeName( attributeId );
LIB_FIELD* field = addNewFieldToSymbol( attributeName, kiSym );
SCH_FIELD* field = addNewFieldToSymbol( attributeName, kiSym );
if( attrValue.HasLocation )
applyToLibraryFieldAttribute( attrValue.AttributeLocation, csSym.Origin, field );
@ -1872,7 +1863,7 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSymbolGateAndPartFields( const SYMDEF_ID& a
tempSymbol->GetValueField().SetVisible( false );
LIB_FIELD* partNameField = tempSymbol->FindField( PartNameFieldName );
SCH_FIELD* partNameField = tempSymbol->FindField( PartNameFieldName );
if( partNameField )
partNameField->SetText( EscapeFieldText( aCadstarPart.Name ) );
@ -1919,7 +1910,7 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSymbolGateAndPartFields( const SYMDEF_ID& a
}
bool attrIsNew = tempSymbol->FindField( attrName ) == nullptr;
LIB_FIELD* attrField = addNewFieldToSymbol( attrName, tempSymbol );
SCH_FIELD* attrField = addNewFieldToSymbol( attrName, tempSymbol );
wxASSERT( attrField->GetName() == attrName );
attrField->SetText( aAttributeVal.Value );
@ -1938,7 +1929,7 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSymbolGateAndPartFields( const SYMDEF_ID& a
{
attrField->SetVisible( false );
applyTextSettings( attrField, wxT( "TC1" ), ALIGNMENT::NO_ALIGNMENT,
JUSTIFICATION::LEFT );
JUSTIFICATION::LEFT, false, true );
}
};
@ -1985,7 +1976,7 @@ void CADSTAR_SCH_ARCHIVE_LOADER::setFootprintOnSymbol( std::unique_ptr<LIB_SYMBO
void CADSTAR_SCH_ARCHIVE_LOADER::loadLibrarySymbolShapeVertices( const std::vector<VERTEX>& aCadstarVertices,
VECTOR2I aSymbolOrigin,
const VECTOR2I& aSymbolOrigin,
LIB_SYMBOL* aSymbol,
int aGateNumber,
int aLineThickness )
@ -2060,17 +2051,15 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadLibrarySymbolShapeVertices( const std::vect
}
void CADSTAR_SCH_ARCHIVE_LOADER::applyToLibraryFieldAttribute(
const ATTRIBUTE_LOCATION& aCadstarAttrLoc, VECTOR2I aSymbolOrigin, LIB_FIELD* aKiCadField )
void CADSTAR_SCH_ARCHIVE_LOADER::applyToLibraryFieldAttribute( const ATTRIBUTE_LOCATION& aCadstarAttrLoc,
const VECTOR2I& aSymbolOrigin,
SCH_FIELD* aKiCadField )
{
aKiCadField->SetTextPos( getKiCadLibraryPoint( aCadstarAttrLoc.Position, aSymbolOrigin ) );
applyTextSettings( aKiCadField,
aCadstarAttrLoc.TextCodeID,
aCadstarAttrLoc.Alignment,
aCadstarAttrLoc.Justification,
aCadstarAttrLoc.OrientAngle,
aCadstarAttrLoc.Mirror );
applyTextSettings( aKiCadField, aCadstarAttrLoc.TextCodeID, aCadstarAttrLoc.Alignment,
aCadstarAttrLoc.Justification, aCadstarAttrLoc.OrientAngle,
aCadstarAttrLoc.Mirror, true );
}
@ -2212,9 +2201,7 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSymbolFieldAttribute( const ATTRIBUTE_LOCAT
alignment = mirrorX( alignment );
}
applyTextSettings( aKiCadField,
aCadstarAttrLoc.TextCodeID,
alignment,
applyTextSettings( aKiCadField, aCadstarAttrLoc.TextCodeID, alignment,
aCadstarAttrLoc.Justification,
getCadstarAngle( textAngle - aComponentOrientation ),
aCadstarAttrLoc.Mirror );
@ -2598,11 +2585,8 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadChildSheets( LAYER_ID aCadstarSheetID,
kiTxt->SetPosition( getKiCadPoint( block.BlockLabel.Position ) );
kiTxt->SetText( block.Name );
applyTextSettings( kiTxt,
block.BlockLabel.TextCodeID,
block.BlockLabel.Alignment,
block.BlockLabel.Justification,
block.BlockLabel.OrientAngle,
applyTextSettings( kiTxt, block.BlockLabel.TextCodeID, block.BlockLabel.Alignment,
block.BlockLabel.Justification, block.BlockLabel.OrientAngle,
block.BlockLabel.Mirror );
loadItemOntoKiCadSheet( aCadstarSheetID, kiTxt );
@ -3003,7 +2987,8 @@ void CADSTAR_SCH_ARCHIVE_LOADER::applyTextSettings( EDA_TEXT* aKiCadT
const ALIGNMENT& aCadstarAlignment,
const JUSTIFICATION& aCadstarJustification,
const long long aCadstarOrientAngle,
bool aMirrored )
bool aMirrored,
bool aInvertY )
{
applyTextCodeIfExists( aKiCadTextItem, aCadstarTextCodeID );
aKiCadTextItem->SetTextAngle( getAngle( aCadstarOrientAngle ) );
@ -3026,7 +3011,7 @@ void CADSTAR_SCH_ARCHIVE_LOADER::applyTextSettings( EDA_TEXT* aKiCadT
{
case ALIGNMENT::NO_ALIGNMENT: // Bottom left of the first line
//No exact KiCad equivalent, so lets move the position of the text
FixTextPositionNoAlignment( aText );
FixTextPositionNoAlignment( aText, aInvertY );
KI_FALLTHROUGH;
case ALIGNMENT::BOTTOMLEFT:
aText->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
@ -3085,7 +3070,6 @@ void CADSTAR_SCH_ARCHIVE_LOADER::applyTextSettings( EDA_TEXT* aKiCadT
// and text justifications
case LIB_TEXT_T:
case SCH_FIELD_T:
case LIB_FIELD_T:
{
// Spin style not used. All text justifications are permitted. However, only orientations
// of 0 deg or 90 deg are supported
@ -3192,11 +3176,8 @@ SCH_TEXT* CADSTAR_SCH_ARCHIVE_LOADER::getKiCadSchText( const TEXT& aCadstarTextE
kiTxt->SetPosition( getKiCadPoint( aCadstarTextElement.Position ) );
kiTxt->SetText( aCadstarTextElement.Text );
applyTextSettings( kiTxt,
aCadstarTextElement.TextCodeID,
aCadstarTextElement.Alignment,
aCadstarTextElement.Justification,
aCadstarTextElement.OrientAngle,
applyTextSettings( kiTxt, aCadstarTextElement.TextCodeID, aCadstarTextElement.Alignment,
aCadstarTextElement.Justification, aCadstarTextElement.OrientAngle,
aCadstarTextElement.Mirror );
return kiTxt;

View File

@ -42,7 +42,6 @@ struct CADSTAR_PART_ENTRY;
class BUS_ALIAS;
class EDA_TEXT;
class SPIN_STYLE;
class LIB_FIELD;
class LIB_SYMBOL;
class REPORTER;
class SCH_SYMBOL;
@ -192,11 +191,11 @@ private:
const wxString& aFootprintAlternate );
void loadLibrarySymbolShapeVertices( const std::vector<VERTEX>& aCadstarVertices,
VECTOR2I aSymbolOrigin, LIB_SYMBOL* aSymbol,
const VECTOR2I& aSymbolOrigin, LIB_SYMBOL* aSymbol,
int aGateNumber, int aLineThickness );
void applyToLibraryFieldAttribute( const ATTRIBUTE_LOCATION& aCadstarAttrLoc,
VECTOR2I aSymbolOrigin, LIB_FIELD* aKiCadField );
const VECTOR2I& aSymbolOrigin, SCH_FIELD* aKiCadField );
//Helper Functions for loading symbols in schematic
SCH_SYMBOL* loadSchematicSymbol( const SYMBOL& aCadstarSymbol, const LIB_SYMBOL& aKiCadPart,
@ -237,7 +236,8 @@ private:
const ALIGNMENT& aCadstarAlignment,
const JUSTIFICATION& aCadstarJustification,
const long long aCadstarOrientAngle = 0,
bool aMirrored = false );
bool aMirrored = false,
bool aInvertY = false );
SCH_TEXT* getKiCadSchText( const TEXT& aCadstarTextElement );
@ -338,7 +338,7 @@ private:
double getPolarRadius( const VECTOR2I& aPoint );
static LIB_FIELD* addNewFieldToSymbol( const wxString& aFieldName,
static SCH_FIELD* addNewFieldToSymbol( const wxString& aFieldName,
std::unique_ptr<LIB_SYMBOL>& aKiCadSymbol );
}; // CADSTAR_SCH_ARCHIVE_LOADER

View File

@ -215,10 +215,10 @@ void SCH_IO_CADSTAR_ARCHIVE::GetAvailableSymbolFields( std::vector<wxString>& aN
for( auto& [libnameStr, libSymbol] : m_libCache )
{
std::vector<LIB_FIELD*> fields;
std::vector<SCH_FIELD*> fields;
libSymbol->GetFields( fields );
for( LIB_FIELD* field : fields )
for( SCH_FIELD* field : fields )
{
if( field->IsMandatory() )
continue;

View File

@ -562,12 +562,12 @@ std::unique_ptr<LIB_SYMBOL> SCH_IO_DATABASE::loadSymbolFromRow( const wxString&
}
}
std::vector<LIB_FIELD*> fields;
std::vector<SCH_FIELD*> fields;
symbol->GetFields( fields );
std::unordered_map<wxString, LIB_FIELD*> fieldsMap;
std::unordered_map<wxString, SCH_FIELD*> fieldsMap;
for( LIB_FIELD* field : fields )
for( SCH_FIELD* field : fields )
fieldsMap[field->GetName()] = field;
static const wxString c_valueFieldName( wxS( "Value" ) );
@ -596,7 +596,7 @@ std::unique_ptr<LIB_SYMBOL> SCH_IO_DATABASE::loadSymbolFromRow( const wxString&
if( mapping.name_wx == c_valueFieldName )
{
LIB_FIELD& field = symbol->GetValueField();
SCH_FIELD& field = symbol->GetValueField();
field.SetText( value );
if( !mapping.inherit_properties )
@ -608,7 +608,7 @@ std::unique_ptr<LIB_SYMBOL> SCH_IO_DATABASE::loadSymbolFromRow( const wxString&
}
else if( mapping.name_wx == c_datasheetFieldName )
{
LIB_FIELD& field = symbol->GetDatasheetField();
SCH_FIELD& field = symbol->GetDatasheetField();
field.SetText( value );
if( !mapping.inherit_properties )
@ -623,7 +623,7 @@ std::unique_ptr<LIB_SYMBOL> SCH_IO_DATABASE::loadSymbolFromRow( const wxString&
continue;
}
LIB_FIELD* field;
SCH_FIELD* field;
bool isNew = false;
if( fieldsMap.count( mapping.name_wx ) )
@ -632,7 +632,7 @@ std::unique_ptr<LIB_SYMBOL> SCH_IO_DATABASE::loadSymbolFromRow( const wxString&
}
else
{
field = new LIB_FIELD( symbol->GetNextAvailableFieldId() );
field = new SCH_FIELD( nullptr, symbol->GetNextAvailableFieldId() );
field->SetName( mapping.name_wx );
isNew = true;
fieldsMap[mapping.name_wx] = field;

View File

@ -1804,10 +1804,10 @@ void SCH_IO_EAGLE::loadInstance( wxXmlNode* aInstanceNode )
symbol->MirrorHorizontally( einstance.x.ToSchUnits() );
}
std::vector<LIB_FIELD*> partFields;
std::vector<SCH_FIELD*> partFields;
part->GetFields( partFields );
for( const LIB_FIELD* field : partFields )
for( const SCH_FIELD* field : partFields )
{
symbol->GetFieldById( field->GetId() )->ImportValues( *field );
symbol->GetFieldById( field->GetId() )->SetTextPos( (VECTOR2I)symbol->GetPosition()
@ -2042,7 +2042,7 @@ EAGLE_LIBRARY* SCH_IO_EAGLE::loadLibrary( wxXmlNode* aLibraryNode, EAGLE_LIBRARY
libSymbol->SetUnitCount( gates_count );
libSymbol->LockUnits( true );
LIB_FIELD* reference = libSymbol->GetFieldById( REFERENCE_FIELD );
SCH_FIELD* reference = libSymbol->GetFieldById( REFERENCE_FIELD );
if( prefix.length() == 0 )
{
@ -2230,7 +2230,7 @@ bool SCH_IO_EAGLE::loadSymbol( wxXmlNode* aSymbolNode, std::unique_ptr<LIB_SYMBO
if( libtext->GetText() == wxT( "${REFERENCE}" ) )
{
// Move text & attributes to Reference field and discard LIB_TEXT item
LIB_FIELD* field = aSymbol->GetFieldById( REFERENCE_FIELD );
SCH_FIELD* field = aSymbol->GetFieldById( REFERENCE_FIELD );
loadFieldAttributes( field, libtext.get() );
// Show Reference field if Eagle reference was uppercase
@ -2239,7 +2239,7 @@ bool SCH_IO_EAGLE::loadSymbol( wxXmlNode* aSymbolNode, std::unique_ptr<LIB_SYMBO
else if( libtext->GetText() == wxT( "${VALUE}" ) )
{
// Move text & attributes to Value field and discard LIB_TEXT item
LIB_FIELD* field = aSymbol->GetFieldById( VALUE_FIELD );
SCH_FIELD* field = aSymbol->GetFieldById( VALUE_FIELD );
loadFieldAttributes( field, libtext.get() );
// Show Value field if Eagle reference was uppercase
@ -2781,7 +2781,7 @@ void SCH_IO_EAGLE::loadTextAttributes( EDA_TEXT* aText, const ETEXT& aAttribs )
}
void SCH_IO_EAGLE::loadFieldAttributes( LIB_FIELD* aField, const LIB_TEXT* aText ) const
void SCH_IO_EAGLE::loadFieldAttributes( SCH_FIELD* aField, const LIB_TEXT* aText ) const
{
aField->SetTextPos( aText->GetPosition() );
aField->SetTextSize( aText->GetTextSize() );

View File

@ -52,7 +52,6 @@ class STRING_UTF8_MAP;
class LIB_SYMBOL;
class SYMBOL_LIB;
class LIB_SHAPE;
class LIB_FIELD;
class LIB_RECTANGLE;
class LIB_POLYLINE;
class LIB_PIN;
@ -172,7 +171,7 @@ private:
void loadSymbolFrame( wxXmlNode* aFrameNode, std::vector<SCH_ITEM*>& aLines );
void loadTextAttributes( EDA_TEXT* aText, const ETEXT& aAttribs ) const;
void loadFieldAttributes( LIB_FIELD* aField, const LIB_TEXT* aText ) const;
void loadFieldAttributes( SCH_FIELD* aField, const LIB_TEXT* aText ) const;
///< Move net labels that are detached from any wire to the nearest wire
void adjustNetLabels();

View File

@ -36,7 +36,6 @@
class EDA_TEXT;
class LIB_SHAPE;
class LIB_FIELD;
class LIB_PIN;
class SCH_LABEL_BASE;
class SCH_SYMBOL;

View File

@ -415,7 +415,7 @@ LIB_SYMBOL* SCH_IO_HTTP_LIB::loadSymbolFromPart( const wxString& aSymbo
symbol->SetExcludedFromBoard( aPart.exclude_from_board );
symbol->SetExcludedFromSim( aPart.exclude_from_sim );
LIB_FIELD* field;
SCH_FIELD* field;
for( auto& _field : aPart.fields )
{
@ -474,7 +474,7 @@ LIB_SYMBOL* SCH_IO_HTTP_LIB::loadSymbolFromPart( const wxString& aSymbo
else
{
// Generic fields
field = new LIB_FIELD( symbol->GetNextAvailableFieldId() );
field = new SCH_FIELD( nullptr, symbol->GetNextAvailableFieldId() );
field->SetName( fieldName );
field->SetText( std::get<0>( fieldProperties ) );

View File

@ -21,7 +21,6 @@
#include <wx/log.h>
#include <lib_shape.h>
#include <lib_field.h>
#include <lib_pin.h>
#include <lib_text.h>
#include <macros.h>
@ -397,7 +396,7 @@ LIB_SYMBOL* SCH_IO_KICAD_LEGACY_LIB_CACHE::LoadPart( LINE_READER& aReader, int a
// Don't set the library alias, this is determined by the symbol library table.
symbol->SetLibId( LIB_ID( wxEmptyString, symbol->GetName() ) );
LIB_FIELD& reference = symbol->GetReferenceField();
SCH_FIELD& reference = symbol->GetReferenceField();
if( prefix == "~" )
{
@ -501,12 +500,12 @@ void SCH_IO_KICAD_LEGACY_LIB_CACHE::loadAliases( std::unique_ptr<LIB_SYMBOL>& aS
// Inherit the parent mandatory field attributes.
for( int id = 0; id < MANDATORY_FIELDS; ++id )
{
LIB_FIELD* field = newSymbol->GetFieldById( id );
SCH_FIELD* field = newSymbol->GetFieldById( id );
// the MANDATORY_FIELDS are exactly that in RAM.
wxASSERT( field );
LIB_FIELD* parentField = aSymbol->GetFieldById( id );
SCH_FIELD* parentField = aSymbol->GetFieldById( id );
wxASSERT( parentField );
@ -540,7 +539,7 @@ void SCH_IO_KICAD_LEGACY_LIB_CACHE::loadField( std::unique_ptr<LIB_SYMBOL>& aSym
if( sscanf( line + 1, "%d", &id ) != 1 || id < 0 )
SCH_PARSE_ERROR( "invalid field ID", aReader, line + 1 );
LIB_FIELD* field;
SCH_FIELD* field;
if( id >= 0 && id < MANDATORY_FIELDS )
{
@ -553,7 +552,7 @@ void SCH_IO_KICAD_LEGACY_LIB_CACHE::loadField( std::unique_ptr<LIB_SYMBOL>& aSym
}
else
{
field = new LIB_FIELD( aSymbol.get(), id );
field = new SCH_FIELD( aSymbol.get(), id );
aSymbol->AddDrawItem( field, false );
}
@ -664,7 +663,7 @@ void SCH_IO_KICAD_LEGACY_LIB_CACHE::loadField( std::unique_ptr<LIB_SYMBOL>& aSym
// Fields in RAM must always have names, because we are trying to get
// less dependent on field ids and more dependent on names.
// Plus assumptions are made in the field editors.
field->m_name = GetCanonicalFieldName( id );
field->SetName( GetCanonicalFieldName( id ) );
// Ensure the VALUE field = the symbol name (can be not the case
// with malformed libraries: edited by hand, or converted from other tools)
@ -686,7 +685,7 @@ void SCH_IO_KICAD_LEGACY_LIB_CACHE::loadField( std::unique_ptr<LIB_SYMBOL>& aSym
while( aSymbol->FindField( candidateFieldName ) != nullptr )
candidateFieldName = wxString::Format( "%s_%d", fieldName, ++suffix );
field->m_name = candidateFieldName;
field->SetName( candidateFieldName );
}
}
@ -1481,7 +1480,7 @@ void SCH_IO_KICAD_LEGACY_LIB_CACHE::SaveSymbol( LIB_SYMBOL* aSymbol, OUTPUTFORMA
}
}
LIB_FIELD& value = aSymbol->GetValueField();
SCH_FIELD& value = aSymbol->GetValueField();
// First line: it s a comment (symbol name for readers)
aFormatter.Print( 0, "#\n# %s\n#\n", TO_UTF8( value.GetText() ) );
@ -1490,7 +1489,7 @@ void SCH_IO_KICAD_LEGACY_LIB_CACHE::SaveSymbol( LIB_SYMBOL* aSymbol, OUTPUTFORMA
aFormatter.Print( 0, "DEF" );
aFormatter.Print( 0, " %s", TO_UTF8( value.GetText() ) );
LIB_FIELD& reference = aSymbol->GetReferenceField();
SCH_FIELD& reference = aSymbol->GetReferenceField();
if( !reference.GetText().IsEmpty() )
aFormatter.Print( 0, " %s", TO_UTF8( reference.GetText() ) );
@ -1518,7 +1517,7 @@ void SCH_IO_KICAD_LEGACY_LIB_CACHE::SaveSymbol( LIB_SYMBOL* aSymbol, OUTPUTFORMA
aFormatter.Print( 0, "Ti %d/%d/%d %d:%d:%d\n", year, mon, day, hour, min, sec );
}
std::vector<LIB_FIELD*> fields;
std::vector<SCH_FIELD*> fields;
aSymbol->GetFields( fields );
// Mandatory fields:
@ -1581,7 +1580,6 @@ void SCH_IO_KICAD_LEGACY_LIB_CACHE::SaveSymbol( LIB_SYMBOL* aSymbol, OUTPUTFORMA
switch( item.Type() )
{
default:
case LIB_FIELD_T: /* Fields have already been saved above. */ break;
case LIB_PIN_T: savePin( (LIB_PIN* ) &item, aFormatter ); break;
case LIB_TEXT_T: saveText( ( LIB_TEXT* ) &item, aFormatter ); break;
case LIB_SHAPE_T:
@ -1673,10 +1671,10 @@ void SCH_IO_KICAD_LEGACY_LIB_CACHE::saveCircle( LIB_SHAPE* aCircle, OUTPUTFORMAT
}
void SCH_IO_KICAD_LEGACY_LIB_CACHE::saveField( const LIB_FIELD* aField,
void SCH_IO_KICAD_LEGACY_LIB_CACHE::saveField( const SCH_FIELD* aField,
OUTPUTFORMATTER& aFormatter )
{
wxCHECK_RET( aField && aField->Type() == LIB_FIELD_T, "Invalid LIB_FIELD object." );
wxCHECK_RET( aField && aField->Type() == SCH_FIELD_T, "Invalid SCH_FIELD object." );
int hjustify, vjustify;
int id = aField->GetId();
@ -1715,8 +1713,8 @@ void SCH_IO_KICAD_LEGACY_LIB_CACHE::saveField( const LIB_FIELD* aField,
*/
wxString defName = TEMPLATE_FIELDNAME::GetDefaultFieldName( id );
if( id >= MANDATORY_FIELDS && !aField->m_name.IsEmpty() && aField->m_name != defName )
aFormatter.Print( 0, " %s", EscapedUTF8( aField->m_name ).c_str() );
if( id >= MANDATORY_FIELDS && !aField->GetName().IsEmpty() && aField->GetName() != defName )
aFormatter.Print( 0, " %s", EscapedUTF8( aField->GetName() ).c_str() );
aFormatter.Print( 0, "\n" );
}

View File

@ -29,7 +29,6 @@
#include "sch_io/sch_io_lib_cache.h"
class FILE_LINE_READER;
class LIB_FIELD;
class LIB_PIN;
class LIB_SHAPE;
class LIB_TEXT;
@ -89,7 +88,7 @@ private:
static void saveArc( LIB_SHAPE* aArc, OUTPUTFORMATTER& aFormatter );
static void saveBezier( LIB_SHAPE* aBezier, OUTPUTFORMATTER& aFormatter );
static void saveCircle( LIB_SHAPE* aCircle, OUTPUTFORMATTER& aFormatter );
static void saveField( const LIB_FIELD* aField, OUTPUTFORMATTER& aFormatter );
static void saveField( const SCH_FIELD* aField, OUTPUTFORMATTER& aFormatter );
static void savePin( const LIB_PIN* aPin, OUTPUTFORMATTER& aFormatter );
static void savePolyLine( LIB_SHAPE* aPolyLine, OUTPUTFORMATTER& aFormatter );
static void saveRectangle( LIB_SHAPE* aRectangle, OUTPUTFORMATTER& aFormatter );

View File

@ -1772,10 +1772,10 @@ void SCH_IO_KICAD_SEXPR::GetAvailableSymbolFields( std::vector<wxString>& aNames
for( LIB_SYMBOL_MAP::const_iterator it = symbols.begin(); it != symbols.end(); ++it )
{
std::vector<LIB_FIELD*> fields;
std::vector<SCH_FIELD*> fields;
it->second->GetFields( fields );
for( LIB_FIELD* field : fields )
for( SCH_FIELD* field : fields )
{
if( field->IsMandatory() )
continue;

View File

@ -140,7 +140,7 @@ void SCH_IO_KICAD_SEXPR_LIB_CACHE::SaveSymbol( LIB_SYMBOL* aSymbol, OUTPUTFORMAT
LOCALE_IO toggle );
int nextFreeFieldId = MANDATORY_FIELDS;
std::vector<LIB_FIELD*> fields;
std::vector<SCH_FIELD*> fields;
std::string name = aFormatter.Quotew( aSymbol->GetLibId().GetLibItemName().wx_str() );
std::string unitName = aSymbol->GetLibId().GetLibItemName();
@ -198,7 +198,7 @@ void SCH_IO_KICAD_SEXPR_LIB_CACHE::SaveSymbol( LIB_SYMBOL* aSymbol, OUTPUTFORMAT
aSymbol->GetFields( fields );
for( LIB_FIELD* field : fields )
for( SCH_FIELD* field : fields )
saveField( field, aFormatter, aNestLevel + 1 );
nextFreeFieldId = aSymbol->GetNextAvailableFieldId();
@ -208,7 +208,7 @@ void SCH_IO_KICAD_SEXPR_LIB_CACHE::SaveSymbol( LIB_SYMBOL* aSymbol, OUTPUTFORMAT
// locked flag state.
if( aSymbol->UnitsLocked() )
{
LIB_FIELD locked( nextFreeFieldId, "ki_locked" );
SCH_FIELD locked( nullptr, nextFreeFieldId, "ki_locked" );
saveField( &locked, aFormatter, aNestLevel + 1 );
nextFreeFieldId += 1;
}
@ -274,7 +274,7 @@ void SCH_IO_KICAD_SEXPR_LIB_CACHE::SaveSymbol( LIB_SYMBOL* aSymbol, OUTPUTFORMAT
aSymbol->GetFields( fields );
for( LIB_FIELD* field : fields )
for( SCH_FIELD* field : fields )
saveField( field, aFormatter, aNestLevel + 1 );
nextFreeFieldId = aSymbol->GetNextAvailableFieldId();
@ -294,7 +294,7 @@ void SCH_IO_KICAD_SEXPR_LIB_CACHE::saveDcmInfoAsFields( LIB_SYMBOL* aSymbol,
if( !aSymbol->GetKeyWords().IsEmpty() )
{
LIB_FIELD keywords( aNextFreeFieldId, wxString( "ki_keywords" ) );
SCH_FIELD keywords( nullptr, aNextFreeFieldId, wxString( "ki_keywords" ) );
keywords.SetVisible( false );
keywords.SetText( aSymbol->GetKeyWords() );
saveField( &keywords, aFormatter, aNestLevel + 1 );
@ -318,7 +318,7 @@ void SCH_IO_KICAD_SEXPR_LIB_CACHE::saveDcmInfoAsFields( LIB_SYMBOL* aSymbol,
tmp += " " + curr_filter;
}
LIB_FIELD description( aNextFreeFieldId, wxString( "ki_fp_filters" ) );
SCH_FIELD description( nullptr, aNextFreeFieldId, wxString( "ki_fp_filters" ) );
description.SetVisible( false );
description.SetText( tmp );
saveField( &description, aFormatter, aNestLevel + 1 );
@ -389,14 +389,14 @@ void SCH_IO_KICAD_SEXPR_LIB_CACHE::saveSymbolDrawItem( SCH_ITEM* aItem, OUTPUTFO
}
void SCH_IO_KICAD_SEXPR_LIB_CACHE::saveField( LIB_FIELD* aField, OUTPUTFORMATTER& aFormatter,
void SCH_IO_KICAD_SEXPR_LIB_CACHE::saveField( SCH_FIELD* aField, OUTPUTFORMATTER& aFormatter,
int aNestLevel )
{
wxCHECK_RET( aField && aField->Type() == LIB_FIELD_T, "Invalid LIB_FIELD object." );
wxCHECK_RET( aField && aField->Type() == SCH_FIELD_T, "Invalid SCH_FIELD object." );
wxString fieldName = aField->GetName();
if( aField->GetId() >= 0 && aField->GetId() < MANDATORY_FIELDS )
if( aField->IsMandatory() )
fieldName = GetCanonicalFieldName( aField->GetId() );
aFormatter.Print( aNestLevel, "(property %s %s (at %s %s %g)",

View File

@ -25,7 +25,6 @@
#include "sch_io/sch_io_lib_cache.h"
class FILE_LINE_READER;
class LIB_FIELD;
class LIB_PIN;
class LIB_TEXT;
class LIB_TEXTBOX;
@ -65,7 +64,7 @@ private:
static void saveSymbolDrawItem( SCH_ITEM* aItem, OUTPUTFORMATTER& aFormatter,
int aNestLevel );
static void saveField( LIB_FIELD* aField, OUTPUTFORMATTER& aFormatter, int aNestLevel );
static void saveField( SCH_FIELD* aField, OUTPUTFORMATTER& aFormatter, int aNestLevel );
static void savePin( LIB_PIN* aPin, OUTPUTFORMATTER& aFormatter, int aNestLevel = 0 );
static void saveText( LIB_TEXT* aText, OUTPUTFORMATTER& aFormatter, int aNestLevel = 0 );
static void saveTextBox( LIB_TEXTBOX* aTextBox, OUTPUTFORMATTER& aFormatter,

View File

@ -880,7 +880,7 @@ void SCH_IO_KICAD_SEXPR_PARSER::parsePinNames( std::unique_ptr<LIB_SYMBOL>& aSym
}
LIB_FIELD* SCH_IO_KICAD_SEXPR_PARSER::parseProperty( std::unique_ptr<LIB_SYMBOL>& aSymbol )
SCH_FIELD* SCH_IO_KICAD_SEXPR_PARSER::parseProperty( std::unique_ptr<LIB_SYMBOL>& aSymbol )
{
wxCHECK_MSG( CurTok() == T_property, nullptr,
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as a property." ) );
@ -888,7 +888,7 @@ LIB_FIELD* SCH_IO_KICAD_SEXPR_PARSER::parseProperty( std::unique_ptr<LIB_SYMBOL>
wxString name;
wxString value;
std::unique_ptr<LIB_FIELD> field = std::make_unique<LIB_FIELD>( aSymbol.get(),
std::unique_ptr<SCH_FIELD> field = std::make_unique<SCH_FIELD>( aSymbol.get(),
MANDATORY_FIELDS );
T token = NextTok();
@ -983,7 +983,7 @@ LIB_FIELD* SCH_IO_KICAD_SEXPR_PARSER::parseProperty( std::unique_ptr<LIB_SYMBOL>
}
// Due to an bug when in #LIB_SYMBOL::Flatten, duplicate ids slipped through
// when writing files. This section replaces duplicate #LIB_FIELD indices on
// when writing files. This section replaces duplicate #SCH_FIELD indices on
// load.
if( ( field->GetId() >= MANDATORY_FIELDS ) && m_fieldIDsRead.count( field->GetId() ) )
{
@ -995,9 +995,9 @@ LIB_FIELD* SCH_IO_KICAD_SEXPR_PARSER::parseProperty( std::unique_ptr<LIB_SYMBOL>
field->SetId( nextAvailableId );
}
LIB_FIELD* existingField;
SCH_FIELD* existingField;
if( field->GetId() < MANDATORY_FIELDS )
if( field->IsMandatory() )
{
existingField = aSymbol->GetFieldById( field->GetId() );
@ -1007,7 +1007,7 @@ LIB_FIELD* SCH_IO_KICAD_SEXPR_PARSER::parseProperty( std::unique_ptr<LIB_SYMBOL>
}
else if( name == "ki_keywords" )
{
// Not a LIB_FIELD object yet.
// Not a SCH_FIELD object yet.
aSymbol->SetKeyWords( value );
return nullptr;
}
@ -1019,7 +1019,7 @@ LIB_FIELD* SCH_IO_KICAD_SEXPR_PARSER::parseProperty( std::unique_ptr<LIB_SYMBOL>
}
else if( name == "ki_fp_filters" )
{
// Not a LIB_FIELD object yet.
// Not a SCH_FIELD object yet.
wxArrayString filters;
wxStringTokenizer tokenizer( value );
@ -1034,7 +1034,7 @@ LIB_FIELD* SCH_IO_KICAD_SEXPR_PARSER::parseProperty( std::unique_ptr<LIB_SYMBOL>
}
else if( name == "ki_locked" )
{
// This is a temporary LIB_FIELD object until interchangeable units are determined on
// This is a temporary SCH_FIELD object until interchangeable units are determined on
// the fly.
aSymbol->LockUnits( true );
return nullptr;

View File

@ -193,7 +193,7 @@ private:
bool aEnforceMinTextSize = true );
void parsePinNames( std::unique_ptr<LIB_SYMBOL>& aSymbol );
LIB_FIELD* parseProperty( std::unique_ptr<LIB_SYMBOL>& aSymbol );
SCH_FIELD* parseProperty( std::unique_ptr<LIB_SYMBOL>& aSymbol );
LIB_SHAPE* parseArc();
LIB_SHAPE* parseBezier();

View File

@ -125,9 +125,9 @@ LIB_SYMBOL* SCH_IO_LIB_CACHE::removeSymbol( LIB_SYMBOL* aSymbol )
{
for( SCH_ITEM& drawItem : aSymbol->GetDrawItems() )
{
if( drawItem.Type() == LIB_FIELD_T )
if( drawItem.Type() == SCH_FIELD_T )
{
LIB_FIELD& field = static_cast<LIB_FIELD&>( drawItem );
SCH_FIELD& field = static_cast<SCH_FIELD&>( drawItem );
if( firstChild->FindField( field.GetCanonicalName() ) )
continue;

View File

@ -35,7 +35,6 @@
#include <geometry/shape_rect.h>
#include <gr_text.h>
#include <lib_shape.h>
#include <lib_field.h>
#include <lib_pin.h>
#include <lib_text.h>
#include <lib_textbox.h>
@ -193,10 +192,6 @@ void SCH_PAINTER::draw( const EDA_ITEM* aItem, int aLayer, bool aDimmed )
drawBoundingBox = false;
draw( static_cast<const LIB_PIN*>( aItem ), aLayer, aDimmed );
break;
case LIB_FIELD_T:
drawBoundingBox = false;
draw( static_cast<const LIB_FIELD*>( aItem ), aLayer, aDimmed );
break;
case LIB_TEXT_T:
draw( static_cast<const LIB_TEXT*>( aItem ), aLayer, aDimmed );
break;
@ -452,7 +447,7 @@ COLOR4D SCH_PAINTER::getRenderColor( const EDA_ITEM* aItem, int aLayer, bool aDr
}
if( m_schSettings.m_ShowDisabled
|| ( m_schSettings.m_ShowGraphicsDisabled && aItem->Type() != LIB_FIELD_T ) )
|| ( m_schSettings.m_ShowGraphicsDisabled && aItem->Type() != SCH_FIELD_T ) )
{
color = color.Darken( 0.5f );
}
@ -521,10 +516,6 @@ float SCH_PAINTER::getTextThickness( const EDA_ITEM* aItem ) const
pen = static_cast<const SCH_TEXTBOX*>( aItem )->GetEffectiveTextPenWidth( pen );
break;
case LIB_FIELD_T:
pen = std::max( pen, static_cast<const LIB_FIELD*>( aItem )->GetEffectiveTextPenWidth() );
break;
case LIB_TEXT_T:
pen = std::max( pen, static_cast<const LIB_TEXT*>( aItem )->GetEffectiveTextPenWidth() );
break;
@ -737,7 +728,7 @@ void SCH_PAINTER::draw( const LIB_SYMBOL* aSymbol, int aLayer, bool aDrawFields,
for( const SCH_ITEM& item : drawnSymbol->GetDrawItems() )
{
if( !aDrawFields && item.Type() == LIB_FIELD_T )
if( !aDrawFields && item.Type() == SCH_FIELD_T )
continue;
if( !childOnLayer( item, aLayer ) )
@ -997,88 +988,6 @@ void SCH_PAINTER::draw( const LIB_SHAPE* aShape, int aLayer, bool aDimmed )
}
void SCH_PAINTER::draw( const LIB_FIELD* aField, int aLayer, bool aDimmed )
{
bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS;
if( drawingShadows && !( aField->IsBrightened() || aField->IsSelected() ) )
return;
if( !isUnitAndConversionShown( aField ) )
return;
// Must check layer as fields are sometimes drawn by their parent rather than
// directly from the view.
int layers[KIGFX::VIEW::VIEW_MAX_LAYERS];
int layers_count;
bool foundLayer = false;
aField->ViewGetLayers( layers, layers_count );
for( int i = 0; i < layers_count; ++i )
{
if( layers[i] == aLayer )
foundLayer = true;
}
if( !foundLayer )
return;
COLOR4D color = getRenderColor( aField, aLayer, drawingShadows, aDimmed );
if( !( aField->IsVisible() || aField->IsForceVisible() ) )
{
bool force_show = m_schematic ? eeconfig()->m_Appearance.show_hidden_fields
: m_schSettings.m_ShowHiddenFields;
if( force_show )
color = getRenderColor( aField, LAYER_HIDDEN, drawingShadows, aDimmed );
else
return;
}
m_gal->SetStrokeColor( color );
m_gal->SetFillColor( color );
BOX2I bbox = aField->GetBoundingBox();
if( drawingShadows && getFont( aField )->IsOutline() )
{
bbox.Inflate( KiROUND( getTextThickness( aField ) * 2 ) );
m_gal->SetIsStroke( false );
m_gal->SetIsFill( true );
m_gal->DrawRectangle( bbox.GetPosition(), bbox.GetEnd() );
}
else
{
VECTOR2I textpos = bbox.Centre();
TEXT_ATTRIBUTES attrs( aField->GetAttributes() );
attrs.m_Halign = GR_TEXT_H_ALIGN_CENTER;
attrs.m_Valign = GR_TEXT_V_ALIGN_CENTER;
attrs.m_StrokeWidth = KiROUND( getTextThickness( aField ) );
if( drawingShadows )
attrs.m_StrokeWidth += getShadowWidth( !aField->IsSelected() );
strokeText( UnescapeString( aField->GetShownText( true ) ), textpos, attrs,
aField->GetFontMetrics() );
}
// Draw the umbilical line when in the schematic editor
if( aField->IsMoving() && m_schematic )
{
m_gal->SetLineWidth( m_schSettings.GetOutlineWidth() );
m_gal->SetStrokeColor( getRenderColor( aField, LAYER_SCHEMATIC_ANCHOR, drawingShadows ) );
m_gal->DrawLine( bbox.Centre(), VECTOR2I( 0, 0 ) );
}
if( m_schSettings.GetDrawBoundingBoxes() )
drawItemBoundingBox( aField );
}
void SCH_PAINTER::draw( const LIB_TEXT* aText, int aLayer, bool aDimmed )
{
if( !isUnitAndConversionShown( aText ) )
@ -2735,7 +2644,24 @@ void SCH_PAINTER::draw( const SCH_FIELD* aField, int aLayer, bool aDimmed )
if( drawingShadows && !( aField->IsBrightened() || aField->IsSelected() ) )
return;
if( !drawingShadows && aField->GetLayer() != aLayer )
if( !isUnitAndConversionShown( aField ) )
return;
// Must check layer as fields are sometimes drawn by their parent rather than directly
// from the view.
int layers[KIGFX::VIEW::VIEW_MAX_LAYERS];
int layers_count;
bool foundLayer = false;
aField->ViewGetLayers( layers, layers_count );
for( int i = 0; i < layers_count; ++i )
{
if( layers[i] == aLayer )
foundLayer = true;
}
if( !foundLayer )
return;
aLayer = aField->GetLayer();
@ -2744,7 +2670,10 @@ void SCH_PAINTER::draw( const SCH_FIELD* aField, int aLayer, bool aDimmed )
if( !( aField->IsVisible() || aField->IsForceVisible() ) )
{
if( !m_schematic || eeconfig()->m_Appearance.show_hidden_fields )
bool force_show = m_schematic ? eeconfig()->m_Appearance.show_hidden_fields
: m_schSettings.m_ShowHiddenFields;
if( force_show )
color = getRenderColor( aField, LAYER_HIDDEN, drawingShadows, aDimmed );
else
return;
@ -2851,7 +2780,7 @@ void SCH_PAINTER::draw( const SCH_FIELD* aField, int aLayer, bool aDimmed )
}
// Draw the umbilical line
if( aField->IsMoving() )
if( aField->IsMoving() && m_schematic )
{
VECTOR2I parentPos = aField->GetParentPosition();

View File

@ -36,7 +36,6 @@
class LIB_PIN;
class LIB_SHAPE;
class LIB_SYMBOL;
class LIB_FIELD;
class LIB_TEXT;
class LIB_TEXTBOX;
class SCH_SYMBOL;
@ -88,7 +87,6 @@ private:
void draw( const LIB_SHAPE* aCircle, int aLayer, bool aDimmed );
void draw( const LIB_SYMBOL* aSymbol, int, bool aDrawFields = true, int aUnit = 0,
int aBodyStyle = 0, bool aDimmed = false );
void draw( const LIB_FIELD* aField, int aLayer, bool aDimmed );
void draw( const LIB_TEXT* aText, int aLayer, bool aDimmed );
void draw( const LIB_TEXTBOX* aTextBox, int aLayer, bool aDimmed );
void draw( const SCH_SYMBOL* aSymbol, int aLayer );

View File

@ -1155,7 +1155,7 @@ void SCH_SCREEN::Plot( PLOTTER* aPlotter, const SCH_PLOT_OPTS& aPlotOpts ) const
return a->Type() > b->Type();
} );
auto* renderSettings = static_cast<const SCH_RENDER_SETTINGS*>( aPlotter->RenderSettings() );
auto* renderSettings = static_cast<SCH_RENDER_SETTINGS*>( aPlotter->RenderSettings() );
constexpr bool background = true;
// Bitmaps are drawn first to ensure they are in the background
@ -1183,8 +1183,11 @@ void SCH_SCREEN::Plot( PLOTTER* aPlotter, const SCH_PLOT_OPTS& aPlotOpts ) const
// After plotting the symbols as a group above (in `other`), we need to overplot the pins
// and symbols to ensure that they are always visible
TRANSFORM savedTransform = renderSettings->m_Transform;
for( const SCH_SYMBOL* sym :symbols )
{
renderSettings->m_Transform = sym->GetTransform();
aPlotter->SetCurrentLineWidth( sym->GetEffectivePenWidth( renderSettings ) );
for( SCH_FIELD field : sym->GetFields() )
@ -1200,6 +1203,8 @@ void SCH_SCREEN::Plot( PLOTTER* aPlotter, const SCH_PLOT_OPTS& aPlotOpts ) const
sym->PlotDNP( aPlotter );
}
renderSettings->m_Transform = savedTransform;
for( SCH_ITEM* item : junctions )
{
aPlotter->SetCurrentLineWidth( item->GetEffectivePenWidth( renderSettings ) );
@ -2164,7 +2169,7 @@ void SCH_SCREEN::MigrateSimModels()
for( SCH_ITEM* item : Items().OfType( SCH_SYMBOL_T ) )
{
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
SIM_MODEL::MigrateSimModel<SCH_SYMBOL, SCH_FIELD>( *symbol, &Schematic()->Prj() );
SIM_MODEL::MigrateSimModel<SCH_SYMBOL>( *symbol, &Schematic()->Prj() );
}
}

View File

@ -239,10 +239,7 @@ EDA_ITEM* SCH_SYMBOL::Clone() const
bool SCH_SYMBOL::IsMissingLibSymbol() const
{
if( !m_part )
return true;
return false;
return m_part == nullptr;
}
@ -455,7 +452,6 @@ bool SCH_SYMBOL::HasAlternateBodyStyle() const
void SCH_SYMBOL::SetTransform( const TRANSFORM& aTransform )
{
if( m_transform != aTransform )
m_transform = aTransform;
}
@ -746,9 +742,7 @@ const wxString SCH_SYMBOL::GetRef( const SCH_SHEET_PATH* sheet, bool aIncludeUni
// file. It will also mean that multiple instances of the same sheet by default all have
// the same symbol references, but perhaps this is best.
if( ref.IsEmpty() && !GetField( REFERENCE_FIELD )->GetText().IsEmpty() )
{
ref = GetField( REFERENCE_FIELD )->GetText();
}
if( ref.IsEmpty() )
ref = UTIL::GetRefDesUnannotated( m_prefix );
@ -1037,16 +1031,15 @@ void SCH_SYMBOL::UpdateFields( const SCH_SHEET_PATH* aPath, bool aUpdateStyle, b
{
if( m_part )
{
std::vector<LIB_FIELD*> fields;
std::vector<SCH_FIELD*> fields;
m_part->GetFields( fields );
for( const LIB_FIELD* libField : fields )
for( const SCH_FIELD* libField : fields )
{
int id = libField->GetId();
SCH_FIELD* schField;
if( id >= 0 && id < MANDATORY_FIELDS )
if( libField->IsMandatory() )
{
schField = GetFieldById( id );
}
@ -2404,7 +2397,7 @@ bool SCH_SYMBOL::doIsConnected( const VECTOR2I& aPosition ) const
{
VECTOR2I new_pos = m_transform.InverseTransform().TransformCoordinate( aPosition - m_pos );
for( const auto& pin : m_pins )
for( const std::unique_ptr<SCH_PIN>& pin : m_pins )
{
if( pin->GetType() == ELECTRICAL_PINTYPE::PT_NC )
continue;

View File

@ -145,15 +145,9 @@ void SCH_VIEW::DisplaySymbol( LIB_SYMBOL* aSymbol )
// Draw the fields.
for( SCH_ITEM& item : aSymbol->GetDrawItems() )
{
if( item.Type() == LIB_FIELD_T )
{
LIB_FIELD* field = static_cast< LIB_FIELD* >( &item );
wxCHECK2( field, continue );
if( item.Type() == SCH_FIELD_T )
Add( &item );
}
}
LIB_SYMBOL* drawnSymbol = aSymbol;
@ -172,7 +166,7 @@ void SCH_VIEW::DisplaySymbol( LIB_SYMBOL* aSymbol )
{
// Fields already drawn above. (Besides, we don't want to show parent symbol fields as
// users may be confused by shown fields that can not be edited.)
if( item.Type() == LIB_FIELD_T )
if( item.Type() == SCH_FIELD_T )
continue;
Add( &item );

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2022 Mikolaj Wielgus
* Copyright (C) 2022-2023 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2022-2024 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -169,25 +169,14 @@ SIM_MODEL& SIM_LIB_MGR::CreateModel( const SIM_MODEL* aBaseModel,
}
template <typename T>
SIM_MODEL& SIM_LIB_MGR::CreateModel( const SIM_MODEL* aBaseModel,
const std::vector<LIB_PIN*>& aPins,
const std::vector<T>& aFields, REPORTER& aReporter )
const std::vector<SCH_FIELD>& aFields, REPORTER& aReporter )
{
m_models.push_back( SIM_MODEL::Create( aBaseModel, aPins, aFields, aReporter ) );
return *m_models.back();
}
template SIM_MODEL& SIM_LIB_MGR::CreateModel( const SIM_MODEL* aBaseModel,
const std::vector<LIB_PIN*>& aPins,
const std::vector<SCH_FIELD>& aFields,
REPORTER& aReporter );
template SIM_MODEL& SIM_LIB_MGR::CreateModel( const SIM_MODEL* aBaseModel,
const std::vector<LIB_PIN*>& aPins,
const std::vector<LIB_FIELD>& aFields,
REPORTER& aReporter );
SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const SCH_SHEET_PATH* aSheetPath, SCH_SYMBOL& aSymbol,
REPORTER& aReporter )
{
@ -259,8 +248,7 @@ SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const SCH_SHEET_PATH* aSheetPath, S
}
template <typename T>
SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const std::vector<T>& aFields,
SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const std::vector<SCH_FIELD>& aFields,
const std::vector<LIB_PIN*>& aPins, bool aResolved,
REPORTER& aReporter )
{
@ -278,18 +266,10 @@ SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const std::vector<T>& aFields,
}
}
template SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const std::vector<SCH_FIELD>& aFields,
const std::vector<LIB_PIN*>& aPins,
bool aResolved, REPORTER& aReporter );
template SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const std::vector<LIB_FIELD>& aFields,
const std::vector<LIB_PIN*>& aPins,
bool aResolved, REPORTER& aReporter );
template <typename T>
SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const wxString& aLibraryPath,
const std::string& aBaseModelName,
const std::vector<T>& aFields,
const std::vector<SCH_FIELD>& aFields,
const std::vector<LIB_PIN*>& aPins,
REPORTER& aReporter )
{

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2022 Mikolaj Wielgus
* Copyright (C) 2022-2023 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2022-2024 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -25,10 +25,8 @@
#ifndef SIM_LIB_MGR_H
#define SIM_LIB_MGR_H
#include <memory>
#include <map>
#include <vector>
#include <string>
#include <sim/sim_library.h>
#include <sim/sim_model.h>
@ -55,23 +53,20 @@ public:
SIM_MODEL& CreateModel( const SIM_MODEL* aBaseModel, const std::vector<LIB_PIN*>& aPins,
REPORTER& aReporter );
template <typename T>
SIM_MODEL& CreateModel( const SIM_MODEL* aBaseModel, const std::vector<LIB_PIN*>& aPins,
const std::vector<T>& aFields, REPORTER& aReporter );
const std::vector<SCH_FIELD>& aFields, REPORTER& aReporter );
// TODO: The argument can be made const.
SIM_LIBRARY::MODEL CreateModel( const SCH_SHEET_PATH* aSheetPath, SCH_SYMBOL& aSymbol,
REPORTER& aReporter );
template <typename T>
SIM_LIBRARY::MODEL CreateModel( const std::vector<T>& aFields,
SIM_LIBRARY::MODEL CreateModel( const std::vector<SCH_FIELD>& aFields,
const std::vector<LIB_PIN*>& aPins, bool aResolved,
REPORTER& aReporter );
template <typename T>
SIM_LIBRARY::MODEL CreateModel( const wxString& aLibraryPath,
const std::string& aBaseModelName,
const std::vector<T>& aFields,
const std::vector<SCH_FIELD>& aFields,
const std::vector<LIB_PIN*>& aPins, REPORTER& aReporter );
void SetModel( int aIndex, std::unique_ptr<SIM_MODEL> aModel );

View File

@ -383,13 +383,7 @@ SIM_MODEL::SPICE_INFO SIM_MODEL::SpiceInfo( TYPE aType )
}
template TYPE SIM_MODEL::ReadTypeFromFields( const std::vector<SCH_FIELD>& aFields,
REPORTER& aReporter );
template TYPE SIM_MODEL::ReadTypeFromFields( const std::vector<LIB_FIELD>& aFields,
REPORTER& aReporter );
template <typename T>
TYPE SIM_MODEL::ReadTypeFromFields( const std::vector<T>& aFields, REPORTER& aReporter )
TYPE SIM_MODEL::ReadTypeFromFields( const std::vector<SCH_FIELD>& aFields, REPORTER& aReporter )
{
std::string deviceTypeFieldValue = GetFieldValue( &aFields, SIM_DEVICE_FIELD );
std::string typeFieldValue = GetFieldValue( &aFields, SIM_DEVICE_SUBTYPE_FIELD );
@ -426,33 +420,72 @@ TYPE SIM_MODEL::ReadTypeFromFields( const std::vector<T>& aFields, REPORTER& aRe
}
template <>
void SIM_MODEL::ReadDataFields( const std::vector<SCH_FIELD>* aFields,
const std::vector<LIB_PIN*>& aPins )
{
doReadDataFields( aFields, aPins );
bool diffMode = GetFieldValue( aFields, SIM_LIBRARY_KIBIS::DIFF_FIELD ) == "1";
SwitchSingleEndedDiff( diffMode );
m_serializer->ParseEnable( GetFieldValue( aFields, SIM_LEGACY_ENABLE_FIELD_V7 ) );
createPins( aPins );
m_serializer->ParsePins( GetFieldValue( aFields, SIM_PINS_FIELD ) );
std::string paramsField = GetFieldValue( aFields, SIM_PARAMS_FIELD );
if( !m_serializer->ParseParams( paramsField ) )
m_serializer->ParseValue( GetFieldValue( aFields, SIM_VALUE_FIELD ) );
}
template <>
void SIM_MODEL::ReadDataFields( const std::vector<LIB_FIELD>* aFields,
const std::vector<LIB_PIN*>& aPins )
{
doReadDataFields( aFields, aPins );
}
template <>
void SIM_MODEL::WriteFields( std::vector<SCH_FIELD>& aFields ) const
{
doWriteFields( aFields );
}
// Remove duplicate fields: they are at the end of list
for( size_t ii = aFields.size() - 1; ii > 0; ii-- )
{
wxString currFieldName = aFields[ii].GetName();
auto end_candidate_list = aFields.begin() + ii - 1;
template <>
void SIM_MODEL::WriteFields( std::vector<LIB_FIELD>& aFields ) const
{
doWriteFields( aFields );
auto fieldIt = std::find_if( aFields.begin(), end_candidate_list,
[&]( const SCH_FIELD& f )
{
return f.GetName() == currFieldName;
} );
// If duplicate field found: remove current checked item
if( fieldIt != end_candidate_list )
aFields.erase( aFields.begin() + ii );
}
SetFieldValue( aFields, SIM_DEVICE_FIELD, m_serializer->GenerateDevice() );
SetFieldValue( aFields, SIM_DEVICE_SUBTYPE_FIELD, m_serializer->GenerateDeviceSubtype() );
SetFieldValue( aFields, SIM_LEGACY_ENABLE_FIELD_V7, m_serializer->GenerateEnable() );
SetFieldValue( aFields, SIM_PINS_FIELD, m_serializer->GeneratePins() );
SetFieldValue( aFields, SIM_PARAMS_FIELD, m_serializer->GenerateParams() );
if( IsStoredInValue() )
SetFieldValue( aFields, SIM_VALUE_FIELD, m_serializer->GenerateValue() );
// New fields have a ID = -1 (undefined). so replace the undefined ID
// by a degined ID
int lastFreeId = MANDATORY_FIELDS;
// Search for the first available value:
for( auto& fld : aFields )
{
if( fld.GetId() >= lastFreeId )
lastFreeId = fld.GetId() + 1;
}
// Set undefined IDs to a better value
for( auto& fld : aFields )
{
if( fld.GetId() < 0 )
fld.SetId( lastFreeId++ );
}
}
@ -512,10 +545,9 @@ std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( const SIM_MODEL* aBaseModel,
}
template <typename T>
std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( const SIM_MODEL* aBaseModel,
const std::vector<LIB_PIN*>& aPins,
const std::vector<T>& aFields,
const std::vector<SCH_FIELD>& aFields,
REPORTER& aReporter )
{
std::unique_ptr<SIM_MODEL> model;
@ -560,19 +592,8 @@ std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( const SIM_MODEL* aBaseModel,
return model;
}
template std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( const SIM_MODEL* aBaseModel,
const std::vector<LIB_PIN*>& aPins,
const std::vector<SCH_FIELD>& aFields,
REPORTER& aReporter );
template std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( const SIM_MODEL* aBaseModel,
const std::vector<LIB_PIN*>& aPins,
const std::vector<LIB_FIELD>& aFields,
REPORTER& aReporter );
template <typename T>
std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( const std::vector<T>& aFields,
std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( const std::vector<SCH_FIELD>& aFields,
const std::vector<LIB_PIN*>& aPins,
bool aResolved, REPORTER& aReporter )
{
@ -620,24 +641,14 @@ std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( const std::vector<T>& aFields,
return model;
}
template std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( const std::vector<SCH_FIELD>& aFields,
const std::vector<LIB_PIN*>& aPins,
bool aResolved, REPORTER& aReporter );
template std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( const std::vector<LIB_FIELD>& aFields,
const std::vector<LIB_PIN*>& aPins,
bool aResolved, REPORTER& aReporter );
template <typename T>
std::string SIM_MODEL::GetFieldValue( const std::vector<T>* aFields, const wxString& aFieldName,
bool aResolve )
std::string SIM_MODEL::GetFieldValue( const std::vector<SCH_FIELD>* aFields,
const wxString& aFieldName, bool aResolve )
{
static_assert( std::is_same<T, SCH_FIELD>::value || std::is_same<T, LIB_FIELD>::value );
if( !aFields )
return ""; // Should not happen, T=void specialization will be called instead.
for( const T& field : *aFields )
for( const SCH_FIELD& field : *aFields )
{
if( field.GetName() == aFieldName )
{
@ -650,23 +661,11 @@ std::string SIM_MODEL::GetFieldValue( const std::vector<T>* aFields, const wxStr
}
// This specialization is used when no fields are passed.
template <>
std::string SIM_MODEL::GetFieldValue( const std::vector<void>* aFields, const wxString& aFieldName,
bool aResolve )
{
return "";
}
template <typename T>
void SIM_MODEL::SetFieldValue( std::vector<T>& aFields, const wxString& aFieldName,
void SIM_MODEL::SetFieldValue( std::vector<SCH_FIELD>& aFields, const wxString& aFieldName,
const std::string& aValue )
{
static_assert( std::is_same<T, SCH_FIELD>::value || std::is_same<T, LIB_FIELD>::value );
auto fieldIt = std::find_if( aFields.begin(), aFields.end(),
[&]( const T& f )
[&]( const SCH_FIELD& f )
{
return f.GetName() == aFieldName;
} );
@ -684,29 +683,13 @@ void SIM_MODEL::SetFieldValue( std::vector<T>& aFields, const wxString& aFieldNa
if( aValue == "" )
return;
if constexpr( std::is_same<T, SCH_FIELD>::value )
{
wxASSERT( aFields.size() >= 1 );
SCH_ITEM* parent = static_cast<SCH_ITEM*>( aFields.at( 0 ).GetParent() );
aFields.emplace_back( VECTOR2I(), aFields.size(), parent, aFieldName );
}
else if constexpr( std::is_same<T, LIB_FIELD>::value )
{
aFields.emplace_back( aFields.size(), aFieldName );
}
aFields.back().SetText( aValue );
}
template void SIM_MODEL::SetFieldValue<SCH_FIELD>( std::vector<SCH_FIELD>& aFields,
const wxString& aFieldName,
const std::string& aValue );
template void SIM_MODEL::SetFieldValue<LIB_FIELD>( std::vector<LIB_FIELD>& aFields,
const wxString& aFieldName,
const std::string& aValue );
SIM_MODEL::~SIM_MODEL() = default;
@ -1032,77 +1015,6 @@ void SIM_MODEL::createPins( const std::vector<LIB_PIN*>& aSymbolPins )
}
template <typename T>
void SIM_MODEL::doReadDataFields( const std::vector<T>* aFields,
const std::vector<LIB_PIN*>& aPins )
{
bool diffMode = GetFieldValue( aFields, SIM_LIBRARY_KIBIS::DIFF_FIELD ) == "1";
SwitchSingleEndedDiff( diffMode );
m_serializer->ParseEnable( GetFieldValue( aFields, SIM_LEGACY_ENABLE_FIELD_V7 ) );
createPins( aPins );
m_serializer->ParsePins( GetFieldValue( aFields, SIM_PINS_FIELD ) );
std::string paramsField = GetFieldValue( aFields, SIM_PARAMS_FIELD );
if( !m_serializer->ParseParams( paramsField ) )
m_serializer->ParseValue( GetFieldValue( aFields, SIM_VALUE_FIELD ) );
}
template <typename T>
void SIM_MODEL::doWriteFields( std::vector<T>& aFields ) const
{
// Remove duplicate fields: they are at the end of list
for( size_t ii = aFields.size() - 1; ii > 0; ii-- )
{
wxString currFieldName = aFields[ii].GetName();
auto end_candidate_list = aFields.begin() + ii - 1;
auto fieldIt = std::find_if( aFields.begin(), end_candidate_list,
[&]( const T& f )
{
return f.GetName() == currFieldName;
} );
// If duplicate field found: remove current checked item
if( fieldIt != end_candidate_list )
aFields.erase( aFields.begin() + ii );
}
SetFieldValue( aFields, SIM_DEVICE_FIELD, m_serializer->GenerateDevice() );
SetFieldValue( aFields, SIM_DEVICE_SUBTYPE_FIELD, m_serializer->GenerateDeviceSubtype() );
SetFieldValue( aFields, SIM_LEGACY_ENABLE_FIELD_V7, m_serializer->GenerateEnable() );
SetFieldValue( aFields, SIM_PINS_FIELD, m_serializer->GeneratePins() );
SetFieldValue( aFields, SIM_PARAMS_FIELD, m_serializer->GenerateParams() );
if( IsStoredInValue() )
SetFieldValue( aFields, SIM_VALUE_FIELD, m_serializer->GenerateValue() );
// New fields have a ID = -1 (undefined). so replace the undefined ID
// by a degined ID
int lastFreeId = MANDATORY_FIELDS;
// Search for the first available value:
for( auto& fld : aFields )
{
if( fld.GetId() >= lastFreeId )
lastFreeId = fld.GetId() + 1;
}
// Set undefined IDs to a better value
for( auto& fld : aFields )
{
if( fld.GetId() < 0 )
fld.SetId( lastFreeId++ );
}
}
bool SIM_MODEL::requiresSpiceModelLine( const SPICE_ITEM& aItem ) const
{
// SUBCKTs are a single level; there's never a baseModel.
@ -1147,8 +1059,8 @@ bool SIM_MODEL::requiresSpiceModelLine( const SPICE_ITEM& aItem ) const
}
template <class T_symbol, class T_field>
bool SIM_MODEL::InferSimModel( T_symbol& aSymbol, std::vector<T_field>* aFields, bool aResolve,
template <class T>
bool SIM_MODEL::InferSimModel( T& aSymbol, std::vector<SCH_FIELD>* aFields, bool aResolve,
SIM_VALUE_GRAMMAR::NOTATION aNotation, wxString* aDeviceType,
wxString* aModelType, wxString* aModelParams, wxString* aPinMap )
{
@ -1465,26 +1377,20 @@ bool SIM_MODEL::InferSimModel( T_symbol& aSymbol, std::vector<T_field>* aFields,
}
template bool SIM_MODEL::InferSimModel<SCH_SYMBOL, SCH_FIELD>( SCH_SYMBOL& aSymbol,
std::vector<SCH_FIELD>* aFields,
bool aResolve,
template bool SIM_MODEL::InferSimModel<SCH_SYMBOL>( SCH_SYMBOL& aSymbol,
std::vector<SCH_FIELD>* aFields, bool aResolve,
SIM_VALUE_GRAMMAR::NOTATION aNotation,
wxString* aDeviceType,
wxString* aModelType,
wxString* aModelParams,
wxString* aPinMap );
template bool SIM_MODEL::InferSimModel<LIB_SYMBOL, LIB_FIELD>( LIB_SYMBOL& aSymbol,
std::vector<LIB_FIELD>* aFields,
bool aResolve,
wxString* aDeviceType, wxString* aModelType,
wxString* aModelParams, wxString* aPinMap );
template bool SIM_MODEL::InferSimModel<LIB_SYMBOL>( LIB_SYMBOL& aSymbol,
std::vector<SCH_FIELD>* aFields, bool aResolve,
SIM_VALUE_GRAMMAR::NOTATION aNotation,
wxString* aDeviceType,
wxString* aModelType,
wxString* aModelParams,
wxString* aPinMap );
wxString* aDeviceType, wxString* aModelType,
wxString* aModelParams, wxString* aPinMap );
template <typename T_symbol, typename T_field>
void SIM_MODEL::MigrateSimModel( T_symbol& aSymbol, const PROJECT* aProject )
template <typename T>
void SIM_MODEL::MigrateSimModel( T& aSymbol, const PROJECT* aProject )
{
class FIELD_INFO
{
@ -1496,17 +1402,17 @@ void SIM_MODEL::MigrateSimModel( T_symbol& aSymbol, const PROJECT* aProject )
DEFAULT_SIZE_TEXT * schIUScale.IU_PER_MILS );
};
FIELD_INFO( const wxString& aText, T_field* aField ) :
FIELD_INFO( const wxString& aText, SCH_FIELD* aField ) :
m_Text( aText ),
m_Attributes( aField->GetAttributes() ),
m_Pos( aField->GetPosition() )
{}
bool IsEmpty() { return m_Text.IsEmpty(); }
bool IsEmpty() const { return m_Text.IsEmpty(); }
T_field CreateField( T_symbol* aSymbol, const wxString& aFieldName )
SCH_FIELD CreateField( T* aSymbol, const wxString& aFieldName )
{
T_field field( aSymbol, -1, aFieldName );
SCH_FIELD field( aSymbol, -1, aFieldName );
field.SetText( m_Text );
field.SetAttributes( m_Attributes );
@ -1521,10 +1427,10 @@ void SIM_MODEL::MigrateSimModel( T_symbol& aSymbol, const PROJECT* aProject )
VECTOR2I m_Pos;
};
T_field* existing_deviceField = aSymbol.FindField( SIM_DEVICE_FIELD );
T_field* existing_deviceSubtypeField = aSymbol.FindField( SIM_DEVICE_SUBTYPE_FIELD );
T_field* existing_pinsField = aSymbol.FindField( SIM_PINS_FIELD );
T_field* existing_paramsField = aSymbol.FindField( SIM_PARAMS_FIELD );
SCH_FIELD* existing_deviceField = aSymbol.FindField( SIM_DEVICE_FIELD );
SCH_FIELD* existing_deviceSubtypeField = aSymbol.FindField( SIM_DEVICE_SUBTYPE_FIELD );
SCH_FIELD* existing_pinsField = aSymbol.FindField( SIM_PINS_FIELD );
SCH_FIELD* existing_paramsField = aSymbol.FindField( SIM_PARAMS_FIELD );
wxString existing_deviceSubtype;
@ -1597,7 +1503,7 @@ void SIM_MODEL::MigrateSimModel( T_symbol& aSymbol, const PROJECT* aProject )
FIELD_INFO deviceFieldInfo;
deviceFieldInfo.m_Text = wxS( "K" );
T_field deviceField = deviceFieldInfo.CreateField( &aSymbol, SIM_DEVICE_FIELD );
SCH_FIELD deviceField = deviceFieldInfo.CreateField( &aSymbol, SIM_DEVICE_FIELD );
aSymbol.AddField( deviceField );
}
}
@ -1606,7 +1512,7 @@ void SIM_MODEL::MigrateSimModel( T_symbol& aSymbol, const PROJECT* aProject )
}
auto getSIValue =
[]( T_field* aField )
[]( SCH_FIELD* aField )
{
if( !aField ) // no, not really, but it keeps Coverity happy
return wxString( wxEmptyString );
@ -1642,7 +1548,7 @@ void SIM_MODEL::MigrateSimModel( T_symbol& aSymbol, const PROJECT* aProject )
};
wxString prefix = aSymbol.GetPrefix();
T_field* valueField = aSymbol.FindField( wxT( "Value" ) );
SCH_FIELD* valueField = aSymbol.FindField( wxT( "Value" ) );
std::vector<LIB_PIN*> sourcePins = aSymbol.GetAllLibPins();
bool sourcePinsSorted = false;
@ -1675,13 +1581,13 @@ void SIM_MODEL::MigrateSimModel( T_symbol& aSymbol, const PROJECT* aProject )
|| aSymbol.FindField( SIM_LEGACY_ENABLE_FIELD )
|| aSymbol.FindField( SIM_LEGACY_LIBRARY_FIELD ) )
{
if( T_field* primitiveField = aSymbol.FindField( SIM_LEGACY_PRIMITIVE_FIELD ) )
if( SCH_FIELD* primitiveField = aSymbol.FindField( SIM_LEGACY_PRIMITIVE_FIELD ) )
{
deviceInfo = FIELD_INFO( primitiveField->GetText(), primitiveField );
aSymbol.RemoveField( primitiveField );
}
if( T_field* nodeSequenceField = aSymbol.FindField( SIM_LEGACY_PINS_FIELD ) )
if( SCH_FIELD* nodeSequenceField = aSymbol.FindField( SIM_LEGACY_PINS_FIELD ) )
{
const wxString delimiters( "{:,; }" );
const wxString& nodeSequence = nodeSequenceField->GetText();
@ -1707,7 +1613,7 @@ void SIM_MODEL::MigrateSimModel( T_symbol& aSymbol, const PROJECT* aProject )
aSymbol.RemoveField( nodeSequenceField );
}
if( T_field* modelField = aSymbol.FindField( SIM_LEGACY_MODEL_FIELD ) )
if( SCH_FIELD* modelField = aSymbol.FindField( SIM_LEGACY_MODEL_FIELD ) )
{
modelInfo = FIELD_INFO( getSIValue( modelField ), modelField );
aSymbol.RemoveField( modelField );
@ -1718,7 +1624,7 @@ void SIM_MODEL::MigrateSimModel( T_symbol& aSymbol, const PROJECT* aProject )
modelFromValueField = true;
}
if( T_field* libFileField = aSymbol.FindField( SIM_LEGACY_LIBRARY_FIELD ) )
if( SCH_FIELD* libFileField = aSymbol.FindField( SIM_LEGACY_LIBRARY_FIELD ) )
{
libInfo = FIELD_INFO( libFileField->GetText(), libFileField );
aSymbol.RemoveField( libFileField );
@ -1728,17 +1634,17 @@ void SIM_MODEL::MigrateSimModel( T_symbol& aSymbol, const PROJECT* aProject )
{
// Auto convert some legacy fields used in the middle of 7.0 development...
if( T_field* legacyType = aSymbol.FindField( wxT( "Sim_Type" ) ) )
if( SCH_FIELD* legacyType = aSymbol.FindField( wxT( "Sim_Type" ) ) )
{
legacyType->SetName( SIM_DEVICE_SUBTYPE_FIELD );
}
if( T_field* legacyDevice = aSymbol.FindField( wxT( "Sim_Device" ) ) )
if( SCH_FIELD* legacyDevice = aSymbol.FindField( wxT( "Sim_Device" ) ) )
{
legacyDevice->SetName( SIM_DEVICE_FIELD );
}
if( T_field* legacyPins = aSymbol.FindField( wxT( "Sim_Pins" ) ) )
if( SCH_FIELD* legacyPins = aSymbol.FindField( wxT( "Sim_Pins" ) ) )
{
bool isPassive = prefix.StartsWith( wxT( "R" ) )
|| prefix.StartsWith( wxT( "L" ) )
@ -1784,7 +1690,7 @@ void SIM_MODEL::MigrateSimModel( T_symbol& aSymbol, const PROJECT* aProject )
legacyPins->SetText( pinMap );
}
if( T_field* legacyParams = aSymbol.FindField( wxT( "Sim_Params" ) ) )
if( SCH_FIELD* legacyParams = aSymbol.FindField( wxT( "Sim_Params" ) ) )
{
legacyParams->SetName( SIM_PARAMS_FIELD );
}
@ -1806,7 +1712,7 @@ void SIM_MODEL::MigrateSimModel( T_symbol& aSymbol, const PROJECT* aProject )
wxString msg;
WX_STRING_REPORTER reporter( &msg );
SIM_LIB_MGR libMgr( aProject );
std::vector<T_field> emptyFields;
std::vector<SCH_FIELD> emptyFields;
// Pull out any following parameters from model name
model = model.BeforeFirst( ' ', &modelLineParams );
@ -1907,10 +1813,10 @@ void SIM_MODEL::MigrateSimModel( T_symbol& aSymbol, const PROJECT* aProject )
if( libraryModel )
{
T_field libField = libInfo.CreateField( &aSymbol, SIM_LIBRARY_FIELD );
SCH_FIELD libField = libInfo.CreateField( &aSymbol, SIM_LIBRARY_FIELD );
aSymbol.AddField( libField );
T_field nameField = modelInfo.CreateField( &aSymbol, SIM_NAME_FIELD );
SCH_FIELD nameField = modelInfo.CreateField( &aSymbol, SIM_NAME_FIELD );
aSymbol.AddField( nameField );
if( !modelLineParams.IsEmpty() )
@ -1930,7 +1836,7 @@ void SIM_MODEL::MigrateSimModel( T_symbol& aSymbol, const PROJECT* aProject )
else
spiceParamsInfo.m_Pos.x += nameWidth;
T_field paramsField = spiceParamsInfo.CreateField( &aSymbol, SIM_PARAMS_FIELD );
SCH_FIELD paramsField = spiceParamsInfo.CreateField( &aSymbol, SIM_PARAMS_FIELD );
aSymbol.AddField( paramsField );
}
@ -1944,18 +1850,18 @@ void SIM_MODEL::MigrateSimModel( T_symbol& aSymbol, const PROJECT* aProject )
}
else if( internalModel )
{
T_field deviceField = deviceInfo.CreateField( &aSymbol, SIM_DEVICE_FIELD );
SCH_FIELD deviceField = deviceInfo.CreateField( &aSymbol, SIM_DEVICE_FIELD );
aSymbol.AddField( deviceField );
if( !deviceSubtypeInfo.m_Text.IsEmpty() )
{
T_field subtypeField = deviceSubtypeInfo.CreateField( &aSymbol, SIM_DEVICE_SUBTYPE_FIELD );
SCH_FIELD subtypeField = deviceSubtypeInfo.CreateField( &aSymbol, SIM_DEVICE_SUBTYPE_FIELD );
aSymbol.AddField( subtypeField );
}
if( !spiceParamsInfo.IsEmpty() )
{
T_field paramsField = spiceParamsInfo.CreateField( &aSymbol, SIM_PARAMS_FIELD );
SCH_FIELD paramsField = spiceParamsInfo.CreateField( &aSymbol, SIM_PARAMS_FIELD );
aSymbol.AddField( paramsField );
}
@ -1976,10 +1882,10 @@ void SIM_MODEL::MigrateSimModel( T_symbol& aSymbol, const PROJECT* aProject )
deviceInfo.m_Text = SIM_MODEL::DeviceInfo( SIM_MODEL::DEVICE_T::SPICE ).fieldValue;
T_field deviceField = deviceInfo.CreateField( &aSymbol, SIM_DEVICE_FIELD );
SCH_FIELD deviceField = deviceInfo.CreateField( &aSymbol, SIM_DEVICE_FIELD );
aSymbol.AddField( deviceField );
T_field paramsField = spiceParamsInfo.CreateField( &aSymbol, SIM_PARAMS_FIELD );
SCH_FIELD paramsField = spiceParamsInfo.CreateField( &aSymbol, SIM_PARAMS_FIELD );
aSymbol.AddField( paramsField );
if( modelFromValueField )
@ -2003,13 +1909,13 @@ void SIM_MODEL::MigrateSimModel( T_symbol& aSymbol, const PROJECT* aProject )
if( !pinMapInfo.IsEmpty() )
{
T_field pinsField = pinMapInfo.CreateField( &aSymbol, SIM_PINS_FIELD );
SCH_FIELD pinsField = pinMapInfo.CreateField( &aSymbol, SIM_PINS_FIELD );
aSymbol.AddField( pinsField );
}
}
template void SIM_MODEL::MigrateSimModel<SCH_SYMBOL, SCH_FIELD>( SCH_SYMBOL& aSymbol,
template void SIM_MODEL::MigrateSimModel<SCH_SYMBOL>( SCH_SYMBOL& aSymbol,
const PROJECT* aProject );
template void SIM_MODEL::MigrateSimModel<LIB_SYMBOL, LIB_FIELD>( LIB_SYMBOL& aSymbol,
template void SIM_MODEL::MigrateSimModel<LIB_SYMBOL>( LIB_SYMBOL& aSymbol,
const PROJECT* aProject );

View File

@ -32,7 +32,6 @@
#include <reporter.h>
#include <sch_field.h>
#include <lib_field.h>
#include <lib_pin.h>
// Must be included after sch_field.h (exactly eda_shape.h) to avoid a colliding
@ -409,8 +408,7 @@ public:
static SPICE_INFO SpiceInfo( TYPE aType );
template <typename T>
static TYPE ReadTypeFromFields( const std::vector<T>& aFields, REPORTER& aReporter );
static TYPE ReadTypeFromFields( const std::vector<SCH_FIELD>& aFields, REPORTER& aReporter );
static std::unique_ptr<SIM_MODEL> Create( TYPE aType, const std::vector<LIB_PIN*>& aPins,
REPORTER& aReporter );
@ -419,23 +417,20 @@ public:
const std::vector<LIB_PIN*>& aPins,
REPORTER& aReporter );
template <typename T>
static std::unique_ptr<SIM_MODEL> Create( const SIM_MODEL* aBaseModel,
const std::vector<LIB_PIN*>& aPins,
const std::vector<T>& aFields,
const std::vector<SCH_FIELD>& aFields,
REPORTER& aReporter );
template <typename T>
static std::unique_ptr<SIM_MODEL> Create( const std::vector<T>& aFields,
static std::unique_ptr<SIM_MODEL> Create( const std::vector<SCH_FIELD>& aFields,
const std::vector<LIB_PIN*>& aPins,
bool aResolved, REPORTER& aReporter );
template <typename T>
static std::string GetFieldValue( const std::vector<T>* aFields, const wxString& aFieldName,
static std::string GetFieldValue( const std::vector<SCH_FIELD>* aFields,
const wxString& aFieldName,
bool aResolve = true );
template <typename T>
static void SetFieldValue( std::vector<T>& aFields, const wxString& aFieldName,
static void SetFieldValue( std::vector<SCH_FIELD>& aFields, const wxString& aFieldName,
const std::string& aValue );
const SPICE_GENERATOR& SpiceGenerator() const { return *m_spiceGenerator; }
@ -450,11 +445,10 @@ public:
SIM_MODEL( SIM_MODEL&& aOther ) = default;
SIM_MODEL& operator=(SIM_MODEL&& aOther ) = delete;
template <typename T>
void ReadDataFields( const std::vector<T>* aFields, const std::vector<LIB_PIN*>& aPins );
void ReadDataFields( const std::vector<SCH_FIELD>* aFields,
const std::vector<LIB_PIN*>& aPins );
template <typename T>
void WriteFields( std::vector<T>& aFields ) const;
void WriteFields( std::vector<SCH_FIELD>& aFields ) const;
SPICE_INFO GetSpiceInfo() const { return SpiceInfo( GetType() ); }
@ -519,13 +513,13 @@ public:
virtual void SwitchSingleEndedDiff( bool aDiff ) { };
template <class T_symbol, class T_field>
static bool InferSimModel( T_symbol& aSymbol, std::vector<T_field>* aFields, bool aResolve,
template <class T>
static bool InferSimModel( T& aSymbol, std::vector<SCH_FIELD>* aFields, bool aResolve,
SIM_VALUE_GRAMMAR::NOTATION aNotation, wxString* aDeviceType,
wxString* aModelType, wxString* aModelParams, wxString* aPinMap );
template <class T_symbol, class T_field>
static void MigrateSimModel( T_symbol& aSymbol, const PROJECT* aProject );
template <class T>
static void MigrateSimModel( T& aSymbol, const PROJECT* aProject );
protected:
static std::unique_ptr<SIM_MODEL> Create( TYPE aType );
@ -541,12 +535,6 @@ protected:
virtual void doSetParamValue( int aParamIndex, const std::string& aValue );
private:
template <typename T>
void doReadDataFields( const std::vector<T>* aFields, const std::vector<LIB_PIN*>& aPins );
template <typename T>
void doWriteFields( std::vector<T>& aFields ) const;
virtual bool requiresSpiceModelLine( const SPICE_ITEM& aItem ) const;
protected:

View File

@ -1392,11 +1392,10 @@ void SYMBOL_EDIT_FRAME::FocusOnItem( SCH_ITEM* aItem )
lastItem = pin;
}
std::vector<LIB_FIELD*> fields;
std::vector<SCH_FIELD*> fields;
m_symbol->GetFields( fields );
for( LIB_FIELD* field : fields )
for( SCH_FIELD* field : fields )
{
if( field->m_Uuid == lastBrightenedItemID )
lastItem = field;
@ -1637,13 +1636,13 @@ void SYMBOL_EDIT_FRAME::LoadSymbolFromSchematic( SCH_SYMBOL* aSymbol )
int orientation = aSymbol->GetOrientation() & ~( SYM_MIRROR_X | SYM_MIRROR_Y );
int mirror = aSymbol->GetOrientation() & ( SYM_MIRROR_X | SYM_MIRROR_Y );
std::vector<LIB_FIELD> fullSetOfFields;
std::vector<SCH_FIELD> fullSetOfFields;
for( int i = 0; i < (int) aSymbol->GetFields().size(); ++i )
{
const SCH_FIELD& field = aSymbol->GetFields()[i];
VECTOR2I pos = field.GetPosition() - aSymbol->GetPosition();
LIB_FIELD libField( symbol.get(), field.GetId() );
SCH_FIELD libField( symbol.get(), field.GetId() );
if( i >= MANDATORY_FIELDS && !field.GetName( false ).IsEmpty() )
libField.SetName( field.GetName( false ) );

View File

@ -36,7 +36,6 @@
class SCH_EDIT_FRAME;
class SYMBOL_LIB_TABLE;
class LIB_SYMBOL;
class LIB_FIELD;
class DIALOG_LIB_TEXT_PROPERTIES;
class SYMBOL_TREE_PANE;
class LIB_TREE_NODE;

View File

@ -456,12 +456,12 @@ void SYMBOL_EDIT_FRAME::CreateNewSymbol( const wxString& aInheritFrom )
// Inherit the parent mandatory field attributes.
for( int id = 0; id < MANDATORY_FIELDS; ++id )
{
LIB_FIELD* field = new_symbol.GetFieldById( id );
SCH_FIELD* field = new_symbol.GetFieldById( id );
// the MANDATORY_FIELDS are exactly that in RAM.
wxCHECK( field, /* void */ );
LIB_FIELD* parentField = parent->GetFieldById( id );
SCH_FIELD* parentField = parent->GetFieldById( id );
wxCHECK( parentField, /* void */ );

View File

@ -432,7 +432,7 @@ LIB_SYMBOL* SYMBOL_LIB_TABLE::LoadSymbol( const wxString& aNickname, const wxStr
id.SetLibNickname( row->GetNickName() );
symbol->SetLibId( id );
SIM_MODEL::MigrateSimModel<LIB_SYMBOL, LIB_FIELD>( *symbol, nullptr );
SIM_MODEL::MigrateSimModel<LIB_SYMBOL>( *symbol, nullptr );
}
return symbol;

View File

@ -168,7 +168,7 @@ LIB_SYMBOL* SYMBOL_LIB::FindSymbol( const wxString& aName ) const
if( !symbol->GetLib() )
symbol->SetLib( const_cast<SYMBOL_LIB*>( this ) );
SIM_MODEL::MigrateSimModel<LIB_SYMBOL, LIB_FIELD>( *symbol, nullptr );
SIM_MODEL::MigrateSimModel<LIB_SYMBOL>( *symbol, nullptr );
}
return symbol;

View File

@ -552,7 +552,7 @@ void BACK_ANNOTATE::applyChangelist()
for( SCH_FIELD& field : symbol->GetFields() )
{
// Never delete mandatory fields
if( field.GetId() < MANDATORY_FIELDS )
if( field.IsMandatory() )
continue;
if( fpData.m_fieldsMap.find( field.GetCanonicalName() )

View File

@ -331,7 +331,7 @@ TOOL_ACTION EE_ACTIONS::showHiddenFields( TOOL_ACTION_ARGS()
.Scope( AS_GLOBAL )
.FriendlyName( _( "Show Hidden Fields" ) )
.Tooltip( _( "Toggle display of hidden text fields" ) )
.Icon( BITMAPS::spreadsheet ) );
.Icon( BITMAPS::text_sketch ) );
// SYMBOL_EDITOR_DRAWING_TOOLS

View File

@ -376,7 +376,6 @@ GRID_HELPER_GRIDS EE_GRID_HELPER::GetItemGrid( const EDA_ITEM* aItem ) const
case SCH_DIRECTIVE_LABEL_T:
return GRID_CONNECTABLE;
case LIB_FIELD_T:
case SCH_FIELD_T:
case LIB_TEXT_T:
case SCH_TEXT_T:

View File

@ -422,11 +422,11 @@ void EE_INSPECTION_TOOL::DiffSymbol( SCH_SYMBOL* symbol )
}
else
{
std::vector<LIB_FIELD> fields;
std::vector<SCH_FIELD> fields;
for( SCH_FIELD& field : symbol->GetFields() )
{
fields.emplace_back( LIB_FIELD( flattenedLibSymbol.get(), field.GetId(),
fields.emplace_back( SCH_FIELD( flattenedLibSymbol.get(), field.GetId(),
field.GetName( false ) ) );
fields.back().CopyText( field );
fields.back().SetAttributes( field );

View File

@ -566,7 +566,7 @@ int EE_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent )
{
if( static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->IsSymbolAlias() )
{
m_selection = RequestSelection( { LIB_FIELD_T } );
m_selection = RequestSelection( { SCH_FIELD_T } );
}
else
{
@ -574,7 +574,7 @@ int EE_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent )
LIB_TEXT_T,
LIB_TEXTBOX_T,
LIB_PIN_T,
LIB_FIELD_T } );
SCH_FIELD_T } );
}
}
else
@ -1076,11 +1076,11 @@ void EE_SELECTION_TOOL::narrowSelection( EE_COLLECTOR& collector, const VECTOR2I
if( symbolEditorFrame )
{
// Do not select invisible items if they are not displayed
EDA_ITEM* item = static_cast<EDA_ITEM*>( collector[i] );
EDA_ITEM* item = collector[i];
if( item->Type() == LIB_FIELD_T )
if( item->Type() == SCH_FIELD_T )
{
if( !static_cast<LIB_FIELD*>( item )->IsVisible()
if( !static_cast<SCH_FIELD*>( item )->IsVisible()
&& !symbolEditorFrame->GetShowInvisibleFields() )
{
collector.Remove( i );
@ -1649,7 +1649,6 @@ bool EE_SELECTION_TOOL::itemPassesFilter( EDA_ITEM* aItem )
case SCH_FIELD_T:
case LIB_TEXT_T:
case LIB_TEXTBOX_T:
case LIB_FIELD_T:
if( !m_filter.text )
return false;
@ -2442,7 +2441,7 @@ bool EE_SELECTION_TOOL::Selectable( const EDA_ITEM* aItem, const VECTOR2I* aPos,
// Do not allow selection of anything except fields when the current symbol in the symbol
// editor is a derived symbol.
if( symEditFrame && symEditFrame->IsSymbolAlias() && aItem->Type() != LIB_FIELD_T )
if( symEditFrame && symEditFrame->IsSymbolAlias() && aItem->Type() != SCH_FIELD_T )
return false;
switch( aItem->Type() )
@ -2481,7 +2480,7 @@ bool EE_SELECTION_TOOL::Selectable( const EDA_ITEM* aItem, const VECTOR2I* aPos,
case LIB_SYMBOL_T: // In symbol_editor we do not want to select the symbol itself.
return false;
case LIB_FIELD_T: // LIB_FIELD object can always be edited.
case SCH_FIELD_T: // SCH_FIELD object can always be edited.
break;
case LIB_SHAPE_T:

View File

@ -1548,19 +1548,18 @@ void SCH_EDIT_TOOL::editFieldText( SCH_FIELD* aField )
wxString caption;
// Use title caps for mandatory fields. "Edit Sheet name Field" looks dorky.
if( parentType == SCH_SYMBOL_T && aField->GetId() >= 0 && aField->GetId() < MANDATORY_FIELDS )
if( parentType == SCH_SYMBOL_T && aField->IsMandatory() )
{
wxString translated_fieldname;
translated_fieldname = TEMPLATE_FIELDNAME::GetDefaultFieldName( aField->GetId(),
wxString translated_fieldname = TEMPLATE_FIELDNAME::GetDefaultFieldName( aField->GetId(),
DO_TRANSLATE );
caption.Printf( _( "Edit %s Field" ), TitleCaps( translated_fieldname ) );
}
else if( parentType == SCH_SHEET_T && aField->GetId() < SHEET_MANDATORY_FIELDS )
else if( parentType == SCH_SHEET_T && aField->IsMandatory() )
caption.Printf( _( "Edit %s Field" ), TitleCaps( aField->GetName() ) );
else
caption.Printf( _( "Edit '%s' Field" ), aField->GetName() );
DIALOG_SCH_FIELD_PROPERTIES dlg( m_frame, caption, aField );
DIALOG_FIELD_PROPERTIES dlg( m_frame, caption, aField );
// The footprint field dialog can invoke a KIWAY_PLAYER so we must use a quasi-modal
if( dlg.ShowQuasiModal() != wxID_OK )

View File

@ -64,24 +64,20 @@ bool SYMBOL_EDITOR_EDIT_TOOL::Init()
auto haveSymbolCondition =
[&]( const SELECTION& sel )
{
return m_isSymbolEditor &&
static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->GetCurSymbol();
return m_isSymbolEditor && m_frame->GetCurSymbol();
};
auto canEdit =
[&]( const SELECTION& sel )
{
SYMBOL_EDIT_FRAME* editor = static_cast<SYMBOL_EDIT_FRAME*>( m_frame );
wxCHECK( editor, false );
if( !editor->IsSymbolEditable() )
if( !m_frame->IsSymbolEditable() )
return false;
if( editor->IsSymbolAlias() )
if( m_frame->IsSymbolAlias() )
{
for( EDA_ITEM* item : sel )
{
if( item->Type() != LIB_FIELD_T )
if( item->Type() != SCH_FIELD_T )
return false;
}
}
@ -186,7 +182,6 @@ int SYMBOL_EDITOR_EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent )
}
else
{
if( selection.IsHover() )
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
@ -218,9 +213,9 @@ int SYMBOL_EDITOR_EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent )
switch( item->Type() )
{
case LIB_FIELD_T:
case SCH_FIELD_T:
{
LIB_FIELD* field = static_cast<LIB_FIELD*>( item );
SCH_FIELD* field = static_cast<SCH_FIELD*>( item );
if( xAxis )
field->SetVertJustify( TO_VJUSTIFY( -field->GetVertJustify() ) );
@ -475,8 +470,8 @@ int SYMBOL_EDITOR_EDIT_TOOL::Properties( const TOOL_EVENT& aEvent )
editTextBoxProperties( item );
break;
case LIB_FIELD_T:
editFieldProperties( (LIB_FIELD*) item );
case SCH_FIELD_T:
editFieldProperties( static_cast<SCH_FIELD*>( item ) );
break;
default:
@ -545,19 +540,19 @@ void SYMBOL_EDITOR_EDIT_TOOL::editTextBoxProperties( SCH_ITEM* aItem )
}
void SYMBOL_EDITOR_EDIT_TOOL::editFieldProperties( LIB_FIELD* aField )
void SYMBOL_EDITOR_EDIT_TOOL::editFieldProperties( SCH_FIELD* aField )
{
if( aField == nullptr )
return;
wxString caption;
if( aField->GetId() >= 0 && aField->GetId() < MANDATORY_FIELDS )
if( aField->IsMandatory() )
caption.Printf( _( "Edit %s Field" ), TitleCaps( aField->GetName() ) );
else
caption.Printf( _( "Edit '%s' Field" ), aField->GetName() );
DIALOG_LIB_FIELD_PROPERTIES dlg( m_frame, caption, aField );
DIALOG_FIELD_PROPERTIES dlg( m_frame, caption, aField );
// The dialog may invoke a kiway player for footprint fields
// so we must use a quasimodal dialog.
@ -767,7 +762,7 @@ int SYMBOL_EDITOR_EDIT_TOOL::Copy( const TOOL_EVENT& aEvent )
for( SCH_ITEM& item : symbol->GetDrawItems() )
{
if( item.Type() == LIB_FIELD_T )
if( item.Type() == SCH_FIELD_T )
continue;
wxASSERT( !item.HasFlag( STRUCT_DELETED ) );
@ -831,7 +826,7 @@ int SYMBOL_EDITOR_EDIT_TOOL::Paste( const TOOL_EVENT& aEvent )
for( SCH_ITEM& item : newPart->GetDrawItems() )
{
if( item.Type() == LIB_FIELD_T )
if( item.Type() == SCH_FIELD_T )
continue;
SCH_ITEM* newItem = item.Duplicate();

View File

@ -68,7 +68,7 @@ private:
void editShapeProperties( LIB_SHAPE* aShape );
void editTextProperties( SCH_ITEM* aItem );
void editTextBoxProperties( SCH_ITEM* aItem );
void editFieldProperties( LIB_FIELD* aField );
void editFieldProperties( SCH_FIELD* aField );
void editSymbolProperties();
void handlePinDuplication(LIB_PIN* aOldPin, LIB_PIN* aNewPin, int &aSymbolLastPinNumber );

View File

@ -64,7 +64,7 @@ bool SYMBOL_EDITOR_MOVE_TOOL::Init()
{
for( EDA_ITEM* item : sel )
{
if( item->Type() != LIB_FIELD_T )
if( item->Type() != SCH_FIELD_T )
return false;
}
}
@ -124,7 +124,7 @@ bool SYMBOL_EDITOR_MOVE_TOOL::doMoveSelection( const TOOL_EVENT& aEvent, SCH_COM
// Be sure that there is at least one item that we can move. If there's no selection try
// looking for the stuff under mouse cursor (i.e. Kicad old-style hover selection).
EE_SELECTION& selection = m_frame->IsSymbolAlias()
? m_selectionTool->RequestSelection( { LIB_FIELD_T } )
? m_selectionTool->RequestSelection( { SCH_FIELD_T } )
: m_selectionTool->RequestSelection();
bool unselect = selection.IsHover();

View File

@ -143,7 +143,7 @@ PANEL_SYMBOL_CHOOSER::PANEL_SYMBOL_CHOOSER( SCH_BASE_FRAME* aFrame, wxWindow* aP
for( const std::pair<int, wxString>& fieldDef : i.Fields )
{
LIB_FIELD* field = storageList.back().GetFieldById( fieldDef.first );
SCH_FIELD* field = storageList.back().GetFieldById( fieldDef.first );
if( field )
field->SetText( fieldDef.second );
@ -545,7 +545,7 @@ void PANEL_SYMBOL_CHOOSER::showFootprintFor( LIB_ID const& aLibId )
if( !symbol )
return;
LIB_FIELD* fp_field = symbol->GetFieldById( FOOTPRINT_FIELD );
SCH_FIELD* fp_field = symbol->GetFieldById( FOOTPRINT_FIELD );
wxString fp_name = fp_field ? fp_field->GetFullText() : wxString( "" );
showFootprint( fp_name );
@ -605,7 +605,7 @@ void PANEL_SYMBOL_CHOOSER::populateFootprintSelector( LIB_ID const& aLibId )
if( symbol != nullptr )
{
std::vector<LIB_PIN*> temp_pins;
LIB_FIELD* fp_field = symbol->GetFieldById( FOOTPRINT_FIELD );
SCH_FIELD* fp_field = symbol->GetFieldById( FOOTPRINT_FIELD );
wxString fp_name = fp_field ? fp_field->GetFullText() : wxString( "" );
// All units, but only a single De Morgan variant.

View File

@ -221,10 +221,10 @@ void SYMBOL_PREVIEW_WIDGET::DisplaySymbol( const LIB_ID& aSymbolID, int aUnit, i
// Hide fields that were added automatically by the library (for example, when using
// database libraries) as they don't have a valid position yet, and we don't support
// autoplacing fields on library symbols yet.
std::vector<LIB_FIELD*> previewFields;
std::vector<SCH_FIELD*> previewFields;
m_previewItem->GetFields( previewFields );
for( LIB_FIELD* field : previewFields )
for( SCH_FIELD* field : previewFields )
{
if( field->IsAutoAdded() )
field->SetVisible( false );

View File

@ -205,12 +205,6 @@ enum KICAD_T
LIB_TEXTBOX_T,
LIB_PIN_T,
/*
* Fields are not saved inside the "DRAW/ENDDRAW". Add new draw item
* types before this line.
*/
LIB_FIELD_T,
/*
* For GerbView: item types:
*/
@ -422,8 +416,6 @@ constexpr bool IsEeschemaType( const KICAD_T aType )
case LIB_TEXT_T:
case LIB_TEXTBOX_T:
case LIB_PIN_T:
case LIB_FIELD_T:
return true;
default:

View File

@ -920,8 +920,7 @@ void CADSTAR_PCB_ARCHIVE_LOADER::loadLibraryCoppers( const SYMDEF_PCB& aComponen
pad->SetSize( { anchorSize, anchorSize } );
pad->SetPosition( anchorPos );
SHAPE_POLY_SET shapePolys = getPolySetFromCadstarShape( compCopper.Shape,
lineThickness,
SHAPE_POLY_SET shapePolys = getPolySetFromCadstarShape( compCopper.Shape, lineThickness,
aFootprint );
shapePolys.Move( -anchorPos );
pad->AddPrimitivePoly( shapePolys, 0, true );
@ -2633,11 +2632,14 @@ int CADSTAR_PCB_ARCHIVE_LOADER::loadNetVia(
}
void CADSTAR_PCB_ARCHIVE_LOADER::drawCadstarText(
const TEXT& aCadstarText, BOARD_ITEM_CONTAINER* aContainer, const GROUP_ID& aCadstarGroupID,
const LAYER_ID& aCadstarLayerOverride, const VECTOR2I& aMoveVector,
const double& aRotationAngle, const double& aScalingFactor,
const VECTOR2I& aTransformCentre, const bool& aMirrorInvert )
void CADSTAR_PCB_ARCHIVE_LOADER::drawCadstarText( const TEXT& aCadstarText,
BOARD_ITEM_CONTAINER* aContainer,
const GROUP_ID& aCadstarGroupID,
const LAYER_ID& aCadstarLayerOverride,
const VECTOR2I& aMoveVector,
double aRotationAngle, double aScalingFactor,
const VECTOR2I& aTransformCentre,
bool aMirrorInvert )
{
PCB_TEXT* txt = new PCB_TEXT( aContainer );
aContainer->Add( txt );
@ -2646,10 +2648,8 @@ void CADSTAR_PCB_ARCHIVE_LOADER::drawCadstarText(
EDA_ANGLE rotationAngle( aRotationAngle, TENTHS_OF_A_DEGREE_T );
VECTOR2I rotatedTextPos = getKiCadPoint( aCadstarText.Position );
RotatePoint( rotatedTextPos, aTransformCentre, rotationAngle );
rotatedTextPos.x =
KiROUND( (double) ( rotatedTextPos.x - aTransformCentre.x ) * aScalingFactor );
rotatedTextPos.y =
KiROUND( (double) ( rotatedTextPos.y - aTransformCentre.y ) * aScalingFactor );
rotatedTextPos.x = KiROUND( ( rotatedTextPos.x - aTransformCentre.x ) * aScalingFactor );
rotatedTextPos.y = KiROUND( ( rotatedTextPos.y - aTransformCentre.y ) * aScalingFactor );
rotatedTextPos += aTransformCentre;
txt->SetTextPos( rotatedTextPos );
txt->SetPosition( rotatedTextPos );
@ -2713,9 +2713,7 @@ void CADSTAR_PCB_ARCHIVE_LOADER::drawCadstarText(
}
if( aMirrorInvert )
{
txt->Flip( aTransformCentre, true );
}
//scale it after flipping:
if( aScalingFactor != 1.0 )
@ -2744,14 +2742,10 @@ void CADSTAR_PCB_ARCHIVE_LOADER::drawCadstarText(
if( isLayerSet( layersToDrawOn ) )
{
//Make a copy on each layer
LSEQ layers = getKiCadLayerSet( layersToDrawOn ).Seq();
PCB_TEXT* newtxt;
for( PCB_LAYER_ID layer : layers )
for( PCB_LAYER_ID layer : getKiCadLayerSet( layersToDrawOn ).Seq() )
{
txt->SetLayer( layer );
newtxt = static_cast<PCB_TEXT*>( txt->Duplicate() );
PCB_TEXT* newtxt = static_cast<PCB_TEXT*>( txt->Duplicate() );
m_board->Add( newtxt, ADD_MODE::APPEND );
if( !aCadstarGroupID.IsEmpty() )
@ -2774,15 +2768,14 @@ void CADSTAR_PCB_ARCHIVE_LOADER::drawCadstarText(
void CADSTAR_PCB_ARCHIVE_LOADER::drawCadstarShape( const SHAPE& aCadstarShape,
const PCB_LAYER_ID& aKiCadLayer,
const int& aLineThickness,
int aLineThickness,
const wxString& aShapeName,
BOARD_ITEM_CONTAINER* aContainer,
const GROUP_ID& aCadstarGroupID,
const VECTOR2I& aMoveVector,
const double& aRotationAngle,
const double& aScalingFactor,
double aRotationAngle, double aScalingFactor,
const VECTOR2I& aTransformCentre,
const bool& aMirrorInvert )
bool aMirrorInvert )
{
auto drawAsOutline = [&]()
{
@ -2844,16 +2837,16 @@ void CADSTAR_PCB_ARCHIVE_LOADER::drawCadstarShape( const SHAPE& aCadstarShape,
void CADSTAR_PCB_ARCHIVE_LOADER::drawCadstarCutoutsAsShapes( const std::vector<CUTOUT>& aCutouts,
const PCB_LAYER_ID& aKiCadLayer,
const int& aLineThickness,
int aLineThickness,
BOARD_ITEM_CONTAINER* aContainer,
const GROUP_ID& aCadstarGroupID,
const VECTOR2I& aMoveVector,
const double& aRotationAngle,
const double& aScalingFactor,
double aRotationAngle,
double aScalingFactor,
const VECTOR2I& aTransformCentre,
const bool& aMirrorInvert )
bool aMirrorInvert )
{
for( CUTOUT cutout : aCutouts )
for( const CUTOUT& cutout : aCutouts )
{
drawCadstarVerticesAsShapes( cutout.Vertices, aKiCadLayer, aLineThickness, aContainer,
aCadstarGroupID, aMoveVector, aRotationAngle, aScalingFactor,
@ -2864,14 +2857,14 @@ void CADSTAR_PCB_ARCHIVE_LOADER::drawCadstarCutoutsAsShapes( const std::vector<C
void CADSTAR_PCB_ARCHIVE_LOADER::drawCadstarVerticesAsShapes( const std::vector<VERTEX>& aCadstarVertices,
const PCB_LAYER_ID& aKiCadLayer,
const int& aLineThickness,
int aLineThickness,
BOARD_ITEM_CONTAINER* aContainer,
const GROUP_ID& aCadstarGroupID,
const VECTOR2I& aMoveVector,
const double& aRotationAngle,
const double& aScalingFactor,
double aRotationAngle,
double aScalingFactor,
const VECTOR2I& aTransformCentre,
const bool& aMirrorInvert )
bool aMirrorInvert )
{
std::vector<PCB_SHAPE*> shapes = getShapesFromVertices( aCadstarVertices, aContainer,
aCadstarGroupID, aMoveVector,
@ -2888,15 +2881,14 @@ void CADSTAR_PCB_ARCHIVE_LOADER::drawCadstarVerticesAsShapes( const std::vector<
}
std::vector<PCB_SHAPE*> CADSTAR_PCB_ARCHIVE_LOADER::getShapesFromVertices(
const std::vector<VERTEX>& aCadstarVertices,
std::vector<PCB_SHAPE*>
CADSTAR_PCB_ARCHIVE_LOADER::getShapesFromVertices( const std::vector<VERTEX>& aCadstarVertices,
BOARD_ITEM_CONTAINER* aContainer,
const GROUP_ID& aCadstarGroupID,
const VECTOR2I& aMoveVector,
const double& aRotationAngle,
const double& aScalingFactor,
double aRotationAngle, double aScalingFactor,
const VECTOR2I& aTransformCentre,
const bool& aMirrorInvert )
bool aMirrorInvert )
{
std::vector<PCB_SHAPE*> shapes;
@ -2925,10 +2917,10 @@ PCB_SHAPE* CADSTAR_PCB_ARCHIVE_LOADER::getShapeFromVertex( const POINT& aCadstar
BOARD_ITEM_CONTAINER* aContainer,
const GROUP_ID& aCadstarGroupID,
const VECTOR2I& aMoveVector,
const double& aRotationAngle,
const double& aScalingFactor,
double aRotationAngle,
double aScalingFactor,
const VECTOR2I& aTransformCentre,
const bool& aMirrorInvert )
bool aMirrorInvert )
{
PCB_SHAPE* shape = nullptr;
bool cw = false;
@ -3037,13 +3029,13 @@ ZONE* CADSTAR_PCB_ARCHIVE_LOADER::getZoneFromCadstarShape( const SHAPE& aCadstar
SHAPE_POLY_SET CADSTAR_PCB_ARCHIVE_LOADER::getPolySetFromCadstarShape( const SHAPE& aCadstarShape,
const int& aLineThickness,
int aLineThickness,
BOARD_ITEM_CONTAINER* aContainer,
const VECTOR2I& aMoveVector,
const double& aRotationAngle,
const double& aScalingFactor,
double aRotationAngle,
double aScalingFactor,
const VECTOR2I& aTransformCentre,
const bool& aMirrorInvert )
bool aMirrorInvert )
{
GROUP_ID noGroup = wxEmptyString;

View File

@ -212,10 +212,9 @@ private:
const GROUP_ID& aCadstarGroupID = wxEmptyString,
const LAYER_ID& aCadstarLayerOverride = wxEmptyString,
const VECTOR2I& aMoveVector = { 0, 0 },
const double& aRotationAngle = 0.0,
const double& aScalingFactor = 1.0,
double aRotationAngle = 0.0, double aScalingFactor = 1.0,
const VECTOR2I& aTransformCentre = { 0, 0 },
const bool& aMirrorInvert = false );
bool aMirrorInvert = false );
/**
* @brief
@ -232,13 +231,13 @@ private:
* @param aMirrorInvert if true, mirrors the shapes
*/
void drawCadstarShape( const SHAPE& aCadstarShape, const PCB_LAYER_ID& aKiCadLayer,
const int& aLineThickness, const wxString& aShapeName,
int aLineThickness, const wxString& aShapeName,
BOARD_ITEM_CONTAINER* aContainer,
const GROUP_ID& aCadstarGroupID = wxEmptyString,
const VECTOR2I& aMoveVector = { 0, 0 },
const double& aRotationAngle = 0.0, const double& aScalingFactor = 1.0,
double aRotationAngle = 0.0, double aScalingFactor = 1.0,
const VECTOR2I& aTransformCentre = { 0, 0 },
const bool& aMirrorInvert = false );
bool aMirrorInvert = false );
/**
* @brief Uses PCB_SHAPEs to draw the cutouts on m_board object
@ -254,14 +253,14 @@ private:
* @param aMirrorInvert if true, mirrors the shapes
*/
void drawCadstarCutoutsAsShapes( const std::vector<CUTOUT>& aCutouts,
const PCB_LAYER_ID& aKiCadLayer, const int& aLineThickness,
const PCB_LAYER_ID& aKiCadLayer, int aLineThickness,
BOARD_ITEM_CONTAINER* aContainer,
const GROUP_ID& aCadstarGroupID = wxEmptyString,
const VECTOR2I& aMoveVector = { 0, 0 },
const double& aRotationAngle = 0.0,
const double& aScalingFactor = 1.0,
double aRotationAngle = 0.0,
double aScalingFactor = 1.0,
const VECTOR2I& aTransformCentre = { 0, 0 },
const bool& aMirrorInvert = false );
bool aMirrorInvert = false );
/**
* @brief Uses PCB_SHAPE to draw the vertices on m_board object
@ -278,14 +277,13 @@ private:
* @param aCadstarGroupID to add the shape to
*/
void drawCadstarVerticesAsShapes( const std::vector<VERTEX>& aCadstarVertices,
const PCB_LAYER_ID& aKiCadLayer, const int& aLineThickness,
const PCB_LAYER_ID& aKiCadLayer, int aLineThickness,
BOARD_ITEM_CONTAINER* aContainer,
const GROUP_ID& aCadstarGroupID = wxEmptyString,
const VECTOR2I& aMoveVector = { 0, 0 },
const double& aRotationAngle = 0.0,
const double& aScalingFactor = 1.0,
double aRotationAngle = 0.0, double aScalingFactor = 1.0,
const VECTOR2I& aTransformCentre = { 0, 0 },
const bool& aMirrorInvert = false );
bool aMirrorInvert = false );
/**
* @brief Returns a vector of pointers to PCB_SHAPE objects. Caller owns the objects.
@ -303,10 +301,10 @@ private:
BOARD_ITEM_CONTAINER* aContainer = nullptr,
const GROUP_ID& aCadstarGroupID = wxEmptyString,
const VECTOR2I& aMoveVector = { 0, 0 },
const double& aRotationAngle = 0.0,
const double& aScalingFactor = 1.0,
double aRotationAngle = 0.0,
double aScalingFactor = 1.0,
const VECTOR2I& aTransformCentre = { 0, 0 },
const bool& aMirrorInvert = false );
bool aMirrorInvert = false );
/**
* @brief Returns a pointer to a PCB_SHAPE object. Caller owns the object.
@ -326,10 +324,9 @@ private:
BOARD_ITEM_CONTAINER* aContainer = nullptr,
const GROUP_ID& aCadstarGroupID = wxEmptyString,
const VECTOR2I& aMoveVector = { 0, 0 },
const double& aRotationAngle = 0.0,
const double& aScalingFactor = 1.0,
double aRotationAngle = 0.0, double aScalingFactor = 1.0,
const VECTOR2I& aTransformCentre = { 0, 0 },
const bool& aMirrorInvert = false );
bool aMirrorInvert = false );
/**
* @brief
@ -353,14 +350,13 @@ private:
* @param aMirrorInvert if true, mirrors the poly
* @return
*/
SHAPE_POLY_SET getPolySetFromCadstarShape( const SHAPE& aCadstarShape,
const int& aLineThickness = -1,
SHAPE_POLY_SET getPolySetFromCadstarShape( const SHAPE& aCadstarShape, int aLineThickness = -1,
BOARD_ITEM_CONTAINER* aContainer = nullptr,
const VECTOR2I& aMoveVector = { 0, 0 },
const double& aRotationAngle = 0.0,
const double& aScalingFactor = 1.0,
double aRotationAngle = 0.0,
double aScalingFactor = 1.0,
const VECTOR2I& aTransformCentre = { 0, 0 },
const bool& aMirrorInvert = false );
bool aMirrorInvert = false );
/**
* @brief Returns a SHAPE_LINE_CHAIN object from a series of PCB_SHAPE objects

View File

@ -23,7 +23,7 @@
/**
* @file
* Test utils (e.g. print helpers and test predicates for LIB_FIELD objects
* Test utils (e.g. print helpers and test predicates for SCH_FIELD objects
*/
#ifndef QA_EESCHEMA_LIB_FIELD_TEST_UTILS__H
@ -37,20 +37,20 @@
namespace BOOST_TEST_PRINT_NAMESPACE_OPEN
{
template <>
struct print_log_value<LIB_FIELD>
struct print_log_value<SCH_FIELD>
{
inline void operator()( std::ostream& os, LIB_FIELD const& f )
inline void operator()( std::ostream& os, SCH_FIELD const& f )
{
os << "LIB_FIELD[ " << f.GetCanonicalName() << " ]";
os << "SCH_FIELD[ " << f.GetCanonicalName() << " ]";
}
};
template <>
struct print_log_value<std::vector<LIB_FIELD>>
struct print_log_value<std::vector<SCH_FIELD>>
{
inline void operator()( std::ostream& os, std::vector<LIB_FIELD> const& f )
inline void operator()( std::ostream& os, std::vector<SCH_FIELD> const& f )
{
os << "LIB_FIELDS[ " << f.size() << " ]";
os << "SCH_FIELDS[ " << f.size() << " ]";
}
};
}
@ -62,13 +62,12 @@ namespace KI_TEST
/**
* Predicate to check a field name is as expected
* @param aField LIB_FIELD to check the name
* @param aField SCH_FIELD to check the name
* @param aExpectedName the expected field name
* @param aExpectedId the expected field id
* @return true if match
*/
bool FieldNameIdMatches( const LIB_FIELD& aField, const std::string& aExpectedName,
int aExpectedId )
bool FieldNameIdMatches( const SCH_FIELD& aField, const std::string& aExpectedName, int aExpectedId )
{
bool ok = true;
const auto gotName = aField.GetCanonicalName();
@ -91,17 +90,15 @@ bool FieldNameIdMatches( const LIB_FIELD& aField, const std::string& aExpectedNa
}
/**
* Predicate to check that the mandatory fields in a LIB_FIELDS object look sensible
* @param aFields the fields to check
* @return true if valid
* Predicate to check that the mandatory fields look sensible
*/
bool AreDefaultFieldsCorrect( const std::vector<LIB_FIELD>& aFields )
bool AreDefaultFieldsCorrect( const std::vector<SCH_FIELD>& aFields )
{
const unsigned expectedCount = MANDATORY_FIELD_T::MANDATORY_FIELDS;
if( aFields.size() < expectedCount )
{
BOOST_TEST_INFO(
"Expected at least " << expectedCount << " fields, got " << aFields.size() );
BOOST_TEST_INFO( "Expected at least " << expectedCount << " fields, got " << aFields.size() );
return false;
}

View File

@ -120,7 +120,6 @@ public:
case LIB_TEXT_T: return new LIB_TEXT( &m_symbol );
case LIB_TEXTBOX_T: return new LIB_TEXTBOX( &m_symbol, 0, FILL_T::NO_FILL, "test" );
case LIB_PIN_T: return new LIB_PIN( &m_symbol );
case LIB_FIELD_T: return new LIB_FIELD( &m_symbol );
case SCHEMATIC_T:
case SCH_PIN_T:

View File

@ -94,7 +94,7 @@ BOOST_AUTO_TEST_CASE( DefaultDrawings )
*/
BOOST_AUTO_TEST_CASE( DefaultFields )
{
std::vector<LIB_FIELD> fields;
std::vector<SCH_FIELD> fields;
m_part_no_data.GetFields( fields );
// Should get the 4 default fields
@ -122,13 +122,13 @@ BOOST_AUTO_TEST_CASE( DefaultFields )
*/
BOOST_AUTO_TEST_CASE( AddedFields )
{
std::vector<LIB_FIELD> fields;
std::vector<SCH_FIELD> fields;
m_part_no_data.GetFields( fields );
// Ctor takes non-const ref (?!)
const std::string newFieldName = "new_field";
wxString nonConstNewFieldName = newFieldName;
fields.push_back( LIB_FIELD( 42, nonConstNewFieldName ) );
fields.push_back( SCH_FIELD( nullptr, 42, nonConstNewFieldName ) );
// fairly roundabout way to add a field, but it is what it is
m_part_no_data.SetFields( fields );
@ -144,7 +144,7 @@ BOOST_AUTO_TEST_CASE( AddedFields )
// Check by-id lookup
LIB_FIELD* gotNewField = m_part_no_data.GetFieldById( 42 );
SCH_FIELD* gotNewField = m_part_no_data.GetFieldById( 42 );
BOOST_REQUIRE_NE( gotNewField, nullptr );
@ -627,12 +627,12 @@ BOOST_AUTO_TEST_CASE( Inheritance )
BOOST_CHECK( *parent == *ref );
ref->SetName( "child" );
LIB_FIELD* field = new LIB_FIELD( MANDATORY_FIELDS, "Manufacturer" );
SCH_FIELD* field = new SCH_FIELD( nullptr, MANDATORY_FIELDS, "Manufacturer" );
field->SetText( "KiCad" );
child->AddField( field );
field->SetParent( child.get() );
field = new LIB_FIELD( MANDATORY_FIELDS, "Manufacturer" );
field = new SCH_FIELD( nullptr, MANDATORY_FIELDS, "Manufacturer" );
field->SetText( "KiCad" );
ref->AddField( field );
field->SetParent( ref.get() );
@ -640,12 +640,12 @@ BOOST_AUTO_TEST_CASE( Inheritance )
BOOST_CHECK( *ref == *child->Flatten() );
ref->SetName( "grandchild" );
field = new LIB_FIELD( MANDATORY_FIELDS + 1, "MPN" );
field = new SCH_FIELD( nullptr, MANDATORY_FIELDS + 1, "MPN" );
field->SetText( "123456" );
grandChild->AddField( field );
field->SetParent( grandChild.get() );
field = new LIB_FIELD( MANDATORY_FIELDS + 1, "MPN" );
field = new SCH_FIELD( nullptr, MANDATORY_FIELDS + 1, "MPN" );
field->SetText( "123456" );
ref->AddField( field );
field->SetParent( ref.get() );

View File

@ -96,7 +96,7 @@ BOOST_AUTO_TEST_CASE( InferPassiveValues )
symbol->GetReferenceField().SetText( testCase.reference );
symbol->GetValueField().SetText( testCase.value );
std::vector<LIB_FIELD> fields;
std::vector<SCH_FIELD> fields;
fields.emplace_back( symbol->GetReferenceField() );
fields.emplace_back( symbol->GetValueField() );