@ -32,7 +32,6 @@
# include <sch_sheet_path.h>
# include <sch_symbol.h>
# include <sch_sheet.h>
# include <sch_textbox.h>
# include <schematic.h>
# include <template_fieldnames.h>
# include <trace_helpers.h>
@ -40,11 +39,6 @@
# include <boost/functional/hash.hpp>
# include <wx/filename.h>
# include <wx/log.h>
# include "erc_item.h"
# include <sim/sim_model.h> // For V6 to V7 simulation model migration.
# include <sim/sim_value.h> //
# include <locale_io.h>
/**
@ -1096,7 +1090,7 @@ SCH_SHEET_LIST SCH_SHEET_LIST::FindAllSheetsForScreen( const SCH_SCREEN* aScreen
}
void SCH_SHEET_LIST : : UpdateSymbolInstances (
void SCH_SHEET_LIST : : UpdateSymbolInstanceData (
const std : : vector < SYMBOL_INSTANCE_REFERENCE > & aSymbolInstances )
{
for ( SCH_SHEET_PATH & sheetPath : * this )
@ -1111,10 +1105,10 @@ void SCH_SHEET_LIST::UpdateSymbolInstances(
sheetPathWithSymbolUuid . push_back ( symbol - > m_Uuid ) ;
auto it = std : : find_if ( aSymbolInstances . begin ( ) , aSymbolInstances . end ( ) ,
[ sheetPathWithSymbolUuid ] ( const SYMBOL_INSTANCE_REFERENCE & r ) - > bool
{
return sheetPathWithSymbolUuid = = r . m_Path ;
} ) ;
[ sheetPathWithSymbolUuid ] ( const SYMBOL_INSTANCE_REFERENCE & r ) - > bool
{
return sheetPathWithSymbolUuid = = r . m_Path ;
} ) ;
if ( it = = aSymbolInstances . end ( ) )
{
@ -1131,13 +1125,10 @@ void SCH_SHEET_LIST::UpdateSymbolInstances(
symbol - > SetFootprintFieldText ( it - > m_Footprint ) ;
}
}
if ( size ( ) > = 1 & & at ( 0 ) . LastScreen ( ) - > GetFileFormatVersionAtLoad ( ) < 20220622 )
MigrateSimModelNameFields ( ) ;
}
void SCH_SHEET_LIST : : UpdateSheetInstances ( const std : : vector < SCH_SHEET_INSTANCE > & aSheetInstances )
void SCH_SHEET_LIST : : UpdateSheetInstanceData ( const std : : vector < SCH_SHEET_INSTANCE > & aSheetInstances )
{
for ( SCH_SHEET_PATH & path : * this )
@ -1269,177 +1260,3 @@ int SCH_SHEET_LIST::GetLastVirtualPageNumber() const
return lastVirtualPageNumber ;
}
void SCH_SHEET_LIST : : MigrateSimModelNameFields ( )
{
LOCALE_IO toggle ;
for ( unsigned sheetIndex = 0 ; sheetIndex < size ( ) ; + + sheetIndex )
{
SCH_SCREEN * screen = at ( sheetIndex ) . LastScreen ( ) ;
// V6 schematics may specify model names in Value fields, which we don't do in V7.
// Migrate by adding an equivalent model for these symbols.
for ( SCH_ITEM * item : screen - > Items ( ) . OfType ( SCH_SYMBOL_T ) )
{
SCH_SYMBOL * symbol = static_cast < SCH_SYMBOL * > ( item ) ;
if ( ! symbol )
{
// Shouldn't happen.
wxFAIL ;
continue ;
}
migrateSimModel ( * symbol , sheetIndex ) ;
}
}
}
void SCH_SHEET_LIST : : migrateSimModel ( SCH_SYMBOL & aSymbol , unsigned aSheetIndex )
{
if ( aSymbol . FindField ( SIM_MODEL : : DEVICE_TYPE_FIELD )
| | aSymbol . FindField ( SIM_MODEL : : TYPE_FIELD )
| | aSymbol . FindField ( SIM_MODEL : : PINS_FIELD )
| | aSymbol . FindField ( SIM_MODEL : : PARAMS_FIELD ) )
{
// Has a V7 model field -- skip.
return ;
}
wxString ref = aSymbol . GetRef ( & at ( aSheetIndex ) , true ) ;
wxString value = aSymbol . GetValueFieldText ( true ) ;
wxString spiceType ;
wxString spiceModel ;
wxString spiceLib ;
wxString pinMap ;
if ( aSymbol . FindField ( " Spice_Primitive " )
| | aSymbol . FindField ( " Spice_Node_Sequence " )
| | aSymbol . FindField ( " Spice_Model " )
| | aSymbol . FindField ( " Spice_Netlist_Enabled " )
| | aSymbol . FindField ( " Spice_Lib_File " ) )
{
if ( SCH_FIELD * primitiveField = aSymbol . FindField ( " Spice_Primitive " ) )
{
spiceType = primitiveField - > GetText ( ) ;
aSymbol . RemoveField ( " Spice_Primitive " ) ;
}
if ( SCH_FIELD * nodeSequenceField = aSymbol . FindField ( " Spice_Node_Sequence " ) )
{
const wxString delimiters ( " {:,; } " ) ;
const wxString & nodeSequence = nodeSequenceField - > GetText ( ) ;
if ( nodeSequence ! = " " )
{
wxStringTokenizer tkz ( nodeSequence , delimiters ) ;
for ( long modelPinNumber = 1 ; tkz . HasMoreTokens ( ) ; + + modelPinNumber )
{
long symbolPinNumber = 1 ;
tkz . GetNextToken ( ) . ToLong ( & symbolPinNumber ) ;
if ( modelPinNumber ! = 1 )
pinMap . Append ( " " ) ;
pinMap . Append ( wxString : : Format ( " %ld=%ld " , symbolPinNumber , modelPinNumber ) ) ;
}
}
aSymbol . RemoveField ( " Spice_Node_Sequence " ) ;
}
if ( SCH_FIELD * modelField = aSymbol . FindField ( " Spice_Model " ) )
{
spiceModel = modelField - > GetText ( ) ;
aSymbol . RemoveField ( " Spice_Model " ) ;
}
else
spiceModel = aSymbol . FindField ( " Value " ) - > GetText ( ) ;
if ( SCH_FIELD * netlistEnabledField = aSymbol . FindField ( " Spice_Netlist_Enabled " ) )
{
wxString netlistEnabled = netlistEnabledField - > GetText ( ) . Lower ( ) ;
if ( netlistEnabled . StartsWith ( " 0 " )
| | netlistEnabled . StartsWith ( " n " )
| | netlistEnabled . StartsWith ( " f " ) )
{
SCH_FIELD enableField ( VECTOR2I ( 0 , 0 ) , aSymbol . GetFieldCount ( ) , & aSymbol ,
SIM_MODEL : : ENABLE_FIELD ) ;
}
}
if ( SCH_FIELD * libFileField = aSymbol . FindField ( " Spice_Lib_File " ) )
{
spiceLib = libFileField - > GetText ( ) ;
aSymbol . RemoveField ( " Spice_Lib_File " ) ;
}
}
else if ( ref . StartsWith ( " R " ) | | ref . StartsWith ( " L " ) | | ref . StartsWith ( " C " ) )
{
wxRegEx passiveVal (
wxT ( " ^([0-9 \\ . ]+)([fFpPnNuUmMkKgGtTμµ𝛍𝜇𝝁 ]|M(e|E)(g|G))?([fFhHΩΩ𝛀𝛺𝝮]|ohm)?([-1-9 ]*)$ " ) ) ;
if ( ! passiveVal . Matches ( value ) )
return ;
wxString prefix ( passiveVal . GetMatch ( value , 1 ) ) ;
wxString unit ( passiveVal . GetMatch ( value , 2 ) ) ;
wxString suffix ( passiveVal . GetMatch ( value , 6 ) ) ;
if ( unit = = " M " )
unit = " Meg " ;
spiceModel = prefix + unit ;
}
else if ( ref . StartsWith ( " V " ) | | ref . StartsWith ( " I " ) )
spiceModel = value ;
else
return ;
// Insert a plaintext model as a substitute.
SCH_FIELD deviceTypeField ( VECTOR2I ( 0 , 0 ) , aSymbol . GetFieldCount ( ) , & aSymbol ,
SIM_MODEL : : DEVICE_TYPE_FIELD ) ;
deviceTypeField . SetText (
SIM_MODEL : : DeviceInfo ( SIM_MODEL : : DEVICE_TYPE_ : : SPICE ) . fieldValue ) ;
aSymbol . AddField ( deviceTypeField ) ;
SCH_FIELD paramsField ( VECTOR2I ( 0 , 0 ) , aSymbol . GetFieldCount ( ) , & aSymbol ,
SIM_MODEL : : PARAMS_FIELD ) ;
paramsField . SetText ( wxString : : Format ( " type= \" %s \" model= \" %s \" lib= \" %s \" " ,
spiceType , spiceModel , spiceLib ) ) ;
aSymbol . AddField ( paramsField ) ;
// Legacy models by default get linear pin mapping.
if ( pinMap ! = " " )
{
SCH_FIELD pinsField ( VECTOR2I ( 0 , 0 ) , aSymbol . GetFieldCount ( ) , & aSymbol ,
SIM_MODEL : : PINS_FIELD ) ;
pinsField . SetText ( pinMap ) ;
aSymbol . AddField ( pinsField ) ;
}
else
{
wxString pins ;
for ( unsigned i = 0 ; i < aSymbol . GetLibPins ( ) . size ( ) ; + + i )
{
if ( i ! = 0 )
pins . Append ( " " ) ;
pins . Append ( wxString : : Format ( " %u=%u " , i + 1 , i + 1 ) ) ;
}
SCH_FIELD pinsField ( VECTOR2I ( 0 , 0 ) , aSymbol . GetFieldCount ( ) , & aSymbol ,
SIM_MODEL : : PINS_FIELD ) ;
pinsField . SetText ( pins ) ;
aSymbol . AddField ( pinsField ) ;
}
}