Sim Model Editor: Improve raw model code preview
- Show whole file below the item line for reference - Fix pin sequence in item line (was not displayed)
This commit is contained in:
parent
b791fff963
commit
f6b1ff821b
|
@ -25,12 +25,14 @@
|
|||
#include <dialog_sim_model.h>
|
||||
#include <sim/sim_property.h>
|
||||
#include <sim/sim_library_spice.h>
|
||||
#include <sim/sim_model_spice.h>
|
||||
#include <widgets/wx_grid.h>
|
||||
#include <kiplatform/ui.h>
|
||||
#include <confirm.h>
|
||||
#include <string_utils.h>
|
||||
#include <locale_io.h>
|
||||
#include <wx/filedlg.h>
|
||||
#include <wx/textfile.h>
|
||||
|
||||
using CATEGORY = SIM_MODEL::PARAM::CATEGORY;
|
||||
|
||||
|
@ -325,9 +327,38 @@ void DIALOG_SIM_MODEL<T>::updateModelCodeTab()
|
|||
if( m_useInstanceModelRadioButton->GetValue() || modelName.IsEmpty() )
|
||||
modelName = m_fields.at( REFERENCE_FIELD ).GetText();
|
||||
|
||||
m_codePreview->SetEditable( true );
|
||||
m_codePreview->SetEditable( true ); // ???
|
||||
|
||||
if( dynamic_cast<SIM_MODEL_SPICE*>( &curModel() ) )
|
||||
{
|
||||
// For raw Spice models display the whole file instead.
|
||||
|
||||
wxString path = curModel().FindParam( "lib" )->value->ToString();
|
||||
wxString absolutePath = Prj().AbsolutePath( path );
|
||||
wxTextFile file;
|
||||
wxString text;
|
||||
|
||||
text << curModel().GenerateSpicePreview( modelName );
|
||||
text << "\n";
|
||||
text << "--- FILE SOURCE (" << path << ") ---\n";
|
||||
text << "\n";
|
||||
|
||||
if( wxFileExists( absolutePath ) && file.Open( absolutePath ) )
|
||||
{
|
||||
for( text << file.GetFirstLine() << "\n";
|
||||
!file.Eof();
|
||||
text << file.GetNextLine() << "\n" )
|
||||
{
|
||||
}
|
||||
|
||||
file.Close();
|
||||
m_codePreview->SetText( text );
|
||||
}
|
||||
}
|
||||
else
|
||||
m_codePreview->SetText( curModel().GenerateSpicePreview( modelName ) );
|
||||
m_codePreview->SetEditable( false );
|
||||
|
||||
m_codePreview->SetEditable( false ); // ???
|
||||
m_wasCodePreviewUpdated = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -977,12 +977,12 @@ wxString SIM_MODEL::GenerateSpiceItemLine( const wxString& aRefName,
|
|||
const wxString& aModelName,
|
||||
const std::vector<wxString>& aSymbolPinNumbers ) const
|
||||
{
|
||||
std::vector<wxString> pinNames;
|
||||
std::vector<wxString> pinNetNames;
|
||||
|
||||
for( const PIN& pin : GetPins() )
|
||||
pinNames.push_back( pin.name );
|
||||
pinNetNames.push_back( pin.name );
|
||||
|
||||
return GenerateSpiceItemLine( aRefName, aModelName, aSymbolPinNumbers, pinNames );
|
||||
return GenerateSpiceItemLine( aRefName, aModelName, aSymbolPinNumbers, pinNetNames );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -77,7 +77,7 @@ std::vector<wxString> SIM_MODEL_NGSPICE::GenerateSpiceCurrentNames( const wxStri
|
|||
return SIM_MODEL::GenerateSpiceCurrentNames( aRefName );
|
||||
|
||||
default:
|
||||
wxFAIL_MSG( "Unhandled model device type" );
|
||||
wxFAIL_MSG( "Unhandled model device type in SIM_MODEL_NGSPICE" );
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,6 +98,21 @@ wxString SIM_MODEL_SPICE::GenerateSpiceItemName( const wxString& aRefName ) cons
|
|||
}
|
||||
|
||||
|
||||
wxString SIM_MODEL_SPICE::GenerateSpicePreview( const wxString& aModelName ) const
|
||||
{
|
||||
std::vector<wxString> pinNumbers;
|
||||
std::vector<wxString> pinNetNames;
|
||||
|
||||
for( int i = 0; i < GetPinCount(); ++i )
|
||||
{
|
||||
pinNumbers.push_back( wxString::FromCDouble( i + 1 ) );
|
||||
pinNetNames.push_back( wxString::FromCDouble( i + 1 ) );
|
||||
}
|
||||
|
||||
return GenerateSpiceItemLine( "", aModelName, pinNumbers, pinNetNames );
|
||||
}
|
||||
|
||||
|
||||
void SIM_MODEL_SPICE::CreatePins( unsigned aSymbolPinCount )
|
||||
{
|
||||
for( unsigned symbolPinIndex = 0; symbolPinIndex < aSymbolPinCount; ++symbolPinIndex )
|
||||
|
|
|
@ -56,6 +56,7 @@ public:
|
|||
|
||||
wxString GenerateSpiceModelLine( const wxString& aModelName ) const override;
|
||||
wxString GenerateSpiceItemName( const wxString& aRefName ) const override;
|
||||
wxString GenerateSpicePreview( const wxString& aModelName ) const override;
|
||||
|
||||
protected:
|
||||
void CreatePins( unsigned aSymbolPinCount ) override;
|
||||
|
|
Loading…
Reference in New Issue