2016-08-11 12:41:42 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016 CERN
|
2021-07-09 20:20:23 +00:00
|
|
|
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
2016-08-11 12:41:42 +00:00
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
2016-08-11 12:41:43 +00:00
|
|
|
* as published by the Free Software Foundation; either version 3
|
2016-08-11 12:41:42 +00:00
|
|
|
* 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:
|
2016-08-11 12:41:43 +00:00
|
|
|
* https://www.gnu.org/licenses/gpl-3.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 3 license,
|
2016-08-11 12:41:42 +00:00
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "dialog_signal_list.h"
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2016-08-11 12:41:42 +00:00
|
|
|
#include <sim/sim_plot_frame.h>
|
|
|
|
|
2022-03-05 23:49:25 +00:00
|
|
|
#include <sim/ngspice_helpers.h>
|
2022-09-15 03:25:57 +00:00
|
|
|
#include <sim/spice_generator.h>
|
2016-08-11 12:41:42 +00:00
|
|
|
|
2021-07-09 20:20:23 +00:00
|
|
|
|
|
|
|
DIALOG_SIGNAL_LIST::DIALOG_SIGNAL_LIST( SIM_PLOT_FRAME* aParent,
|
2022-03-28 22:02:49 +00:00
|
|
|
NGSPICE_CIRCUIT_MODEL* aCircuitModel ) :
|
2021-07-09 20:20:23 +00:00
|
|
|
DIALOG_SIGNAL_LIST_BASE( aParent ),
|
|
|
|
m_plotFrame( aParent ),
|
2022-03-28 22:02:49 +00:00
|
|
|
m_circuitModel( aCircuitModel )
|
2016-08-11 12:41:42 +00:00
|
|
|
{
|
2016-08-20 15:25:51 +00:00
|
|
|
|
2016-08-11 12:41:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DIALOG_SIGNAL_LIST::TransferDataFromWindow()
|
|
|
|
{
|
|
|
|
if( !DIALOG_SIGNAL_LIST_BASE::TransferDataFromWindow() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
addSelectionToPlotFrame();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DIALOG_SIGNAL_LIST::TransferDataToWindow()
|
|
|
|
{
|
|
|
|
// Create a list of possible signals
|
2022-04-12 14:37:06 +00:00
|
|
|
/// TODO: it could include separated mag & phase for AC analysis
|
2022-03-28 22:02:49 +00:00
|
|
|
if( m_circuitModel )
|
2016-08-11 12:41:42 +00:00
|
|
|
{
|
2016-08-11 12:41:52 +00:00
|
|
|
// Voltage list
|
2022-04-12 14:37:06 +00:00
|
|
|
for( const auto& net : m_circuitModel->GetNets() )
|
2016-08-11 12:41:42 +00:00
|
|
|
{
|
2019-06-09 15:46:02 +00:00
|
|
|
// netnames are escaped (can contain "{slash}" for '/') Unscape them:
|
2022-04-12 14:37:06 +00:00
|
|
|
wxString netname = UnescapeString( net );
|
2019-06-09 15:46:02 +00:00
|
|
|
|
|
|
|
if( netname != "GND" && netname != "0" )
|
|
|
|
m_signals->Append( wxString::Format( "V(%s)", netname ) );
|
2016-08-11 12:41:52 +00:00
|
|
|
}
|
|
|
|
|
2022-03-28 22:02:49 +00:00
|
|
|
auto simType = m_circuitModel->GetSimType();
|
2018-04-27 22:58:16 +00:00
|
|
|
|
|
|
|
if( simType == ST_TRANSIENT || simType == ST_DC )
|
2016-08-11 12:41:52 +00:00
|
|
|
{
|
2022-04-12 14:37:06 +00:00
|
|
|
for( const auto& item : m_circuitModel->GetItems() )
|
2016-08-11 12:41:52 +00:00
|
|
|
{
|
2022-04-12 14:37:06 +00:00
|
|
|
// Add all possible currents for the primitive.
|
2022-10-10 23:23:00 +00:00
|
|
|
for( const auto& currentName : item.model->SpiceGenerator().CurrentNames( item ) )
|
2022-04-12 14:37:06 +00:00
|
|
|
m_signals->Append( currentName );
|
2016-08-11 12:41:52 +00:00
|
|
|
}
|
2016-08-11 12:41:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-20 15:25:51 +00:00
|
|
|
bool success = DIALOG_SIGNAL_LIST_BASE::TransferDataToWindow();
|
|
|
|
|
|
|
|
// Now all widgets have the size fixed, call FinishDialogSettings
|
2020-11-16 11:16:44 +00:00
|
|
|
finishDialogSettings();
|
2016-08-20 15:25:51 +00:00
|
|
|
|
|
|
|
return success;
|
2016-08-11 12:41:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-11-07 08:47:12 +00:00
|
|
|
bool DIALOG_SIGNAL_LIST::addSignalToPlotFrame( const wxString& aPlotName )
|
|
|
|
{
|
|
|
|
|
|
|
|
// Get the part in the parentheses
|
|
|
|
wxString name = aPlotName.AfterFirst( '(' ).BeforeLast( ')' );
|
|
|
|
|
|
|
|
if( !name.IsEmpty() )
|
|
|
|
{
|
|
|
|
wxUniChar firstChar = aPlotName[0];
|
2021-07-09 20:20:23 +00:00
|
|
|
|
2019-11-07 08:47:12 +00:00
|
|
|
if( firstChar == 'V' || firstChar == 'v' )
|
2022-04-12 14:37:06 +00:00
|
|
|
m_plotFrame->AddVoltagePlot( aPlotName );
|
2019-11-07 08:47:12 +00:00
|
|
|
else if( firstChar == 'I' || firstChar == 'i' )
|
2022-04-12 14:37:06 +00:00
|
|
|
m_plotFrame->AddCurrentPlot( aPlotName );
|
2019-11-07 08:47:12 +00:00
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-11 12:41:42 +00:00
|
|
|
void DIALOG_SIGNAL_LIST::addSelectionToPlotFrame()
|
|
|
|
{
|
|
|
|
for( unsigned int i = 0; i < m_signals->GetCount(); ++i )
|
|
|
|
{
|
|
|
|
if( m_signals->IsSelected( i ) )
|
2016-08-11 12:41:52 +00:00
|
|
|
{
|
|
|
|
const wxString& plotName = m_signals->GetString( i );
|
2021-07-09 20:20:23 +00:00
|
|
|
|
2019-11-07 08:47:12 +00:00
|
|
|
if( !addSignalToPlotFrame( plotName ) )
|
2016-08-11 12:41:52 +00:00
|
|
|
wxASSERT_MSG( false, "Unhandled plot type" );
|
|
|
|
}
|
2016-08-11 12:41:42 +00:00
|
|
|
}
|
2019-11-07 08:47:12 +00:00
|
|
|
|
|
|
|
// Add manually entered signal, if any
|
|
|
|
const wxString& plotName = m_signalEntry->GetValue();
|
|
|
|
|
|
|
|
if( !plotName.IsEmpty() )
|
|
|
|
{
|
|
|
|
if( !addSignalToPlotFrame( plotName ) )
|
|
|
|
m_plotFrame->AddVoltagePlot( plotName ); // Assume it's a V plot by default
|
|
|
|
|
|
|
|
m_signalEntry->SetSelection( -1, -1 );
|
|
|
|
}
|
2016-08-11 12:41:42 +00:00
|
|
|
}
|