From 7fd707952b9b70ea9d40b0b56da2a4385e3b73b5 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 21 Feb 2023 11:36:14 +0000 Subject: [PATCH] Easier editing of new sim measurements. --- eeschema/dialogs/dialog_sim_format_value.cpp | 55 ++--- eeschema/dialogs/dialog_sim_format_value.h | 8 +- eeschema/sim/sim_plot_frame.cpp | 206 ++++++++++--------- eeschema/sim/sim_plot_frame.h | 29 +-- eeschema/sim/sim_plot_frame_base.cpp | 10 +- eeschema/sim/sim_plot_frame_base.fbp | 10 +- eeschema/sim/spice_value.cpp | 26 +++ eeschema/sim/spice_value.h | 5 + 8 files changed, 195 insertions(+), 154 deletions(-) diff --git a/eeschema/dialogs/dialog_sim_format_value.cpp b/eeschema/dialogs/dialog_sim_format_value.cpp index 7b5a666697..4f8d46fd9c 100644 --- a/eeschema/dialogs/dialog_sim_format_value.cpp +++ b/eeschema/dialogs/dialog_sim_format_value.cpp @@ -22,75 +22,78 @@ */ #include -#include "sim/spice_value.h" +#include -DIALOG_SIM_FORMAT_VALUE::DIALOG_SIM_FORMAT_VALUE( wxWindow* aParent, int* aPrecision, - wxString* aRange ) : +DIALOG_SIM_FORMAT_VALUE::DIALOG_SIM_FORMAT_VALUE( wxWindow* aParent, SPICE_VALUE_FORMAT* aFormat ) : DIALOG_SIM_FORMAT_VALUE_BASE( aParent ), - m_precision( aPrecision ), - m_range( aRange ) + m_format( aFormat ) { - m_units = aRange->Right( 1 ); - - if( m_units == wxS( "V" ) ) + if( aFormat->Range.EndsWith( wxS( "V" ) ) ) { + m_units = aFormat->Range.Right( 1 ); SetTitle( wxString::Format( GetTitle(), _( "Voltage" ) ) ); } - else if( m_units == wxS( "A" ) ) + else if( aFormat->Range.EndsWith( wxS( "A" ) ) ) { + m_units = aFormat->Range.Right( 1 ); SetTitle( wxString::Format( GetTitle(), _( "Current" ) ) ); } - else if( m_units == wxS( "s" ) ) + else if( aFormat->Range.EndsWith( wxS( "s" ) ) ) { + m_units = aFormat->Range.Right( 1 ); SetTitle( wxString::Format( GetTitle(), _( "Time" ) ) ); } - else if( aRange->Right( 2 ) == wxS( "Hz" ) ) + else if( aFormat->Range.EndsWith( wxS( "Hz" ) ) ) { - m_units = aRange->Right( 2 ); + m_units = aFormat->Range.Right( 2 ); SetTitle( wxString::Format( GetTitle(), _( "Frequency" ) ) ); } - else if( aRange->Right( 3 ) == wxS( "dBV" ) ) + else if( aFormat->Range.EndsWith( wxS( "dBV" ) ) ) { - m_units = aRange->Right( 3 ); + m_units = aFormat->Range.Right( 3 ); SetTitle( wxString::Format( GetTitle(), _( "Gain" ) ) ); } - else if( m_units == wxS( "°" ) ) + else if( aFormat->Range.EndsWith( wxS( "°" ) ) ) { + m_units = aFormat->Range.Right( 1 ); SetTitle( wxString::Format( GetTitle(), _( "Phase" ) ) ); } + else if( aFormat->Range.StartsWith( wxS( "~" ), &m_units ) ) + { + // m_units set as remainder in StartsWith() call.... + SetTitle( wxString::Format( GetTitle(), _( "Value" ) ) ); + } else { - if( aRange->GetChar( 0 ) == '~' ) - m_units = aRange->Right( aRange->Length() - 1 ); - else if( SPICE_VALUE::ParseSIPrefix( aRange->GetChar( 0 ) ) != SPICE_VALUE::PFX_NONE ) - m_units = aRange->Right( aRange->Length() - 1 ); + if( SPICE_VALUE::ParseSIPrefix( aFormat->Range.GetChar( 0 ) ) != SPICE_VALUE::PFX_NONE ) + m_units = aFormat->Range.Right( aFormat->Range.Length() - 1 ); else - m_units = *aRange; + m_units = aFormat->Range; SetTitle( wxString::Format( GetTitle(), _( "Value" ) ) ); } - m_precisionCtrl->SetValue( *aPrecision ); + m_precisionCtrl->SetValue( aFormat->Precision ); for( int ii = 1; ii < (int) m_rangeCtrl->GetCount(); ++ii ) m_rangeCtrl->SetString( ii, m_rangeCtrl->GetString( ii ) + m_units ); - if( aRange->GetChar( 0 ) == '~' ) + if( aFormat->Range.GetChar( 0 ) == '~' ) m_rangeCtrl->SetSelection( 0 ); else - m_rangeCtrl->SetStringSelection( *aRange ); + m_rangeCtrl->SetStringSelection( aFormat->Range ); } bool DIALOG_SIM_FORMAT_VALUE::TransferDataFromWindow() { - *m_precision = m_precisionCtrl->GetValue(); + m_format->Precision = std::max( 1, std::min( m_precisionCtrl->GetValue(), 9 ) ); if( m_rangeCtrl->GetSelection() == 0 ) - *m_range = wxS( "~" ) + m_units; + m_format->Range = wxS( "~" ) + m_units; else - *m_range = m_rangeCtrl->GetStringSelection(); + m_format->Range = m_rangeCtrl->GetStringSelection(); return true; } diff --git a/eeschema/dialogs/dialog_sim_format_value.h b/eeschema/dialogs/dialog_sim_format_value.h index 799a924ea0..b40344d714 100644 --- a/eeschema/dialogs/dialog_sim_format_value.h +++ b/eeschema/dialogs/dialog_sim_format_value.h @@ -26,19 +26,19 @@ #include +struct SPICE_VALUE_FORMAT; class DIALOG_SIM_FORMAT_VALUE : public DIALOG_SIM_FORMAT_VALUE_BASE { public: - DIALOG_SIM_FORMAT_VALUE( wxWindow* aParent, int* aPrecision, wxString* aRange ); + DIALOG_SIM_FORMAT_VALUE( wxWindow* aParent, SPICE_VALUE_FORMAT* aFormat ); private: bool TransferDataFromWindow() override; private: - int* m_precision; - wxString* m_range; - wxString m_units; + SPICE_VALUE_FORMAT* m_format; + wxString m_units; }; #endif /* DIALOG_SIM_FORMAT_VALUE_H */ diff --git a/eeschema/sim/sim_plot_frame.cpp b/eeschema/sim/sim_plot_frame.cpp index d24574b76a..5e2a52cec6 100644 --- a/eeschema/sim/sim_plot_frame.cpp +++ b/eeschema/sim/sim_plot_frame.cpp @@ -134,7 +134,8 @@ enum CURSORS_GRID_COLUMNS enum MEASUREMENTS_GIRD_COLUMNS { COL_MEASUREMENT = 0, - COL_MEASUREMENT_VALUE + COL_MEASUREMENT_VALUE, + COL_MEASUREMENT_FORMAT }; @@ -263,7 +264,7 @@ void CURSORS_GRID_TRICKS::doPopupSelection( wxCommandEvent& event ) int cursorId = m_menuRow; int cursorAxis = m_menuCol - COL_CURSOR_X; SPICE_VALUE_FORMAT format = m_parent->GetCursorFormat( cursorId, cursorAxis ); - DIALOG_SIM_FORMAT_VALUE formatDialog( m_parent, &format.Precision, &format.Range ); + DIALOG_SIM_FORMAT_VALUE formatDialog( m_parent, &format ); if( formatDialog.ShowModal() == wxID_OK ) m_parent->SetCursorFormat( cursorId, cursorAxis, format ); @@ -316,10 +317,13 @@ void MEASUREMENTS_GRID_TRICKS::doPopupSelection( wxCommandEvent& event ) if( event.GetId() == MYID_FORMAT_VALUE ) { SPICE_VALUE_FORMAT format = m_parent->GetMeasureFormat( m_menuRow ); - DIALOG_SIM_FORMAT_VALUE formatDialog( m_parent, &format.Precision, &format.Range ); + DIALOG_SIM_FORMAT_VALUE formatDialog( m_parent, &format ); if( formatDialog.ShowModal() == wxID_OK ) + { m_parent->SetMeasureFormat( m_menuRow, format ); + m_parent->UpdateMeasurement( m_menuRow ); + } } else if( event.GetId() == MYID_DELETE_MEASUREMENT ) { @@ -358,7 +362,6 @@ SIM_PLOT_FRAME::SIM_PLOT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : m_darkMode( true ), m_plotNumber( 0 ), m_simFinished( false ), - m_outputCounter( 1 ), m_workbookModified( false ) { SetKiway( this, aKiway ); @@ -1014,17 +1017,6 @@ void SIM_PLOT_FRAME::OnFilterMouseMoved( wxMouseEvent& aEvent ) } -void updateRangeUnits( wxString* aRange, const wxString& aUnits ) -{ - if( aRange->GetChar( 0 ) == '~' ) - *aRange = aRange->Left( 1 ) + aUnits; - else if( SPICE_VALUE::ParseSIPrefix( aRange->GetChar( 0 ) ) != SPICE_VALUE::PFX_NONE ) - *aRange = aRange->Left( 1 ) + aUnits; - else - *aRange = aUnits; -} - - wxString SIM_PLOT_FRAME::getTraceName( int aRow ) { wxString signalName = m_signalsGrid->GetCellValue( aRow, COL_SIGNAL_NAME ); @@ -1134,15 +1126,23 @@ void SIM_PLOT_FRAME::onCursorsGridCellChanged( wxGridEvent& aEvent ) } +SPICE_VALUE_FORMAT SIM_PLOT_FRAME::GetMeasureFormat( int aRow ) const +{ + SPICE_VALUE_FORMAT result; + result.FromString( m_measurementsGrid->GetCellValue( aRow, COL_MEASUREMENT_FORMAT ) ); + return result; +} + + +void SIM_PLOT_FRAME::SetMeasureFormat( int aRow, const SPICE_VALUE_FORMAT& aFormat ) +{ + m_measurementsGrid->SetCellValue( aRow, COL_MEASUREMENT_FORMAT, aFormat.ToString() ); +} + + void SIM_PLOT_FRAME::DeleteMeasurement( int aRow ) { m_measurementsGrid->DeleteRows( aRow, 1 ); - - for( int ii = aRow; ii < (int) m_measurementFormats.size() - 1; ++ii ) - m_measurementFormats[ aRow ] = m_measurementFormats[ aRow + 1 ]; - - m_measurementFormats.pop_back(); - m_workbookModified = true; } @@ -1159,20 +1159,19 @@ void SIM_PLOT_FRAME::onMeasurementsGridCellChanged( wxGridEvent& aEvent ) wxString text = m_measurementsGrid->GetCellValue( row, col ); if( col == COL_MEASUREMENT ) - { - if( text.IsEmpty() ) - DeleteMeasurement( row ); - else - updateMeasurement( row ); - } + UpdateMeasurement( row ); else - { wxFAIL_MSG( wxT( "All other columns are supposed to be read-only!" ) ); - } + + // Always leave at least one empty row for type-in: + row = m_measurementsGrid->GetNumberRows() - 1; + + if( !m_measurementsGrid->GetCellValue( row, COL_MEASUREMENT ).IsEmpty() ) + m_measurementsGrid->AppendRows( 1 ); } -void SIM_PLOT_FRAME::updateMeasurement( int aRow ) +void SIM_PLOT_FRAME::UpdateMeasurement( int aRow ) { static wxRegEx measureParamsRegEx( wxT( "^" " *" @@ -1188,41 +1187,50 @@ void SIM_PLOT_FRAME::updateMeasurement( int aRow ) return; wxString text = m_measurementsGrid->GetCellValue( aRow, COL_MEASUREMENT ); + + if( text.IsEmpty() ) + { + m_measurementsGrid->SetCellValue( aRow, COL_MEASUREMENT_VALUE, wxEmptyString ); + return; + } + wxString simType = m_simulator->TypeToName( plotPanel->GetType(), true ); - wxString resultName = wxString::Format( wxS( "meas_result_%u" ), m_outputCounter++ ); + wxString resultName = wxString::Format( wxS( "meas_result_%u" ), aRow ); wxString result = wxS( "?" ); - m_simulator->Command( (const char*) wxString::Format( wxS( "meas %s %s %s" ), - simType, - resultName, - text ).c_str() ); - - std::vector resultVec = m_simulator->GetMagPlot( (const char*) resultName.c_str() ); - - if( resultVec.size() > 0 ) + if( measureParamsRegEx.Matches( text ) ) { - if( measureParamsRegEx.Matches( text ) ) - { - wxString func = measureParamsRegEx.GetMatch( text, 1 ).Upper(); - wxUniChar signalType = measureParamsRegEx.GetMatch( text, 2 ).Upper()[0]; - wxString units; + wxString func = measureParamsRegEx.GetMatch( text, 1 ).Upper(); + wxUniChar signalType = measureParamsRegEx.GetMatch( text, 2 ).Upper()[0]; + wxString units; + SPICE_VALUE_FORMAT fmt = GetMeasureFormat( aRow ); - if( signalType == 'I' ) - units = wxS( "A" ); - else if( signalType == 'P' ) - units = wxS( "W" ); - else - units = wxS( "V" ); + if( signalType == 'I' ) + units = wxS( "A" ); + else if( signalType == 'P' ) + units = wxS( "W" ); + else + units = wxS( "V" ); - if( func.EndsWith( wxS( "_AT" ) ) ) - units = wxS( "s" ); - else if( func.StartsWith( wxS( "INTEG" ) ) ) - units += wxS( "·s" ); + if( func.EndsWith( wxS( "_AT" ) ) ) + units = wxS( "s" ); + else if( func.StartsWith( wxS( "INTEG" ) ) ) + units += wxS( "·s" ); - updateRangeUnits( &m_measurementFormats[ aRow ].Range, units ); - } + fmt.UpdateUnits( units ); + SetMeasureFormat( aRow, fmt ); + } - result = SPICE_VALUE( resultVec[0] ).ToString( m_measurementFormats[ aRow ] ); + if( m_simFinished ) + { + wxString cmd = wxString::Format( wxS( "meas %s %s %s" ), simType, resultName, text ); + m_simulator->Command( "echo " + cmd.ToStdString() ); + m_simulator->Command( cmd.ToStdString() ); + + std::vector resultVec = m_simulator->GetMagPlot( resultName.ToStdString() ); + + if( resultVec.size() > 0 ) + result = SPICE_VALUE( resultVec[0] ).ToString( GetMeasureFormat( aRow ) ); } m_measurementsGrid->SetCellValue( aRow, COL_MEASUREMENT_VALUE, result ); @@ -1330,15 +1338,31 @@ void SIM_PLOT_FRAME::AddMeasurement( const wxString& aCmd, const wxString& aSign return; wxString simType = m_simulator->TypeToName( plotPanel->GetType(), true ); - int row = m_measurementsGrid->GetNumberRows(); + int row; - m_measurementFormats.push_back( { 3, wxS( "~V" ) } ); + for( row = 0; row < m_measurementsGrid->GetNumberRows(); ++row ) + { + if( m_measurementsGrid->GetCellValue( row, COL_MEASUREMENT ).IsEmpty() ) + break; + } + + if( !m_measurementsGrid->GetCellValue( row, COL_MEASUREMENT ).IsEmpty() ) + { + m_measurementsGrid->AppendRows( 1 ); + row = m_measurementsGrid->GetNumberRows() - 1; + } - m_measurementsGrid->AppendRows(); m_measurementsGrid->SetCellValue( row, COL_MEASUREMENT, aCmd + wxS( " " ) + aSignal ); + SetMeasureFormat( row, { 3, wxS( "~V" ) } ); - updateMeasurement( row ); + UpdateMeasurement( row ); m_workbookModified = true; + + // Always leave at least one empty row for type-in: + row = m_measurementsGrid->GetNumberRows() - 1; + + if( !m_measurementsGrid->GetCellValue( row, COL_MEASUREMENT ).IsEmpty() ) + m_measurementsGrid->AppendRows( 1 ); } @@ -1844,15 +1868,6 @@ bool SIM_PLOT_FRAME::LoadWorkbook( const wxString& aPath ) if( version >= 4 && trace ) { - auto readFormat = - []( SPICE_VALUE_FORMAT* format, const wxString& text ) - { - long val; - text.Left( 1 ).ToLong( &val ); - format->Precision = (int) val; - format->Range = text.Right( text.Length() - 1 ); - }; - auto addCursor = []( int aCursorId, SIM_PLOT_PANEL* aPlotPanel, TRACE* aTrace, double x ) { @@ -1886,8 +1901,8 @@ bool SIM_PLOT_FRAME::LoadWorkbook( const wxString& aPath ) if( parts.size() == 3 ) { parts[0].AfterFirst( '=' ).ToDouble( &val ); - readFormat( &m_cursorFormats[0][0], parts[1] ); - readFormat( &m_cursorFormats[0][1], parts[2] ); + m_cursorFormats[0][0].FromString( parts[1] ); + m_cursorFormats[0][1].FromString( parts[2] ); addCursor( 1, plotPanel, trace, val ); } } @@ -1899,8 +1914,8 @@ bool SIM_PLOT_FRAME::LoadWorkbook( const wxString& aPath ) if( parts.size() == 3 ) { parts[0].AfterFirst( '=' ).ToDouble( &val ); - readFormat( &m_cursorFormats[1][0], parts[1] ); - readFormat( &m_cursorFormats[1][1], parts[2] ); + m_cursorFormats[1][0].FromString( parts[1] ); + m_cursorFormats[1][1].FromString( parts[2] ); addCursor( 2, plotPanel, trace, val ); } } @@ -1910,8 +1925,8 @@ bool SIM_PLOT_FRAME::LoadWorkbook( const wxString& aPath ) if( parts.size() == 3 ) { - readFormat( &m_cursorFormats[2][0], parts[1] ); - readFormat( &m_cursorFormats[2][1], parts[2] ); + m_cursorFormats[2][0].FromString( parts[1] ); + m_cursorFormats[2][1].FromString( parts[2] ); } } } @@ -2020,31 +2035,25 @@ bool SIM_PLOT_FRAME::SaveWorkbook( const wxString& aPath ) if( CURSOR* cursor = trace->GetCursor( 1 ) ) { - msg += wxString::Format( wxS( "|cursor1=%E:%d%s:%d%s" ), + msg += wxString::Format( wxS( "|cursor1=%E:%s:%s" ), cursor->GetCoords().x, - m_cursorFormats[0][0].Precision, - m_cursorFormats[0][0].Range, - m_cursorFormats[0][1].Precision, - m_cursorFormats[0][1].Range ); + m_cursorFormats[0][0].ToString(), + m_cursorFormats[0][1].ToString() ); } if( CURSOR* cursor = trace->GetCursor( 2 ) ) { - msg += wxString::Format( wxS( "|cursor2=%E:%d%s:%d%s" ), + msg += wxString::Format( wxS( "|cursor2=%E:%s:%s" ), cursor->GetCoords().x, - m_cursorFormats[1][0].Precision, - m_cursorFormats[1][0].Range, - m_cursorFormats[1][1].Precision, - m_cursorFormats[1][1].Range ); + m_cursorFormats[1][0].ToString(), + m_cursorFormats[1][1].ToString() ); } if( trace->GetCursor( 1 ) || trace->GetCursor( 2 ) ) { - msg += wxString::Format( wxS( "|cursorD:%d%s:%d%s" ), - m_cursorFormats[2][0].Precision, - m_cursorFormats[2][0].Range, - m_cursorFormats[2][1].Precision, - m_cursorFormats[2][1].Range ); + msg += wxString::Format( wxS( "|cursorD:%s:%s" ), + m_cursorFormats[2][0].ToString(), + m_cursorFormats[2][1].ToString() ); } file.AddLine( msg ); @@ -2308,8 +2317,8 @@ void SIM_PLOT_FRAME::updateCursors() wxRealPoint coords = cursor->GetCoords(); int row = m_cursorsGrid->GetNumberRows(); - updateRangeUnits( &m_cursorFormats[0][0].Range, plotPanel->GetUnitsX() ); - updateRangeUnits( &m_cursorFormats[0][1].Range, cursor1Units ); + m_cursorFormats[0][0].UpdateUnits( plotPanel->GetUnitsX() ); + m_cursorFormats[0][1].UpdateUnits( cursor1Units ); m_cursorsGrid->AppendRows( 1 ); m_cursorsGrid->SetCellValue( row, COL_CURSOR_NAME, wxS( "1" ) ); @@ -2331,8 +2340,8 @@ void SIM_PLOT_FRAME::updateCursors() wxRealPoint coords = cursor->GetCoords(); int row = m_cursorsGrid->GetNumberRows(); - updateRangeUnits( &m_cursorFormats[1][0].Range, plotPanel->GetUnitsX() ); - updateRangeUnits( &m_cursorFormats[1][1].Range, cursor2Units ); + m_cursorFormats[1][0].UpdateUnits( plotPanel->GetUnitsX() ); + m_cursorFormats[1][1].UpdateUnits( cursor2Units ); m_cursorsGrid->AppendRows( 1 ); m_cursorsGrid->SetCellValue( row, COL_CURSOR_NAME, wxS( "2" ) ); @@ -2348,8 +2357,8 @@ void SIM_PLOT_FRAME::updateCursors() wxRealPoint coords = cursor2->GetCoords() - cursor1->GetCoords(); wxString signal; - updateRangeUnits( &m_cursorFormats[2][0].Range, plotPanel->GetUnitsX() ); - updateRangeUnits( &m_cursorFormats[2][1].Range, cursor1Units ); + m_cursorFormats[2][0].UpdateUnits( plotPanel->GetUnitsX() ); + m_cursorFormats[2][1].UpdateUnits( cursor1Units ); if( cursor1->GetName() == cursor2->GetName() ) signal = wxString::Format( wxS( "%s[2 - 1]" ), cursor2->GetName() ); @@ -2588,6 +2597,9 @@ void SIM_PLOT_FRAME::onSimFinished( wxCommandEvent& aEvent ) m_schematicFrame->RefreshOperatingPointDisplay(); } + for( int row = 0; row < m_measurementsGrid->GetNumberRows(); ++row ) + UpdateMeasurement( row ); + m_lastSimPlot = plotPanelWindow; } diff --git a/eeschema/sim/sim_plot_frame.h b/eeschema/sim/sim_plot_frame.h index 518f4de737..4f160eff2d 100644 --- a/eeschema/sim/sim_plot_frame.h +++ b/eeschema/sim/sim_plot_frame.h @@ -122,17 +122,6 @@ public: onCursorUpdate( dummy ); } - SPICE_VALUE_FORMAT GetMeasureFormat( int aRow ) const - { - return m_measurementFormats[ aRow ]; - } - - void SetMeasureFormat( int aRow, const SPICE_VALUE_FORMAT& aFormat ) - { - m_measurementFormats[ aRow ] = aFormat; - updateMeasurement( aRow ); - } - /** * Add a tuner for a symbol. */ @@ -170,6 +159,17 @@ public: */ void DeleteMeasurement( int aRow ); + /** + * Get/Set the format of a value in the measurements grid. + */ + SPICE_VALUE_FORMAT GetMeasureFormat( int aRow ) const; + void SetMeasureFormat( int aRow, const SPICE_VALUE_FORMAT& aFormat ); + + /** + * Update a measurement in the measurements grid. + */ + void UpdateMeasurement( int aRow ); + /** * Return the currently opened plot panel (or NULL if there is none). */ @@ -309,11 +309,6 @@ private: */ void updateCursors(); - /** - * Update a measurement in the measurements grid. - */ - void updateMeasurement( int aRow ); - /** * Apply user-defined signals to the SPICE session. */ @@ -395,7 +390,6 @@ private: SIM_PANEL_BASE* m_lastSimPlot; SPICE_VALUE_FORMAT m_cursorFormats[3][2]; - std::vector m_measurementFormats; // Variables for temporary storage: int m_splitterLeftRightSashPosition; @@ -406,7 +400,6 @@ private: bool m_darkMode; unsigned int m_plotNumber; bool m_simFinished; - unsigned int m_outputCounter; bool m_workbookModified; }; diff --git a/eeschema/sim/sim_plot_frame_base.cpp b/eeschema/sim/sim_plot_frame_base.cpp index 375d7fbb0f..c054391dc3 100644 --- a/eeschema/sim/sim_plot_frame_base.cpp +++ b/eeschema/sim/sim_plot_frame_base.cpp @@ -108,9 +108,9 @@ SIM_PLOT_FRAME_BASE::SIM_PLOT_FRAME_BASE( wxWindow* parent, wxWindowID id, const m_signalsGrid->SetMargins( 0, 0 ); // Columns - m_signalsGrid->SetColSize( 0, 200 ); - m_signalsGrid->SetColSize( 1, 36 ); - m_signalsGrid->SetColSize( 2, 42 ); + m_signalsGrid->SetColSize( 0, 207 ); + m_signalsGrid->SetColSize( 1, 33 ); + m_signalsGrid->SetColSize( 2, 38 ); m_signalsGrid->SetColSize( 3, 55 ); m_signalsGrid->SetColSize( 4, 55 ); m_signalsGrid->EnableDragColMove( false ); @@ -213,7 +213,7 @@ SIM_PLOT_FRAME_BASE::SIM_PLOT_FRAME_BASE( wxWindow* parent, wxWindowID id, const m_measurementsGrid = new WX_GRID( m_panelMeasurements, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); // Grid - m_measurementsGrid->CreateGrid( 0, 2 ); + m_measurementsGrid->CreateGrid( 1, 3 ); m_measurementsGrid->EnableEditing( true ); m_measurementsGrid->EnableGridLines( true ); m_measurementsGrid->EnableDragGridSize( false ); @@ -222,10 +222,12 @@ SIM_PLOT_FRAME_BASE::SIM_PLOT_FRAME_BASE( wxWindow* parent, wxWindowID id, const // Columns m_measurementsGrid->SetColSize( 0, 297 ); m_measurementsGrid->SetColSize( 1, 90 ); + m_measurementsGrid->SetColSize( 2, 0 ); m_measurementsGrid->EnableDragColMove( false ); m_measurementsGrid->EnableDragColSize( true ); m_measurementsGrid->SetColLabelValue( 0, _("Measurement") ); m_measurementsGrid->SetColLabelValue( 1, _("Value") ); + m_measurementsGrid->SetColLabelValue( 2, _("Format") ); m_measurementsGrid->SetColLabelSize( -1 ); m_measurementsGrid->SetColLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER ); diff --git a/eeschema/sim/sim_plot_frame_base.fbp b/eeschema/sim/sim_plot_frame_base.fbp index 4d7a990d22..5b378a0550 100644 --- a/eeschema/sim/sim_plot_frame_base.fbp +++ b/eeschema/sim/sim_plot_frame_base.fbp @@ -832,7 +832,7 @@ "Signal" "Plot" "Color" "Cursor 1" "Cursor 2" wxALIGN_CENTER 5 - 200,36,42,55,55 + 207,33,38,55,55 1 0 @@ -1363,10 +1363,10 @@ 1 wxALIGN_CENTER -1 - "Measurement" "Value" + "Measurement" "Value" "Format" wxALIGN_CENTER - 2 - 297,90 + 3 + 297,90,0 1 0 @@ -1412,7 +1412,7 @@ wxALIGN_CENTER - 0 + 1 1 WX_GRID; widgets/wx_grid.h; forward_declare diff --git a/eeschema/sim/spice_value.cpp b/eeschema/sim/spice_value.cpp index ac37fe2738..c31d5fd6b8 100644 --- a/eeschema/sim/spice_value.cpp +++ b/eeschema/sim/spice_value.cpp @@ -36,6 +36,32 @@ #include +void SPICE_VALUE_FORMAT::FromString( const wxString& aString ) +{ + long val; + aString.Left( 1 ).ToLong( &val ); + Precision = (int) val; + Range = aString.Right( aString.Length() - 1 ); +} + + +wxString SPICE_VALUE_FORMAT::ToString() const +{ + return wxString::Format( wxS( "%d%s" ), std::max( 0, std::min( Precision, 9 ) ), Range ); +} + + +void SPICE_VALUE_FORMAT::UpdateUnits( const wxString& aUnits ) +{ + if( Range.GetChar( 0 ) == '~' ) + Range = Range.Left( 1 ) + aUnits; + else if( SPICE_VALUE::ParseSIPrefix( Range.GetChar( 0 ) ) != SPICE_VALUE::PFX_NONE ) + Range = Range.Left( 1 ) + aUnits; + else + Range = aUnits; +} + + SPICE_VALUE::SPICE_VALUE( const wxString& aString ) { char buf[8] = { 0, }; diff --git a/eeschema/sim/spice_value.h b/eeschema/sim/spice_value.h index c6f0b1262f..f148bc9d1f 100644 --- a/eeschema/sim/spice_value.h +++ b/eeschema/sim/spice_value.h @@ -32,6 +32,11 @@ struct SPICE_VALUE_FORMAT { + void FromString( const wxString& aString ); + wxString ToString() const; + + void UpdateUnits( const wxString& aUnits ); + int Precision; wxString Range; };