ADDED use-settable simulation trace colors.
Fixes https://gitlab.com/kicad/code/kicad/issues/2536
This commit is contained in:
parent
09822c7f18
commit
f0bd25b397
|
@ -143,7 +143,7 @@ void GRID_CELL_COLOR_SELECTOR::Create( wxWindow* aParent, wxWindowID aId,
|
|||
wxEvtHandler* aEventHandler )
|
||||
{
|
||||
// wxWidgets needs a control to hold on to the event handler
|
||||
m_control = new wxCheckBox( aParent, wxID_ANY, wxEmptyString );
|
||||
m_control = new wxTextCtrl( aParent, wxID_ANY, wxEmptyString );
|
||||
|
||||
wxGridCellEditor::Create( aParent, aId, aEventHandler );
|
||||
}
|
||||
|
@ -159,16 +159,25 @@ void GRID_CELL_COLOR_SELECTOR::BeginEdit( int row, int col, wxGrid* grid )
|
|||
{
|
||||
m_value.SetFromWxString( grid->GetTable()->GetValue( row, col ) );
|
||||
|
||||
grid->CallAfter(
|
||||
[=]()
|
||||
{
|
||||
DIALOG_COLOR_PICKER dialog( m_parent, m_value, false );
|
||||
|
||||
if( dialog.ShowModal() == wxID_OK )
|
||||
m_value = dialog.GetColor();
|
||||
|
||||
m_grid->GetTable()->SetValue( row, col, GetValue() );
|
||||
m_grid->ForceRefresh();
|
||||
|
||||
// Let any clients know
|
||||
wxGridEvent event( m_grid->GetId(), wxEVT_GRID_CELL_CHANGED, m_grid, row, col );
|
||||
event.SetString( GetValue() );
|
||||
m_grid->GetEventHandler()->ProcessEvent( event );
|
||||
} );
|
||||
|
||||
// That's it; we're all done
|
||||
m_grid->HideCellEditControl();
|
||||
m_grid->ForceRefresh();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -704,7 +704,7 @@ bool DIALOG_SIM_MODEL<T_symbol, T_field>::loadLibrary( const wxString& aLibraryP
|
|||
|
||||
std::string modelName = SIM_MODEL::GetFieldValue( &m_fields, SIM_LIBRARY::NAME_FIELD );
|
||||
|
||||
for( auto& [baseModelName, baseModel] : library()->GetModels() )
|
||||
for( const auto& [baseModelName, baseModel] : library()->GetModels() )
|
||||
{
|
||||
if( baseModelName == modelName )
|
||||
m_libraryModelsMgr.CreateModel( &baseModel, sourcePins, m_fields );
|
||||
|
@ -720,7 +720,7 @@ bool DIALOG_SIM_MODEL<T_symbol, T_field>::loadLibrary( const wxString& aLibraryP
|
|||
|
||||
wxArrayString modelNames;
|
||||
|
||||
for( auto& [name, model] : library()->GetModels() )
|
||||
for( const auto& [name, model] : library()->GetModels() )
|
||||
modelNames.Add( name );
|
||||
|
||||
m_modelNameChoice->Clear();
|
||||
|
|
|
@ -588,7 +588,7 @@ void NETLIST_EXPORTER_SPICE::writeInclude( OUTPUTFORMATTER& aFormatter, unsigned
|
|||
|
||||
void NETLIST_EXPORTER_SPICE::writeIncludes( OUTPUTFORMATTER& aFormatter, unsigned aNetlistOptions )
|
||||
{
|
||||
for( auto& [path, library] : m_libMgr.GetLibraries() )
|
||||
for( const auto& [path, library] : m_libMgr.GetLibraries() )
|
||||
{
|
||||
if( dynamic_cast<const SIM_LIBRARY_SPICE*>( &library.get() ) )
|
||||
writeInclude( aFormatter, aNetlistOptions, path );
|
||||
|
|
|
@ -657,6 +657,7 @@ void SIM_PLOT_FRAME::onSignalsGridCellChanged( wxGridEvent& aEvent )
|
|||
int row = aEvent.GetRow();
|
||||
int col = aEvent.GetCol();
|
||||
wxString text = m_signalsGrid->GetCellValue( row, col );
|
||||
SIM_PLOT_PANEL* plot = GetCurrentPlot();
|
||||
|
||||
if( col == COL_SIGNAL_SHOW )
|
||||
{
|
||||
|
@ -684,11 +685,25 @@ void SIM_PLOT_FRAME::onSignalsGridCellChanged( wxGridEvent& aEvent )
|
|||
{
|
||||
removeTrace( m_signalsGrid->GetCellValue( row, COL_SIGNAL_NAME ) );
|
||||
}
|
||||
|
||||
// Update enabled/visible states of other controls
|
||||
updateSignalsGrid();
|
||||
}
|
||||
else if( col == COL_SIGNAL_COLOR )
|
||||
{
|
||||
KIGFX::COLOR4D color( m_signalsGrid->GetCellValue( row, COL_SIGNAL_COLOR ) );
|
||||
wxString signalName = m_signalsGrid->GetCellValue( row, COL_SIGNAL_NAME );
|
||||
TRACE* trace = plot->GetTrace( signalName );
|
||||
|
||||
if( trace )
|
||||
{
|
||||
trace->SetTraceColour( color.ToColour() );
|
||||
plot->UpdateTraceStyle( trace );
|
||||
plot->UpdatePlotColors();
|
||||
}
|
||||
}
|
||||
else if( col == COL_CURSOR_1 || col == COL_CURSOR_2 )
|
||||
{
|
||||
SIM_PLOT_PANEL* plot = GetCurrentPlot();
|
||||
|
||||
for( int ii = 0; ii < m_signalsGrid->GetNumberRows(); ++ii )
|
||||
{
|
||||
wxString signalName = m_signalsGrid->GetCellValue( ii, COL_SIGNAL_NAME );
|
||||
|
@ -696,10 +711,11 @@ void SIM_PLOT_FRAME::onSignalsGridCellChanged( wxGridEvent& aEvent )
|
|||
|
||||
plot->EnableCursor( signalName, col == COL_CURSOR_1 ? 1 : 2, enable );
|
||||
}
|
||||
}
|
||||
|
||||
// Update cursor checkboxes (which are really radio buttons)
|
||||
updateSignalsGrid();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SIM_PLOT_FRAME::onCursorsGridCellChanged( wxGridEvent& aEvent )
|
||||
|
@ -1808,7 +1824,7 @@ void SIM_PLOT_FRAME::onSimFinished( wxCommandEvent& aEvent )
|
|||
std::vector<struct TRACE_DESC> traceInfo;
|
||||
|
||||
// Get information about all the traces on the plot, remove and add again
|
||||
for( auto& [name, trace] : plotPanel->GetTraces() )
|
||||
for( const auto& [name, trace] : plotPanel->GetTraces() )
|
||||
{
|
||||
struct TRACE_DESC placeholder;
|
||||
placeholder.m_name = trace->GetName();
|
||||
|
|
|
@ -172,7 +172,7 @@ SIM_PLOT_FRAME_BASE::SIM_PLOT_FRAME_BASE( wxWindow* parent, wxWindowID id, const
|
|||
|
||||
// Columns
|
||||
m_cursorsGrid->SetColSize( 0, 44 );
|
||||
m_cursorsGrid->SetColSize( 1, 140 );
|
||||
m_cursorsGrid->SetColSize( 1, 152 );
|
||||
m_cursorsGrid->SetColSize( 2, 110 );
|
||||
m_cursorsGrid->SetColSize( 3, 110 );
|
||||
m_cursorsGrid->EnableDragColMove( false );
|
||||
|
|
|
@ -1110,7 +1110,7 @@
|
|||
<property name="col_label_values">"Cursor" "Signal" "Time" "Voltage / Current"</property>
|
||||
<property name="col_label_vert_alignment">wxALIGN_CENTER</property>
|
||||
<property name="cols">4</property>
|
||||
<property name="column_sizes">44,140,110,110</property>
|
||||
<property name="column_sizes">44,152,110,110</property>
|
||||
<property name="context_help"></property>
|
||||
<property name="context_menu">1</property>
|
||||
<property name="default_pane">0</property>
|
||||
|
|
|
@ -260,6 +260,18 @@ void CURSOR::doSetCoordX( double aValue )
|
|||
}
|
||||
|
||||
|
||||
wxString CURSOR::getID()
|
||||
{
|
||||
for( const auto& [ id, cursor ] : m_trace->GetCursors() )
|
||||
{
|
||||
if( cursor == this )
|
||||
return wxString::Format( _( "%d" ), id );
|
||||
}
|
||||
|
||||
return wxEmptyString;
|
||||
}
|
||||
|
||||
|
||||
void CURSOR::Plot( wxDC& aDC, mpWindow& aWindow )
|
||||
{
|
||||
if( !m_window )
|
||||
|
@ -299,6 +311,9 @@ void CURSOR::Plot( wxDC& aDC, mpWindow& aWindow )
|
|||
aWindow.GetScrY() - aWindow.GetMarginBottom();
|
||||
|
||||
wxPen pen = GetPen();
|
||||
wxColour fg = GetPen().GetColour();
|
||||
|
||||
pen.SetColour( COLOR4D( m_trace->GetTraceColour() ).Mix( fg, 0.6 ).ToColour() );
|
||||
pen.SetStyle( m_continuous ? wxPENSTYLE_SOLID : wxPENSTYLE_LONG_DASH );
|
||||
aDC.SetPen( pen );
|
||||
|
||||
|
@ -306,7 +321,35 @@ void CURSOR::Plot( wxDC& aDC, mpWindow& aWindow )
|
|||
aDC.DrawLine( leftPx, cursorPos.y, rightPx, cursorPos.y );
|
||||
|
||||
if( leftPx < cursorPos.x && cursorPos.x < rightPx )
|
||||
{
|
||||
aDC.DrawLine( cursorPos.x, topPx, cursorPos.x, bottomPx );
|
||||
|
||||
wxString id = getID();
|
||||
wxSize size = aDC.GetTextExtent( wxS( "M" ) );
|
||||
wxRect textRect( wxPoint( cursorPos.x + 1 - size.x / 2, topPx - 4 - size.y ), size );
|
||||
wxBrush brush;
|
||||
wxPoint poly[3];
|
||||
|
||||
// Because a "1" looks off-center if it's actually centred.
|
||||
if( id == "1" )
|
||||
textRect.x -= 1;
|
||||
|
||||
// We want an equalateral triangle, so use size.y for both axes.
|
||||
size.y += 3;
|
||||
// Make sure it's an even number so the slopes of the sides will be identical.
|
||||
size.y = ( size.y / 2 ) * 2;
|
||||
poly[0] = { cursorPos.x - 1 - size.y / 2, topPx - size.y };
|
||||
poly[1] = { cursorPos.x + 1 + size.y / 2, topPx - size.y };
|
||||
poly[2] = { cursorPos.x, topPx };
|
||||
|
||||
brush.SetStyle( wxBRUSHSTYLE_SOLID );
|
||||
brush.SetColour( m_trace->GetTraceColour() );
|
||||
aDC.SetBrush( brush );
|
||||
aDC.DrawPolygon( 3, poly );
|
||||
|
||||
aDC.SetTextForeground( fg );
|
||||
aDC.DrawLabel( id, textRect, wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -345,7 +388,7 @@ SIM_PLOT_PANEL::SIM_PLOT_PANEL( const wxString& aCommand, int aOptions, wxWindow
|
|||
m_plotWin = new mpWindow( this, wxID_ANY, pos, size, style );
|
||||
|
||||
m_plotWin->LimitView( true );
|
||||
m_plotWin->SetMargins( 50, 80, 50, 80 );
|
||||
m_plotWin->SetMargins( 35, 70, 35, 70 );
|
||||
|
||||
UpdatePlotColors();
|
||||
|
||||
|
@ -540,9 +583,9 @@ void SIM_PLOT_PANEL::UpdatePlotColors()
|
|||
m_colors.GetPlotColor( SIM_PLOT_COLORS::COLOR_SET::AXIS ) );
|
||||
|
||||
// Update color of all traces
|
||||
for( auto& [ name, trace ] : m_traces )
|
||||
for( const auto& [ name, trace ] : m_traces )
|
||||
{
|
||||
for( auto& [ id, cursor ] : trace->GetCursors() )
|
||||
for( const auto& [ id, cursor ] : trace->GetCursors() )
|
||||
{
|
||||
if( cursor )
|
||||
cursor->SetPen( wxPen( m_colors.GetPlotColor( SIM_PLOT_COLORS::COLOR_SET::CURSOR ) ) );
|
||||
|
@ -657,7 +700,7 @@ bool SIM_PLOT_PANEL::deleteTrace( const wxString& aName )
|
|||
TRACE* trace = it->second;
|
||||
m_traces.erase( it );
|
||||
|
||||
for( auto& [ id, cursor ] : trace->GetCursors() )
|
||||
for( const auto& [ id, cursor ] : trace->GetCursors() )
|
||||
{
|
||||
if( cursor )
|
||||
m_plotWin->DelLayer( cursor, true );
|
||||
|
|
|
@ -44,7 +44,7 @@ class TRACE;
|
|||
class CURSOR : public mpInfoLayer
|
||||
{
|
||||
public:
|
||||
CURSOR( const TRACE* aTrace, SIM_PLOT_PANEL* aPlotPanel ) :
|
||||
CURSOR( TRACE* aTrace, SIM_PLOT_PANEL* aPlotPanel ) :
|
||||
mpInfoLayer( wxRect( 0, 0, DRAG_MARGIN, DRAG_MARGIN ), wxTRANSPARENT_BRUSH ),
|
||||
m_trace( aTrace ),
|
||||
m_updateRequired( true ),
|
||||
|
@ -89,8 +89,10 @@ public:
|
|||
private:
|
||||
void doSetCoordX( double aValue );
|
||||
|
||||
wxString getID();
|
||||
|
||||
private:
|
||||
const TRACE* m_trace;
|
||||
TRACE* m_trace;
|
||||
bool m_updateRequired;
|
||||
bool m_updateRef;
|
||||
wxRealPoint m_coords;
|
||||
|
@ -169,7 +171,7 @@ public:
|
|||
m_traceColour = aColour;
|
||||
}
|
||||
|
||||
wxColour GetTraceColour()
|
||||
wxColour GetTraceColour() const
|
||||
{
|
||||
return m_traceColour;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue