KiCad PCB EDA Suite
dialog_signal_list.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2016 CERN
5 * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * @author Maciej Suminski <[email protected]>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 3
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, you may find one here:
21 * https://www.gnu.org/licenses/gpl-3.0.html
22 * or you may search the http://www.gnu.org website for the version 3 license,
23 * or you may write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 */
26
27#include "dialog_signal_list.h"
28#include <string_utils.h>
29#include <sim/sim_plot_frame.h>
30
31#include <sim/ngspice_helpers.h>
32#include <sim/spice_generator.h>
33
34
36 NGSPICE_CIRCUIT_MODEL* aCircuitModel ) :
37 DIALOG_SIGNAL_LIST_BASE( aParent ),
38 m_plotFrame( aParent ),
39 m_circuitModel( aCircuitModel )
40{
41
42}
43
44
46{
47 if( !DIALOG_SIGNAL_LIST_BASE::TransferDataFromWindow() )
48 return false;
49
51
52 return true;
53}
54
55
57{
58 // Create a list of possible signals
60 if( m_circuitModel )
61 {
62 // Voltage list
63 for( const auto& net : m_circuitModel->GetNets() )
64 {
65 // netnames are escaped (can contain "{slash}" for '/') Unscape them:
66 wxString netname = UnescapeString( net );
67
68 if( netname != "GND" && netname != "0" )
69 m_signals->Append( wxString::Format( "V(%s)", netname ) );
70 }
71
72 auto simType = m_circuitModel->GetSimType();
73
74 if( simType == ST_TRANSIENT || simType == ST_DC )
75 {
76 for( const auto& item : m_circuitModel->GetItems() )
77 {
78 // Add all possible currents for the primitive.
79 for( const auto& currentName : item.model->SpiceGenerator().CurrentNames( item ) )
80 m_signals->Append( currentName );
81 }
82 }
83 }
84
85 bool success = DIALOG_SIGNAL_LIST_BASE::TransferDataToWindow();
86
87 // Now all widgets have the size fixed, call FinishDialogSettings
89
90 return success;
91}
92
93
94bool DIALOG_SIGNAL_LIST::addSignalToPlotFrame( const wxString& aPlotName )
95{
96
97 // Get the part in the parentheses
98 wxString name = aPlotName.AfterFirst( '(' ).BeforeLast( ')' );
99
100 if( !name.IsEmpty() )
101 {
102 wxUniChar firstChar = aPlotName[0];
103
104 if( firstChar == 'V' || firstChar == 'v' )
105 m_plotFrame->AddVoltagePlot( aPlotName );
106 else if( firstChar == 'I' || firstChar == 'i' )
107 m_plotFrame->AddCurrentPlot( aPlotName );
108 else
109 return false;
110 }
111 else
112 return false;
113
114 return true;
115}
116
117
119{
120 for( unsigned int i = 0; i < m_signals->GetCount(); ++i )
121 {
122 if( m_signals->IsSelected( i ) )
123 {
124 const wxString& plotName = m_signals->GetString( i );
125
126 if( !addSignalToPlotFrame( plotName ) )
127 wxASSERT_MSG( false, "Unhandled plot type" );
128 }
129 }
130
131 // Add manually entered signal, if any
132 const wxString& plotName = m_signalEntry->GetValue();
133
134 if( !plotName.IsEmpty() )
135 {
136 if( !addSignalToPlotFrame( plotName ) )
137 m_plotFrame->AddVoltagePlot( plotName ); // Assume it's a V plot by default
138
139 m_signalEntry->SetSelection( -1, -1 );
140 }
141}
const char * name
Definition: DXF_plotter.cpp:56
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
Class DIALOG_SIGNAL_LIST_BASE.
SIM_PLOT_FRAME * m_plotFrame
bool TransferDataFromWindow() override
bool addSignalToPlotFrame(const wxString &aPlotName)
NGSPICE_CIRCUIT_MODEL * m_circuitModel
bool TransferDataToWindow() override
DIALOG_SIGNAL_LIST(SIM_PLOT_FRAME *aParent, NGSPICE_CIRCUIT_MODEL *aCircuitModel)
std::set< std::string > GetNets() const
Return the list of nets.
const std::list< SPICE_ITEM > & GetItems() const
Return the list of items representing schematic symbols in the Spice world.
Special netlist exporter flavor that allows one to override simulation commands.
SIM_TYPE GetSimType()
Return simulation type basing on the simulation command directives.
Implementing SIM_PLOT_FRAME_BASE.
void AddVoltagePlot(const wxString &aNetName)
Add a voltage plot for a given net name.
void AddCurrentPlot(const wxString &aDeviceName)
Add a current plot for a particular device.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
Subclass of SIM_PLOT_FRAME_BASE, which is generated by wxFormBuilder.
@ ST_TRANSIENT
Definition: sim_types.h:42
@ ST_DC
Definition: sim_types.h:35
wxString UnescapeString(const wxString &aSource)